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.