as3 Native Progress – Air native extension for a popup progressbar

Native Progress demo picture

My new Updates on the as3NativeAlert.
I’v implemented a new class NativeProgress.
It extends the “ane” with the ability to display the native dialog showing a progress bar or a spinner.

Available themes for android :

THEME_DEVICE_DEFAULT_DARK
THEME_DEVICE_DEFAULT_LIGHT
THEME_HOLO_DARK
THEME_HOLO_LIGHT
THEME_TRADITIONAL

Usage:

private var progressPopup:NativeProgress;
private var p:int = 0;
private var myTimer:Timer = new Timer(100);

protected function openProgressPopup(style:int):void
{
     progressPopup = new NativeProgress(style);
     progressPopup.theme = NativeProgress.THEME_HOLO_DARK;
     progressPopup.setSecondaryProgress(45);
     progressPopup.addEventListener(NativeDialogEvent.OPENED,traceEvent);
     progressPopup.addEventListener(NativeDialogEvent.CANCLED,closeNativeProcessHandler);
     progressPopup.addEventListener(NativeDialogEvent.CLOSED,closeNativeProcessHandler);
     progressPopup.addEventListener(NativeExtensionErrorEvent.ERROR,onError);
     progressPopup.setMax(50);
     progressPopup.setIndeterminate = true;
     progressPopup.show(0, titleInput.text , messageInput.text,true);

     myTimer.addEventListener(TimerEvent.TIMER, updateProgress);
     myTimer.start();
}

private function closeNativeProcessHandler(event:Event):void
{
     progressPopup.removeEventListener(NativeDialogEvent.CANCLED,closeNativeProcessHandler);
     progressPopup.removeEventListener(NativeDialogEvent.CLOSED,closeNativeProcessHandler);
     progressPopup.removeEventListener(NativeExtensionErrorEvent.ERROR,onError);
     progressPopup.removeEventListener(NativeDialogEvent.OPENED,traceEvent);

     progressPopup.kill();

     myTimer.removeEventListener(TimerEvent.TIMER,updateProgress);
     myTimer.stop();
     p = 0;
}
private function updateProgress(event:TimerEvent):void
{
     p++;
     if(p>=50){
          p = 0;
          progressPopup.hide();
	  (event.target as Timer).stop();
     }else
	progressPopup.setProgress(p);
}
			
protected function viewBackKeyPressedHandler(event:FlexEvent):void
{
     event.preventDefault();
     myTimer.removeEventListener(TimerEvent.TIMER,updateProgress);
     myTimer.stop();
     p = 0;
     if(progressPopup){
	progressPopup.hide();
     }
}
//NativeApplication.nativeApplication.addEventListener(Event.EXITING,exiting);
protected function exiting(event:Event):void
{
     if(progressPopup)
	progressPopup.kill();
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: