diff --git a/bin/deviceinfo.ane b/bin/deviceinfo.ane index d02126d..33e0675 100644 Binary files a/bin/deviceinfo.ane and b/bin/deviceinfo.ane differ diff --git a/build/default/deviceinfo-default.swc b/build/default/deviceinfo-default.swc index 82b870c..dd0f78d 100644 Binary files a/build/default/deviceinfo-default.swc and b/build/default/deviceinfo-default.swc differ diff --git a/build/deviceinfo.ane b/build/deviceinfo.ane index 7ad04a7..33e0675 100644 Binary files a/build/deviceinfo.ane and b/build/deviceinfo.ane differ diff --git a/build/deviceinfo.swc b/build/deviceinfo.swc index feebeb8..b3b2154 100644 Binary files a/build/deviceinfo.swc and b/build/deviceinfo.swc differ diff --git a/build/extension.xml b/build/extension.xml index 02c45c4..3c81944 100644 --- a/build/extension.xml +++ b/build/extension.xml @@ -1,7 +1,7 @@ com.github.airext.DeviceInfo - 1.0.0 + 1.1.0 diff --git a/build/libDeviceInfo.a b/build/libDeviceInfo.a index 6a17dc1..de06871 100644 Binary files a/build/libDeviceInfo.a and b/build/libDeviceInfo.a differ diff --git a/build/platform.xml b/build/platform.xml index d7c3d07..14933c4 100644 --- a/build/platform.xml +++ b/build/platform.xml @@ -2,7 +2,7 @@ 6.0 - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/deviceinfo-air/deviceinfo-debug/src/DeviceInfoDebug.as b/deviceinfo-air/deviceinfo-debug/src/DeviceInfoDebugStarling.as similarity index 84% rename from deviceinfo-air/deviceinfo-debug/src/DeviceInfoDebug.as rename to deviceinfo-air/deviceinfo-debug/src/DeviceInfoDebugStarling.as index 828b727..474e03d 100644 --- a/deviceinfo-air/deviceinfo-debug/src/DeviceInfoDebug.as +++ b/deviceinfo-air/deviceinfo-debug/src/DeviceInfoDebugStarling.as @@ -1,6 +1,7 @@ package { import com.github.airext.DeviceInfo; +import com.github.airext.data.DeviceInfoGeneral; import flash.display.Sprite; import flash.display.StageAlign; @@ -8,9 +9,9 @@ import flash.display.StageScaleMode; import flash.events.Event; import flash.text.TextField; -public class DeviceInfoDebug extends Sprite +public class DeviceInfoDebugStarling extends Sprite { - public function DeviceInfoDebug() + public function DeviceInfoDebugStarling() { super(); @@ -19,8 +20,8 @@ public class DeviceInfoDebug extends Sprite { tf.text += "getting imei... \n"; - tf.text += "imei: " + DeviceInfo.getInstance().getIMEI() + "\n"; - trace(DeviceInfo.getInstance().getIMEI()); + tf.text += "imei: " + DeviceInfo.sharedInstance().getIMEI() + "\n"; + trace(DeviceInfo.sharedInstance().getIMEI()); } ); @@ -29,8 +30,8 @@ public class DeviceInfoDebug extends Sprite { tf.text += "getting identifier... \n"; - tf.text += "deviceIdentifier: " + DeviceInfo.getInstance().getDeviceIdentifier() + "\n"; - trace(DeviceInfo.getInstance().getDeviceIdentifier()); + tf.text += "getVendorIdentifier: " + DeviceInfo.sharedInstance().general.ios.getVendorIdentifier() + "\n"; + trace(DeviceInfo.sharedInstance().general.ios.getVendorIdentifier()); } ); @@ -39,7 +40,7 @@ public class DeviceInfoDebug extends Sprite { tf.text += "getting info... \n"; - var info:Object = DeviceInfo.getInstance().getDeviceInfo() || {}; + var info:DeviceInfoGeneral = DeviceInfo.sharedInstance().general || {}; tf.text += "name: " + info.name + "\n"; tf.text += "model: " + info.model + "\n"; diff --git a/deviceinfo-air/deviceinfo-default/src/com/github/airext/data/DeviceInfoBattery.as b/deviceinfo-air/deviceinfo-default/src/com/github/airext/data/DeviceInfoBattery.as new file mode 100644 index 0000000..68688bb --- /dev/null +++ b/deviceinfo-air/deviceinfo-default/src/com/github/airext/data/DeviceInfoBattery.as @@ -0,0 +1,118 @@ +/** + * Created by mobitile on 10/22/14. + */ +package com.github.airext.data +{ +import flash.events.Event; +import flash.events.EventDispatcher; +import flash.system.Capabilities; + +public class DeviceInfoBattery extends EventDispatcher +{ + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + public function DeviceInfoBattery() + { + super(); + } + + //-------------------------------------------------------------------------- + // + // Properties + // + //-------------------------------------------------------------------------- + + //------------------------------------ + // level + //------------------------------------ + + private var _level:Number; + + [Bindable(event="levelChanged")] + public function get level():Number + { + if (isNaN(_level)) + { + _level = getLevel(); + } + + return _level; + } + + private function setLevel(value:Number):void + { + if (value == _level) return; + _level = value; + dispatchEvent(new Event("levelChanged")); + } + + //------------------------------------ + // state + //------------------------------------ + + private var _state:String; + + [Bindable(event="stateChanged")] + public function get state():String + { + if (_state == null) + { + _state = getState(); + } + + return _state; + } + + private function setState(value:String):void + { + if (value == _state) return; + _state = value; + dispatchEvent(new Event("stateChanged")); + } + + //-------------------------------------------------------------------------- + // + // Methods + // + //-------------------------------------------------------------------------- + + public function getLevel():Number + { + trace("DeviceInfo is not supported for " + Capabilities.os); + + return null; + } + + public function getState():String + { + trace("DeviceInfo is not supported for " + Capabilities.os); + + return null; + } + + public function startMonitoring():void + { + trace("DeviceInfo is not supported for " + Capabilities.os); + } + + public function stopMonitoring():void + { + trace("DeviceInfo is not supported for " + Capabilities.os); + } + + //-------------------------------------------------------------------------- + // + // Overridden methods + // + //-------------------------------------------------------------------------- + + override public function toString():String + { + return '[DeviceInfoBattery level="'+_level+'", state="'+_state+'"]'; + } +} +} diff --git a/deviceinfo-air/deviceinfo-default/src/com/github/airext/data/DeviceInfoGeneral.as b/deviceinfo-air/deviceinfo-default/src/com/github/airext/data/DeviceInfoGeneral.as new file mode 100644 index 0000000..14c780e --- /dev/null +++ b/deviceinfo-air/deviceinfo-default/src/com/github/airext/data/DeviceInfoGeneral.as @@ -0,0 +1,109 @@ +/** + * Created by mobitile on 10/22/14. + */ +package com.github.airext.data +{ + +public class DeviceInfoGeneral +{ + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + public function DeviceInfoGeneral() + { + super(); + } + + //-------------------------------------------------------------------------- + // + // Properties + // + //-------------------------------------------------------------------------- + + //------------------------------------- + // name + //------------------------------------- + + public var name:String; + + //------------------------------------- + // model + //------------------------------------- + + public var model:String; + + //------------------------------------- + // manufacturer + //------------------------------------- + + public var manufacturer:String; + + //------------------------------------- + // systemName + //------------------------------------- + + public var systemName:String; + + //------------------------------------- + // systemVersion + //------------------------------------- + + public var systemVersion:String; + + //------------------------------------- + // platform + //------------------------------------- + + public var platform:String; + + //-------------------------------------------------------------------------- + // + // Platform-specific properties + // + //-------------------------------------------------------------------------- + + //------------------------------------- + // ios + //------------------------------------- + + private var _ios:DeviceInfoGeneralIOS; + + public function get ios():DeviceInfoGeneralIOS + { + if (_ios == null) + { + _ios = new DeviceInfoGeneralIOS(); + } + + return _ios; + } + + //------------------------------------- + // osx + //------------------------------------- + + //------------------------------------- + // win + //------------------------------------- + + //-------------------------------------------------------------------------- + // + // Methods + // + //-------------------------------------------------------------------------- + + public function toString():String + { + return '[DeviceInfoGeneral ' + + 'name="'+name+'", ' + + 'model="'+model+'", ' + + 'manufacturer="'+manufacturer+', ' + + 'systemName="'+systemName+'", ' + + 'systemVersion="'+systemVersion+'", ' + + 'ios="'+ios+'"]'; + } +} +} diff --git a/deviceinfo-air/deviceinfo-default/src/com/github/airext/data/DeviceInfoGeneralAndroid.as b/deviceinfo-air/deviceinfo-default/src/com/github/airext/data/DeviceInfoGeneralAndroid.as new file mode 100644 index 0000000..b179f0e --- /dev/null +++ b/deviceinfo-air/deviceinfo-default/src/com/github/airext/data/DeviceInfoGeneralAndroid.as @@ -0,0 +1,19 @@ +/** + * Created by mobitile on 10/23/14. + */ +package com.github.airext.data +{ +public class DeviceInfoGeneralAndroid +{ + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + public function DeviceInfoGeneralAndroid() + { + super(); + } +} +} diff --git a/deviceinfo-air/deviceinfo-default/src/com/github/airext/data/DeviceInfoGeneralIOS.as b/deviceinfo-air/deviceinfo-default/src/com/github/airext/data/DeviceInfoGeneralIOS.as new file mode 100644 index 0000000..9fa049d --- /dev/null +++ b/deviceinfo-air/deviceinfo-default/src/com/github/airext/data/DeviceInfoGeneralIOS.as @@ -0,0 +1,34 @@ +/** + * Created by mobitile on 10/22/14. + */ +package com.github.airext.data +{ +import flash.system.Capabilities; + +public class DeviceInfoGeneralIOS +{ + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + public function DeviceInfoGeneralIOS() + { + super(); + } + + //-------------------------------------------------------------------------- + // + // Methods + // + //-------------------------------------------------------------------------- + + public function getVendorIdentifier():String + { + trace("DeviceInfo is not supported for " + Capabilities.os); + + return null; + } +} +} diff --git a/deviceinfo-air/deviceinfo-default/src/com/github/airext/data/DeviceInfoNetwork.as b/deviceinfo-air/deviceinfo-default/src/com/github/airext/data/DeviceInfoNetwork.as new file mode 100644 index 0000000..b49c52b --- /dev/null +++ b/deviceinfo-air/deviceinfo-default/src/com/github/airext/data/DeviceInfoNetwork.as @@ -0,0 +1,12 @@ +/** + * Created by mobitile on 10/22/14. + */ +package com.github.airext.data +{ +public class DeviceInfoNetwork +{ + public function DeviceInfoNetwork() + { + } +} +} diff --git a/deviceinfo-air/deviceinfo-default/src/com/github/airext/enum/DeviceInfoBatteryState.as b/deviceinfo-air/deviceinfo-default/src/com/github/airext/enum/DeviceInfoBatteryState.as new file mode 100644 index 0000000..1a912a1 --- /dev/null +++ b/deviceinfo-air/deviceinfo-default/src/com/github/airext/enum/DeviceInfoBatteryState.as @@ -0,0 +1,13 @@ +/** + * Created by mobitile on 10/23/14. + */ +package com.github.airext.enum +{ +public class DeviceInfoBatteryState +{ + public static const FULL:String = "full"; + public static const CHARGING:String = "charging"; + public static const UNPLUGGED:String = "unplugged"; + public static const UNKNOWN:String = "unknown"; +} +} diff --git a/deviceinfo-air/deviceinfo-default/src/com/github/airext/enum/DeviceInfoPlatform.as b/deviceinfo-air/deviceinfo-default/src/com/github/airext/enum/DeviceInfoGeneralPlatform.as similarity index 88% rename from deviceinfo-air/deviceinfo-default/src/com/github/airext/enum/DeviceInfoPlatform.as rename to deviceinfo-air/deviceinfo-default/src/com/github/airext/enum/DeviceInfoGeneralPlatform.as index 453a20d..ba40d68 100644 --- a/deviceinfo-air/deviceinfo-default/src/com/github/airext/enum/DeviceInfoPlatform.as +++ b/deviceinfo-air/deviceinfo-default/src/com/github/airext/enum/DeviceInfoGeneralPlatform.as @@ -7,7 +7,7 @@ */ package com.github.airext.enum { -public class DeviceInfoPlatform +public class DeviceInfoGeneralPlatform { public static const IOS:String = "ios"; diff --git a/deviceinfo-air/deviceinfo-default/src/com/github/airext/events/DeviceInfoBatteryEvent.as b/deviceinfo-air/deviceinfo-default/src/com/github/airext/events/DeviceInfoBatteryEvent.as new file mode 100644 index 0000000..957eb97 --- /dev/null +++ b/deviceinfo-air/deviceinfo-default/src/com/github/airext/events/DeviceInfoBatteryEvent.as @@ -0,0 +1,16 @@ +/** + * Created by mobitile on 10/23/14. + */ +package com.github.airext.events +{ +public class DeviceInfoBatteryEvent +{ + public static const BATTERY_LEVEL_CHANGE:String = "batteryLevelChange"; + public static const BATTERY_STATE_CHANGE:String = "batteryStateChange"; + + public function DeviceInfoBatteryEvent() + { + super(); + } +} +} diff --git a/deviceinfo-air/deviceinfo/src/com/github/airext/DeviceInfo.as b/deviceinfo-air/deviceinfo/src/com/github/airext/DeviceInfo.as index 06c10b9..266806a 100644 --- a/deviceinfo-air/deviceinfo/src/com/github/airext/DeviceInfo.as +++ b/deviceinfo-air/deviceinfo/src/com/github/airext/DeviceInfo.as @@ -8,10 +8,14 @@ package com.github.airext { import com.github.airext.core.device_info; +import com.github.airext.data.DeviceInfoBattery; +import com.github.airext.data.DeviceInfoGeneral; import flash.events.StatusEvent; import flash.external.ExtensionContext; +import flash.net.registerClassAlias; +import flash.system.Capabilities; use namespace device_info; @@ -33,7 +37,7 @@ public class DeviceInfo private static var _context:ExtensionContext; - private static function get context():ExtensionContext + device_info static function get context():ExtensionContext { if (_context == null) { @@ -56,7 +60,7 @@ public class DeviceInfo private static var instance:DeviceInfo; - public static function getInstance():DeviceInfo + public static function sharedInstance():DeviceInfo { if (instance == null) { @@ -66,6 +70,16 @@ public class DeviceInfo return instance; } + //-------------------------------------------------------------------------- + // + // Static initialization + // + //-------------------------------------------------------------------------- + + { + registerClassAlias("com.github.airext.data.DeviceInfoGeneral", DeviceInfoGeneral); + } + //-------------------------------------------------------------------------- // // Constructor @@ -75,34 +89,89 @@ public class DeviceInfo public function DeviceInfo() { super(); - - context.addEventListener(StatusEvent.STATUS, statusHandler); } //-------------------------------------------------------------------------- // - // Methods + // Properties // //-------------------------------------------------------------------------- - public function getIMEI():String + //------------------------------------- + // imei + //------------------------------------- + + private var _imei:String; + + public function get imei():String { - return context.call("getIMEI") as String; + if (_imei == null) + { + _imei = getIMEI(); + } + + return _imei; } - public function getPlatform():String + //------------------------------------- + // general + //------------------------------------- + + private var _general:DeviceInfoGeneral; + + public function get general():DeviceInfoGeneral { - return context.call("getPlatform") as String; + if (_general == null) + { + _general = getGeneral(); + } + + return _general; } - public function getDeviceInfo():Object + //------------------------------------- + // battery + //------------------------------------- + + private var _battery:DeviceInfoBattery; + + public function get battery():DeviceInfoBattery { - return context.call("getDeviceInfo"); + if (_battery == null) + { + _battery = getBattery(); + } + + return _battery; } - public function getDeviceIdentifier():String + //------------------------------------- + // network + //------------------------------------- + + //------------------------------------- + // display + //------------------------------------- + + //-------------------------------------------------------------------------- + // + // Methods + // + //-------------------------------------------------------------------------- + + public function getGeneral():DeviceInfoGeneral + { + return context.call("getGeneralInfo") as DeviceInfoGeneral; + } + + public function getBattery():DeviceInfoBattery { - return context.call("getDeviceIdentifier") as String; + return new DeviceInfoBattery(); + } + + public function getIMEI():String + { + return context.call("getIMEI") as String; } //-------------------------------------------------------------------------- diff --git a/deviceinfo-air/deviceinfo/src/com/github/airext/data/DeviceInfoBattery.as b/deviceinfo-air/deviceinfo/src/com/github/airext/data/DeviceInfoBattery.as new file mode 100644 index 0000000..4aa466c --- /dev/null +++ b/deviceinfo-air/deviceinfo/src/com/github/airext/data/DeviceInfoBattery.as @@ -0,0 +1,166 @@ +/** + * Created by mobitile on 10/22/14. + */ +package com.github.airext.data +{ +import com.github.airext.DeviceInfo; +import com.github.airext.core.device_info; + +import flash.events.Event; +import flash.events.EventDispatcher; +import flash.events.StatusEvent; + +use namespace device_info; + +public class DeviceInfoBattery extends EventDispatcher +{ + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + public function DeviceInfoBattery() + { + super(); + } + + //-------------------------------------------------------------------------- + // + // Variables + // + //-------------------------------------------------------------------------- + + private var isMonitoring:Boolean = false; + + //-------------------------------------------------------------------------- + // + // Properties + // + //-------------------------------------------------------------------------- + + //------------------------------------ + // level + //------------------------------------ + + private var _level:Number; + + [Bindable(event="levelChanged")] + public function get level():Number + { + if (isNaN(_level)) + { + _level = getLevel(); + } + + return _level; + } + + private function setLevel(value:Number):void + { + if (value == _level) return; + _level = value; + dispatchEvent(new Event("levelChanged")); + } + + //------------------------------------ + // state + //------------------------------------ + + private var _state:String; + + [Bindable(event="stateChanged")] + public function get state():String + { + if (_state == null) + { + _state = getState(); + } + + return _state; + } + + private function setState(value:String):void + { + if (value == _state) return; + _state = value; + dispatchEvent(new Event("stateChanged")); + } + + //-------------------------------------------------------------------------- + // + // Methods + // + //-------------------------------------------------------------------------- + + public function getLevel():Number + { + return DeviceInfo.context.call("getBatteryLevel") as Number; + } + + public function getState():String + { + return DeviceInfo.context.call("getBatteryState") as String; + } + + public function startMonitoring():void + { + if (!isMonitoring) + { + DeviceInfo.context.addEventListener(StatusEvent.STATUS, statusHandler); + + DeviceInfo.context.call("startBatteryMonitor"); + + isMonitoring = true; + } + } + + public function stopMonitoring():void + { + if (isMonitoring) + { + DeviceInfo.context.removeEventListener(StatusEvent.STATUS, statusHandler); + + DeviceInfo.context.call("stopBatteryMonitor"); + + isMonitoring = false; + } + } + + //-------------------------------------------------------------------------- + // + // Overridden methods + // + //-------------------------------------------------------------------------- + + override public function toString():String + { + return '[DeviceInfoBattery level="'+_level+'", state="'+_state+'"]'; + } + + //-------------------------------------------------------------------------- + // + // Event handler + // + //-------------------------------------------------------------------------- + + private function statusHandler(event:StatusEvent):void + { + switch (event.code) + { + case "DeviceInfo.Battery.State.Change" : + + setState(event.level); + + break; + + case "DeviceInfo.Battery.Level.Change" : + + setLevel(parseFloat(event.level)); + + break; + } + } + +} +} diff --git a/deviceinfo-air/deviceinfo/src/com/github/airext/data/DeviceInfoGeneral.as b/deviceinfo-air/deviceinfo/src/com/github/airext/data/DeviceInfoGeneral.as new file mode 100644 index 0000000..759bc47 --- /dev/null +++ b/deviceinfo-air/deviceinfo/src/com/github/airext/data/DeviceInfoGeneral.as @@ -0,0 +1,113 @@ +/** + * Created by mobitile on 10/22/14. + */ +package com.github.airext.data +{ +import com.github.airext.DeviceInfo; +import com.github.airext.core.device_info; + +use namespace device_info; + +public class DeviceInfoGeneral +{ + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + public function DeviceInfoGeneral() + { + super(); + } + + //-------------------------------------------------------------------------- + // + // Properties + // + //-------------------------------------------------------------------------- + + //------------------------------------- + // name + //------------------------------------- + + public var name:String; + + //------------------------------------- + // model + //------------------------------------- + + public var model:String; + + //------------------------------------- + // manufacturer + //------------------------------------- + + public var manufacturer:String; + + //------------------------------------- + // systemName + //------------------------------------- + + public var systemName:String; + + //------------------------------------- + // systemVersion + //------------------------------------- + + public var systemVersion:String; + + //------------------------------------- + // platform + //------------------------------------- + + public var platform:String; + + //-------------------------------------------------------------------------- + // + // Platform-specific properties + // + //-------------------------------------------------------------------------- + + //------------------------------------- + // ios + //------------------------------------- + + private var _ios:DeviceInfoGeneralIOS; + + public function get ios():DeviceInfoGeneralIOS + { + if (_ios == null) + { + _ios = new DeviceInfoGeneralIOS(); + } + + return _ios; + } + + //------------------------------------- + // osx + //------------------------------------- + + //------------------------------------- + // win + //------------------------------------- + + //-------------------------------------------------------------------------- + // + // Methods + // + //-------------------------------------------------------------------------- + + public function toString():String + { + return '[DeviceInfoGeneral ' + + 'name="'+name+'", ' + + 'model="'+model+'", ' + + 'manufacturer="'+manufacturer+', ' + + 'systemName="'+systemName+'", ' + + 'systemVersion="'+systemVersion+'", ' + + 'ios="'+ios+'"]'; + } +} +} diff --git a/deviceinfo-air/deviceinfo/src/com/github/airext/data/DeviceInfoGeneralAndroid.as b/deviceinfo-air/deviceinfo/src/com/github/airext/data/DeviceInfoGeneralAndroid.as new file mode 100644 index 0000000..ddecbd7 --- /dev/null +++ b/deviceinfo-air/deviceinfo/src/com/github/airext/data/DeviceInfoGeneralAndroid.as @@ -0,0 +1,24 @@ +/** + * Created by mobitile on 10/23/14. + */ +package com.github.airext.data +{ +import com.github.airext.DeviceInfo; +import com.github.airext.core.device_info; + +use namespace device_info; + +public class DeviceInfoGeneralAndroid +{ + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + public function DeviceInfoGeneralAndroid() + { + super(); + } +} +} diff --git a/deviceinfo-air/deviceinfo/src/com/github/airext/data/DeviceInfoGeneralIOS.as b/deviceinfo-air/deviceinfo/src/com/github/airext/data/DeviceInfoGeneralIOS.as new file mode 100644 index 0000000..f2c1296 --- /dev/null +++ b/deviceinfo-air/deviceinfo/src/com/github/airext/data/DeviceInfoGeneralIOS.as @@ -0,0 +1,35 @@ +/** + * Created by mobitile on 10/22/14. + */ +package com.github.airext.data +{ +import com.github.airext.DeviceInfo; +import com.github.airext.core.device_info; + +use namespace device_info; + +public class DeviceInfoGeneralIOS +{ + //-------------------------------------------------------------------------- + // + // Constructor + // + //-------------------------------------------------------------------------- + + public function DeviceInfoGeneralIOS() + { + super(); + } + + //-------------------------------------------------------------------------- + // + // Methods + // + //-------------------------------------------------------------------------- + + public function getVendorIdentifier():String + { + return DeviceInfo.context.call("iosGetVendorIdentifier") as String; + } +} +} diff --git a/deviceinfo-air/deviceinfo/src/com/github/airext/data/DeviceInfoNetwork.as b/deviceinfo-air/deviceinfo/src/com/github/airext/data/DeviceInfoNetwork.as new file mode 100644 index 0000000..b49c52b --- /dev/null +++ b/deviceinfo-air/deviceinfo/src/com/github/airext/data/DeviceInfoNetwork.as @@ -0,0 +1,12 @@ +/** + * Created by mobitile on 10/22/14. + */ +package com.github.airext.data +{ +public class DeviceInfoNetwork +{ + public function DeviceInfoNetwork() + { + } +} +} diff --git a/deviceinfo-air/deviceinfo/src/com/github/airext/enum/DeviceInfoBatteryState.as b/deviceinfo-air/deviceinfo/src/com/github/airext/enum/DeviceInfoBatteryState.as new file mode 100644 index 0000000..1a912a1 --- /dev/null +++ b/deviceinfo-air/deviceinfo/src/com/github/airext/enum/DeviceInfoBatteryState.as @@ -0,0 +1,13 @@ +/** + * Created by mobitile on 10/23/14. + */ +package com.github.airext.enum +{ +public class DeviceInfoBatteryState +{ + public static const FULL:String = "full"; + public static const CHARGING:String = "charging"; + public static const UNPLUGGED:String = "unplugged"; + public static const UNKNOWN:String = "unknown"; +} +} diff --git a/deviceinfo-air/deviceinfo/src/com/github/airext/enum/DeviceInfoPlatform.as b/deviceinfo-air/deviceinfo/src/com/github/airext/enum/DeviceInfoGeneralPlatform.as similarity index 88% rename from deviceinfo-air/deviceinfo/src/com/github/airext/enum/DeviceInfoPlatform.as rename to deviceinfo-air/deviceinfo/src/com/github/airext/enum/DeviceInfoGeneralPlatform.as index 453a20d..ba40d68 100644 --- a/deviceinfo-air/deviceinfo/src/com/github/airext/enum/DeviceInfoPlatform.as +++ b/deviceinfo-air/deviceinfo/src/com/github/airext/enum/DeviceInfoGeneralPlatform.as @@ -7,7 +7,7 @@ */ package com.github.airext.enum { -public class DeviceInfoPlatform +public class DeviceInfoGeneralPlatform { public static const IOS:String = "ios"; diff --git a/deviceinfo-air/deviceinfo/src/com/github/airext/events/DeviceInfoBatteryEvent.as b/deviceinfo-air/deviceinfo/src/com/github/airext/events/DeviceInfoBatteryEvent.as new file mode 100644 index 0000000..957eb97 --- /dev/null +++ b/deviceinfo-air/deviceinfo/src/com/github/airext/events/DeviceInfoBatteryEvent.as @@ -0,0 +1,16 @@ +/** + * Created by mobitile on 10/23/14. + */ +package com.github.airext.events +{ +public class DeviceInfoBatteryEvent +{ + public static const BATTERY_LEVEL_CHANGE:String = "batteryLevelChange"; + public static const BATTERY_STATE_CHANGE:String = "batteryStateChange"; + + public function DeviceInfoBatteryEvent() + { + super(); + } +} +} diff --git a/deviceinfo-ios/DeviceInfo/DeviceInfo.xcodeproj/project.pbxproj b/deviceinfo-ios/DeviceInfo/DeviceInfo.xcodeproj/project.pbxproj index db463c8..ad3f40a 100644 --- a/deviceinfo-ios/DeviceInfo/DeviceInfo.xcodeproj/project.pbxproj +++ b/deviceinfo-ios/DeviceInfo/DeviceInfo.xcodeproj/project.pbxproj @@ -30,6 +30,12 @@ 0E22C81117FDBA3D00A828A8 /* ANXDeviceInfoConversionRoutines.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E22C81017FDBA3D00A828A8 /* ANXDeviceInfoConversionRoutines.m */; }; 0E22C81A17FDC3F800A828A8 /* ANXDeviceInfoFacade.m in Sources */ = {isa = PBXBuildFile; fileRef = 0E22C81917FDC3F800A828A8 /* ANXDeviceInfoFacade.m */; }; 0E22C81E17FEB28100A828A8 /* libDeviceInfo.a in CopyFiles */ = {isa = PBXBuildFile; fileRef = 0E22C7AD17FD891D00A828A8 /* libDeviceInfo.a */; }; + 0EBAC15519F91D590038A137 /* ANXDeviceInfoGeneral.h in Headers */ = {isa = PBXBuildFile; fileRef = 0EBAC15319F91D590038A137 /* ANXDeviceInfoGeneral.h */; }; + 0EBAC15619F91D590038A137 /* ANXDeviceInfoGeneral.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EBAC15419F91D590038A137 /* ANXDeviceInfoGeneral.m */; }; + 0EBC743819F90BF400054F57 /* ANXDeviceInfoGeneralProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 0EBC743619F90BF400054F57 /* ANXDeviceInfoGeneralProvider.h */; }; + 0EBC743919F90BF400054F57 /* ANXDeviceInfoGeneralProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EBC743719F90BF400054F57 /* ANXDeviceInfoGeneralProvider.m */; }; + 0EDB3FFE19FA280B0080256C /* ANXDeviceInfoBattery.h in Headers */ = {isa = PBXBuildFile; fileRef = 0EDB3FFC19FA280B0080256C /* ANXDeviceInfoBattery.h */; }; + 0EDB3FFF19FA280B0080256C /* ANXDeviceInfoBattery.m in Sources */ = {isa = PBXBuildFile; fileRef = 0EDB3FFD19FA280B0080256C /* ANXDeviceInfoBattery.m */; }; 0EDD1CF718191BAC00B1FF6F /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0EDD1CF618191BAC00B1FF6F /* CoreTelephony.framework */; }; /* End PBXBuildFile section */ @@ -101,6 +107,12 @@ 0E22C81017FDBA3D00A828A8 /* ANXDeviceInfoConversionRoutines.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANXDeviceInfoConversionRoutines.m; sourceTree = ""; }; 0E22C81817FDC30900A828A8 /* ANXDeviceInfoFacade.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANXDeviceInfoFacade.h; sourceTree = ""; }; 0E22C81917FDC3F800A828A8 /* ANXDeviceInfoFacade.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANXDeviceInfoFacade.m; sourceTree = ""; }; + 0EBAC15319F91D590038A137 /* ANXDeviceInfoGeneral.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANXDeviceInfoGeneral.h; sourceTree = ""; }; + 0EBAC15419F91D590038A137 /* ANXDeviceInfoGeneral.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANXDeviceInfoGeneral.m; sourceTree = ""; }; + 0EBC743619F90BF400054F57 /* ANXDeviceInfoGeneralProvider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANXDeviceInfoGeneralProvider.h; sourceTree = ""; }; + 0EBC743719F90BF400054F57 /* ANXDeviceInfoGeneralProvider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANXDeviceInfoGeneralProvider.m; sourceTree = ""; }; + 0EDB3FFC19FA280B0080256C /* ANXDeviceInfoBattery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ANXDeviceInfoBattery.h; sourceTree = ""; }; + 0EDB3FFD19FA280B0080256C /* ANXDeviceInfoBattery.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ANXDeviceInfoBattery.m; sourceTree = ""; }; 0EDD1CF618191BAC00B1FF6F /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; }; /* End PBXFileReference section */ @@ -175,14 +187,6 @@ name = "Supporting Files"; sourceTree = ""; }; - 0E10F56C19F7993F004A7E69 /* Supporting Files */ = { - isa = PBXGroup; - children = ( - 0E0CA0D119F7A0A3003C5176 /* FlashRuntimeExtensions.h */, - ); - name = "Supporting Files"; - sourceTree = ""; - }; 0E22C7A417FD891D00A828A8 = { isa = PBXGroup; children = ( @@ -219,14 +223,19 @@ 0E22C7B217FD891D00A828A8 /* DeviceInfo */ = { isa = PBXGroup; children = ( - 0E10F56C19F7993F004A7E69 /* Supporting Files */, + 0E22C7B317FD891D00A828A8 /* Supporting Files */, 0E22C81917FDC3F800A828A8 /* ANXDeviceInfoFacade.m */, 0E22C81817FDC30900A828A8 /* ANXDeviceInfoFacade.h */, 0E22C7B517FD891D00A828A8 /* ANXDeviceInfo.h */, 0E22C7B717FD891D00A828A8 /* ANXDeviceInfo.m */, 0E22C80F17FDBA3D00A828A8 /* ANXDeviceInfoConversionRoutines.h */, 0E22C81017FDBA3D00A828A8 /* ANXDeviceInfoConversionRoutines.m */, - 0E22C7B317FD891D00A828A8 /* Supporting Files */, + 0EBC743619F90BF400054F57 /* ANXDeviceInfoGeneralProvider.h */, + 0EBAC15319F91D590038A137 /* ANXDeviceInfoGeneral.h */, + 0EBAC15419F91D590038A137 /* ANXDeviceInfoGeneral.m */, + 0EBC743719F90BF400054F57 /* ANXDeviceInfoGeneralProvider.m */, + 0EDB3FFC19FA280B0080256C /* ANXDeviceInfoBattery.h */, + 0EDB3FFD19FA280B0080256C /* ANXDeviceInfoBattery.m */, ); path = DeviceInfo; sourceTree = ""; @@ -234,6 +243,7 @@ 0E22C7B317FD891D00A828A8 /* Supporting Files */ = { isa = PBXGroup; children = ( + 0E0CA0D119F7A0A3003C5176 /* FlashRuntimeExtensions.h */, 0E22C7B417FD891D00A828A8 /* DeviceInfo-Prefix.pch */, ); name = "Supporting Files"; @@ -273,6 +283,9 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 0EBC743819F90BF400054F57 /* ANXDeviceInfoGeneralProvider.h in Headers */, + 0EBAC15519F91D590038A137 /* ANXDeviceInfoGeneral.h in Headers */, + 0EDB3FFE19FA280B0080256C /* ANXDeviceInfoBattery.h in Headers */, 0E0CA0D219F7A0A3003C5176 /* FlashRuntimeExtensions.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; @@ -425,7 +438,10 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 0EBAC15619F91D590038A137 /* ANXDeviceInfoGeneral.m in Sources */, + 0EDB3FFF19FA280B0080256C /* ANXDeviceInfoBattery.m in Sources */, 0E22C7B817FD891D00A828A8 /* ANXDeviceInfo.m in Sources */, + 0EBC743919F90BF400054F57 /* ANXDeviceInfoGeneralProvider.m in Sources */, 0E22C81117FDBA3D00A828A8 /* ANXDeviceInfoConversionRoutines.m in Sources */, 0E22C81A17FDC3F800A828A8 /* ANXDeviceInfoFacade.m in Sources */, ); @@ -675,6 +691,7 @@ 0E0CA0F919F7A6D2003C5176 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 0E22C7A817FD891D00A828A8 /* Build configuration list for PBXProject "DeviceInfo" */ = { isa = XCConfigurationList; diff --git a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfo.h b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfo.h index b6c5a3d..5010c94 100644 --- a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfo.h +++ b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfo.h @@ -12,16 +12,36 @@ #import "FlashRuntimeExtensions.h" +#import "ANXDeviceInfoGeneral.h" + #import "ANXDeviceInfoConversionRoutines.h" @interface ANXDeviceInfo : NSObject +#pragma mark Shared Instance + + (ANXDeviceInfo*) sharedInstance; -- (NSString*) getIMEI; +#pragma mark Properties + +@property FREContext context; + +#pragma mark API Funcitons + +-(BOOL) isSupported; + +-(ANXDeviceInfoGeneral*) getGeneralInfo; + +-(NSString *) getIMEI; + +-(NSString *) getVendorIdentifier; + +#pragma mark Dispatch events + +-(void) dispatch: (NSString *) code withLevel: (NSString *) level; -- (NSDictionary*) getDeviceInfo; +-(void) dispatchError: (NSString *)code; -- (NSString*) getDeviceIdentifier; +-(void) dispatchStatus: (NSString *)code; @end \ No newline at end of file diff --git a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfo.m b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfo.m index cf6425b..ae10029 100644 --- a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfo.m +++ b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfo.m @@ -6,6 +6,8 @@ // Copyright (c) 2013 Max Rozdobudko. All rights reserved. // +#import + #import "ANXDeviceInfo.h" @implementation ANXDeviceInfo @@ -24,45 +26,30 @@ + (ANXDeviceInfo*) sharedInstance return _sharedInstance; } -- (NSString*) getIMEI +#pragma mark Properties + +@synthesize context; + +#pragma mark API Funcitons + +-(BOOL) isSupported { - NSLog(@"ANXDeviceInfo.getIMEI"); - - return nil; + return YES; } -- (NSDictionary*) getDeviceInfo +-(ANXDeviceInfoGeneral *) getGeneralInfo { - NSLog(@"ANXDeviceInfo.getDeviceInfo"); - - NSMutableDictionary* result; - - @try - { - result = [NSMutableDictionary dictionary]; - - UIDevice* device = [UIDevice currentDevice]; - - [result setObject:device.name forKey:@"name"]; - [result setObject:device.model forKey:@"model"]; - [result setObject:device.systemName forKey:@"systemName"]; - [result setObject:device.systemVersion forKey:@"systemVersion"]; - - [result setObject:@"Apple" forKey:@"manufacturer"]; - } - @catch (NSException *exception) - { - NSLog(@"ANXDeviceInfo.getDeviceInfo: %@", exception); - } - @finally - { - // does nothing - } + return [[ANXDeviceInfoGeneral alloc] init]; +} + +- (NSString*) getIMEI +{ + NSLog(@"[DeviceInfo] Warning: IMEI is not supported on iOS."); - return result; + return nil; } -- (NSString*) getDeviceIdentifier +-(NSString *) getVendorIdentifier { NSUUID* id = [[UIDevice currentDevice] identifierForVendor]; @@ -72,4 +59,21 @@ - (NSString*) getDeviceIdentifier return nil; } +#pragma mark Dispatch events + +-(void) dispatch: (NSString *) code withLevel: (NSString *) level +{ + FREDispatchStatusEventAsync(context, (const uint8_t*) [code UTF8String], (const uint8_t*) [level UTF8String]); +} + +-(void) dispatchError: (NSString *)code +{ + [self dispatch:code withLevel:@"error"]; +} + +-(void) dispatchStatus: (NSString *)code +{ + [self dispatch:code withLevel:@"status"]; +} + @end \ No newline at end of file diff --git a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoBattery.h b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoBattery.h new file mode 100644 index 0000000..69c3bf9 --- /dev/null +++ b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoBattery.h @@ -0,0 +1,25 @@ +// +// ANXDeviceInfoBattery.h +// DeviceInfo +// +// Created by Max Rozdobudko on 10/24/14. +// Copyright (c) 2014 Max Rozdobudko. All rights reserved. +// + +#import + +#import + +#import "ANXDeviceInfo.h" + +@interface ANXDeviceInfoBattery : NSObject + ++(float) getBatteryLevel; + ++(NSString *) getBatteryState; + ++(void) startMonitoring; + ++(void) stopMonitoring; + +@end diff --git a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoBattery.m b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoBattery.m new file mode 100644 index 0000000..9d291e9 --- /dev/null +++ b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoBattery.m @@ -0,0 +1,126 @@ +// +// ANXDeviceInfoBattery.m +// DeviceInfo +// +// Created by Max Rozdobudko on 10/24/14. +// Copyright (c) 2014 Max Rozdobudko. All rights reserved. +// + +#import "ANXDeviceInfoBattery.h" + +@implementation ANXDeviceInfoBattery + +BOOL isMonitoring = NO; + +id batteryStateChangeObserver; + +id batteryLevelChangeObserver; + ++(float) getBatteryLevel +{ + UIDevice *device = [UIDevice currentDevice]; + + float batteryLevel = 0.0; + + if (device.isBatteryMonitoringEnabled) + { + batteryLevel = device.batteryLevel; + } + else + { + [device setBatteryMonitoringEnabled:YES]; + + batteryLevel = device.batteryLevel; + + [device setBatteryMonitoringEnabled:NO]; + + } + + return batteryLevel; +} + ++(NSString *) getBatteryState +{ + UIDevice *device = [UIDevice currentDevice]; + + UIDeviceBatteryState batteryState; + + if (device.isBatteryMonitoringEnabled) + { + batteryState = device.batteryState; + } + else + { + [device setBatteryMonitoringEnabled:YES]; + + batteryState = device.batteryState; + + [device setBatteryMonitoringEnabled:NO]; + } + + switch (batteryState) + { + case UIDeviceBatteryStateCharging: + return @"charging"; + break; + + case UIDeviceBatteryStateFull: + return @"full"; + break; + + case UIDeviceBatteryStateUnplugged: + return @"unplugged"; + break; + + case UIDeviceBatteryStateUnknown : + default: + return @"unknown"; + break; + } +} + ++(void) startMonitoring +{ + if (!isMonitoring) + { + [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES]; + + batteryStateChangeObserver = + [[NSNotificationCenter defaultCenter] + addObserverForName:UIDeviceBatteryStateDidChangeNotification + object:nil queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + [[ANXDeviceInfo sharedInstance] dispatch:@"DeviceInfo.Battery.State" withLevel:[self getBatteryState]]; + }]; + + + batteryLevelChangeObserver = + [[NSNotificationCenter defaultCenter] + addObserverForName:UIDeviceBatteryLevelDidChangeNotification + object:nil queue:[NSOperationQueue mainQueue] + usingBlock:^(NSNotification *note) + { + NSString *levelAsString = [NSString stringWithFormat:@"%f", [self getBatteryLevel]]; + + [[ANXDeviceInfo sharedInstance] dispatch:@"DeviceInfo.Battery.Level" withLevel:levelAsString]; + }]; + + isMonitoring = YES; + } +} + ++(void) stopMonitoring +{ + if (isMonitoring) + { + [[UIDevice currentDevice] setBatteryMonitoringEnabled:NO]; + + [[NSNotificationCenter defaultCenter] removeObserver:batteryStateChangeObserver]; + [[NSNotificationCenter defaultCenter] removeObserver:batteryLevelChangeObserver]; + + isMonitoring = NO; + } +} + +@end diff --git a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoConversionRoutines.h b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoConversionRoutines.h index e989afc..fd085b3 100644 --- a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoConversionRoutines.h +++ b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoConversionRoutines.h @@ -12,12 +12,21 @@ @interface ANXDeviceInfoConversionRoutines : NSObject -+ (FREResult) convertFREStringToNSString:(FREObject) string asString:(NSString**) toString; -+ (FREResult) convertNSStringToFREString:(NSString*) string asString:(FREObject*) toString; +#pragma mark Write object's properties -+ (FREResult) convertFREDateToNSDate:(FREObject) date asDate:(NSDate**) toDate; -+ (FREResult) convertNSDateToFREDate:(NSDate*) date asDate:(FREObject*) toDate; ++(void) setStringTo: (FREObject) object withValue: (NSString *) value forProperty: (NSString *) property; -+ (FREResult) convertNSDictionaryToFREObject:(NSDictionary*) dictionary asObject:(FREObject*) toObject; +#pragma mark Conversion methods + ++(FREObject) convertNSStringToFREObject:(NSString*) string; ++(NSString*) convertFREObjectToNSString: (FREObject) string; + ++(NSDate*) convertFREObjectToNSDate: (FREObject) date; + ++(NSUInteger) convertFREObjectToNSUInteger: (FREObject) integer withDefault: (NSUInteger) defaultValue; + ++(FREObject) convertLongLongToFREObject: (long long) number; + ++(double) convertFREObjectToDouble: (FREObject) number; @end diff --git a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoConversionRoutines.m b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoConversionRoutines.m index 2b3fb8b..ddd53e5 100644 --- a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoConversionRoutines.m +++ b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoConversionRoutines.m @@ -14,96 +14,111 @@ @implementation ANXDeviceInfoConversionRoutines -+ (FREResult) convertFREStringToNSString:(FREObject) string asString:(NSString**) toString +#pragma mark Write object's properties + ++(void) setStringTo: (FREObject) object withValue: (NSString *) value forProperty: (NSString *) property { - FREResult result; + FREObject temp = [self convertNSStringToFREObject: value]; - uint32_t length = 0; - const uint8_t* tempValue = NULL; + if (temp == NULL) + { + return; + } - result = FREGetObjectAsUTF8(string, &length, &tempValue); + FRESetObjectProperty(object, (const uint8_t*) [property UTF8String], temp, NULL); +} + +#pragma mark Conversion methods + ++(FREObject) convertNSStringToFREObject:(NSString*) string +{ + if (string == nil) return NULL; - if(result != FRE_OK) return result; + const char* utf8String = string.UTF8String; + + unsigned long length = strlen( utf8String ); - *toString = [NSString stringWithUTF8String: (char*) tempValue]; + FREObject converted; + FREResult result = FRENewObjectFromUTF8((uint32_t) length + 1, (const uint8_t*) utf8String, &converted); - return FRE_OK; + if (result != FRE_OK) + return NULL; + + return converted; } -+ (FREResult) convertNSStringToFREString:(NSString*) string asString:(FREObject*) toString ++(NSString*) convertFREObjectToNSString: (FREObject) string { - if (string == nil) return FRE_INVALID_ARGUMENT; + FREResult result; - const char* utf8String = string.UTF8String; + uint32_t length = 0; + const uint8_t* tempValue = NULL; - unsigned long length = strlen( utf8String ); + result = FREGetObjectAsUTF8(string, &length, &tempValue); - return FRENewObjectFromUTF8((uint32_t)length + 1, (const uint8_t*) utf8String, toString); + if (result != FRE_OK) + return nil; + + return [NSString stringWithUTF8String: (char*) tempValue]; } -+ (FREResult) convertFREDateToNSDate:(FREObject) date asDate:(NSDate**) toDate + ++(NSDate*) convertFREObjectToNSDate: (FREObject) date { FREResult result; FREObject time; result = FREGetObjectProperty(date, (const uint8_t*) "time", &time, NULL); - if (result != FRE_OK) return result; + + if (result != FRE_OK) + return nil; NSTimeInterval interval; + result = FREGetObjectAsDouble(time, &interval); - if (result != FRE_OK) return result; - interval = interval / 1000; + if (result != FRE_OK) + return nil; - *toDate = [NSDate dateWithTimeIntervalSince1970:interval]; + interval = interval / 1000; - return result; + return [NSDate dateWithTimeIntervalSince1970:interval]; } -+ (FREResult) convertNSDateToFREDate:(NSDate*) date asDate:(FREObject*) toDate ++(NSUInteger) convertFREObjectToNSUInteger: (FREObject) integer withDefault: (NSUInteger) defaultValue; { - NSTimeInterval timestamp = date.timeIntervalSince1970 * 1000; - FREResult result; - FREObject time; - result = FRENewObjectFromDouble( timestamp, &time ); - if( result != FRE_OK ) return result; - result = FRENewObject( (const uint8_t*) "Date", 0, NULL, toDate, NULL ); - if( result != FRE_OK ) return result; - result = FRESetObjectProperty( *toDate, (const uint8_t*) "time", time, NULL); - if( result != FRE_OK ) return result; + uint32_t tempValue; + + result = FREGetObjectAsUint32(integer, &tempValue); - return FRE_OK; + if (result != FRE_OK) + return defaultValue; + + return (NSUInteger) tempValue; } -+ (FREResult) convertNSDictionaryToFREObject:(NSDictionary*) dictionary asObject:(FREObject*) toObject ++(FREObject) convertLongLongToFREObject: (long long) number { - FREResult result; + FREObject result; + FRENewObjectFromUint32((uint32_t) number, &result); - result = FRENewObject((const uint8_t*) "Object", 0, NULL, toObject, NULL); - if (result != FRE_OK) return result; + return result; +} + ++(double) convertFREObjectToDouble: (FREObject) number +{ + FREResult result; - NSArray* keys = [dictionary allKeys]; - NSArray* vals = [dictionary allValues]; + double value; - NSUInteger n = [keys count]; + result = FREGetObjectAsDouble(number, &value); - for (NSUInteger i = 0; i < n; i++) - { - FREObject propertyKey; - result = [self convertNSStringToFREString:[keys objectAtIndex:i] asString:&propertyKey]; - if (result != FRE_OK) return result; - - FREObject propertyValue; - result = [self convertNSStringToFREString:[vals objectAtIndex:i] asString:&propertyValue]; - if (result != FRE_OK) return result; - - result = FRESetObjectProperty(*toObject, propertyKey, propertyValue, NULL); - if (result != FRE_OK) return result; - } + if (result != FRE_OK) + return 0.0; - return result; + return value; } @end diff --git a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoFacade.h b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoFacade.h index da24a82..50feb11 100644 --- a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoFacade.h +++ b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoFacade.h @@ -12,6 +12,8 @@ #import "ANXDeviceInfo.h" +#import "ANXDeviceInfoBattery.h" + #pragma mark API FREObject ANXDeviceInfoIsSupported(FREContext context, void* functionData, uint32_t argc, FREObject argv[]); @@ -22,7 +24,7 @@ FREObject ANXDeviceInfoGetPlatform(FREContext context, void* functionData, uint3 FREObject ANXDeviceInfoGetDeviceInfo(FREContext context, void* functionData, uint32_t argc, FREObject argv[]); -FREObject ANXDeviceInfoGetDeviceIdentifier(FREContext context, void* functionData, uint32_t argc, FREObject argv[]); +FREObject ANXDeviceInfoGetVendorIdentifier(FREContext context, void* functionData, uint32_t argc, FREObject argv[]); #pragma mark ContextInitialize/ContextFinalizer diff --git a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoFacade.m b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoFacade.m index ed419a8..d7ea5ad 100644 --- a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoFacade.m +++ b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoFacade.m @@ -8,85 +8,72 @@ #import "ANXDeviceInfoFacade.h" -#pragma mark API +#pragma mark General API FREObject ANXDeviceInfoIsSupported(FREContext context, void* functionData, uint32_t argc, FREObject argv[]) { FREObject result; - FRENewObjectFromBool(TRUE, &result); + FRENewObjectFromBool([[ANXDeviceInfo sharedInstance] isSupported], &result); return result; } FREObject ANXDeviceInfoGetIMEI(FREContext context, void* functionData, uint32_t argc, FREObject argv[]) { - FREObject result; - - [ANXDeviceInfoConversionRoutines convertNSStringToFREString:[[ANXDeviceInfo sharedInstance] getIMEI] asString:&result]; - - return result; + return [ANXDeviceInfoConversionRoutines convertNSStringToFREObject:[[ANXDeviceInfo sharedInstance] getIMEI]]; } -FREObject ANXDeviceInfoGetPlatform(FREContext context, void* functionData, uint32_t argc, FREObject argv[]) +FREObject ANXDeviceInfoGetGeneralInfo(FREContext context, void* functionData, uint32_t argc, FREObject argv[]) { - FREObject result; + ANXDeviceInfoGeneral *general = [[ANXDeviceInfo sharedInstance] getGeneralInfo]; - FRENewObjectFromUTF8(4, (const uint8_t*) "ios", &result); - - return result; + return [general toFREOject]; } -FREObject ANXDeviceInfoGetDeviceInfo(FREContext context, void* functionData, uint32_t argc, FREObject argv[]) +#pragma mark Battery API + +FREObject ANXDeviceInfoGetBatteryLevel(FREContext context, void* functionData, uint32_t argc, FREObject argv[]) { - FREObject result; - - NSDictionary* info = [[ANXDeviceInfo sharedInstance] getDeviceInfo]; - - FRENewObject((const uint8_t*) "Object", 0, NULL, &result, NULL); - - FREObject name; - [ANXDeviceInfoConversionRoutines convertNSStringToFREString:[info objectForKey:@"name"] asString:&name]; - FRESetObjectProperty(result, (const uint8_t*) "name", name, NULL); - - FREObject model; - [ANXDeviceInfoConversionRoutines convertNSStringToFREString:[info objectForKey:@"model"] asString:&model]; - FRESetObjectProperty(result, (const uint8_t*) "model", model, NULL); - - FREObject manufacturer; - [ANXDeviceInfoConversionRoutines convertNSStringToFREString:[info objectForKey:@"manufacturer"] asString:&manufacturer]; - FRESetObjectProperty(result, (const uint8_t*) "manufacturer", manufacturer, NULL); - - FREObject systemName; - [ANXDeviceInfoConversionRoutines convertNSStringToFREString:[info objectForKey:@"systemName"] asString:&systemName]; - FRESetObjectProperty(result, (const uint8_t*) "systemName", systemName, NULL); - - FREObject systemVersion; - [ANXDeviceInfoConversionRoutines convertNSStringToFREString:[info objectForKey:@"systemVersion"] asString:&systemVersion]; - FRESetObjectProperty(result, (const uint8_t*) "systemVersion", systemVersion, NULL); - -// [FRETypeConversion convertNSDictionaryToFREObject:[[DeviceInfo sharedInstance] getDeviceInfo] asObject:&result]; - - return result; + return [ANXDeviceInfoConversionRoutines convertLongLongToFREObject:(long long)[ANXDeviceInfoBattery getBatteryLevel]]; } -FREObject ANXDeviceInfoGetDeviceIdentifier(FREContext context, void* functionData, uint32_t argc, FREObject argv[]) +FREObject ANXDeviceInfoGetBatteryState(FREContext context, void* functionData, uint32_t argc, FREObject argv[]) { - FREObject result; + return [ANXDeviceInfoConversionRoutines convertNSStringToFREObject:[ANXDeviceInfoBattery getBatteryState]]; +} + +FREObject ANXDeviceInfoStartBatteryMonitoring(FREContext context, void* functionData, uint32_t argc, FREObject argv[]) +{ + [ANXDeviceInfoBattery startMonitoring]; - [ANXDeviceInfoConversionRoutines convertNSStringToFREString:[[ANXDeviceInfo sharedInstance] getDeviceIdentifier] asString:&result]; + return NULL; +} + +FREObject ANXDeviceInfoStopBatteryMonitoring(FREContext context, void* functionData, uint32_t argc, FREObject argv[]) +{ + [ANXDeviceInfoBattery stopMonitoring]; - return result; + return NULL; +} + +#pragma mark iOS specific API + +FREObject ANXDeviceInfoGetVendorIdentifier(FREContext context, void* functionData, uint32_t argc, FREObject argv[]) +{ + return [ANXDeviceInfoConversionRoutines convertNSStringToFREObject:[[ANXDeviceInfo sharedInstance] getVendorIdentifier]]; } #pragma mark ContextInitialize/ContextFinalizer void ANXDeviceInfoContextInitializer(void* extData, const uint8_t* ctxType, FREContext ctx, uint32_t* numFunctionsToTest, const FRENamedFunction** functionsToSet) { - *numFunctionsToTest = 5; + *numFunctionsToTest = 8; FRENamedFunction* func = (FRENamedFunction*) malloc(sizeof(FRENamedFunction) * (*numFunctionsToTest)); + // general + func[0].name = (const uint8_t*) "isSupported"; func[0].functionData = NULL; func[0].function = &ANXDeviceInfoIsSupported; @@ -95,24 +82,43 @@ void ANXDeviceInfoContextInitializer(void* extData, const uint8_t* ctxType, FREC func[1].functionData = NULL; func[1].function = &ANXDeviceInfoGetIMEI; - func[2].name = (const uint8_t*) "getDeviceInfo"; + func[2].name = (const uint8_t*) "getGeneralInfo"; func[2].functionData = NULL; - func[2].function = &ANXDeviceInfoGetDeviceInfo; + func[2].function = &ANXDeviceInfoGetGeneralInfo; + + // battery - func[3].name = (const uint8_t*) "getPlatform"; + func[3].name = (const uint8_t*) "getBatteryLevel"; func[3].functionData = NULL; - func[3].function = &ANXDeviceInfoGetPlatform; + func[3].function = &ANXDeviceInfoGetBatteryLevel; - func[4].name = (const uint8_t*) "getDeviceIdentifier"; + func[4].name = (const uint8_t*) "getBatteryState"; func[4].functionData = NULL; - func[4].function = &ANXDeviceInfoGetDeviceIdentifier; + func[4].function = &ANXDeviceInfoGetBatteryState; + + + func[5].name = (const uint8_t*) "startBatteryMonitoring"; + func[5].functionData = NULL; + func[5].function = &ANXDeviceInfoStartBatteryMonitoring; + + func[6].name = (const uint8_t*) "stopBatteryMonitoring"; + func[6].functionData = NULL; + func[6].function = &ANXDeviceInfoStopBatteryMonitoring; + + // ios + + func[7].name = (const uint8_t*) "iosGetVendorIdentifier"; + func[7].functionData = NULL; + func[7].function = &ANXDeviceInfoGetVendorIdentifier; *functionsToSet = func; + + [ANXDeviceInfo sharedInstance].context = ctx; } void ANXDeviceInfoContextFinalizer(FREContext ctx) { - + [ANXDeviceInfo sharedInstance].context = nil; } #pragma mark Initializer/Finalizer diff --git a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoGeneral.h b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoGeneral.h new file mode 100644 index 0000000..f7b111e --- /dev/null +++ b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoGeneral.h @@ -0,0 +1,21 @@ +// +// ANXDeviceInfoGeneral.h +// DeviceInfo +// +// Created by Max Rozdobudko on 10/23/14. +// Copyright (c) 2014 Max Rozdobudko. All rights reserved. +// + +#import + +#import + +#import "FlashRuntimeExtensions.h" + +#import "ANXDeviceInfoConversionRoutines.h" + +@interface ANXDeviceInfoGeneral : NSObject + +-(FREObject) toFREOject; + +@end diff --git a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoGeneral.m b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoGeneral.m new file mode 100644 index 0000000..807aca8 --- /dev/null +++ b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoGeneral.m @@ -0,0 +1,48 @@ +// +// ANXDeviceInfoGeneral.m +// DeviceInfo +// +// Created by Max Rozdobudko on 10/23/14. +// Copyright (c) 2014 Max Rozdobudko. All rights reserved. +// + +#import "ANXDeviceInfoGeneral.h" + +@implementation ANXDeviceInfoGeneral + +-(FREObject) toFREOject +{ + @try + { + FREResult result; + + FREObject info; + result = FRENewObject((const uint8_t *) "com.github.airext.data.DeviceInfoGeneral", 0, NULL, &info, NULL); + + if (result != FRE_OK) + return NULL; + + UIDevice* device = [UIDevice currentDevice]; + + [ANXDeviceInfoConversionRoutines setStringTo:info withValue:device.name forProperty:@"name"]; + [ANXDeviceInfoConversionRoutines setStringTo:info withValue:device.model forProperty:@"model"]; + [ANXDeviceInfoConversionRoutines setStringTo:info withValue:device.systemName forProperty:@"systemName"]; + [ANXDeviceInfoConversionRoutines setStringTo:info withValue:device.systemVersion forProperty:@"systemVersion"]; + [ANXDeviceInfoConversionRoutines setStringTo:info withValue:@"Apple" forProperty:@"manufacturer"]; + [ANXDeviceInfoConversionRoutines setStringTo:info withValue:@"ios" forProperty:@"platform"]; + + return info; + } + @catch (NSException *exception) + { + NSLog(@"[DeviceInfo] Error: %@", [exception description]); + } + @finally + { + // does nothing + } + + return NULL; +} + +@end diff --git a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoGeneralProvider.h b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoGeneralProvider.h new file mode 100644 index 0000000..87f6600 --- /dev/null +++ b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoGeneralProvider.h @@ -0,0 +1,19 @@ +// +// ANXDeviceInfoGeneralProvider.h +// DeviceInfo +// +// Created by Max Rozdobudko on 10/23/14. +// Copyright (c) 2014 Max Rozdobudko. All rights reserved. +// + +#import + +#import + +#import "FlashRuntimeExtensions.h" + +@interface ANXDeviceInfoGeneralProvider : NSObject + ++(FREObject) getGeneralInfo; + +@end diff --git a/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoGeneralProvider.m b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoGeneralProvider.m new file mode 100644 index 0000000..06c8e06 --- /dev/null +++ b/deviceinfo-ios/DeviceInfo/DeviceInfo/ANXDeviceInfoGeneralProvider.m @@ -0,0 +1,49 @@ +// +// ANXDeviceInfoGeneralProvider.m +// DeviceInfo +// +// Created by Max Rozdobudko on 10/23/14. +// Copyright (c) 2014 Max Rozdobudko. All rights reserved. +// + +#import "ANXDeviceInfoGeneralProvider.h" + +#import "ANXDeviceInfo.h" + +@implementation ANXDeviceInfoGeneralProvider + ++(FREObject) getGeneralInfo +{ + @try + { + FREResult result; + + FREObject info; + result = FRENewObject((const uint8_t *) "com.github.airext.data.DeviceInfoGeneral", 0, NULL, &info, NULL); + + if (result != FRE_OK) + return NULL; + + UIDevice* device = [UIDevice currentDevice]; + + [ANXDeviceInfoConversionRoutines setStringTo:info withValue:device.name forProperty:@"name"]; + [ANXDeviceInfoConversionRoutines setStringTo:info withValue:device.model forProperty:@"model"]; + [ANXDeviceInfoConversionRoutines setStringTo:info withValue:device.systemName forProperty:@"systemName"]; + [ANXDeviceInfoConversionRoutines setStringTo:info withValue:device.systemVersion forProperty:@"systemVersion"]; + [ANXDeviceInfoConversionRoutines setStringTo:info withValue:@"Apple" forProperty:@"manufacturer"]; + + return info; + } + @catch (NSException *exception) + { + [[ANXDeviceInfo sharedInstance] dispatch:@"DeviceInfo.GeneralInfo.Get.Failed" withLevel:[exception description]]; + } + @finally + { + // does nothing + } + + return NULL; +} + +@end