AIR Native Extentions for Android ( ActionScript 部分 )


  AIR Native Extentions for Android ( ActionScript 部分 )




AndroidExtensions.as
package lightbox
{
	import flash.events.EventDispatcher;
	import flash.events.StatusEvent;
	import flash.external.ExtensionContext;
	import flash.system.Capabilities;

	
	/**
	 * This class defines a simple AIR Native Extension exposing a set of simple
	 * and useful Android native facilities:
	 * 
	 * <li>sharing (image or text)</li>
	 * <li>SMS sending</li>
	 * <li>Toast messages</li>
	 * 
	 * 
	 * @author mr_archano (twitter: mr_archano)
	 * 
	 */
	public class AndroidExtensions
	{
		/////////////////////////////////////////
		// Static fields
		//
		
		protected static var _dispatcher:EventDispatcher = new EventDispatcher();
		protected static var _context:ExtensionContext = null;
		
		/**
		 * Used to prompt an Android Toast message on the screen.
		 * @param text			the text to be shown.
		 * @param showForLong	set the duration of the toast. 
		 * 						If true, the value <code>Toast.LENGTH_LONG</code> is used.
		 * 						<code>Toast.LENGTH_SHORT</code> otherwise.
		 * 
		 */
		public static function toast(text:String, showForLong:Boolean = false) : void
		{
			if( isSupported )
				context.call("toast", text, showForLong);
			else
				trace(	"DEBUG: called AndroidExtensions.toast\n" +
					"- text: "+text+"\n" +
					"- showForLong: "+showForLong+"\n");
		}

		public static function openURL(text:String) : void
		{
			if( isSupported )
				context.call("openURL", text);
			else
				trace(	"DEBUG: called AndroidExtensions.toast\n" +
					"- text: "+text);
		}
		
		public static function getVersion() : String
		{
			if( isSupported ) 
				return context.call("getVersion") as String;
			else
				trace(	"DEBUG: called AndroidExtensions.GetVersion");
				return "not Supported";
		}
		
		
		
		/**
		 * Used to dispose the extension.
		 * 
		 */
		public static function dispose() : void
		{
			if(_context)
			{
				_context.removeEventListener(StatusEvent.STATUS, onStatusEventHandler);
				_context.dispose();
			}
			_context = null;
		}
		
		/////////////////////////////////////////
		// Event handling functions
		//
		
		public static function addEventListener(type:String, listener:Function) : void
		{
			_dispatcher.addEventListener(type, listener);
		}
		
		public static function removeEventListener(type:String, listener:Function) : void
		{
			_dispatcher.removeEventListener(type,listener);
		}
		
		
		
		
		/////////////////////////////////////////
		// Protected functions
		//
		
		protected static function get context() : ExtensionContext 
		{
			if(!_context)
			{
				_context = ExtensionContext.createExtensionContext("lightbox.ane.androidextensions","");
				_context.addEventListener(StatusEvent.STATUS, onStatusEventHandler);
			}
			return _context;
		}
		
		protected static function get isSupported() : Boolean
		{
			return (Capabilities.os.indexOf("Linux") >= 0);
		}
		
		
		/////////////////////////////////////////
		// Callbacks
		//
		
		protected static function onStatusEventHandler(event:StatusEvent) : void
		{
			if(event == null || event.level == null)
				return;
			
			// debug
			trace("[AndroidExtensions.onStatusHandler] level: "+event.level);
			
			// handle StatusEvent
			switch(event.level)
			{
				case AndroidExtensionsEvent.TYPE_ERROR:
					onError();
					break;
				/* TODO: add cases here ... */
			}
		}
		
		protected static function onError() : void
		{
			_dispatcher.dispatchEvent(new AndroidExtensionsEvent(AndroidExtensionsEvent.TYPE_ERROR));
		}
	}
}
AndroidExtensionsEvent.as
package lightbox
{
	import flash.events.Event;
	
	public class AndroidExtensionsEvent extends Event
	{
		public static const TYPE_ERROR:String = "error";
		
		public function AndroidExtensionsEvent(type:String, bubbles:Boolean=true, cancelable:Boolean=false)
		{
			super(type, bubbles, cancelable);
		}
		
		override public function clone():Event
		{
			return new AndroidExtensionsEvent(this.type, this.bubbles, this.cancelable);
		}
		
		
	}
}
extension.xml
<extension xmlns="http://ns.adobe.com/air/extension/3.1">
  <id>lightbox.ane.androidextensions</id>
  <versionNumber>1.1.0</versionNumber>
  <platforms>
	<platform name="Android-ARM">
      <applicationDeployment>
        <nativeLibrary>ANElib.jar</nativeLibrary>
        <initializer>lightbox.AndroidExtensions</initializer>
        <finalizer>lightbox.AndroidExtensions</finalizer>
      </applicationDeployment>
    </platform>
  </platforms>
</extension>











yahoo  google  MSDN  MSDN(us)  WinFAQ  Win Howto  tohoho  ie_DHTML  vector  wdic  辞書  天気 


[sh_web]
claudebot
24/03/29 01:32:56
InfoBoard Version 1.00 : Language=Perl

1 BatchHelper COMprog CommonSpec Cprog CprogBase CprogSAMPLE CprogSTD CprogSTD2 CprogWinsock Cygwin GameScript HTML HTMLcss InstallShield InstallShieldFunc JScript JScriptSAMPLE Jsfuncs LLINK OldProg OracleGold OracleSilver PRO PRObrowser PROc PROconePOINT PROcontrol PROftpclient PROjscript PROmailer PROperl PROperlCHAT PROphp PROphpLesson PROphpLesson2 PROphpLesson3 PROphpfunction PROphpfunctionArray PROphpfunctionMisc PROphpfunctionString PROsql PROvb PROvbFunction PROvbString PROvbdbmtn PROvbonepoint PROwebapp PROwin1POINT PROwinSYSTEM PROwinYOROZU PROwindows ProjectBoard RealPHP ScriptAPP ScriptMaster VBRealtime Vsfuncs a1root access accreq adsi ajax amazon argus asp aspSample aspVarious aspdotnet aw2kinst cappvariety centura ckeyword classStyle cmaterial cmbin cmdbapp cmenum cmlang cmlistbox cmstd cmstdseed cmtxt cs daz3d db dbCommon dbaccess dnettool dos download flex2 flex3 flex4 framemtn framereq freeWorld freesoft gimp ginpro giodownload google hdml home hta htmlDom ie9svg install java javaSwing javascript jetsql jquery jsp jspTest jspVarious lightbox listasp listmsapi listmsie listmsiis listmsnt listmspatch listmsscript listmsvb listmsvc memo ms msde mysql netbeans oraPlsql oracle oracleWiper oraclehelper orafunc other panoramio pear perl personal pgdojo pgdojo_cal pgdojo_holiday pgdojo_idx pgdojo_ref pgdojo_req php phpVarious phpguide plsql postgres ps r205 realC realwebapp regex rgaki ruby rule sboard sc scprint scquest sdb sdbquest seesaa setup sh_Imagick sh_canvas sh_dotnet sh_google sh_tool sh_web shadowbox shgm shjquery shvbs shweb sjscript skadai skywalker smalltech sperl sqlq src systemdoc tcpip tegaki three toolbox twitter typeface usb useXML vb vbdb vbsfunc vbsguide vbsrc vpc wcsignup webanymind webappgen webclass webparts webtool webwsh win8 winofsql wmi work wp youtube