14.01.2013 Views

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

Android™ Application Development - Bahar Ali Khan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<br />

<br />

Chapter 11: Advanced Android <strong>Development</strong><br />

Android includes several predefi ned themes as part of the base package, including:<br />

❑ Theme.Black Features a black background with white foreground controls and text.<br />

❑ Theme.Light Features a white background with dark borders and text.<br />

❑ Theme.Translucent Features a partially transparent Form.<br />

You can set the theme of an Activity at run time, but it’s generally not recommended, as Android uses<br />

your Activity’s theme for intra-Activity animations, which happens before your application is loaded. If<br />

you do apply a theme programmatically, be sure to do so before you lay out the Activity as shown in the<br />

code snippet below:<br />

protected void onCreate(Bundle icicle) {<br />

super.onCreate(icicle);<br />

setTheme(android.R.style.Theme_Translucent);<br />

setContentView(R.layout.main);<br />

}<br />

If you don’t apply a theme to your application or any of its Activities, it will use the default theme<br />

android.R.style.Theme.<br />

Advanced Canvas Drawing<br />

You were introduced to the Canvas class in Chapter 4, where you learned how to create your own<br />

Views. The Canvas was also used in Chapter 7 to annotate Overlays for MapViews.<br />

The concept of the Canvas is a common metaphor used in graphics programming and generally consists<br />

of three basic drawing components:<br />

❑ Canvas Supplies the draw methods that paint drawing primitives onto the underlying bitmap.<br />

❑ Paint Also referred to as a “brush,” Paint lets you specify how a primitive is drawn on the<br />

bitmap.<br />

❑ Bitmap Is the surface being drawn on.<br />

Most of the advanced techniques described in this chapter involve variations and modifi cations to the<br />

Paint object that let you add depth and texture to otherwise fl at raster drawings.<br />

The Android drawing API supports translucency, gradient fi lls, rounded rectangles, and anti-aliasing.<br />

Unfortunately, owing to resource limitations, it does not yet support vector graphics; instead, it uses<br />

traditional raster-style repaints.<br />

The result of this raster approach is improved effi ciency, but changing a Paint object will not affect<br />

primitives that have already been drawn; it will only affect new elements.<br />

If you’ve got a Windows development background, the two-dimensional (2D) drawing capabilities of<br />

Android are roughly equivalent to those available in GDI+.<br />

373

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!