Fixing Copy in Eclipse

I use Eclipse for Android development and one of the issues I have come across is that sometimes Command-C on Mac (Control-C on Windows) doesn’t work properly. I will copy, but paste will paste what was previously in the buffer, not what the latest I wanted.
My previous workaround was to hit Command-C twice which always seems to work. This is a pain, however.
Fortunately I came across this blog post: Ctrl+C to copy does not always work in Eclipse which describes a simple fix: Unbind the copy command in Eclipse. Note that this also applies to the Android Developer Tools distribution, since it is built on Eclipse.

The workaround is to unbind the Copy command in Eclipse. The reason this works is that the native Copy will be used instead.

To do so, go into the menu:
ADT or Eclipse
> General
>> Keys

Search for Copy
Select Copy
Press the button “Unbind Command”

Here are some screenshots:

Before (Copy is bound to a shortcut key):
Copy command bound to a shortcut key

After (Copy command no longer bound to a shortcut key):
Copy command no longer bound to a shortcut key

LG Optimus V Black Screen Fix

I have an LG Optimus V that I use for testing. Its battery had run down and when I plugged it back in, the buttons would light up but the screen was black. So what to do with a blank screen?
Unplug from wall. Remove the back cover. Remove the battery. Put the battery back. Replace cover. Plug it back in. The screen is back!

Official Android SDK

There’s a new official Android SDK available that was released this past week. It is basically Eclipse 3.8 + Android Developer Tools (ADT) 21, pre-installed in a single downloadable package. Previously, Android programmers had to go through a multi-step process to locate the ADT update site, accept licenses, etc. This should save time for new installs. If you’ve got a working setup, I’d stick with that for now, but just update your ADT to version 21.

New Android UI Testing Tools in ADT 21

There are new UI Testing tools in the Android Development Tools (ADT), version 21. This is an exciting development for a testing advocate like me. It reminds me of Square’s KIF framework, but for Android. It’ll be interesting to compare this against Robotium and MonkeyTalk.

Why you should participate in Stack Overflow

If you’re reading this blog, you’re probably a programmer and you probably use Stack Overflow daily. It launched back in 2008 and I’ve been using it, sometimes without knowing it for these past few years. This year, I decided to consciously contribute back to Stack Overflow and also try to rack up 1000 reputation points, aka rep. As of this writing, I’m up to 2,106 rep and very happy about my experience contributing. So… why should you participate on Stack Overflow and what tips can I offer on how to do that?

Save the programmer, save the world (or Why you should participate)

Stack Overflow (SO) shows up frequently in Google searches. Google any Android exception or iOS error message and you’ll get at least one SO hit, if not several. It is the programming world’s equivalent to Wikipedia, being somewhat of a canonical resource for programming questions and answers.

Programmers seem to turn to SO first nowadays, even before asking other programmers or consulting documentation. Why is that? Well my theory is that we don’t want to interrupt other people and documentation can be hard to parse. On the other hand, a lot of times you can find either working code or good pseudo-code in an SO answer. If you think this is just my opinion, consider that SO has 15,000,000+ software developers visiting every month.

SO is also a great case study in gamification. Most programmers I know are avid game players (both board and video), so incentivizing us to contribute by rewarding us with points is a natural fit with our brains. SO has tuned this game mechanic over the years to encourage good questions, great answers and discourage spam, which is the natural enemy of any online community. I confess that some nights I would stay up later than I would so I could try to answer just one more question, which might lead to a few more rep.

Stack Overflow icon

Those are the obvious reasons, but there are deeper, more meaningful ones to contribute to Stack Overflow:

SO is good for your resume. Before I interview a potential programmer to join my team, I always check their SO profile, not just to see how much rep, which is a rough measure of how much they participate and how valued their contributions are, but to see how well they communicate. Programmers don’t just write code, but they also have to discuss potential problems, solutions, relay their progress, etc. Reading someone’s set of SO answers is a proxy for that. In past years, I would have said that I would go to read their technical blog, but those are sadly in decline due to a combination of SO, Twitter, Google+, App.net, etc.

You will learn as a consequence of answering questions. Even if you already know it, having to communicate an answer clearly to someone else will ingrain that knowledge into your brain further. Sometimes it is good to find a question that has interested you before that you can do a bit of research into and you’ll satisfy your curiosity while answering someone’s question.

“I play the Stack Exchange game happily alongside everyone else, collecting reputation and badges and rank and upvotes, and I am proud to do so, because I believe it ultimately helps me become more knowledgeable and a better communicator while also improving the very fabric of the web for everyone. I hope you feel the same way.”
- Jeff Atwood in The Gamification

Best of all, you will be helping people. We exist in a larger community of programmers and I think it is a good policy to help others when you can. Whether you subscribe to The Golden Rule, you should consider that if you use open source, if you rely on the answers in Stack Overflow, that it took someone willing to help to write those things that you use when you write your own apps.

Now the hard part… (or Tips on participating)

When you first register with Stack Overflow, you’ll start out with 1 rep. Which means that the only thing you can really do is ask a question or answer one. You can suggest edits too. I would suggest starting out by asking a good question, including what you have tried and any relevant code. That’s probably the easiest way to get started and you’ll get 5 points every time someone votes your question up. Voting a question up means that it is well worded and usually meaningful to the voter.

If you ask a question, make sure to check back and accept the best answer that you get. You will reward the answerer and you’ll get an additional 2 points yourself. Note that your accept rate is tracked and if you ask too many questions without accepting, people may stop answering your questions, since that is a sign that you’re not being a good member of the community.

Another way to participate is to share your knowledge by answering questions. That’s what I have been doing, since I’ve learned a thing or two over my 18 year programming career. (I feel old now.) In any case, I think everyone has some expertise to share and that’s how we all learn as a community: I share what I know, you share what you know, we both get better.

Make sure you answer questions thoroughly. Don’t just do a quick link to a blog post. Code is probably the best. If you do include code, make sure it compiles and works correctly. Include screenshots if it is relevant, for example if someone is asking how to change the background of an action bar, show a screenshot with a multi-colored action bar. Learn the right markup, which is in Markdown or use the toolbar to format your answer to properly insert hyperlinks, quote the question, quote documentation, etc.

Multi-color action bar

Once you get up to 15 rep, which shouldn’t take too long, then start to vote up questions and answers. This will help others figure out which answer is better than the others if there are multiple answers to a question. It also helps figure out which questions are popular.

Fill out your profile and include an avatar. I greatly prefer answering people’s questions that have a face to them, not just some randomly generated artwork. Include your qualifications and this might also help people judge whether you are credible or not, especially when you are first starting out.

Be persistent. Ultimately, you’re dealing with other people who have their own schedules. Just because you ask a question, it doesn’t mean that people are going to answer it right away. If you really want it answered and haven’t had any takers yet, then share the link to it on App.Net or Google+ or Twitter. Conversely, just because you answer a question, it does not mean that the system will automatically recognize your contribution and award you 15 points. The person asking the question has to do that and they may have some follow-up comments. Sometimes you just have to wait. Sometimes you will never get rewarded and that’s alright – you still have contributed to the community. And who knows – weeks, months or years later, someone might come across your question because they have it themselves or appreciate the answer that you gave and upvote you, sending a few more rep your way.

Preparing an iPhone for power outages

We just survived Hurricane Sandy here in the Washington DC area. We were fortunate that we did not get more damage in this area. The Derecho in June seems to have prepared the area. However, I wanted to be prepared this time and I wanted to make sure I could use my iPhone if the power went out.

I have a few devices available to me: I was going to use an iPhone solely for emergency calls. I prepared a 5th gen iPod Touch for listening to audio books and reading social media while my WiFi stayed up. I saved the iPad and my Android devices for entertainment. I still also have a landline, but you never know if you will have to leave your house in a disaster and then you’ll really want your smartphone with you.

So how can you prepare an iPhone for emergency calling usage? (Note that while I’ll be discussing iPhones, this applies to Android phones too, but the setting names will be different.)

The primary concern I had was battery life. I’m currently using an iPhone 4S and it has a reputation for not having a long lasting battery. However, I was determined to make it last and preferably for several days in case the power were to go out for that long.

I prepared my iPhone at 3:30PM on Monday when the storm started picking up. On 3:30PM Tuesday, the worst was over. I had made one 6 minute phone call to change an upcoming hotel reservation. In 24 hours, the battery had only gone from 100% to 95%. At that rate, the iPhone would last for approximately 20 days.

Full battery

Here’s the steps I took to prolong my battery life (all of these are found in the Settings app):

  • Location Services: Off. You won’t be able to use Find My Phone, but that’s not really your top priority in an emergency since you’ll likely keep a tight leash on your phone. This relies on GPS which is a big power drain for phones.
  • Wi-Fi: Off. WiFi takes less power than GPS, but it still is a drain especially if you have background services like iCloud, which do work even when you’re not using an app. Use another device for WiFi if you need it. Better yet, get a battery-powered AM/FM radio to get news during emergencies.
  • Brightness: All the way to the left. Screens use a lot of power, but you save power by setting it to the dimmest setting.
  • General > Network > Cellular Data: Off. 2G, 3G and LTE all utilize power, with the newer technologies using the most. If you need to leave the house, then I’d turn this on when you need it.
  • General > Usage > Battery Percentage: On. This provides a nice percentage next to the battery icon to let you know how much battery you have left.
  • General > Bluetooth: Off. Yes, bluetooth uses power too.
  • General > Auto-Lock: 1 Minute. For the most power savings, turn off the screen manually when you’re done using your phone. However, this will make sure you don’t leave it on for more than a minute.

Why not just enable Airplane Mode, you say? It turns off all of these, but it also turns off cellular voice, which defeats the purpose of having an emergency smart phone.

Recommended Tablets for Android Development

Last week, I discussed the different handsets that I recommended for Android development. Today, I want to recommend tablets for Android development.

Why tablets?

Tablets are a big growth market currently. The iPad is the current king of the hill, with a roughly 60% marketshare. Android tablets make up most of the rest. Microsoft is coming out with its own tablets as well.

From a user’s perspective, tablets are the more leisurely counterpart to the phone. You use a phone while you are out and about, traveling, waiting in line, etc. You probably use a computer while you’re at work. But at home, if you can afford it, you can relax with a bigger screen on your couch in the form of a tablet. Some people call this the lean-back experience.

Android has a wider variety than the iPad

Currently, the iPad has a 9.7” screen and there may be a smaller brother coming soon, AKA the iPad Mini. However, the Android world currently defines everything 5” and larger as a tablet. The largest Android tablet that I know if is the 13” Toshiba Excite 13. We may see even larger ones in the future – imagine a newspaper-thin Android tablet that imitated a real newspaper. So keep in mind that because of the potentially infinite variety of sizes of Android tablets, that you will need to have responsive design in your apps.

5 inch is a tablet?

I actually don’t consider 5” devices to be a tablet. The current winner in this category is the Galaxy Note. It was reporting itself as a large screen when it debuted, but when it got the Ice Cream Sandwich update, it started reporting itself as a normal sized screen. There will be more entries here, but I think most users want a larger phone experience here, since there isn’t really that much more room than the latest 4.5”+ phones. I fully expect more 5” handsets in the future.

The two main sizes: 7” and 10”

Although there are an infinite variety of possibilities, there are actually 2 sizes that users have come to love: 7” tablets and 10” tablets. I’ll spend the rest of this review talking about 7” tablets since that market is better defined. There is also a dark horse size: 8.9”/9” represented by the Kindle Fire HD and Nook HD+, which may be important in the future.

7” Tablet: Runner-ups

The most important 7” runner-up is the Kindle Fire HD. Amazon is in a unique position due to its online retail dominance, its media catalog and that it has directly challenged both Google and Apple with its own Amazon Appstore. If you want to sell your app in the Amazon Appstore, then you will probably want to get this tablet as well as the Nexus 7, since it has unique capabilities and also a different “skin” that you’ll want to test against and optimize your app for. Note the latest Kindle Fire HD runs on an ICS variant (4.0), while the original Kindle Fire ran on Gingerbread (2.3).

Next up is the Samsung Galaxy Tab 2 7”. This is starting to show its age already, but is a good tablet if you want to do pure ICS (4.0) testing, with the TouchWiz skin.

Soon there will also be the Nook HD, running on an ICS variant (4.0), which will have the best display of the bunch. Barnes and Noble has its own Nook Apps store, so if you are targeting that store, you’ll want to get a Nook as well.

Note that all these tablets are retailing for $199 currently. The Tab 2 was $249, but seems to have dropped in price to remain competitive with its rivals.

7” Tablet Winner: Nexus 7

The tablet to get right now is the (Asus) Nexus 7, which is manufactured by Asus but marketed and sold by Google. It is a pure Google Experience device, meaning there are no manufacturer skins. It is has a quad-core processor so it is fast. It runs the latest, Jelly Bean (4.1), so it is smooth like butter. Since it is a Nexus device, you can create custom ROMs for it, flash it back to a factory ROM if you need to reset it, and it will get OS updates faster than any other tablet. Probably the only downside is that there is no microSD slot nor a rear facing camera, but I think Google wanted to make it sleek and inexpensive.

You can buy a Nexus 7 for only $199 direct from Google at the Google Play Store. I bought mine at Staples, where it has limited availability. You only need to get the lowest one, which is currently the 8GB, with a rumored bump to 16GB in a week for the same price. Since it is a development device, you probably don’t need to store too much on there and most of the media apps are cloud-based, there’s not as big a need for storage.

Note that the Nexus 7 is an interesting device also for developing Google TV apps, since it uses TVDPI (TV density) and has the same width as a 720P TV, with only 80 pixels more in height. More on that in the future.

Speaking of the future, we may be seeing a Nexus 10 at the October 29th event by Google. I certainly hope so and will pre-order one if it becomes available. I will probably hold off on doing 10 inch tablet recommendations until after that event. In the meantime, if you need a 10 inch Android tablet right now, I would point you towards the Asus Transformer Infinity 700, which is the top of the line at around $500. If you want to save some money, the Asus Transformer Pad TF300 is a good bet and retails for less than $400.

Which Android Handsets Are Good for Developing Android Apps?

Hopefully these guidelines will help you choose which device to get for Android development.

Someone was asking on the Android Enthusiasts forum: Will an Android phone connect to Wi-Fi and download apps without a subscription? When I was answering this question, I was thinking to myself – the best way to get into developing apps on iOS is to do it on an iPod Touch. Likewise, the best way in my opinion to get into developing apps for Android is to do it on a WiFi-only device. – something that connects to WiFi, doesn’t cost too much and most importantly, will not interfere with your normal communications.

If you’ve already got an Android phone:

I’ve already got an Android phone you say. Why don’t I just develop on that? You can. Just like an iPhone developer can develop on their iPhone. However, what if you want to install a userdebug build or change some settings on the device for development or testing that makes it behave differently? You run the risk of messing up your phone, at least in the short term, and losing phone calls, texts, etc.

Still, using your existing Android phone is probably the most straightforward way to develop if you’ve already got an Android handset. After all, when I started in Mac development, I developed on the Mac that I had.

You still will probably want to get other handsets though, because you won’t be able to test on different platform versions and as you can see by the chart below, there are a lot of them in the wild currently.

Android Platform Versions as of October 1, 2012

If you don’t have an Android phone:

Option 1. Cheap, coverage of 2.2 or 2.3:

Buy a prepaid phone from a carrier like Virgin Mobile, but don’t activate it (unless you want a lower phone bill.)

A good choice right now is the LG Optimus Slider, which will give you a test device for Android 2.2, aka Froyo. Froyo at the time of this writing still holds 12.9% of the market, which is substantial, while earlier versions represent less than 4% of the market. It also gives you test coverage for slider keyboards, which will give you some interesting behavior.

Another good choice is the LG Optimus Elite, which runs on Android 2.3, aka Gingerbread. Gingerbread is the heavyweight in the arena, representing 55.8% of all devices in the Android universe. If your primary Android phone isn’t on 2.3, you should definitely get this or another 2.3 device.

Option 2. Premium, Nexus, Google Experience, coverage of 4.0 or 4.1:

Once upon a time, you had to spend $529 to get an unlocked Google Experience device. And you had to go to Best Buy to get it. That was the Samsung Nexus S, which still remains an interesting device, mostly because you can use flash it with factory images to test 2.3, 4.0, and 4.1. You could say it is the doppleganger of the Android world. However, it is relatively pricey.

The device to get right now is the Samsung Galaxy Nexus, available direct from Google for $349. This is probably the best Android phone on the market, fast, smooth and with the pure Google Experience. Galaxy Nexus (or GNex) runs 4.1 right now, but you can flash it with a factory image back to 4.0.

Why should you get a Nexus device?
You should get one because it doesn’t have any sort of manufacturer skin that could slow you down, nor carrier added apps, nor carrier locked bootloaders. They also tend to have additional developer-friendly features and benefits. Many of the proprietary drivers are available for including in custom ROMs. Factory images are available for Nexus devices, meaning that if you want to re-install a specific platform level, say go back and test on 4.0, it is easy to do so. Also if you create a custom ROM and it doesn’t work, you can get it back to its factory default using the factory image, where other phones could be bricked.

Other considerations:

Density – the LG Optimus phones I mentioned are mdpi or medium density, the baseline (1x). Nexus S is hdpi or high density (1.5x). Galaxy Nexus is xhdpi or extra high density (2x).

GPS – all the suggested support GPS, which is useful for apps that require location.

NFC – except for the LG Optimus Slider, the others support NFC, which is a consideration if your app will utilize NFC. Be careful when installing the battery as most of the NFC antennas are in the back case.

Speed – LG Optimus Slider is the slowest, followed by the LG Optimus Elite, then the Nexus S and Galaxy Nexus is the fastest. While Galaxy Nexus will be pleasant to work with, using a slow device is actually useful because it will help you identify places where your apps are noticeably slow.

Connectors – all these devices thanksfully use a standard microUSB connector.

How many devices should you have?
If you can afford it, it is best to have at least one of each Android platform level that your apps are targeting. Currently, 2.2+ gives you 96% of the market, which means 4 devices: 2.2, 2.3, 4.0, 4.1. However, start with what you have and build from there as needed. Fill in the gaps with emulator configurations, aka AVDs (Android Virtual Devices).

What about tablets? I’ll cover those in the near future, but the short answer is: buy a Nexus 7 direct from Google. It is a Nexus device, it runs the latest (4.1 Jelly Bean), and is a bargain at $199.

I’ve Added Android to my Toolbox

For the past 2 years, I’ve been working on Android apps. It started in mid 2010 when I was doing some work for Push IO. They sent me a Motorola Droid (the original one with the slide out keyboard and built like a tank) to experiment with. I was impressed by its turn by turn navigation and it handled basic smartphone functions well. I was even more amazed at how easy it was write a simple app and deploy it to the device. I was used to fiddling with certificates, provisioning profiles, entitlement plists and if I was wearing my 0xE800003A Open Radar t-shirt that I got from @timburks correctly.

In 2011, I bought an unlocked Nexus S and then swapped in my iPhone sim to see what it was like to truly be an Android user full-time. At first I did not like it, since I had gotten used to the bounce scrolling, tapping the top bar to scroll to the top, etc. But I got used to it and realized that this was actually a nice platform. I took to carrying around an iPod Touch with me at this time since I like both iOS and Android. Currently, I’m toting an iPhone 4S and a Nexus 7.

I’ve built several Android apps now, for both Android handsets and tablets, while still building iOS and Mac apps. I started building Android apps for clients in early 2011. I had been concentrating on iOS and Mac apps up to that point, but the demand for apps for Android handsets had reached a tipping point.

I’ve found that I have a unique perspective on and appreciation of Android because in my pre-Indie life, I had been the lead developer on a large client Java application and during the past 4+ years of my Indie career, I have been focusing on mobile apps. No, Android is not SWT or Swing. It is not exactly equivalent to iOS either. However, it is a nice fusion of those concepts. While many of my developer friends regard Eclipse as an abomination of an IDE, I find it comforting. This is partially due to having rebuilt that large Java app as a series of Eclipse plug-ins (instead of being a monolithic Swing app) and being immersed in the Eclipse codebase and community.

If you look at the archives of this blog, this isn’t the first time I’ve pivoted. I started out blogging exclusively about Java and Eclipse. In 2005, I started blogging about Cocoa and Rails. Going forward, I’m planning on blogging about Android, iOS and Mac.

iOSDevCampDC 2012

About two weeks ago, on Saturday August 11th, we held our fourth iOS-related event in the Washington DC area: iOSDevCampDC 2012. We had a great mix of talks, six in all, from local iOS experts, with a select group of sponsors and a great group of attendees. Verisign hosted us and provided the venue in Reston, VA, allowing us to accommodate more people than last year. The dual screens were a nice touch too.

Let me give a brief wrap-up of the talks:

Ken (chief doer of savvy apps) gave a talk about how gestures affect the designs of iOS apps.  He talked about some good lessons learned.  I was impressed that he mirrored both his iPhone and iPad on his Mac so that he could project both on the screen.  Ken’s definitely been a proponent of gestural (or gesture-first) interfaces with apps like Agenda.

Jon (DC area Managing Director of Big Nerd Ranch) dived into the technical details of concurrency on iOS.  He covered both GCD and also NSOperation.  I hear he’s going to be giving an OpenGL class soon.

Mark (Director of Mobile Development at Politico) discussed how to make iOS apps more flexible by having them adapt to changes via a dynamic configuration that’s downloaded.  He also showed some good practices around that such as validating the configuration and having a good download manager.

Mark (Senior Lead Developer at Odyssey Computing) showed us how to do slick animations to do things like folding screens like origami and flipping screens like a book. I really liked that he wrote an app that allows you to toggle some switches and sliders to try out different permutations to see how they affect the animations.  He blogged about his experiences and his presentation titled “Enter the Matrix.”

Chris (Director of Strategy, Global Monetization Solutions at Millennial Media) explained how to use metadata to make more money with ads.  The more you know your users, the better the ads you show them will be.  One point that stood out was tangential: every app needs a privacy policy.  This is due to many forces in our industry but is probably going to be forced in the near future due to government oversight.

James (Principal Software Architect at YellowBrix) took us through how to embed Lua, a dynamic scripting language, into iOS apps.  He also discussed his open source framework for making it easier to do Lua in iOS called Gemini.

As the Lead Organizer of iOSDevCampDC, it was satisfying to put together another event and have it go well.  Sean was a great help as a fellow Organizer, heading up the delicious food that we all savored and assisting with countless other things.  Jose helped out as well, taking pictures and also giving a good overview of our local weekly (NSCoderNightDC) and monthly (CocoaHeadsDC) get-togethers.  My kids Diego and Mateo manned the registration booth and got a taste of what professional developers do. They’re getting started with programming themselves.

Special thanks to Happy Apps, Millennial Media, savvy apps and Verisign for sponsoring the event!