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.

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.

Eclipse Tip: Use Bookmarks to track important places in your code

A nice feature in Eclipse that is somewhat hidden is the bookmarking feature. It lets you keep track of important places in your code and get back to them.

For example, let’s say you’re reading some code and you notice a nice algorithm. Or you’re looking for where something specific is happening, like calling a certain web service that is critical and you find it. Or whatever piques your interest.

You could rely on the navigational features of Eclipse to get you back to that code, but that could mean a lot of presses on the back button. You could put in a // TODO , which adds an item to the Tasks view, but when you just want to remember where something is, that is an awkward way to get back to it.

So, instead, use Bookmarks. The only problem is that isn’t an obvious feature in Eclipse, like it is in say IntelliJ.

There’s really only a few things to learn though.

First, to add a bookmark, navigate to an interesting line of code, and then click on Edit | Add Bookmark… from the main menu. A dialog box will pop up asking you for a name. You should see a little blue bookmark appear in the left hand column and if you look carefully, you will also notice a little green rectangle in the right hand column.

Second, show the Bookmarks View. In my opinion, this should be on by default in the Java and Plug-in Development Perspectives, just like the Problems view. To see the Bookmarks View, select Window > Show View > Other… from the main menu. This will bring up a “Show View” dialog. Open up the “Basic” category, select “Bookmarks”, and press the OK button. You should see the bookmark you created in step one.

Third, when you find that you need to go back to your bookmark, just switch to the Bookmarks View and double-click on the bookmark you want to go back to. Note that from this view, you can also single-click to edit or delete with the red “X”. You can also sort and filter if you’ve got a lot of bookmarks.

Fourth, set up a keyboard shortcut for Adding a Bookmark. If you look at the useful Eclipse 3.0 full keyboard shortcut reference from the Eclipse Tutorial by Enrique (available in both Español and English.), you’ll notice that there is not a keyboard shortcut for Add Bookmark in the default Eclipse 3.0.1 install. (And it’s not there in 3.1M4 either.)

To get to the keyboard shortcuts, choose Window > Preferences from the main menu, which brings up the Preferences dialog. In 3.1M4, you can just type in “key” in the filter text box, which takes you to General>Keys. You then have to click the “Edit” button. In 3.0.1, you just navigate to Workbench>Keys.

Once you’re at the Keys preference, choose “Edit” from the Category drop-down. Then choose “Add Bookmark” from the Name drop-down. Then click in the Key Sequence > Name text box. Then hold down the keys you want to use for your keyboard shortcut. Being an Eclipse on Mac OS X user, I chose the available “Option-Cmd-B”. Then click the “Add” button. You should see the keyboard shortcut appear in both of the Assignments lists. (Note that “When: In Windows” always throws me off as a Mac user, but it just means not to use it within a dialog, which is OK since editors can only be in a window.)

Cool… now what? Well, it’d be nice if in Eclipse, we could:

1. Have bookmarks turned on by default, with the Bookmarks View showing, and a keyboard shortcut defined for all platforms for adding a bookmark.

2. Improve Bookmarks by adding an option to create a “quick” bookmark which didn’t need a description, like IntelliJ does. Allow quick navigation between bookmarks, at least in a file (previous/next bookmark in this file), like you can do with going to the next/previous error.

3. Allow sharing of bookmarks between team members. This might be overkill, since you can always tell people, go to this class and look at line #103, but it would be an interesting way to share code annotations.

Some tidbits:

1. If you hover over the blue bookmark marker in the left hand column of the editor, you’ll see a tooltip showing the description.

2. You can bookmark whole files by selecting the file in a view like the Package Explorer, then choosing Edit > Add Bookmark…