Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Getting Down and Dirty with Google's Android : Page 4

The best way to understand a new SDK is to work with it. With that in mind, we'll show you how to do some basic location based services and simple UI layout using Google's newest upstart mobile offering.


advertisement
Using Custom Views
In its most simplistic form, a View in Android must overload only one function onDraw(). Custom Views can be complicated 3D playback implementations or they can be ultra simplistic text rendering. Here's what the CreateView function listed above looks like:

public void CreateView() { customView = new CustomView(this); }

This function simply evokes the constructor for the CustomView object. The definition of which follows below:

public class CustomView extends View { LocateMe overlord; public CustomView(LocateMe pCtx) { super(pCtx); overlord = pCtx; } public void onDraw(Canvas cvs) { Paint p = new Paint(); String sLat = "Latitude: " + overlord.getLat(); String sLon = "Longitude: " + overlord.getLon(); cvs.drawText(sLat , 32, 32, p); cvs.drawText(sLon, 32, 44, p); } }

This custom Android view renders the latitude and longitude test data to the screen in text. It requires a pointer to LocateMe, the Activity extender that is the heart of this application. Its two methods are the constructor and the onDraw methods. The constructor evokes the super-class constructor and stashes off the Activity pointer. onDraw will create a new Paint object (an object that encapsulates color, transparency, and other basic theme information) which will access the default color theme. From there, it's a matter of setting up the display strings, and drawing them to the screen using the Canvas pointer. For those of you who know something about J2ME's game canvas, this should look very familiar.



The Waiting Game
From purely a development standpoint, Android is a very powerful SDK. It combines XML layout schemes with custom view rendering and in house scrollbar, maps, and other in house widgets. All which can be overloaded and customized on the whim of a developer. Its documentation is rough; there are missing features and gaps in functionality (like SMS interop and a clear monetization plan), but overall Android looks very promising for what even Google acknowledges is a "First Look" SDK. Now we'll just have to see if anyone actually deploys a phone that uses it.



Chris Haseman is an independent software engineer specializing in wireless development. He can be found riding his bike between coffee shops in San Francisco. He's the author of the book Android Essentials (published by Apress). In his spare time, he's a resident DJ at xtcradio.com and a martial arts instructor.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap