flex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject git commit: [flex-asjs] [refs/heads/develop] - Added an example of using Cordova/PhoneGap with FlexJS that makes use of a mobile device's camera and photo library. The example lets you take a photo, or select one from the gallery, and display it using th
Date Fri, 02 May 2014 18:22:40 GMT
Repository: flex-asjs
Updated Branches:
  refs/heads/develop 79fa531b3 -> 28a54c49a


Added an example of using Cordova/PhoneGap with FlexJS that makes use of a mobile device's
camera and photo library. The example lets you take a photo, or select one from the gallery,
and display it using the Image tag. This update includes wrapper classes for the Camera object
in AS and JS.


Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/28a54c49
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/28a54c49
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/28a54c49

Branch: refs/heads/develop
Commit: 28a54c49a114a5d21443806db9778e56cb8b208e
Parents: 79fa531
Author: Peter Ent <pent@apache.org>
Authored: Fri May 2 14:22:28 2014 -0400
Committer: Peter Ent <pent@apache.org>
Committed: Fri May 2 14:22:28 2014 -0400

----------------------------------------------------------------------
 examples/CordovaCameraExample/build.xml         |  45 ++++++++
 .../src/CordovaCameraExample.mxml               |  33 ++++++
 .../CordovaCameraExample/src/MyInitialView.mxml |  67 +++++++++++
 examples/CordovaCameraExample/src/README.txt    |  24 ++++
 examples/build.xml                              |   2 +
 .../as/projects/FlexJSUI/src/FlexJSUIClasses.as |   1 +
 .../src/org/apache/cordova/camera/Camera.as     |  76 +++++++++++++
 .../src/org/apache/cordova/camera/Camera.js     | 113 +++++++++++++++++++
 8 files changed, 361 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/28a54c49/examples/CordovaCameraExample/build.xml
----------------------------------------------------------------------
diff --git a/examples/CordovaCameraExample/build.xml b/examples/CordovaCameraExample/build.xml
new file mode 100644
index 0000000..d8c19ae
--- /dev/null
+++ b/examples/CordovaCameraExample/build.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0"?>
+<!--
+
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+
+-->
+
+
+<project name="cordovacameraexample" default="main" basedir=".">
+    <property name="FLEXJS_HOME" location="../.."/>
+    <property name="example" value="CordovaCameraExample" />
+    
+    <property file="${FLEXJS_HOME}/env.properties"/>
+    <property environment="env"/>
+    <property file="${FLEXJS_HOME}/build.properties"/>
+    <property name="FLEX_HOME" value="${FLEXJS_HOME}"/>
+    <property name="FALCON_HOME" value="${env.FALCON_HOME}"/>
+    <property name="FALCONJX_HOME" value="${env.FALCONJX_HOME}"/>
+    <property name="GOOG_HOME" value="${env.GOOG_HOME}"/>
+    
+    <include file="${basedir}/../build_example.xml" />
+
+    <target name="main" depends="clean,build_example.compile,build_example.compilejs"
description="Clean build of ${example}">
+    </target>
+    
+    <target name="clean">
+        <delete dir="${basedir}/bin" failonerror="false" />
+        <delete dir="${basedir}/bin-debug" failonerror="false" />
+        <delete dir="${basedir}/bin-release" failonerror="false" />
+    </target>    
+    
+</project>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/28a54c49/examples/CordovaCameraExample/src/CordovaCameraExample.mxml
----------------------------------------------------------------------
diff --git a/examples/CordovaCameraExample/src/CordovaCameraExample.mxml b/examples/CordovaCameraExample/src/CordovaCameraExample.mxml
new file mode 100644
index 0000000..c77e690
--- /dev/null
+++ b/examples/CordovaCameraExample/src/CordovaCameraExample.mxml
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!---
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+-->
+<basic:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
+				   xmlns:local="*"
+				   xmlns:models="models.*"
+				   xmlns:basic="library://ns.apache.org/flexjs/basic" 
+				   >
+	
+	<basic:valuesImpl>
+		<basic:SimpleCSSValuesImpl />
+	</basic:valuesImpl>
+	<basic:initialView>
+		<local:MyInitialView />
+	</basic:initialView>
+</basic:Application>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/28a54c49/examples/CordovaCameraExample/src/MyInitialView.mxml
----------------------------------------------------------------------
diff --git a/examples/CordovaCameraExample/src/MyInitialView.mxml b/examples/CordovaCameraExample/src/MyInitialView.mxml
new file mode 100644
index 0000000..6eeeeca
--- /dev/null
+++ b/examples/CordovaCameraExample/src/MyInitialView.mxml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+-->
+<basic:ViewBase xmlns:fx="http://ns.adobe.com/mxml/2009"
+				xmlns:basic="library://ns.apache.org/flexjs/basic"
+				xmlns:local="*" xmlns:media="org.apache.flex.mobile.media.*">
+    <fx:Script>
+        <![CDATA[
+			
+			import org.apache.cordova.camera.Camera;
+			
+			private var cam:org.apache.cordova.camera.Camera = new org.apache.cordova.camera.Camera();
+			
+			public function snapPicture() : void
+			{
+				cam.getPicture(success,failure,{quality:60, destinationType:org.apache.cordova.camera.Camera.DestinationType.FILE_URI});
+			}
+			
+			private function success(data:Object):void
+			{
+				output.text = "Success: "+String(data);
+				image.source = String(data);
+			}
+			
+			private function failure(message:Object):void
+			{
+				output.text = "Failed: "+String(message);
+			}
+			
+			private function onFromPhotoLibrary() : void
+			{
+				cam.getPicture(success,failure,{ quality: 50,
+					destinationType: org.apache.cordova.camera.Camera.DestinationType.FILE_URI,
+					sourceType: org.apache.cordova.camera.Camera.PictureSourceType.PHOTOLIBRARY });
+			}
+			
+		]]>
+    </fx:Script>
+	
+	<fx:Style>
+	
+	</fx:Style>
+	
+	<basic:TextButton text="From Photo Library" x="20" y="20" click="onFromPhotoLibrary()"
/>
+	<basic:TextButton text="Snap Picture" x="20" y="55" click="snapPicture()" />
+	
+	<basic:Label id="output" x="20" y="110" />
+	
+	<basic:Image id="image" x="20" y="200" width="200" height="200" />
+
+</basic:ViewBase>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/28a54c49/examples/CordovaCameraExample/src/README.txt
----------------------------------------------------------------------
diff --git a/examples/CordovaCameraExample/src/README.txt b/examples/CordovaCameraExample/src/README.txt
new file mode 100644
index 0000000..52d21ff
--- /dev/null
+++ b/examples/CordovaCameraExample/src/README.txt
@@ -0,0 +1,24 @@
+Running the CordovaCameraExample on an Android Device
+
+From Flash Builder or the command line, run the FlexJS cross compiler, FalconJX, to build
the HTML/JavaScript version of your app.
+% cd ~/dev/flex-asjs/examples/CordovaCameraExample
+% ant
+
+Go to your mobile development directory:
+%cd ~/mobile
+
+Copy into this directory, the cordova-build.xml ANT script:
+% cp ~/dev/flex-asjs/cordova-build.xml
+
+Create the Cordova project for your FlexJS application:
+% ant -f cordova-build.xml -DPROJECT_NAME=CordovaCameraExample -DTARGET_DIR=. -DPROJECT_DIR=/Users/home/dev/flex-asjs/examples/CordovaCameraExample/
+
+Load the Cordova camera plugin:
+cd CordovaCameraExample
+% cordova plugin add org.apache.cordova.camera
+
+Modify the www/index.html file to include the cordova.js source (place this line with the
other <script> elements):
+<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
+
+Run your app on your connected device:
+% cordova run
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/28a54c49/examples/build.xml
----------------------------------------------------------------------
diff --git a/examples/build.xml b/examples/build.xml
index 9a47b8b..51976ed 100644
--- a/examples/build.xml
+++ b/examples/build.xml
@@ -74,6 +74,7 @@
     </target>
     
     <target name="compile" description="Compile Examples">
+        <ant dir="${basedir}/CordovaCameraExample"/>
         <ant dir="${basedir}/DataBindingTest"/>
         <ant dir="${basedir}/DataGridExample"/>
         <ant dir="${basedir}/FlexJSTest_basic"/>
@@ -103,6 +104,7 @@
     </target>
     
     <target name="clean" description="Cleans all SWCs and their resource bundles">
+        <ant dir="${basedir}/CordovaCameraExample" target="clean"/>
         <ant dir="${basedir}/DataBindingTest" target="clean"/>
         <ant dir="${basedir}/DataGridExample" target="clean"/>
         <ant dir="${basedir}/FlexJSTest_basic" target="clean"/>

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/28a54c49/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as b/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as
index dfcb78d..064128e 100644
--- a/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as
+++ b/frameworks/as/projects/FlexJSUI/src/FlexJSUIClasses.as
@@ -27,6 +27,7 @@ package
  */
 internal class FlexJSUIClasses
 {
+	import org.apache.cordova.camera.Camera; Camera;
 	
 	import org.apache.flex.html.accessories.NumericOnlyTextInputBead; NumericOnlyTextInputBead;
 	import org.apache.flex.html.accessories.PasswordInputBead; PasswordInputBead;

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/28a54c49/frameworks/as/projects/FlexJSUI/src/org/apache/cordova/camera/Camera.as
----------------------------------------------------------------------
diff --git a/frameworks/as/projects/FlexJSUI/src/org/apache/cordova/camera/Camera.as b/frameworks/as/projects/FlexJSUI/src/org/apache/cordova/camera/Camera.as
new file mode 100644
index 0000000..9a8a980
--- /dev/null
+++ b/frameworks/as/projects/FlexJSUI/src/org/apache/cordova/camera/Camera.as
@@ -0,0 +1,76 @@
+////////////////////////////////////////////////////////////////////////////////
+//
+//  Licensed to the Apache Software Foundation (ASF) under one or more
+//  contributor license agreements.  See the NOTICE file distributed with
+//  this work for additional information regarding copyright ownership.
+//  The ASF licenses this file to You under the Apache License, Version 2.0
+//  (the "License"); you may not use this file except in compliance with
+//  the License.  You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+//
+////////////////////////////////////////////////////////////////////////////////
+package org.apache.cordova.camera
+{
+	public class Camera
+	{
+		public static var DestinationType:Object = {
+			DATA_URL : 0,      // Return image as base64-encoded string
+			FILE_URI : 1,      // Return image file URI
+			NATIVE_URI : 2     // Return image native URI (e.g., assets-library:// on iOS or content://
on Android)
+		};
+		
+		public static var PictureSourceType:Object = {
+			PHOTOLIBRARY : 0,
+			CAMERA : 1,
+			SAVEDPHOTOALBUM : 2
+		};
+		
+		public static var EncodingType:Object = {
+			JPEG : 0,               // Return JPEG encoded image
+			PNG : 1                 // Return PNG encoded image
+		};
+		
+		public static var MediaType:Object = {
+			PICTURE: 0,    // allow selection of still pictures only. DEFAULT. Will return format
specified via DestinationType
+			VIDEO: 1,      // allow selection of video only, WILL ALWAYS RETURN FILE_URI
+			ALLMEDIA : 2   // allow selection from all media types
+		};
+		
+		public static var Direction:Object = {
+			BACK : 0,      // Use the back-facing camera
+			FRONT : 1      // Use the front-facing camera
+		};
+
+		public function Camera()
+		{
+			pictureSourceType = Camera.PictureSourceType.PHOTOLIBRARY;
+			destinationType = Camera.DestinationType.DATA_URL;
+			mediaType = Camera.MediaType.PICTURE;
+			encodingType = Camera.EncodingType.JPEG;
+			direction = Camera.Direction.BACK;
+		}
+		
+		public var pictureSourceType:int;
+		public var destinationType:int;
+		public var mediaType:int;
+		public var encodingType:int;
+		public var direction:int;
+		
+		public function getPicture( cameraSuccess:Function, cameraError:Function, cameraOptions:Object
) : void
+		{
+			// stub for JavaScript version
+		}
+		
+		public function cleanup( cameraSuccess:Function, cameraError:Function ) : void
+		{
+			// stub for JavaScript version
+		}
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/28a54c49/frameworks/js/FlexJS/src/org/apache/cordova/camera/Camera.js
----------------------------------------------------------------------
diff --git a/frameworks/js/FlexJS/src/org/apache/cordova/camera/Camera.js b/frameworks/js/FlexJS/src/org/apache/cordova/camera/Camera.js
new file mode 100644
index 0000000..41af8e5
--- /dev/null
+++ b/frameworks/js/FlexJS/src/org/apache/cordova/camera/Camera.js
@@ -0,0 +1,113 @@
+/**
+ * org.apache.cordova.camera.Camera
+ *
+ * @fileoverview
+ *
+ * @suppress {checkTypes}
+ */
+
+goog.provide('org.apache.cordova.camera.Camera');
+
+
+
+/**
+ * @constructor
+ */
+org.apache.cordova.camera.Camera = function() {
+  this.pictureSourceType = org.apache.cordova.camera.Camera.PictureSourceType.PHOTOLIBRARY;
+  this.destinationType = org.apache.cordova.camera.Camera.DestinationType.DATA_URL;
+  this.mediaType = org.apache.cordova.camera.Camera.MediaType.PICTURE;
+  this.encodingType = org.apache.cordova.camera.Camera.EncodingType.JPEG;
+  this.direction = org.apache.cordova.camera.Camera.Direction.BACK;
+};
+
+
+/**
+ * @type {Object}
+ */
+org.apache.cordova.camera.Camera.DestinationType = {DATA_URL: 0, FILE_URI: 1, NATIVE_URI:
2};
+
+
+/**
+ * @type {Object}
+ */
+org.apache.cordova.camera.Camera.PictureSourceType = {PHOTOLIBRARY: 0, CAMERA: 1, SAVEDPHOTOALBUM:
2};
+
+
+/**
+ * @type {Object}
+ */
+org.apache.cordova.camera.Camera.EncodingType = {JPEG: 0, PNG: 1};
+
+
+/**
+ * @type {Object}
+ */
+org.apache.cordova.camera.Camera.MediaType = {PICTURE: 0, VIDEO: 1, ALLMEDIA: 2};
+
+
+/**
+ * @type {Object}
+ */
+org.apache.cordova.camera.Camera.Direction = {BACK: 0, FRONT: 1};
+
+
+/**
+ * @type {number}
+ */
+//org.apache.cordova.camera.Camera.prototype.pictureSourceType;
+
+
+/**
+ * @type {number}
+ */
+//org.apache.cordova.camera.Camera.prototype.destinationType;
+
+
+/**
+ * @type {number}
+ */
+//org.apache.cordova.camera.Camera.prototype.mediaType;
+
+
+/**
+ * @type {number}
+ */
+//org.apache.cordova.camera.Camera.prototype.encodingType;
+
+
+/**
+ * @type {number}
+ */
+//org.apache.cordova.camera.Camera.prototype.direction;
+
+
+/**
+ * @expose
+ * @param {Function} cameraSuccess
+ * @param {Function} cameraError
+ * @param {Object} cameraOptions
+ */
+org.apache.cordova.camera.Camera.prototype.getPicture = function(cameraSuccess, cameraError,
cameraOptions) {
+  navigator.camera.getPicture(cameraSuccess, cameraError, cameraOptions);
+};
+
+
+/**
+ * @expose
+ * @param {Function} cameraSuccess
+ * @param {Function} cameraError
+ */
+org.apache.cordova.camera.Camera.prototype.cleanup = function(cameraSuccess, cameraError)
{
+  navigator.camera.cleanup();
+};
+
+
+/**
+ * Metadata
+ *
+ * @type {Object.<string, Array.<Object>>}
+ */
+org.apache.cordova.camera.Camera.prototype.FLEXJS_CLASS_INFO = {
+  names: [{ name: 'Camera', qName: 'org.apache.cordova.camera.Camera'}]
+};


Mime
View raw message