Archive for April, 2008

Android Activity Designer

Posted in Other Android Stuff on April 30th, 2008 by matt

Found this graphical Activity designer for Android. I will let you know what I think..
http://droiddraw.org/

Working with OptionMenus

Posted in News on April 27th, 2008 by matt

Each activity can have it’s own menu defined. Here’s a quick info on getting your menu up and running.

OptionsMenu event cycle

  1. onCreateOptionsMenu(Menu menu) - The point at which you should add all the items you need into the menu. Call the super inherited method to have the menu populated with the default items.
  2. onPrepareOptionsMenu(Menu menu) - The point at which you can enable / disable and dynamic content, etc to respond to the state of the activity.
  3. onOptionsMenuClosed(Menu menu) - called when the menu is closed.

When items are added to the Menu in OnCreateOptionsMenu you can either pass a runnable in at that point to associate with the menu item, or alternatively you can override the onOptionsItemSelected to provide a central place where you can call out to methods that the menu items invoke.

Other OptionsMenu methods

  • openOptionsMenu() - Opens the OptionsMenu
  • closeOptionsMenu() - Closes the OptionsMenu if open.

SD Cards and the Emulator

Posted in Code snippets on April 25th, 2008 by matt

From a command prompt / terminal navigate to the android sdk’s tools folder.

Resetting the emulator

To reset the emulator and wipe all the stored data, returning as it were to factory settings run:

emulator -wipe-data

Create a blank SD card image:

mksdcard <size> <filename>

e.g. mksdcard 512M halfagig.sd

will create a 512 MegaByte sdcard image called halfgig.sd.

Mounting an SD Card in the emulator:

emulator -sdcard <filepathandname>

This will mount the card under the path /sdcard

Mounting an SD Card image under Linux:

mount -o loop [filename] [/media/mountpoint]

Background Intents (non-visual)

Posted in Tutorials on April 24th, 2008 by matt

Intents have multiple uses on the android platform and this fact makes them inherently confusing. In the single mechanism a variety of uses are implemented and this is only too apparent when you look at the Intent class constructor. When delving into the intents with Craig, he wondered why a nice Intent class hierarchy had not been implement to cleanly segment their uses.

This article addresses the use of Intents for sending and receiving messages in the background, for those circumstances, where you do not wish any impact on the users experience and will usually respond the notification asynchronously.

Read more »

Syntax Highlighting

Posted in News on April 23rd, 2008 by matt

The droidapps blog is using Dean Lee’s Syntax Highlighting plug in for wordpress. http://www.deanlee.cn/wordpress/code_highlighter_plugin_for_wordpress/

Code is simply wrapped with <pre lang=”java”> </pre> and the plugin does the rest. It will syntax highlight various languages including javascript, php, c sharp

Android Developer Challenge

Posted in News on April 23rd, 2008 by matt

Craig and I (no relation despite the common surname) submitted an application into the Google Android Developer challenge. We only came across android about three weeks ago, and as we both have a full time job and families, it was a bit of a push to learn as much as we could about the platform and code an app in two weeks. It was a bit close to the wire, and we took full advantage of the time difference on day now known as “can’t type tuesday”. At about 3:30am we finally submitted the application, a Podcast down loader and player.

So the long wait ’till May 5th continues…. a 1 in 35 chance isn’t that bad…. is it?

How to capture key pad presses in an Activity.

Posted in Code snippets on April 23rd, 2008 by matt

To capture the keypad presses and any other keys on the phone…
Override the Activities OnKeyDown and compare the keycode against one of the constants in KeyEvent.KEYCODE_*

        @Override
        public boolean onKeyDown(int keyCode, KeyEvent ev) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_LEFT:
                        // do something
                        return true;
                case KeyEvent.KEYCODE_DPAD_RIGHT:
                        // do something
                        return true;
                default:
                                return super.onKeyDown(keyCode, ev);
                }
        }
 

A couple of things to note are, returning true informs the caller that you have handled the keypress and it does not need to propagate to other views. Don’t forget to return the result of super.onKeyDown as the last resort or you’ll find out the default handling of keys no longer gets processed for your activity. (e.g. the back button will no longer navigate back through the Activity stack)