[Oreilly.Developing.Android.Applications.with.Adobe.AIR.Apr]

本文概述了移动开发领域的关键技术,包括Android和iOS平台的开发、多媒体处理、GPS定位和音频麦克风的使用,以及如何在移动设备上实现高质量的用户体验。重点介绍了设备特性、网络连接检查、屏幕方向调整、数据库管理、文件存储、多点触控手势识别和多媒体事件处理等核心概念。

万恶的破地,将近一个月断网...补笔记ing


-------------------第一章----------------------

The following desktop functionalities arenot supportedon Android

     ActionScript 2, ContextMenu, DatagramSocket, Dockicon, EncryptedLocalStore,  HTMLoader, LocalConnection, NativeMenu, NativeWindow, PrintJob, SecureSocket, ServerSocket, StorageVolumeInfo, SystemTrayIcon, Updater, XMLSignatureValidator 


-------------------第5章----------------------

关于屏幕朝向

The default orientation is up and right: 

                          import flash.events.StageOrientationEvent; 

                          if (stage.supportsOrientationChange) { 
                               stage.addEventListener(StageOrientationEvent.ORIENTATION_CHANGE,onChange); 
                          } 

                          function onChange(event:StageOrientationEvent):void { 
                               trace(event.beforeOrientation); 
                               trace(event.afterOrientation); 
                               // default 
                               // rotatedLeft 
                               // rotatedRight 
                          } 


检查设备网络是否可连接

Unlike with the desktop experience, you cannot assume your user is always connected when using a mobile device. She might be moving in and out of networks. Be prepared to display a message if your application is not able to function because of this. 


You can check the status on URLMonitor for an HTTP request or onSocketMonitor for  socket connection request. Both classes extend from the ServiceMonitor class. 

     import URLMonitor; 
     import SocketMonitor; 
     import flash.net.URLRequest; 
     import flash.events.StatusEvent; 

     var monitor:URLMonitor = new URLMonitor(new URLRequest("http://www.google.com")); 

     monitor.pollInterval = 1000; 
     monitor.addEventListener(StatusEvent.STATUS, onStatus); 
     monitor.start(); 

     function onStatus(event:StatusEvent):void { 
          monitor.stop(); 
          trace(event.code); // Service.available or Service.unavailable 
          trace(event.target.available); // true or false 


-------------------第6章----------------------

如何隐藏屏幕下方的状态栏

By default, your application occupies the screen underneath the 38-pixel-tall status bar that displays information such as network signal, battery life, time, and notifications. If you wish to hide this bar and go full screen, in Flash Professional selectFull Screen under File→AIR Android settings→General. In Flash Builder, add the following node as a child of the<initialWindow> node in the application descriptor: 

     <fullScreen>true</fullScreen> 

监听应用是否处于存活状态

NativeApplication dispatches an exiting event when it starts the closing process. You can register for that event and be prepared to act quickly according to your application needs: 

     import flash.desktop.NativeApplication; 
     import flash.events.Event; 
     function onExit(event:Event):void { 
             // save application's current state 
     } 
However, the Android OS may choose to terminate background processes immediately  if RAM is needed. In some cases, such as receiving a phone call, there isno guarantee that NativeApplication will have a chance to dispatch the exiting event before being shut down. It is therefore a good practice tosave critical data often while the applicationis active. We will discuss how to save data locally later in this chapter. 

关于设备的不同目录

File.ApplicationStorageDirectory, the storage directory allocated to your application. Use this location to savefairly small amounts of data and information such as preferences and user settings.


Externally, data can be saved on the device’s SD card under the File.documentsDirectory directory, also referred to asFile.userDirectory orFile.desktopDirectory. Use this approach for any relativelylarge amounts of data, such as images or video or temporary files. Create a directory with your application name to keep it distinct from other applications’ data. 


Writing to the card requires a permission, which needs to be added to the descriptor file. If you don’t have this permission, AIR will throw a runtime error: 

     <uses-permission android:name= "android.permission.WRITE_EXTERNAL_STORAGE" /> 

Before installing any data, make sure the user’s phone has an SD card: 
     if (File.userDirectory) 
          // proceeds with saving data 


Here is the list of directories and their equivalent paths: 
/data/data/app.appId/app/assets 

           app:/ 
           File.applicationDirectory 

/data/data/app.appID/appID/Local Store 

           app-storage:/ 

/data/data/app.appID/appID/Local Store 
           File.applicationStorageDirectory 

/sdcard 
           File.documentsDirectory 
           File.userDirectory 
           File.desktopDirectory 

/data/data/app.appId/cache 
           File.createTempDirectory() 
           File.createTempFile() 


监听shareObject是否将数据存储成功
If you wish to monitor the save process, create a  String variable to store what the flush method returns. If the result is pending, set a listener to trace the reason the data 
was not stored: 

     import flash.net.SharedObjectFlushStatus; 
     import flash.events.NetStatusEvent; 


     var flushStatus:String = so.flush(); 
     if (flushStatus != null) { 
          switch(flushStatus) { 
               case SharedObjectFlushStatus.PENDING: 
                   so.addEventListener(NetStatusEvent.NET_STATUS, 
                                                    onFlushStatus); 
                   break; 
               case SharedObjectFlushStatus.FLUSHED:
                   trace("success"); 
                   break; 
               } 
          } 

读删文件之前要验证文件是否存在

      if (!file.exists) { 
               return; 
      } 


创建数据库文件

  import flash.filesystem.File; 

     function createDatabase():void { 
          var file:File = 
               File.applicationStorageDirectory.resolvePath("myData.db"); 
          if (file.exists) { 
               trace("I already exist, ready to be used"); 
          } else { 
               trace("I did not exist, now I am created"); 
          } 
     } 


建立数据库连接

                           import flash.data.SQLConnection; 
                           import flash.events.SQLEvent; 
                           import flash.events.SQLErrorEvent; 

                           var connection:SQLConnection; 
                           connection = new SQLConnection(); 

                           try { 
                                connection.open(file); 
                                trace("connection opened"); 
                           } catch(error:Error) { 
                                trace(error.message); 
                           } 


数据库操作-带变量的条件匹配

      var statement:SQLStatement = new SQLStatement(); 
      statement.sqlConnection = connection; 
      var insert:String =  "INSERT INTO geography (country, city) VALUES (:co, :ci)"; 
      statement.text = insert; 
      statement.parameters[":co"] = object.country; 
      statement.parameters[":ci"] = object.city;
     try { 
               statement.execute(); 
               trace("item created"); 
          } catch(error:SQLError) { 
               trace(error.message); 
          } 
      }  


.execute(1)的用法

Instead of requesting the entire table, you may want to receive only one item in the table. Let’s request the country that has New York as a city.Execute(1)only returns 
the item stored under table ID 1: 

     var statement:SQLStatement = new SQLStatement(); 
     statement.sqlConnection = connection; 
     statement.text = "SELECT country FROM geography WHERE city = 'New York'"; 
     try { 
          statement.execute(1); 
          var result:SQLResult = statement.getResult(); 
          if (result.data != null) { 
               trace(result.data[0].country); 
          } 
      } catch(error:Error) { 
          trace("item", error.message); 
      } 

 -------------------第7章----------------------

检测设备是否支持多点触控

Testing support for multitouch is done separately: 

     if (Multitouch.supportsTouchEvents == true) { 
          trace(Multitouch.maxTouchPoints); 
     } 


zoom手势

TransformGestureEvent.GESTURE_ZOOM



rotate手势

TransformGestureEvent.GESTURE_ROTATION


pan手势

TransformGestureEvent.GESTURE_PAN



swipe手势

TransformGestureEvent.GESTURE_SWIPE

Left to right and bottom to top returns -1. Right to left and bottom to top returns 1.


Press and Tap手势

PressAndTapGestureEvent.GESTURE_PRESS_AND_TAP



Two-Finger Tap手势

PressAndTapGestureEvent.GESTURE_TOW_FINGER_TAP



物体拖拽实例




-------------------第7章----------------------

      When using these classes, you should first check at runtime that the user’s device has a motion sensor and that it is available for reading. Look at the value of the isSuppor ted boolean property: 

     import flash.sensors.Accelerometer; 
     if (Accelerometer.isSupported == false) { 
            return; 
     }

The accelerometer muted property is false if the userblocks access to the accelerometer  sensor. Android devices do not provide an option to disable access at the time of this writing, so you can ignore it.

The flash.media.CameraRoll class is a subclass of the EventDispatcher class. It gives you access to the Gallery.It is not supported for AIR desktop applications


-------------------第9章----------------------

A  Media Event.COMPLETE is dispatched after a picture is taken, an  Event.CANCEL if no media is selected, and anErrorEvent if there is an error in the process: 

     cameraUI.addEventListener(MediaEvent.COMPLETE, onComplete); 
     cameraUI.addEventListener(Event.CANCEL, onCancel); 
     cameraUI.addEventListener(ErrorEvent.ERROR, onError); 


EXIF data
Several open source AS3 libraries are available for reading EXIF data. I chose the one by Kenichi Ishibashi. You can download his library using Subversion at  http://code 
.shichiseki.jp/as3/ExifInfo/
.
      import flash.display.Loader; 
      import flash.display.MovieClip; 
      import flash.media.CameraRoll; 
      import flash.media.MediaPromise; 
      import flash.events.MediaEvent; 
      import flash.events.Event; 
      import flash.net.URLRequest 
      import jp.shichiseki.exif.*; 


     var loader:ExifLoader; 
     var cameraRoll:CameraRoll; 


      function Exif1() { 
          if (CameraRoll.supportsBrowseForImage) { 
               init(); 
          } 
      } 

      function init():void { 
          cameraRoll = new CameraRoll(); 
          cameraRoll.addEventListener(MediaEvent.SELECT, onSelect); 
          cameraRoll.browseForImage(); 
      } 


      function onSelect(event:MediaEvent):void { 
          var promise:MediaPromise = event.data as MediaPromise; 
          loader = new ExifLoader(); 
          loader.addEventListener(Event.COMPLETE, imageLoaded); 
          loader.load(new URLRequest(promise.file.url)); 
      } 

     function imageLoaded(event:Event):void { 
          var exif:ExifInfo = loader.exif as ExifInfo; 

          if (exif.thumbnailData) { 
               var thumbLoader:Loader = new Loader(); 
               thumbLoader.loadBytes(exif.thumbnailData); 
               addChild(thumbLoader); 
          } 
      }

-------------------第10章----------------------

关于GPS(global-positoning-system)

                           import flash.sensors.Geolocation; 
                           import flash.events.GeolocationEvent; 

                          var geolocation:Geolocation; 

                           if (Geolocation.isSupported) { 
                               geolocation = new Geolocation(); 
                               geolocation.addEventListener(GeolocationEvent.UPDATE, onTravel); 
                           } 

                           function onTravel(event:GeolocationEvent):void { 
                               trace(event.latitude); 
                               trace(event.longitude); 
                           } 

实时方位更新

     import flash.events.StatusEvent; 

     if (!geolocation.muted) { 
          geolocation.addEventListener(StatusEvent.STATUS, onStatusChange); 
     } else { 
          // inform the user to turn on the location sensor 
     } 

     function onStatusChange(event:StatusEvent):void { 
          trace("status:" + event.code); 
          if (event.code == "Geolocation.Muted") { 
               // inform the user to turn on the location sensor 
          } 
     } 


Using the geolocation API drains the battery very quickly


-------------------第11章----------------------

使用麦克风

     <uses-permission android:name="android.permission.RECORD_AUDIO"/> 

     import flash.media.Microphone; 

     if (Microphone.isSupported) { 
         // continue on 
     }
      var microphone:Microphone = Microphone.getMicrophone(); 

gain works as a volume multiplier and has a value between 0 and 100. The default value is 50 or a multiplier of 1. Any value above 50 boosts the microphone and below reduces it.

activityLevel is a read-only property that returns the amount of sound detected, from 0 to 100. It can be used as a visual aid for users to monitor how loud they should be 
speaking:

计及风电并网运行的微电网及集群电动汽车综合需求侧响应的优化调度策略研究(Matlab代码实现)内容概要:本文研究了计及风电并网运行的微电网及集群电动汽车综合需求侧响应的优化调度策略,并提供了基于Matlab的代码实现。研究聚焦于在高渗透率可再生能源接入背景下,如何协调微电网内部分布式电源、储能系统与大规模电动汽车充电负荷之间的互动关系,通过引入需求侧响应机制,建立多目标优化调度模型,实现系统运行成本最小化、可再生能源消纳最大化以及电网负荷曲线的削峰填谷。文中详细阐述了风电出力不确定性处理、电动汽车集群充放电行为建模、电价型与激励型需求响应机制设计以及优化求解算法的应用。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事新能源、微电网、电动汽车等领域技术研发的工程师。; 使用场景及目标:①用于复现相关硕士论文研究成果,深入理解含高比例风电的微电网优化调度建模方法;②为开展电动汽车参与电网互动(V2G)、需求侧响应等课题提供仿真平台和技术参考;③适用于电力系统优化、能源互联网、综合能源系统等相关领域的教学与科研项目开发。; 阅读建议:建议读者结合文中提供的Matlab代码进行实践操作,重点关注模型构建逻辑与算法实现细节,同时可参考文档中提及的其他相关案例(如储能优化、负荷预测等),以拓宽研究视野并促进交叉创新。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值