• Home
  • About
  • Android and IDEA for the Eclipse Refugee

    October 18th, 2011

    Earlier this month I switched from writing my Android projects in Eclipse to writing them in IntelliJ IDEA. Overall the experience has been great, and I much prefer using IDEA to Eclipse for Android development. And now that IntelliJ IDEA 11 EAP (Early Access) has a visual layout window, there is almost no reason for me to write my Android apps in anything else. I wrote this post to help other users along their way when converting between the IDEs.

    Why IntelliJ IDEA for Android?

    There’s no need to ask why if IDEA is already your favorite IDE or if your company is forcing you to use it. But just in case you’re not already a raving fanboy, here are some of the features specific to Android that made me want to switch.

    Find usages (Alt+F7) is aware of Android XML resources (and the semantic meaning of their content), so searching across project assets is easier. Plus, I just find IDEA’s search capabilities a little saner than Eclipse’s. Below you can see what happens when I search from within my layout XML file for a certain widget ID:

    01. Find Usages

    Find Usages in IDEA

    Because IDEA knows about the Android XML resources, refactorings like Rename (Shift+F6) work across Java code and XML. You can rename a widget’s ID from the XML file and have the Java code updated, or rename from the Java code and have the XML updated. Here I am renaming a widget ID in XML. Nice. In general, I do not search within comments and Strings because it is a little too aggressive.

    02. Rename Refactor

    02. Rename Refactor

    There are several Android specific intentions that make life easier in IDEA. Intentions are the quick-fixes that are activated in Eclipse with Ctrl+1. In IDEA you use Alt+Enter. For example, if there is a static String referenced from your code then you should make that String a resource by moving it to strings.xml. Put your cursor into the String, press Alt+Enter, accept the name suggestion, and you’re ready to go. Ctrl+Z for undo on refactorings work great, too. One of the big differences between IDEA and Eclipse is refactoring support. In IDEA, the source files do not need to compile in order for refactorings to work. It is quite common to have a broken file and fix it through a couple automated renames or refactors.

    03. Move Refactor

    03. Move Refactor

    Finally, before IDEA 11, the killer feature for Eclipse Android was the visual editor for XML based layout files. Personally, I don’t often use drag and drop layout editors but I do value seeing my code changes immediately without recompiling and redeploying. Eclipse had the better feature set. But IDEA 11 now has a layout “Preview” mode. Make a change in the XML and see it immediately updated in the preview. You can also quickly change the theme, preview in landscape and portrait, switch to night mode, and select different screen sizes. If you absolutely need a visual editor, then Eclipse is the way to go. Otherwise, the Preview in IDEA 11 is good enough. More info available on the IDEA blog.

    04. Visual Preview

    04. Visual Preview

    Let’s get started with a tour of IDEA.

    Getting Oriented in IDEA

    The basic layout of IDEA is not all that different from Eclipse. You have a main code window (right, in image below), you have a Project View (upper left), and you have a Structure View (lower left). If there is a window for it in Eclipse, then there is probably a window for it in IDEA. A good way to get started and get familiar with IDEA is to read the DZone IDEA RefCard I wrote a few years ago. It is still relevant today. I highlighted the image to show the relevant details.

    05. Project View

    05. Project View

    At any time you can jump to the code window by pressing Escape, and you can close any open tool window with Shift+Escape. On thing that IDEA does not have is perspectives. Maybe you love Eclipse perspectives. Maybe you love when your code view shrinks up into a postage sized porthole whenever you launch a debugger. Who knows, perhaps this is useful to you somehow. I am trying very hard to be positive here, and the nicest thing I have to say about perspectives is that I hate them. Another thing IDEA does not have is a “Team Plugin”. There is no single “Team” abstraction that somehow fits on top of every version control system. Instead, when you enable Subversion then you use Subversion features. Git uses Git Features. Version control systems are enabled using the Tools->Enable Version Control menu item. Then the Alt+9 shortcut brings up the Version Control View.

    Running, Debugging, and the Android Tools

    Running and Debugging an application is slightly different in IDEA than in Eclipse. You manage your “Run Configurations” using your Run/Debug dropdown menu at the top of the screen:

    06. Run/Debug Configurations

    06. Run/Debug Configurations

    You can create temporary and permanent run configurations. Right clicking a test and choosing Run creates a temporary run config. If you want to run the target repeatedly then just save it so it is permanent. And you Maven users: you can right click a goal in the Maven view and create a run target, such as a run:jetty goal. The Maven support is amazing in IDEA, so you are actually lucky to be a Maven user in this case.

    The features of the debuggers are fairly close between the two products. Set a break point by clicking in the gutter (Ctrl+F8), select and right click a reference to add to the watch window. I’ve noticed that Eclipse users love to enable and disable breakpoints rather than just set and remove them. Well, you can press Ctrl+Shift+F8 to manage all your breakpoints if that’s the sort of thing you like to do. Also, notice the Logcat tab on the debugger, which shows you the Android log. If you are Running (and not debugging), then the Logcat output is in the “Android Logcat” view that you see on the bottom toolbar:

    07. Debug Window

    07. Debug Window

    The main Android Tools from the SDK are available under the Tools->Android menu. You can export a signed package this way and also launch the AVD to manage your emulators and environments. If you need the other SDK tools like “hierarchyviewer” or “monkeyrunner” then you’ll have to launch them from the command line. There is built-in Android testing support in IDEA, and when you run a unit test then the IDE will ask you whether to run it as a JUnit test or an Android test. It remembers your answer, so if you make a mistake then just delete the run configuration and start over. It will ask you again.

    Managing Your IDEA Project

    The two hardest parts of switching IDEs is Project configuration and Web Server configuration. Luckily we avoid the latter in an Android tutorial. But you still need to set up the project. First, some terminology. An “Eclipse Workspace” is an “IDEA Project”. An “Eclipse Project” is an “IDEA Module”. An Eclipse Workspace is composed of several projects. An IDEA Project is composed of several modules. If you have Eclipse project files then IDEA should be able to import them with no problems, and this is the fastest way to get started.

    The Project is configured using the File->Project Structure menu item. You can also open the window using the Ctrl+Alt+Shift+S shortcut, which I call the Paw Mash because holding your left hand like a bear paw and mashing the keyboard usually suffices to open the window. This is where you specify your source folders, your SDK version, and your dependencies. If there is no Project SDK selected in the dropdown list, or if the list shows an error, then click on the SDKs item in the left side pane to create a new one.

    08. Project Configuration

    08. Project Configuration

    Configure the modules by clicking the module entry on the left side. Here you can mark certain folders as source or as tests. By default, a fresh IDEA Android project has no “tests” folder, so you should add the folder and then come in here as mark it as Test Sources. You can also change some of the Android compiler settings by clicking the Android facet shown in the middle.

    09. Module Configuration

    09. Module Configuration

    One last thing to configure before leaving the window. If you are writing JUnit tests then you’ll need to add JUnit to your project dependencies. If you just annotate a method as @Test then IDEA prompts you to add the junit.jar to your classpath. The problem is that they add it as the last dependency, which causes the test to fail with the error “java.lang.RuntimeException: Stub!”. Come into this window and move JUnit up in the dependency list. Or configure Ivy/Maven/Whatever to do this automatically for you.

    10. Module Dependencies

    10. Module Dependencies

    That’s the quick tour of Project Structure… lets move on to Settings. Settings are the options not directly related to compiling the project. Things like code style, version control, plugins, and much more. Open Settings using File->Settings or use your Claw Attack to hit Ctrl+Alt+S. I call this shortcut the claw attack because if you pinch your left hand into an eagle claw and swoop it down on your keyboard then the Settings window usually opens right up. It helps to let out a mighty, “Ka-KAW” when you do it.

    There are thousands of settings in here. I heard the advice recently that new users of either IDE should spent a few hours just clicking around the settings page, and I honestly think that is pretty good advice. If you know what you’re looking for but can’t find it, then enter your search term in the upper left side search box and the settings list dynamically displays only those pages with matching entries. For instance, if you know you want to show line numbers, then type in Line or Line Numbers and click through the resulting pages. In this case, the highlighting you see in the image was created by IDEA and is used to point you to the correct setting.

    11. Settings Configuration

    11. Settings Configuration

    You most definitely want to change some of the default settings. Showing Line Numbers is under Editor->Appearance. Changing your tabs and space settings are done on a per-file type basis, and is accessed from Editor -> Code Style. By default IDEA allows you to place the cursor past the end of the line in a text file, and you turn this off under the Editor page. And Version Control is something you really must configure as well, which is under Version Control. GitHub integration in IDEA is tip-top and goes beyond just Git support, but lately I’ve been using and recommending BitBucket for free, private git hosting. In general I find myself using the IDE to make local commits and manage changelists, and the command line to perform pushes.

    Links

    That’s it! There are tons of ways to learn more, and here are my favorite links:

    As always, feel free to keep in touch by leaving a comment. You can read more from me on my blog at http://hamletdarcy.blogspot.com/, see my YouTube channel for more screencasts, and follow me on Twitter: @HamletDRC


    Learning Android in Switzerland? Upcoming Workshops in the next Month

    September 14th, 2011

    Canoo is helping organize three different Android workshops in the next month, so now is a great time to get started if you’ve been wanting to take a shot at Android development.

    The first event is starting today (14 September) at ch/open in Zürich. If you hurry you can still get down there in time. It is a German language session called Umgang mit Fragmentierung auf der Android Plattform” presented by Andreas Hölzl and Andrei Socaciu. It’s a full day session, so feel free to drop in. Better late than never.

    The second event is Wednesday 28 September in Basel. Hackergarten, the monthly user group, is hosting Andreas who will lead us in an Android development night. We plan to develop and publish a full Android app during the evening. This is a free event and Canoo provides food and drinks. You can read the mailing list thread for more information. The group is in English and German, and it’s generally a lot of fun.

    The third event is in Geneva/Genf. The SoftShake conference is the 3rd and 4th of October. Andreas and Andrei are presenting Tackling fragmentation on the Android platform”, another full day workshop but this time in English. (By the way, I’ll be presenting there on Code Generation and Java Boilerplate Busting).

    Do none of these fit your schedule? Would you rather have them presented on-site? Canooies are always available to come to your worksplace and present on topics, whether it is Java, Groovy, Andriod, iOS, or whatever. It’s actually more fun to speak at a customer-site than at a conference. Just email info@canoo.com for more info or to set something up.


    GWT and HTML5 Canvas, the future of the web?

    August 25th, 2011

    The future of computing lies in mobile computing, more and more devices come on the market, tablets and phones that will connect through the Internet as technology is getting cheaper and wifi and 3g more common. That means our software will also need to run on these handheld devices, because our clients will want their services on all platforms. This is what Java set out to do 15 years ago, so that we have the ability to write software once and run it everywhere. The problem is these new platforms, that I believe will make up a large part of the future have, until now, no Java. It would be great if we can find something that will give us the ability to write our software only once.

    I believe that the technology that is going to deliver us this promise is called HTML5. More and more applications will run inside you browser. I’m typing this article in google docs, which is a perfect example of how applications will evolve. No need to install anything or maintain up to date versions, even an operating system could be very minimalistic (google chrome). So Google is obviously sharing this vision, but also Microsoft is building it’s next version of office on something that is based on their web-browser.

    Sadly the development language of HTML5 Javascript and not Java. Java has been around a long time and there are a lot of libraries that people have made. Would be cool if we can still use these, the answer is Googles Web Toolkit. GWT provides a way to code in Java and then translate that code into Javascript. This way we can still use all that great stuff that others made.

    A good example of this future is Angry Birds, you have probably heard of this game. To create this game they have taken the java implementation of box2d called jbox2d and created a javascript version of that with the help of GWT. Once that is done you can use HTML5 Canvas to draw the Birds and calculate their positions if they are falling. Now because they have build it this way with HTML5 this game could also work on an iPhone, but even better because android is based on java you could create from this source a android version with only one line of code.

    Have a look at some of the great things people are building with the HTML5, be sure that your browser supports it.

    1. Drawing program deviantART
    2. Old style game with new technology area5
    3. Quake GWT HTML5 port

    MobileTech Conference 2010 wrap up

    September 10th, 2010

    This years MobileTech Conference took place from 6.-8.9. in Mainz at the Rheingoldhalle.

    In his keynote Tim Bray (Google Android advocate) did not fail to stress the importance of the mobile business by showing some impressive numbers, charts and statements.
    6.8 Billion people worldwide, 3.6 Billion mobile subscriptions, +1 Billion mobile devices / year.
    The whole mobile business is a Trillion (yes, T!) dollar business and the the biggest digital business (asymco.com).
    Eric Schmidt: if your web strategy won’t be successful on mobile, it will not succeed at all.
    Steve Jobs: we are a mobile company.

    Web vs. native?

    Actually to Google the question is open. Both approaches have their know advantages and disadvantages. The market will show and in the meantime they’ll do both (see Chrome and Android).

    Whats the ideal number of mobile platforms in the world? (provocative)

    Certainly 1 is not ideal, that’s the conclusion from the Windows Desktop OS experience.
    Will the technical aspects decide, compiling down to the metal vs. running a VM?
    Certainly the big players are iOS, Android and web.
    Again, the market will decide. He believes that Blackberry is here to stay (well at least for some more time), he wouldn’t count Nokia out, but Windows is certainly not a player showing only vaporware atm. He was wishing WebOS (Palm) to succeed, but questioned that HP has the necessary brains to achieve that.

    How to earn money in the mobile software business?

    With respect to monetization through Appstores the revenue distribution is inverse squared. That means not many people are earning serious money by selling apps.
    Potential ways of monetizing apps are as follows:
    sell apps, sell app upgrades, sell in app ads, do in app sales, sell whats on the server
    Currently selling apps and selling ads in apps generate equal amounts of revenue. For the future he is expecting the ad side to increase a lot.
    He concluded the talk by stressing the importance of privacy in the mobile business.
    He himself actually does not feel easy giving away his physical location, interesting …
    Privacy is not only a question of guidelines, but of culture within a company. Google obviously takes the issue very seriously …
    Last but not least he shifted the audience focus to the emerging mobile markets of India, China and Africa. One shouldn’t limit oneself to a western perspective on the issue.

    The conference had a good mix of technical and executive level talks.
    Here are my notes on some of them:

    iAds

    According to Steve Jobs a totally new experience of advertising. Emotional as TV but targeted to a persons specific profile.
    Current problems: the ratio of ads to advertising space is very low. Well who wonders given that there are currently only 2 iAds around (Nissan and Unilever). A reason for that is the current restriction that you need a Mio.$ budget to be eligible for advertising on the platform.
    Technically iAds are applications you write in the iAd framework, which is an interesting fact and opens up a new market for software company (and closes one for the classical ad designer with no software skills). Atm Apple is doing most of the ads themselves …
    A much more lightweight form of iAds are iAds for developers (less costly, less impressive).
    That way app developers can ad for their apps.
    Some very interesting legal informations are:
    Since you might not agree with user profile Apple is generating secretly of you to optimally target you with iAds, there is an out option: Go to oo.apple.com/ you disallow personal data collection. The consequence might be worth considering: untargeted ads …
    Certainly one might ask oneself the question, how other ad frameworks fit into this new scene?
    Well, as long as you (as an ad framework maintainer) to not run a mobile platform in parallel you are safe … (read that again!)
    That means apps with integrated admob ads will no longer make it through the review process.

    Mobile couponing

    interesting facts: classical paper couponing has a conversion rate of 0.2% whereas mobile couponing has 9%.
    Have a look at MyMobai if you are searching for a service provider in that area.

    Usability and mobile platforms

    bottom line: there are significant differences between the existing mobile platforms.
    In order to promote discoverability one should stick to the customs of the given platform.
    consequence: read the usability guideline (if there is one)
    consequence2: crossplatform approaches won’t be that successful
    take home message: do not develop for a platform you are not using youself

    Lessons learned from swoodoo

    Good wrap up of iterative, user centric development.
    Prototyping can be easily done with keynote/powerpoint and paper models (have a look at uistencils.com for your favorite UI elements …).
    Actually when developing mobile applications proper usability engineering is key. Users won’t forgive bad design.

    The state of AR

    Gardeya started off with an example of Desktop AR (Tissot) went on to Layar, currently the biggest AR platform.
    It might be surprising, but AR actually sells smartphones (Samsung Galaxy comes with Layar preinstalled).
    Next evolutionary step: form video overlay to video analysis
    Did you know that Google has a patent on street view to replace real world billboards with virtual ones?
    Final statement about AR: kiichi matsuda – domestic robocop

    Staying connected with jwebsocket.org

    good framework, full-duplex efficient real-time communication using a permanent connection.
    Good talk, but to be “web” in the sense of “web scale” the server implementation should provide support to handle 100k+ simultaneous connections.


    Jazoon 08 Day I

    June 25th, 2008

    jazoon

    Here are some quick notes on the sessions I attended yesterday at Sihlcity. I believe Jazoon will be uploading videos and slides very soon:

    First in my lineup was a talk on using Google Web Toolkit for a business application in a typical enterprise environment. This was kind of like a case study. Dmitry Buzdin talked about the experience his company gained and listed the various pros and cons.

    Next, I listened in to Bruno Schäffer’s talk together with Christoph Henrici and Daniel Buffet of APG. The talk described the migration of an Oracle Forms application to Java forms for the advertising industry. Main requirement: development and application performance had to remain just as fast as with Oracle Forms. A requirement that the migrated application managed to over-fulfill.

    IMG_5023

    Canoo’s Andreas Hölzl and Christian Stettler presented their Google Android experience report. They showed an application they developed for the Android Developer Challenge called Mobile Zoo. Their baseline: “What’s here looks promising. Let’s see the devices!”

    Brian Sletten’s presentation on data-driven applications was very interesting. I particularly liked the analogy between resampling music and data.