Ane [original] flexmobile IOS/Android Electronic Compass azimuth (2)

Source: Internet
Author: User

2. Android Azimuth

The general idea is: jar + SWC + related files --- ADT packaging ---> ANE

 

 

1. Android Library

 

Create an android Project (you can skip activity)

Import the flashruntimeextensions. jar package. The package address is as follows:

 

The library project directory is as follows:

 

Implement logical content based on the flashruntimeextensions framework:

The core logic class orientationlistener for obtaining the azimuth is sensoreventlistener:

View code

 Package  Com. yyf. nativeextension;  Import  Android. Hardware. sensor;  Import Android. Hardware. sensorevent;  Import  Android. Hardware. sensoreventlistener;  Import  Android. util. log;  Public   Class Orientationlistener Implements  Sensoreventlistener {  Private  Orientationextensioncontext CTX;  Public  Orientationlistener (orientationextensioncontext CTX ){ This . CTX = CTX ;}@ override  Public   Void Onaccuracychanged (sensor arg0, Int  Arg1 ){  //  Todo auto-generated method stub  } @ Override  Public   Void  Onsensorchanged (sensorevent EVT ){  If (CTX! = Null ) {Stringbuilder s = New Stringbuilder (float. tostring (EVT. Values [0 ]); S. append ( "&"). Append (float. tostring (EVT. Values [1]). append ("&"). append (float. tostring (EVT. Values [2 ]); Log. I ( "Orientationlistener" , S. tostring (); CTX. dispatchstatuseventasync ( "Change" , S. tostring ());}}  Public   Void  Dispose () {log. I ( "Orientationlistener", "dispose");  This . CTX = Null  ;}} 

(Source codeArticleFinally, download is provided)

 

 

2. ActionScript Library

 

This SWC library is responsibleCodeInterfaces for as development

The library project directory is as follows:

See the source code for specific implementation

Here we will mention the file extension. xml

View code

<Extension xmlns = "http://ns.adobe.com/air/extension/3.1"> <ID> COM. yyf. orientation </ID> <versionnumber> 1 </versionnumber> <platforms> <platform name = "Android-arm"> <applicationdeployment> <nativelibrary> orientationnative. jar </nativelibrary> <initializer> COM. yyf. nativeextension. orientationextension </initializer> <finalizer> COM. yyf. nativeextension. orientationextension </finalizer> </applicationdeployment> </platform> </platforms> </extension>

ID: ApplicationProgramWill try this ID

Platform: platform type

Nativelibrary: name of the source Library (here is the android jar package, IOS is.)

Initializer: COM. yyf. nativeextension. orientationextension matches the path in the android library project.

Finalizer: COM. yyf. nativeextension. orientationextension matches the path in the android library project.

(The source code article is finally available for download)

 

 

3. ADT Packaging

 

Create a folder.

Note:

Extension. XML is the extension. xml file corresponding to the ActionScript library.

Anetest. p12 is a self-Signed file, and no signature is provided here.

 

The content in the Android-arm folder is as follows:

Note: catalog.xml library.swf is the file extracted from orientation. SWC.

 

ADT command:

Note: If you are configuring environment variables, go to the absolute path where the flashbuilder package ADT. bat is located.

 

Packaging Commands include:

Note: Do not forget the last space point.

After the package is successful, the com. yyf. Orientation. Ane file is generated in the directory of the same level.

 

 

3. Demo program

 

Import the ANE file to be used:

 

 

After being imported and referenced, app-XML automatically generates the following code:

Note: This ID must be exactly the same as the ID written in extension. XML in The ActionScript library project.

 

Code of the first view:

View code

<? XML version = "1.0" encoding = "UTF-8"?> <S: View xmlns: FX = "http://ns.adobe.com/mxml/2009" Xmlns: S = "Library: // ns.adobe.com/flex/spark" Title = "Homepage View" Creationcomplete = "Viewequalcreationcompletehandler (event)"> <s: layout> <s: verticallayout/> </S: layout> <FX: SCRIPT> <! [CDATA [  Import  Com. yyf. nativeextensions. orientation;  Import  Com. yyf. nativeextensions. orientationevent;  Import  MX. Events. flexevent;  Private VaR g1: Orientation = Null  ;  Protected Function view1_creationcompletehandler (Event: flexevent ): Void  {Trace ( "I am rotate ..." ); Trace (orientation. issupported); LBL. Text = Orientation. issupported. tostring ();  If  (Orientation. issupported) {G1 = New  Orientation (); g1.addeventlistener (orientationevent. Update, onchange1 );}  Else {Trace ( "No orientation" );}}  Private Function onchange1 (E: orientationevent ): Void  {Trace ( "From O1:" + E. x + "" + E. Y + "" + "+ E. z); t1.text = E. x + "" + E. Y + "" + "" + E. Z;}] > </FX: SCRIPT> <FX: declarations> </FX: declarations> <s: vgroup> <s: Label id = "LBL"/> <s: textinput id = "T1"/> </S: vgroup> </S: View>

(The source code article is finally available for download)

 

 

3. Download source code

 

Must be tested on a real machine. Source Code:

Android Library Project:

Http://files.cnblogs.com/loveFlex/OrientationNative.rar

ActionScript Library Project:

Http://files.cnblogs.com/loveFlex/Lib_Orientation.rar

Demo sample program:

Http://files.cnblogs.com/loveFlex/Eg_1.rar

Ane package Folder: (including jar, SWC, and ANE)

Http://files.cnblogs.com/loveFlex/Package_ANE_Android_Orientation.rar

 

 

For original works, you are welcome to comment on them. For reprinting, you must mark the original source, author information, and this statement in the form of a hyperlink. Otherwise, legal liability will be held. Http://www.cnblogs.com/loveflex/archive/2012/07/26/2610391.html :binyy

If you have any questions, contact me, 3q ~

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.