Tuesday, August 17, 2010

Android Run-Down, Tuesday August 17th

I have been building the Google Android applications using Eclipse, ADT and my HTC Sprint EVO phone. Started by installing the Android SDK Starter Package.

While working on a number of application projects, I have created a few public domain sample projects, like AndroidDemoViewTrain, which is hosted on CodePlex and contains a number of coded, commented and clarified (I hope!) Google samples.

Once I was done with basic TextView and Button demos, I moved onto more complex tasks -- the so called Common Tasks in Android list. You can tell from Google that Android is pretty new -- a lot of unanswered questions on the boards -- maybe just a reflection of the community or whatever, but the information on solving Android issues and error messages is scant compared to C# or Apache. Also, I found a lot of bad information out there as well -- lots of posts full of bad assumptions or incorrect statements, so take what you read back to the Google documentation and test laboratories.

One of the first things that I needed to do was include two database tables in a single Android application database. I will blog about that later, it was harder to find the real-deal info than you might imagine. Got it done though.

Next thing I needed to do was populate a Spinner with an SQLite database query. If you have two tables in your database, one of those tables is probably a "Type" table and you need drop downs to select types.

Populating an Android Spinner Control from Database is pretty similar to populating an Android Spinner Control from XML. This dcPages story has a good write up of the database process here at Android Tutorial: Populating Spinners - Populate Spinner using Database Query

Then I discovered that you have to be very careful trying to feed Int or Long java primitives to the Android API because it assumes that they're keys for special resource collections. Instead of passing in TextView.setText(i) you need to use TextView.setText(Integer.toString(int i))

Now, all that was well and good -- I was populating Spinner controls and using setText() on integers to put database state onto the screen. Then I realized that Spinner controls were no good for me if I could not figure out what had been selected and then I was off again -- reading about Retrieving Selected Spinner Values on Android -- an important question if you are going to spend time populating them from the database. I blogged about that part earlier here, at How to Know What is Selected in Android Spinner.

Once I started calling lots of additional Android Activities and exploring the advanced features of the Android Application Manifest file, I became aware of a strong need to reach a full understanding of Intents and Intent Filters. To that end, I read a series of lectures by Victor Matos (PPT of Google Docs, basically) here at CSUOhio.edu: http://grail.cba.csuohio.edu/~matos/notes/cis-493/lecture-notes/Android-Chapter12-Intents-1.pdf

Also, another good page on Using Intents to Transfer Data between Android 2.0 Activities. Very similar information to this page about Passing Bundles Around Activities but still good reading.

Soon after that I needed to create Dialog Boxes in Android and therefore, I went back to Google for more searching and ended up playing with Scrollable CellMaps instead. SurfaceHolder is a hell of a class, my friends! Then I started back on Displaying Alert Dialog in Android. Any type of alerting is bound to contain concerns about modality so here is Modal Dialogs in Android for your reading pleasure.

After getting the advanced use of system events (Intents, Activities and Intent Filters) I moved onto the Handling of UI Events in Android. A critical topic for any serious developer, Android events are managed very differently than the three-type event engine (jQuery, WCF and BI) I am familiar with.

Event Listeners
An event listener is an interface in the View class that contains a single callback method. These methods will be called by the Android framework when the View to which the listener has been registered is triggered by user interaction with the item in the UI.

Event Handlers
If you're building a custom component from View, then you'll be able to define several callback methods used as default event handlers. In the document on Building Custom Components, you'll learn see some of the common callbacks used for event handling.


After that I started adding some visual styles of my applications and read the Icon Design Guidelines for Android 2.0 which, I admit, did put the fear into me. I'm looking for a graphic artist now. However, that somewhat daunting trip down pixel lane did clear up a number of pressing concerns I had with my application's resources and the file structure in Eclipse.

First was -- "In Android Eclipse, what are all these mdpi and hdpi folders for? Which one do I use and what does it mean?" Well the answer can be found here where Google outlines The Android 2.0 UI Guide's Best Practices for Supported Screens. Here are the physical examples of the device screens and how they sort out by Density and diagonal: Range of Android Screens Supported by the OS.

Still too complicated? Yah, I know. How about this link? What Size Do I Make My Icons and What Folder Do I Use in Android 2.0 with Eclipse? Another one is How do I make Android Icon Packs and get Free Android Icons? I hope you have mad Photoshop CS3 skills that I don't posses if you are thinking about creating Icons.

Then, soon after that, I discovered TableLayouts. A few days later, I read this guy's blog post Android Nuts and Bolts IV where he also discovered TableLayouts. He might like them a little too much, but the blog is good.

Once you have tables, you will need Menus! http://developer.android.com/guide/topics/ui/menus.html

This guy's question claims that he has a bug with TextView, but when I read it saw how his "bug" is actually exactly how it needs to work and what valuable feature "Hint" is: Android 2.0 TextView Automatically Adjusts Width when Configured.

I started using a SeekBar. Nice UI: http://developer.android.com/reference/android/widget/SeekBar.OnSeekBarChangeListener.html

Once I had the SeekBar in place I started looking at the rest of the controls and reading a few Android 2.0 GUI Examples blogs helped me get a visual idea of what they all look like. Another Android 2.0 GUI Example Blog with TextView and TableLayout. Did I mention TableLayout is really very valuable? Android has a great TableLayout control, once you learn how to make it work. It is not CALS-Model SGML / XHTML tables, but it works on your phone.

I started looking at Android 2.0 UI Themes but only found this incomplete Android 101 blog entry about defining XML themes.

READ THE ANDROID DEVELOPER BLOG
Was that aggressive enough? Reading the blog taught me a lot -- and today I learned about Back Button, Hard Keys and Long Press in Android 2.0 UI.

Rotating Bitmap with Bitmap.createBitmap and Matrix objects -- you will find the details in someone's code on this page: http://www.anddev.org/resize_and_rotate_image_-_example-t621.html

How do I center text horizontally and vertical in a TextView in Android?


Very soon after that I was adding additional tables to my DbAdapter class and once you have 4 or five tables, you need to have JOIN! SQLite Join Syntax

No comments: