Android Tutorial

(avery) #1

By : Ketan Bhimani


420 

You must set a flag on the Notification object to use the indicator
light. Then, the color of the light must be set and information about
how it should blink. The following block of code configures the
indicator light to shine green and blink at rate of 1 second on and 1
second off:

notify.flags |= Notification.FLAG_SHOW_LIGHTS;
notify.ledARGB = Color.GREEN;
notify.ledOnMS = 1000;
notify.ledOffMS = 1000;


Although you can set arbitrary color values, a typical physical
implementation of the indicator light has three small LEDs in red,
green, and blue. Although the colors blend reasonably well, they
won’t be as accurate as the colors on the screen. For instance, on
the T-Mobile G1, the color white looks a tad pink.

An application can use different colors and different blinking rates
to indicate different information to the user. For instance, the more
times an event occurs, the more urgent the indicator light could be.
The following block of code shows changing the light based on the
number of notifications that have been triggered:

notify.number++;
notify.flags |= Notification.FLAG_SHOW_LIGHTS;
if (notify.number < 2) {
notify.ledARGB = Color.GREEN;
notify.ledOnMS = 1000;
notify.ledOffMS = 1000;
} else if (notify.number < 3) {
notify.ledARGB = Color.BLUE;
notify.ledOnMS = 750;
notify.ledOffMS = 750;
} else if (notify.number < 4) {
notify.ledARGB = Color.WHITE;
notify.ledOnMS = 500;
notify.ledOffMS = 500;
} else {

Free download pdf