Book Review: Android Wireless Application Development

I’ve read a few books on Android development over the last couple of years, so it was interesting to see how this book would compare in style and content. Android is a very fast evolving platform, so it’s always hard for a book to stay up to date. Androi…

I’ve just finished reading through a copy of Android Wireless Application Development (Addison Wesley Developer’s Library, 2010 by Lauren Darcey & Shane Condor). Having read a few books on Android development over the last couple of years, it’s always interesting to see how a book tackles this big, constantly evolving platform. The book covers Android up to version 2.2 and includes access to the online Safari edition which hopefully means they can add a few post-print updates where necessary.

android_wireless_app_dev

To be honest, if you’re just getting into Android development, it’s not so important to learn about the newest additions of the latest and greatest version, just to have a firm understanding of the core components which haven’t really changed all that much. Android 2 covers you for development on all current phones, and your apps can still support Android 3 devices if desired, but if you did want to target Honeycomb tablets, you may want to continue your learning by reading up on topics such as Fragments and Loaders.

What’s inside?

The book sets out to be a fairly complete reference and pretty much runs the gamut. Starting off with an overview of Android, a look at the anatomy of Android apps and an understanding of the component parts that make up a project; it leads on to user interface design, a multitude of common APIs (far too many to list, but this includes subjects like data storage, networking/web, location and multimedia) and then runs through important design principals and more advanced topics such as how to be a good Android citizen and make your app feel fully native. The topic of deployment, signing and testing is covered in depth including selling your app. Finally the appendices collate a lot of information you’d otherwise need to search around for, such as various options and usage of the emulator, DDMS, ADB, Eclipse and a SQL Lite quick start guide.

Reference or cookbook?

Most tech books seem to lean toward either being a pretty dry reference, or a cookbook. By cookbook I’m talking about a collection of short practical examples of specific tasks, and I tend to prefer cookbook-style as I find it more enjoyable to read, with searchable online references filling in the minutiae and specific details when needed.

I think this book is a combination of the two styles. There are a lot of tables outlining the various options around certain functions and classes and also plenty of references. This satisfies the “developer’s library” label. But I would say a large part seems to be presented in the form of cookbook-like recipes, particularly in later chapters. For example “processing asynchronously” which teaches the reader the importance of running code on another thread to keep the UI from being blocked and the dreaded “Application not responding” alert.

Suitable for beginners?

It has a gentle enough introduction to suit most skill levels, but enough depth to provide new information for even the most seasoned Android programmers. I did say it felt more like a cookbook but it is structured well enough to be able to dip into a specific topic and quickly retrieve the example you need without much reading around the topic.

The book does touch on some pretty advanced topics such as OpenGL 3D graphics. If you’ve ever done any OpenGL programming you’ll know this stuff easily fills a book (or 3) itself. But it’s nice of them to include a springboard into this kind of development for those interested in real-time game programming.

Further comments

It was nice to see some time had been put into writing a chapter on the history of mobile development. It helps those new to the field understand just how we got to where we are. Remember WAP? This chapter brought back a flurry of deeply buried memories of J2ME; we live in better times.

Two unexpected (but nice) additions were the chapters on “The Mobile Software Development Process” and “Best Practices in Bulletproof Mobile Applications” which discuss application requirements gathering, documentation practices, testing/QA and all kinds of experience-garnered gems.

All in all this is a bumper book at nearly 700 pages with a massive range of topics covered, a worthwhile addition to the bookshelf.

Android Workshop September 2011 at UpdateConf in Brighton

I’ll be running a 2 day introduction to Android development workshop at UpdateConf in Brighton this September. If you’re looking to get into Android development, this will get you up and running lickety-split. Sign up for updates over at the website and…

I’ll be running a 2 day introduction to Android development workshop at UpdateConf in Brighton this September. If you’re looking to get into Android development, this will get you up and running lickety-split. Sign up for updates over at the website and follow the Twitter account @androidws.

android_workshop_2

If you have any questions about the content anything else, please drop me a comment or tweet.

Jamie Oliver’s 20 Minute Meals for Android is Out Now

Just a quick post to say Zolmo’s latest application is now on the Android Market, and for a limited time at an introductory price. It was a genuine pleasure to work on this, I hope you have a lot of fun cooking great meals with it.

Just a quick post to say Zolmo’s latest application is now on the Android Market, and for a limited time at an introductory price. It was a genuine pleasure to work on this, I hope you have a lot of fun cooking great meals with it.

20mm1 20mm2

Download Jamie Oliver’s 20 Minute Meals from the Android Market.

Android UX Patterns

I just stumbled across this truly excellent collection of Android UX Pattern wireframes and examples. This is certainly essential reading for anyone starting Android development as the official documentation is somewhat lacking here.
http://www.androidp…

I just stumbled across this truly excellent collection of Android UX Pattern wireframes and examples. This is certainly essential reading for anyone starting Android development as the official documentation is somewhat lacking here.
http://www.androidpatterns.com

Android Patterns

Using ProGuard with Android

ProGuard obfuscates and shrinks .apk files, providing some added protection for your app, but you may encounter some problems using it up right now, at least with ADT 9 preview 3.By default ADT creates a proguard.cfg file with every new project, so i…

ProGuard obfuscates and shrinks .apk files, providing some added protection for your app, but you may encounter some problems using it right now, at least with ADT 9 preview 3.

By default ADT creates a proguard.cfg file with every new project, so if you have an existing project just copy it over from a new dummy project. The next step is to enable ProGuard, you do this by adding the following to your default.properties file:

proguard.config=proguard.cfg

(assuming proguard.cfg is the ProGuard configuration file created for you, or copied from a new project, into the project root folder.)

When you export an APK release ADT will now run ProGuard on the code, however if like me you have any spaces in your project folder path it will fail. So for now please avoid any spaces in both your project folder path, and the Android SDK path. I believe Google are looking to resolve this in an update.

If you are using something like remote-stack-trace to receive crash reports you will need to follow the instructions on the Android site for automatically mapping the obfuscated code to make it human readable again.

Applications of NFC Chips

Google recently announced the Nexus S phone, created in partnership with Samsung. This is the latest in the developer phone range, aimed at providing a reference device for the next wave of consumer Android devices running Android OS 2.3 (Gingerbread) an…

Google recently announced the Nexus S phone, created in partnership with Samsung. This is the latest in the developer phone range, aimed at providing a reference device for the next wave of consumer Android devices running Android OS 2.3 (Gingerbread) and higher.

One of the features of this phone is an NFC chip, which is capable of transmitting and reading data at a distance of up to 10cm. It is compatible with existing systems such as RFID tags: tiny, incredibly cheap slithers of componentry able to store information and be embedded in anything from food packaging to stickers.

We’ve not had long to think about the potential applications of wide-spread NFC usage, but I can see this breeding some fantastic new ways to use technology. Last night I visited the London Android group, and a few ideas came to mind on the trip home. These are some potentially common use-cases that we’ll see in the next few years…

PayPal / Visa / MasterCard

This will allow us to pay for goods without physical credit/debit cards, or even send a friend or eBay seller money. For in-store purchases equipment will be in place to swipe your phone against and let you acknowledge the payment, and for private transfers you’d simply fire up the PayPal app and type in the amount you wish to send. The NFC chip in the receiving phone can be “activated” passively by swiping the phones together, or opening the app could enable it for 10-15 seconds. Swipe it over your friend’s phone, their details appear on-screen and you hit “send”. The system will send the money to their registered account. The nice thing about this is that you don’t even need to know the person you’re paying, you could literally transfer money to someone you’ve never met, securely, on the street.

Bar Tab

An NFC chip is embedded or stuck to a table in a bar or restaurant. By swiping your phone you’ll be able to uniquely identify your table, placing orders, requesting service and ultimately taking your phone over to the bar to settle up via an NFC capable payment device such as Barclays PayWave found all over the UK. A white-label app could be used at multiple destinations, acting as central gatekeeper to the UIDs in order to also provide the order and payment systems so the phone owner doesn’t need to download an app per destination.

Social Gaming

There are too many possibilities to mention here. But the way that the Android Intents and Service systems works provides plenty of incredibly hassle-free ways to make use of tag “intents” combined with existing location-based social gaming. You swipe a tag or phone near another and the GameService registers the occasion to whatever ends your game needs. Stealth may even come into it, swiping a phone near another without them realising, alternatively enabling geo-caches with RFIDs for 1 player games.

Lots of fun to be had with NFC, any other suggestions off the top of your head?

Chrome Web Store: Why Online Apps?

Yesterday Google unveiled the Chrome Web Store. In a nutshell this is an App Store for the Chrome browser and a critical component in the upcoming Chrome OS. The Chrome browser is found on all major desktop operating systems, on the enormous numbers of A…

Yesterday Google unveiled the Chrome Web Store. In a nutshell this is an App Store for the Chrome browser and a critical component in the upcoming Chrome OS. The Chrome browser is found on all major desktop operating systems, on the enormous numbers of Android phones and tablets, and the new TVs and set top boxes from companies like Sony, Logitech and reportedly the biggest of them all, Samsung. Chrome OS is a desktop operating system replacement designed to operate entirely in the cloud, using web technologies, with almost negligible startup times for the instant-on, always connected generation. Chrome touts automatic synchronisation of everything from bookmarks, to auto-fill info and passwords, and preferences.

How do regular people use computers?

I must first apologise for the use of the word “regular” to differentiate users here, but the truth is there are a very small number power users; people that are even remotely interested in how their operating system works and how it can be modified. We manually install software onto a computer because it provides a fast experience, utilising the full power of the machine. The other camp includes everyone else; using Office, the Web (Facebook, webmail), maybe intranet applications at work, and of course shopping and having fun at home. These camps do overlap, but the key point here is the latter camp is the vast majority, and we must always look at technology from their perspective in order to see the bigger shifts.

In a previous post regarding web technologies I proposed that nearly all applications would be web-based within 5 years, I’m an eternal optimist so any numbers I give always need seasoning with a pinch of salt. For a professional programmer or designer this is something really hard to swallow, and the “why a web app store” comments are already proliferating the twitter-sphere. I’m always observing how my group of friends use computers, some have more skill than others, but they rarely install desktop applications any more and would appear to prefer not to have to as they feel comfortable having already learned how to live in browser-land.

The word computer in the heading is a little outdated, it’s already clear to most that computers are, for the most part, being used in the form of mobile phones, tablets and other devices, not laptops and desktops. This is also key, the inevitable decline of the laptop and the desktop, those specialist and indirect machines, from the computing landscape.

Native and offline, the 90% rule

Traditionally we’ve had to install applications to specific operating systems to make use of certain features, certain hardware. One example would be the ability to write files or a database to disk, these might contain a user’s data from several sessions – this feature alone is the decider for a large percentage of mobile apps. Another might be to make use of the graphics card to display massive amounts of 3D polygons for a game. Finally I think notifications are worth mentioning. I’ve had issues with online messengers, twitter clients, apps that are buried in a tab, unable to do more than flash the title bar to let you know *something’s happening!*.

The change that’s occurring is that new web technologies are bringing some of these native-only features to web developers, through HTML5 and Flash, even for the problem of notifications. This means that instead of only being able to produce 50% of the apps you could on desktop, you can now produce 90% and growing.

I like to call this the 90% rule. The added bonus is that the other 10% is typically what our “power users” need, so in effect it’s pretty much 100% of what our “regular” users need. That’s the critical mass required to make the shift away from traditional desktop operating systems, onto something new with many new benefits.

Benefits

There are potential pitfalls and challenges (security, limited connectivity), but also benefits associated with moving entirely to the cloud. I’d like to pick out a few key benefits over traditional computing models.

Backup

Fire, burglary, lost property, batteries a’sploding. In some cases you can lose all your devices in one foul swoop. You backup your computer right? I backup to Timemachine continually, I run a weekly secondary hard-drive backup, I use SVN for all my projects, and I use Dropbox with an encrypted DMG to make sure I always have some important information to hand. Regular computer users do not do this, then inevitably hard drives crash, drinks get spilled, I can’t even begin to count the number of times a non-geek, and even plenty of less paranoid geeks have simply lost everything bar the postage stamp sized photos they uploaded to Facebook. iTunes doesn’t let you re-download music anymore, you really have to back up. This was easier to deal with when people had physical backups, real photos, CDs, real letters, but it’s increasingly becoming an issue.

The immediate win here, admittedly at the cost of a trust relationship, comes from having all your stuff backed up by professionals with backups of their own across the globe. It would take a fairly major worldwide catastrophe before both the server and your local copies were destroyed.

Updates

Probably one of the original reasons apps started moving to web was that you can guarantee your users are all running the same version. From their perspective they don’t have to install anything, and they get updates and bug-fixes with zero effort. No checking for updates and waiting, no updater apps popping up every Wednesday because they changed the kerning in iTunes.

Migration Between Devices

With a great many devices at our disposal; the phones in our pockets, the tablet on the table, the laptop under the sofa, the PC in the back room, the TV in the living room and the watch on our wrist, we have so many overlapping choices in what we use to go online and do things. If each of these runs its own operating system, operates its own App Store, its own way of installing applications and games, having to pay for a copy of an app that only runs on one specific device you may lose or replace, we are simply limiting ourselves.

One of the things a unified web-based operating system does is turn upside-down the notion that you’re going to show someone that photo which is on your INSERT_DEVICE, instead you pick up any device and off you go. Ubiquitous computing, ultimate convenience.

This also makes sense when the inevitable happens, and that new shiny device comes out, you migrate to a new device. The experience on something like an Android phone can be pretty good, should you decide not to switch to another OS. You turn it on, enter your username and password, and all of your settings and apps are immediately re-downloaded. Apple provide a backup mechanism using a cable and desktop/laptop computer running a copy of iTunes (though that doesn’t solve the problem of a house fire where you lose both devices).

Chrome Web Store

Unfortunately Google have done the usual technology-driven thing and put out a rather functional experience for later finessing, rather than launching with a polished user experience as might another user-focused company, but it’s not too bad, certainly better than the Android market even in its present state.

So what do you think to Chrome Web Store and Chrome OS? Comments welcome as always.

Speaking: An Introduction to Android

I’ll be speaking at this month’s London Flash Platform User Group meeting (27th May) on the subject of native Android application development.The presentation will get you up and running from installing the tools to building and skinning applications…

I’ll be speaking at this month’s London Flash Platform User Group meeting (27th May) on the subject of native Android application development.

The presentation will get you up and running from installing the tools to building and skinning applications.

You can sign up to attend and find out more details here.

UPDATE: Recording here. (Volume is very low, so without external speakers you may have trouble hearing).

jQuery CSS3 3D Animation

I’ve just finished a jQuery extension which adds support for modifying and animating CSS3 transformations in 2D and 3D. This was based on the 2D transform monkey-patch by Zachary Johnson. I needed this for a project I’m working on which specificall…

Update: The code has now been updated to support jQuery 1.6+, thanks again to Zachstronaught. Please bear in mind the original date on the post below, there may be some inaccuracies due to new browser versions.

I’ve just finished a jQuery extension which adds support for modifying and animating CSS3 transformations in 2D and 3D. This was based on the 2D transform monkey-patch by Zachary Johnson.

I needed this for a project I’m working on which specifically targets Webkit (tablet devices), but I’m releasing the code under the existing MIT license for anyone to use as they wish. I’ve put together a little demo to show how it can be used. This demo has been tested on Safari and Chrome, in Firefox you’ll likely only see the 2D transformations, I haven’t tried IE.

DEMO

I had very little spare time to put this together so it’s rough around the edges, very basic, and doesn’t really show the full potential of this technique. But hopefully you’ll see that 3D transformations can be used in a subtle manner with your existing JS/CSS, or in a very obvious manner in a game perhaps.

Click image to see demo. Move mouse around to rotate images in 3D, roll-over buttons and click to view transform animations.

(images are CC non-commercial share-alike, link)

Notes

There has been quite some discussion regarding the position of “HTML5″ (usually referring to HTML5, CSS3 and JS), and Flash. Steve Jobs made his thoughts clear on the subject, even though that particular letter was full of inaccuracies and errors, in particular with regards to video and touch events. Personally I’ll always use whatever tech works for the job, many of the posts bashing Flash in the last decade have been written by people that haven’t necessarily tried it. Many refer to Flash from brief experiences they had many years ago, with the timeline, slow performance and pre-AS3 code. So I thought it might be useful to write up some of the notes I made along the way as I weighed up when I might use this.

CSS Animations/Transitions

So far it’s really only Webkit that supports these. Everything is optimised for fairly non-interactive content, animations are defined ahead of time, not very dynamic. You can do some cool stuff with keyframes (at 10%, 20% etc) but I see way too many holes if you want to use these in RIAs and games.

Of course using JavaScript you can pretty much animate things as you wish, which is why I wrote the jQuery extension to support the 3D CSS transformations in the animate() function. The downside is performance. Testing on the 1Ghz Nexus One webkit browser shows that JS powered CSS animation will be severely limited on devices, certainly when compared with performance tests shown for Flash Player 10.1.

I was unable to find a way to perform a circular path (orbit) animation in CSS, anyone know if this is possible? This is something very common in UI work, rather than sticking to straight lines, transitions can benefit from having a touch of curvature to soften the effect, as well as standard (non-mouse-related) “hover” type animation. So again in this case I had to resort to using JS for this, losing the benefit of CSS animations, if anyone knows how to do this I’d really appreciate the comment.

Filters

I can’t seem to find anything that works in Webkit or Mozilla, here I’m talking about the sorts of things you do to highlight something of importance to the user to subtly improve usability; things like glow and non-box-shaped shadows (I’m aware of text-shadows and box shadows). I would have thought this was a given when the spec was being written, this could make for a pretty dated look and feel.

Blend Modes

I really just expected these to be in… there are a few things in Webkit related to this, but it’s a worry; blend modes make for an improved look and feel in modern UIs (especially when dragging things around as objects become obscured). Will have to wait and see what happens with this. Of course all of this would be almost moot if the IE 9 team decided Canvas wasn’t too much of a threat and implemented support. So many great Canvas experiments are essentially in vain as a result, so many apps still only possible using the pixel manipulating features in Flash Player 8+.

CPU usage / Performance

I was using a jQuery plugin for animating elements on a curve/arc to get the circle animation but I found CPU usage went straight to 100% with the four animals, so I presume either my usage was wrong (there wasn’t much to it) or there’s something wrong with that plugin.

Safari uses 100% CPU just to run the setInterval() for the first 30 seconds before dropping down to <5%, Chrome doesn’t suffer from this. I’m not sure whether this is a bug in Safari or not, hopefully someone can shed some light on this. Outside of setInterval() there are no built in ways to do real-time games in JS that I am aware of (Flash has setInterval and Timers but it’s much more efficient to use the ENTER_FRAME event which results in no CPU overhead).

If you are doing real-time games in JS, I would probably avoid the overhead of jQuery for the most part and keep it as low-level as possible, the DOM with its history of laying out mostly static content doesn’t lend itself amazingly well to high-performance graphics, this is akin to building a game in the Flex (app) framework, you just wouldn’t, you’d use Sprite/MovieClip etc which doesn’t have the enormous measurement overheads for liquid layout, padding, margins, accessibility and so on. Perhaps Canvas is an option, which unfortunately still means Flash for the next few years (flashcanvas) due to IE9 (SVG could take up a large amount of slack, but that’s about equivalent to FP8 so not particularly exciting).

The other day I saw this video which appears to confirm my performance worries with HTML. It’s very easy to say HTML provides better performance than Flash until you try to do the same sort of things people do with Flash but I imagine the FUD will continue long after people start to question why we aren’t seeing these cutting edge apps being built with HTML.

Cross browser inconsistencies

I mentioned I’m only targeting Webkit, luckily the two big OSs in tablet devices (Apple iPhone OS and Android) both run Webkit, but I am a little worried by the fact that something as basic as text-stroke only works in Webkit, there’s nothing very concrete to go on as to who’s going to support what in the coming years. Even Firefox doesn’t support it, and that actually has a big impact on design as I’d also have to remove the (fairly supported) text drop-shadow because without the text stroke it just looks ugly. What a nightmare the next few years will be, with frustration and constant set-backs; I’ve gotten used to being 100% confident anything I can achieve in Flash will work across all browsers, the thought of hacking and rolling back to simpler times is a pain.

Conclusions

So this has been a learning experience… it certainly works for me when targeting mobile devices for fairly simple apps/games, where you don’t have a lot of heavy graphics or effects to deal with. I can definitely see a huge chunk of current-gen Flash web apps being cut-down a little and written in HTML+CSS+JS in order to support Apple devices and in favour of Web standards, but I fear if Flash becomes too niche we’re going to take one step forward and two steps back just as web apps and games were really beginning to rival the desktop; leaving us with a rather uninspiring experience based on what you simply can’t do in HTML5/JS/CSS3. In short it’s only about 60% of the way to Flash Player 10 in raw technical capabilities and before widespread use we’ll see Flash Player 11, 12, with who knows what.

So it’s not quite as great as I hoped, but I’m gonna jump on board as best I can and push it as far as I’m able. Still, what I’d really love to see is browser vendors pushed in the right direction by us developers demanding some of these things as soon as possible.

Implementing SpellCheck (Squiggly) with the Text Layout Framework (TLF)

I’ve just posted over in the Text Layout forums how I went about implementing Squiggly with “pure” Text Layout Framework… so that’s not using TLF/FTETextField or the Spark components.This is really just an overview which should give plenty to help yo…

I’ve just posted over in the Text Layout forums how I went about implementing Squiggly with “pure” Text Layout Framework… so that’s not using TLF/FTETextField or the Spark components.

This is really just an overview which should give plenty to help you figure out the steps. I can’t paste the exact code because it’s embedded in a client project, but I do refer to some of the TLF functions throughout that you have to make use of, if anyone can suggest improvements, please drop them in the comments.

Copied from the forum post…

Find TextRanges for misspelled words:

  • Get the first Paragraph using textFlow.getFirstLeaf().getParagraph()
  • Loop through all Paragraphs using para.getNextParagraph()
  • For each, run a Regex match (/bw+b/) on para.getText()
  • Spellcheck each result using Squiggly, and for bad words store a TextRange: TextRange(textFlow, para.getAbsoluteStart()+index, para.getAbsoluteStart()+index+word.length-1); where index is incremented to the position proceeding the end of each word (match or no match).

Spellcheck class:

  • Created a static SpellCheck class which loads language dictionary (downloaded from OpenOffice website) and a UserDictionary (stored as a simple text file)
  • Added methods for checkTextFlow(textFlow:TextFlow):Array which returns an array of “bad” TextRanges, a method for getSuggestions(word:String):Array and methods for checkWord() and addUserWord().

Context menu:

  • Extend ContainerController and override menuSelectHandler()… use an instance of my CustomContainerController when creating the TextFlow:
    textFlow.flowComposer.addController( new CustomContainerController() );
  • Loop through flowComposer.numLines, obtain each TextFlowLine from flowComposer and therefore each TextLine.
  • Determine if textLine.getBounds(container).container(container.mouseX, container.mouseY) to find the line they right-clicked.
  • Get the “raw text” for the line: textLine.textBlock.content.rawText.substr(textLine.textBlockBeginIndex);
  • Find the atom clicked: textLine.getAtomIndexAtPoint(container.stage.mouseX, container.stage.mouseY).
  • Find the starting atom of the word (reverse lookup for word boundary i.e.. ” ” or first char in raw text).
  • Determine the word itself by using regex to find the first word from this starting point (/bw+b/).
  • Add ContextMenuItems for “add to dictionary” and suggested words (for the latter also store start/end atoms in ContextMenuItem.data).
  • When user clicks a suggested word, use (interactionManager as EditManager).selectRange(data.start, data.end); (interactionManager as EditManager).insertText(data.word) where “data” is the data property of the clicked ContextMenuItem.

In my “EditableTextField” class, I call my SpellCheck.checkTextFlow() to get the bad TextRanges and…

  • Loop through the badRanges array.
  • Loop from range.absoluteStart to range.absoluteEnd for each TextRange.
  • Find TextFlowLine for “i” in this loop, and therefore the TextLine: containerController.flowComposer.findLineAtPosition(i); textFlowLine.getTextLine();
  • Find atom bounds using textLine.getAtomBounds(charIndex); where charIndex is: i – textFlowLine.absoluteStart.
    Underline… drawRect( bounds.x + textLine.x, bounds.y + textLine.y + bounds.height – textLine.descent – 1, bounds.width, 3)

I’m sure there is a more elegant way, but this seems to work. I believe I read Adobe are working on Squiggly for pure TLF, if not, I hope this helps somebody get on the right track.