Phone Mood Indicator

Battery Level Indicator
Just thought of creating this cool application which shows you your phone’s battery level. Now instead of having to look at the small teeny weeny battery icon of your phone, set this up as your wallpaper and watch it tell you the battery power as as a mood change.
Ideal for flash lite 2.0 and above. I have tested it on quiet a few resolutions, so i guess that shouldnt be much of a problem. The project is intended for learning purposes but may be used for personal purposes as well.
I have even tried to include a short tutorial to this thing as i understand it.
Short Tutorial:
1. Create a new flash lite project.
2. Set target to flash lite 2.0 in publish settings
3. Select your favorite phone to use as emulator from device central.
4. Start Coding
.. well i personally use either flash cs3 built in editor or flashdevelop ..
Set Stage defaults such that there is no scaling or alignment issues.
Firstly we set the stage to noscale and alignment to top-left.
Then we set up a listener for the stage, so that each time the stage is resized we can align our assets accordingly.
Stage.align = ‘tl’;
var stageListener:Object = new Object();
stageListener.onResize = onStageSizeChange;
Stage.addListener(stageListener);
Next we add the assets to our stage with code so that they remain unaffected by difference in resolution.
var bg:MovieClip = this.attachMovie("bg","bg",this.getNextHighestDepth());
//attach a holder for our moody smiley clip
var holder:MovieClip = this.attachMovie("holder","holder",this.getNextHighestDepth());
holder._xscale = holder._yscale = 40;
//logo code (not needed in your code, just attaching copyright)
var logo:MovieClip = this.attachMovie("logo","logo",this.getNextHighestDepth());
//align added content
alignContent();
Calculate and set up initial variable values
previousLevel = 100;
maxBatt = parseInt(fscommand2("GetMaxBatteryLevel"));
battLevel = parseInt(fscommand2("GetBatteryLevel"));
currentLevel = Math.round((battLevel/maxBatt)*100);
Now that we have set up the variables we are ready to start up the fun stuff
setDisplaySmiley(currentLevel);
// monitor every 3 seconds for state change
batteryListener = setInterval(this,"observerBattery",3000);
Next we calculate maximum battery level and currrentlevel in each interval and display smiley according to that. if battery is charging ie: getting power from power socket we assume full battery and set the best smile. Otherwise we check whether there is a change in battery level and set the appropriate smiley.
In the end set previousLevel as currentLevel.
{
battLevel = parseInt(fscommand2("GetBatteryLevel"));
currentLevel = Math.round((battLevel/maxBatt)*100);
// if charging
if(parseInt(fscommand2("GetPowerSource")) == 1)
{
currentLevel = previousLevel = 100;
setDisplaySmiley(currentLevel);
}
else if(currentLevel != previousLevel) setDisplaySmiley(currentLevel);
previousLevel = currentLevel;
currentLevel = null;
}
And lastly here is the main magic:
The setDisplaySmiley function receives the battery Level as parameter. It then divides 100% battery level into five ranges to represent five smileys.ten depending on which range the current Level falls into we display the appropriate smiley.
function setDisplaySmiley(Level)
{
holder.getInstanceAtDepth(0).removeMovieClip();
if(Level > 80)
{
holder.attachMovie("smile100","smile100",0);
}
else if(Level > 60)
{
holder.attachMovie("smile80","smile80",0);
}
else if(Level > 40)
{
holder.attachMovie("smile60","smile60",0);
}
else if(Level > 20)
{
holder.attachMovie("smile40","smile40",0);
}
else
{
holder.attachMovie("smile20","smile20",0);
}
alignContent();
}
If you notice, there is a call to alignContent in the end. I do this to ensure no matter what condition make occur , my content’s alignment stays ok. And also we might take a look at what the alignment function does.
{
//center align smiley
holder._x = Stage.width/2;
holder._y = Stage.height/2;
//align logo
logo._x = Stage.width/2;
logo._y = Stage.height – logo._height;
//calculate resolution and set background
Width = System.capabilities.screenResolutionX;
Height = System.capabilities.screenResolutionY;
bg._width = Width; // set to width
bg._height = Height; // set to height
bg._x = Stage.width/2; // align bg x
bg._y = Stage.height/2;// align bg y
}
This function is also called on stage resize event as we set up in the first part of the code. you can see the handler code below.
{
alignContent();
}
Well this is how a basic active wallpaper may function using the power of flash lite api and creative ability of the mind
Get the full source code :Here
Phone Mood Indicator by Rajdeep Rath is licensed under a Creative Commons Attribution-Noncommercial 3.0 United States License.
Based on a work at flashvisions.com.
July 4, 2009
Posted in: Flash Lite



2 Responses
The article is ver good. Write please more
Lifeline – EKG simulating screensaver - August 13, 2009
[...] Phone Mood Indicator by Rajdeep Rath is licensed under a Creative Commons Attribution-Noncommercial 3.0 United States License. Based on a work at flashvisions.com. [...]
Leave a Reply