You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ma...@apache.org on 2012/06/06 16:46:50 UTC
[3/7] android commit: Changing all tabs to spaces
Changing all tabs to spaces
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/6d1e0356
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/6d1e0356
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/6d1e0356
Branch: refs/heads/master
Commit: 6d1e0356ac65db16ea8a0b4e3141640159ce6ac5
Parents: adfdb16
Author: macdonst <si...@gmail.com>
Authored: Tue Jun 5 09:49:50 2012 -0400
Committer: macdonst <si...@gmail.com>
Committed: Tue Jun 5 09:49:50 2012 -0400
----------------------------------------------------------------------
framework/.project | 60 +-
framework/AndroidManifest.xml | 12 +-
framework/assets/www/index.html | 2 +-
framework/build.xml | 12 +-
framework/default.properties | 4 +-
framework/res/layout/main.xml | 6 +-
framework/res/values/strings.xml | 2 +-
framework/res/xml/cordova.xml | 16 +-
framework/res/xml/plugins.xml | 2 +-
framework/src/com/phonegap/api/LOG.java | 2 +-
framework/src/com/phonegap/api/PluginManager.java | 2 +-
framework/src/com/phonegap/api/PluginResult.java | 38 +-
.../src/org/apache/cordova/AccelListener.java | 109 +--
framework/src/org/apache/cordova/App.java | 196 ++--
framework/src/org/apache/cordova/AudioHandler.java | 430 +++++-----
framework/src/org/apache/cordova/AudioPlayer.java | 740 +++++++-------
.../org/apache/cordova/AuthenticationToken.java | 24 +-
.../src/org/apache/cordova/BatteryListener.java | 52 +-
.../src/org/apache/cordova/CallbackServer.java | 615 ++++++------
.../src/org/apache/cordova/CameraLauncher.java | 140 ++--
framework/src/org/apache/cordova/Capture.java | 78 +-
.../src/org/apache/cordova/CompassListener.java | 62 +-
.../src/org/apache/cordova/ContactAccessor.java | 28 +-
.../org/apache/cordova/ContactAccessorSdk5.java | 555 ++++++------
.../src/org/apache/cordova/ContactManager.java | 4 +-
.../org/apache/cordova/CordovaChromeClient.java | 56 +-
.../apache/cordova/CordovaLocationListener.java | 246 +++---
.../org/apache/cordova/CordovaWebViewClient.java | 53 +-
framework/src/org/apache/cordova/Device.java | 54 +-
.../src/org/apache/cordova/DirectoryManager.java | 204 ++--
framework/src/org/apache/cordova/DroidGap.java | 375 ++++----
framework/src/org/apache/cordova/ExifHelper.java | 28 +-
framework/src/org/apache/cordova/FileTransfer.java | 6 +-
.../src/org/apache/cordova/FileUploadResult.java | 18 +-
framework/src/org/apache/cordova/FileUtils.java | 13 +-
framework/src/org/apache/cordova/GPSListener.java | 40 +-
framework/src/org/apache/cordova/GeoBroker.java | 168 ++--
framework/src/org/apache/cordova/HttpHandler.java | 96 +-
.../cordova/LinearLayoutSoftKeyboardDetect.java | 29 +-
.../src/org/apache/cordova/NetworkListener.java | 6 +-
.../src/org/apache/cordova/NetworkManager.java | 50 +-
framework/src/org/apache/cordova/Notification.java | 54 +-
framework/src/org/apache/cordova/StandAlone.java | 17 +-
framework/src/org/apache/cordova/Storage.java | 400 ++++----
framework/src/org/apache/cordova/TempListener.java | 126 ++--
.../org/apache/cordova/api/CordovaInterface.java | 43 +-
framework/src/org/apache/cordova/api/IPlugin.java | 90 +-
framework/src/org/apache/cordova/api/LOG.java | 52 +-
framework/src/org/apache/cordova/api/Plugin.java | 152 ++--
.../src/org/apache/cordova/api/PluginEntry.java | 10 +-
.../src/org/apache/cordova/api/PluginManager.java | 38 +-
.../src/org/apache/cordova/api/PluginResult.java | 186 ++--
.../org/apache/cordova/file/EncodingException.java | 8 +-
.../apache/cordova/file/FileExistsException.java | 6 +-
.../cordova/file/InvalidModificationException.java | 6 +-
.../file/NoModificationAllowedException.java | 6 +-
.../apache/cordova/file/TypeMismatchException.java | 6 +-
57 files changed, 2903 insertions(+), 2930 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/.project
----------------------------------------------------------------------
diff --git a/framework/.project b/framework/.project
index 56d6763..ed4a955 100644
--- a/framework/.project
+++ b/framework/.project
@@ -1,33 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>Cordova</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>com.android.ide.eclipse.adt.ApkBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
+ <name>Cordova</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>com.android.ide.eclipse.adt.ApkBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>com.android.ide.eclipse.adt.AndroidNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
</projectDescription>
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/AndroidManifest.xml
----------------------------------------------------------------------
diff --git a/framework/AndroidManifest.xml b/framework/AndroidManifest.xml
index 316009b..a267683 100755
--- a/framework/AndroidManifest.xml
+++ b/framework/AndroidManifest.xml
@@ -1,5 +1,5 @@
<?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
@@ -39,12 +39,12 @@
<uses-permission android:name="android.permission.RECORD_VIDEO"/>
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
- <uses-permission android:name="android.permission.WRITE_CONTACTS" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <uses-permission android:name="android.permission.WRITE_CONTACTS" />
+ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
-
+
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
@@ -57,7 +57,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
- <activity android:name="org.apache.cordova.DroidGap" android:label="@string/app_name"
+ <activity android:name="org.apache.cordova.DroidGap" android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
<intent-filter>
</intent-filter>
@@ -65,4 +65,4 @@
</application>
<uses-sdk android:minSdkVersion="2" />
-</manifest>
+</manifest>
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/assets/www/index.html
----------------------------------------------------------------------
diff --git a/framework/assets/www/index.html b/framework/assets/www/index.html
index 1f39dc5..1a51674 100644
--- a/framework/assets/www/index.html
+++ b/framework/assets/www/index.html
@@ -1,4 +1,4 @@
-<!--
+<!--
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
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/build.xml
----------------------------------------------------------------------
diff --git a/framework/build.xml b/framework/build.xml
index 452a8d6..5554bc6 100644
--- a/framework/build.xml
+++ b/framework/build.xml
@@ -1,5 +1,5 @@
<?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
@@ -51,7 +51,7 @@
-->
<property file="ant.properties" />
-
+
<!-- We need to setup the double quote. -->
<property name="dblQuote">"</property>
@@ -110,10 +110,10 @@
<!-- Combine JavaScript files into one cordova-uncompressed.js file. -->
<target name="build-javascript" depends="clean">
-
+
<!-- Clean up existing files -->
<!--<delete file="assets/www/cordova_${version}.js"/>-->
-
+
<!-- Create uncompressed JS file -->
<concat destfile="assets/www/cordova-${version}.js">
<filelist dir="assets/js" files="cordova.android.js"/>
@@ -121,8 +121,8 @@
<!-- update project files to reference cordova-x.x.x.min.js -->
<replaceregexp match="cordova(.*)\.js" replace="cordova-${version}.js" byline="true">
- <fileset file="assets/www/index.html" />
- <fileset file="../bin/templates/project/cordova/templates/project/assets/www/index.html" />
+ <fileset file="assets/www/index.html" />
+ <fileset file="../bin/templates/project/cordova/templates/project/assets/www/index.html" />
</replaceregexp>
<!-- This is sketchy, but it works, ${dblQuote} does not -->
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/default.properties
----------------------------------------------------------------------
diff --git a/framework/default.properties b/framework/default.properties
index d035c7c..d4e24dc 100644
--- a/framework/default.properties
+++ b/framework/default.properties
@@ -1,8 +1,8 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
-#
+#
# This file must be checked in Version Control Systems.
-#
+#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/res/layout/main.xml
----------------------------------------------------------------------
diff --git a/framework/res/layout/main.xml b/framework/res/layout/main.xml
index 514318c..bf8a0ff 100644
--- a/framework/res/layout/main.xml
+++ b/framework/res/layout/main.xml
@@ -1,5 +1,5 @@
<?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
@@ -21,9 +21,9 @@
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
- >
+ >
<WebView android:id="@+id/appView"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
- />
+ />
</LinearLayout>
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/res/values/strings.xml
----------------------------------------------------------------------
diff --git a/framework/res/values/strings.xml b/framework/res/values/strings.xml
index e290e32..8bfae7c 100644
--- a/framework/res/values/strings.xml
+++ b/framework/res/values/strings.xml
@@ -1,5 +1,5 @@
<?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
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/res/xml/cordova.xml
----------------------------------------------------------------------
diff --git a/framework/res/xml/cordova.xml b/framework/res/xml/cordova.xml
index 8f347e7..0eb8d5e 100644
--- a/framework/res/xml/cordova.xml
+++ b/framework/res/xml/cordova.xml
@@ -1,5 +1,5 @@
<?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
@@ -18,16 +18,16 @@
under the License.
-->
<cordova>
- <!--
- access elements control the Android whitelist.
- Domains are assumed blocked unless set otherwise
- -->
+ <!--
+ access elements control the Android whitelist.
+ Domains are assumed blocked unless set otherwise
+ -->
<access origin="http://127.0.0.1*"/> <!-- allow local pages -->
- <!-- <access origin="https://example.com" /> allow any secure requests to example.com -->
- <!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www -->
- <!-- <access origin=".*"/> Allow all domains, suggested development use only -->
+ <!-- <access origin="https://example.com" /> allow any secure requests to example.com -->
+ <!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www -->
+ <!-- <access origin=".*"/> Allow all domains, suggested development use only -->
<log level="DEBUG"/>
<preference name="classicRender" value="true" />
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/res/xml/plugins.xml
----------------------------------------------------------------------
diff --git a/framework/res/xml/plugins.xml b/framework/res/xml/plugins.xml
index 76879a1..1e0f191 100755
--- a/framework/res/xml/plugins.xml
+++ b/framework/res/xml/plugins.xml
@@ -1,5 +1,5 @@
<?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
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/src/com/phonegap/api/LOG.java
----------------------------------------------------------------------
diff --git a/framework/src/com/phonegap/api/LOG.java b/framework/src/com/phonegap/api/LOG.java
index 3520425..e9a37d2 100755
--- a/framework/src/com/phonegap/api/LOG.java
+++ b/framework/src/com/phonegap/api/LOG.java
@@ -20,7 +20,7 @@ package com.phonegap.api;
/**
* Log to Android logging system.
- *
+ *
* Log message can be a string or a printf formatted string with arguments.
* See http://developer.android.com/reference/java/util/Formatter.html
*/
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/src/com/phonegap/api/PluginManager.java
----------------------------------------------------------------------
diff --git a/framework/src/com/phonegap/api/PluginManager.java b/framework/src/com/phonegap/api/PluginManager.java
index 4f0f13f..7781901 100755
--- a/framework/src/com/phonegap/api/PluginManager.java
+++ b/framework/src/com/phonegap/api/PluginManager.java
@@ -24,7 +24,7 @@ import android.webkit.WebView;
/**
* PluginManager is exposed to JavaScript in the Cordova WebView.
- *
+ *
* Calling native plugin code can be done by calling PluginManager.exec(...)
* from JavaScript.
*/
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/src/com/phonegap/api/PluginResult.java
----------------------------------------------------------------------
diff --git a/framework/src/com/phonegap/api/PluginResult.java b/framework/src/com/phonegap/api/PluginResult.java
index 01f69c3..8649135 100755
--- a/framework/src/com/phonegap/api/PluginResult.java
+++ b/framework/src/com/phonegap/api/PluginResult.java
@@ -22,32 +22,32 @@ import org.json.JSONArray;
import org.json.JSONObject;
public class PluginResult extends org.apache.cordova.api.PluginResult {
-
- public PluginResult(Status status) {
- super(status);
- }
-
- public PluginResult(Status status, String message) {
- super(status, message);
- }
-
- public PluginResult(Status status, JSONArray message) {
+
+ public PluginResult(Status status) {
+ super(status);
+ }
+
+ public PluginResult(Status status, String message) {
+ super(status, message);
+ }
+
+ public PluginResult(Status status, JSONArray message) {
super(status, message);
- }
+ }
- public PluginResult(Status status, JSONObject message) {
+ public PluginResult(Status status, JSONObject message) {
super(status, message);
- }
+ }
- public PluginResult(Status status, int i) {
+ public PluginResult(Status status, int i) {
super(status, i);
- }
+ }
- public PluginResult(Status status, float f) {
+ public PluginResult(Status status, float f) {
super(status, f);
- }
+ }
- public PluginResult(Status status, boolean b) {
+ public PluginResult(Status status, boolean b) {
super(status, b);
- }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/src/org/apache/cordova/AccelListener.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/AccelListener.java b/framework/src/org/apache/cordova/AccelListener.java
index 83a322d..6422dbb 100755
--- a/framework/src/org/apache/cordova/AccelListener.java
+++ b/framework/src/org/apache/cordova/AccelListener.java
@@ -18,12 +18,7 @@
*/
package org.apache.cordova;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
-import java.util.Map;
-
import org.apache.cordova.api.CordovaInterface;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
@@ -36,12 +31,10 @@ import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
-import android.location.Location;
-import android.util.Log;
import android.content.Context;
/**
- * This class listens to the accelerometer sensor and stores the latest
+ * This class listens to the accelerometer sensor and stores the latest
* acceleration values x,y,z.
*/
public class AccelListener extends Plugin implements SensorEventListener {
@@ -50,7 +43,7 @@ public class AccelListener extends Plugin implements SensorEventListener {
public static int STARTING = 1;
public static int RUNNING = 2;
public static int ERROR_FAILED_TO_START = 3;
-
+
private float x,y,z; // most recent acceleration values
private long timestamp; // time of most recent value
private int status; // status of listener
@@ -71,11 +64,11 @@ public class AccelListener extends Plugin implements SensorEventListener {
this.timestamp = 0;
this.setStatus(AccelListener.STOPPED);
}
-
+
/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
- *
+ *
* @param ctx The context of the main Activity.
*/
public void setContext(CordovaInterface ctx) {
@@ -85,7 +78,7 @@ public class AccelListener extends Plugin implements SensorEventListener {
/**
* Executes the request and returns PluginResult.
- *
+ *
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @param callbackId The callback id used when calling back into JavaScript.
@@ -95,7 +88,7 @@ public class AccelListener extends Plugin implements SensorEventListener {
PluginResult.Status status = PluginResult.Status.NO_RESULT;
String message = "";
PluginResult result = new PluginResult(status, message);
- result.setKeepCallback(true);
+ result.setKeepCallback(true);
if (action.equals("start")) {
this.callbackId = callbackId;
@@ -115,7 +108,7 @@ public class AccelListener extends Plugin implements SensorEventListener {
}
return result;
}
-
+
/**
* Called by AccelBroker when listener is to be shut down.
* Stop listener.
@@ -130,46 +123,46 @@ public class AccelListener extends Plugin implements SensorEventListener {
//
/**
* Start listening for acceleration sensor.
- *
+ *
* @return status of listener
*/
private int start() {
- // If already starting or running, then just return
- if ((this.status == AccelListener.RUNNING) || (this.status == AccelListener.STARTING)) {
- return this.status;
- }
-
- this.setStatus(AccelListener.STARTING);
-
- // Get accelerometer from sensor manager
- List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
-
- // If found, then register as listener
- if ((list != null) && (list.size() > 0)) {
- this.mSensor = list.get(0);
- this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_UI);
- this.setStatus(AccelListener.STARTING);
- } else {
- this.setStatus(AccelListener.ERROR_FAILED_TO_START);
- this.fail(AccelListener.ERROR_FAILED_TO_START, "No sensors found to register accelerometer listening to.");
- return this.status;
- }
-
- // Wait until running
- long timeout = 2000;
- while ((this.status == STARTING) && (timeout > 0)) {
- timeout = timeout - 100;
- try {
- Thread.sleep(100);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- if (timeout == 0) {
+ // If already starting or running, then just return
+ if ((this.status == AccelListener.RUNNING) || (this.status == AccelListener.STARTING)) {
+ return this.status;
+ }
+
+ this.setStatus(AccelListener.STARTING);
+
+ // Get accelerometer from sensor manager
+ List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
+
+ // If found, then register as listener
+ if ((list != null) && (list.size() > 0)) {
+ this.mSensor = list.get(0);
+ this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_UI);
+ this.setStatus(AccelListener.STARTING);
+ } else {
+ this.setStatus(AccelListener.ERROR_FAILED_TO_START);
+ this.fail(AccelListener.ERROR_FAILED_TO_START, "No sensors found to register accelerometer listening to.");
+ return this.status;
+ }
+
+ // Wait until running
+ long timeout = 2000;
+ while ((this.status == STARTING) && (timeout > 0)) {
+ timeout = timeout - 100;
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ if (timeout == 0) {
this.setStatus(AccelListener.ERROR_FAILED_TO_START);
this.fail(AccelListener.ERROR_FAILED_TO_START, "Accelerometer could not be started.");
- }
- return this.status;
+ }
+ return this.status;
}
/**
@@ -185,16 +178,16 @@ public class AccelListener extends Plugin implements SensorEventListener {
/**
* Called when the accuracy of the sensor has changed.
- *
+ *
* @param sensor
* @param accuracy
*/
public void onAccuracyChanged(Sensor sensor, int accuracy) {
- // Only look at accelerometer events
+ // Only look at accelerometer events
if (sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
return;
}
-
+
// If not running, then just return
if (this.status == AccelListener.STOPPED) {
return;
@@ -204,7 +197,7 @@ public class AccelListener extends Plugin implements SensorEventListener {
/**
* Sensor listener event.
- *
+ *
* @param SensorEvent event
*/
public void onSensorChanged(SensorEvent event) {
@@ -212,14 +205,14 @@ public class AccelListener extends Plugin implements SensorEventListener {
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
return;
}
-
+
// If not running, then just return
if (this.status == AccelListener.STOPPED) {
return;
}
-
+
this.setStatus(AccelListener.RUNNING);
-
+
if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) {
// Save time that event was received
@@ -247,7 +240,7 @@ public class AccelListener extends Plugin implements SensorEventListener {
this.error(err, this.callbackId);
}
-
+
private void win() {
// Success return object
PluginResult result = new PluginResult(PluginResult.Status.OK, this.getAccelerationJSON());
@@ -259,7 +252,7 @@ public class AccelListener extends Plugin implements SensorEventListener {
private void setStatus(int status) {
this.status = status;
}
-
+
private JSONObject getAccelerationJSON() {
JSONObject r = new JSONObject();
try {
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/src/org/apache/cordova/App.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/App.java b/framework/src/org/apache/cordova/App.java
index 9b1c96a..5b63921 100755
--- a/framework/src/org/apache/cordova/App.java
+++ b/framework/src/org/apache/cordova/App.java
@@ -45,30 +45,30 @@ public class App extends Plugin {
String result = "";
try {
- if (action.equals("clearCache")) {
- this.clearCache();
- }
- else if (action.equals("loadUrl")) {
- this.loadUrl(args.getString(0), args.optJSONObject(1));
+ if (action.equals("clearCache")) {
+ this.clearCache();
}
- else if (action.equals("cancelLoadUrl")) {
- this.cancelLoadUrl();
+ else if (action.equals("loadUrl")) {
+ this.loadUrl(args.getString(0), args.optJSONObject(1));
}
- else if (action.equals("clearHistory")) {
- this.clearHistory();
+ else if (action.equals("cancelLoadUrl")) {
+ this.cancelLoadUrl();
+ }
+ else if (action.equals("clearHistory")) {
+ this.clearHistory();
}
else if (action.equals("backHistory")) {
this.backHistory();
}
- else if (action.equals("overrideBackbutton")) {
- this.overrideBackbutton(args.getBoolean(0));
+ else if (action.equals("overrideBackbutton")) {
+ this.overrideBackbutton(args.getBoolean(0));
}
- else if (action.equals("isBackbuttonOverridden")) {
- boolean b = this.isBackbuttonOverridden();
- return new PluginResult(status, b);
+ else if (action.equals("isBackbuttonOverridden")) {
+ boolean b = this.isBackbuttonOverridden();
+ return new PluginResult(status, b);
}
- else if (action.equals("exitApp")) {
- this.exitApp();
+ else if (action.equals("exitApp")) {
+ this.exitApp();
}
return new PluginResult(status, result);
} catch (JSONException e) {
@@ -80,87 +80,87 @@ public class App extends Plugin {
// LOCAL METHODS
//--------------------------------------------------------------------------
- /**
- * Clear the resource cache.
- */
- public void clearCache() {
- ((DroidGap)this.ctx).clearCache();
- }
-
- /**
- * Load the url into the webview.
- *
- * @param url
- * @param props Properties that can be passed in to the DroidGap activity (i.e. loadingDialog, wait, ...)
- * @throws JSONException
- */
- public void loadUrl(String url, JSONObject props) throws JSONException {
- LOG.d("App", "App.loadUrl("+url+","+props+")");
- int wait = 0;
- boolean openExternal = false;
- boolean clearHistory = false;
-
- // If there are properties, then set them on the Activity
- HashMap<String, Object> params = new HashMap<String, Object>();
- if (props != null) {
- JSONArray keys = props.names();
- for (int i=0; i<keys.length(); i++) {
- String key = keys.getString(i);
- if (key.equals("wait")) {
- wait = props.getInt(key);
- }
- else if (key.equalsIgnoreCase("openexternal")) {
- openExternal = props.getBoolean(key);
- }
- else if (key.equalsIgnoreCase("clearhistory")) {
- clearHistory = props.getBoolean(key);
- }
- else {
- Object value = props.get(key);
- if (value == null) {
-
- }
- else if (value.getClass().equals(String.class)) {
- params.put(key, (String)value);
- }
- else if (value.getClass().equals(Boolean.class)) {
- params.put(key, (Boolean)value);
- }
- else if (value.getClass().equals(Integer.class)) {
- params.put(key, (Integer)value);
- }
- }
- }
- }
-
- // If wait property, then delay loading
-
- if (wait > 0) {
- try {
- synchronized(this) {
- this.wait(wait);
- }
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- ((DroidGap)this.ctx).showWebPage(url, openExternal, clearHistory, params);
- }
-
- /**
- * Cancel loadUrl before it has been loaded.
- */
- public void cancelLoadUrl() {
- ((DroidGap)this.ctx).cancelLoadUrl();
- }
-
+ /**
+ * Clear the resource cache.
+ */
+ public void clearCache() {
+ ((DroidGap)this.ctx).clearCache();
+ }
+
+ /**
+ * Load the url into the webview.
+ *
+ * @param url
+ * @param props Properties that can be passed in to the DroidGap activity (i.e. loadingDialog, wait, ...)
+ * @throws JSONException
+ */
+ public void loadUrl(String url, JSONObject props) throws JSONException {
+ LOG.d("App", "App.loadUrl("+url+","+props+")");
+ int wait = 0;
+ boolean openExternal = false;
+ boolean clearHistory = false;
+
+ // If there are properties, then set them on the Activity
+ HashMap<String, Object> params = new HashMap<String, Object>();
+ if (props != null) {
+ JSONArray keys = props.names();
+ for (int i=0; i<keys.length(); i++) {
+ String key = keys.getString(i);
+ if (key.equals("wait")) {
+ wait = props.getInt(key);
+ }
+ else if (key.equalsIgnoreCase("openexternal")) {
+ openExternal = props.getBoolean(key);
+ }
+ else if (key.equalsIgnoreCase("clearhistory")) {
+ clearHistory = props.getBoolean(key);
+ }
+ else {
+ Object value = props.get(key);
+ if (value == null) {
+
+ }
+ else if (value.getClass().equals(String.class)) {
+ params.put(key, (String)value);
+ }
+ else if (value.getClass().equals(Boolean.class)) {
+ params.put(key, (Boolean)value);
+ }
+ else if (value.getClass().equals(Integer.class)) {
+ params.put(key, (Integer)value);
+ }
+ }
+ }
+ }
+
+ // If wait property, then delay loading
+
+ if (wait > 0) {
+ try {
+ synchronized(this) {
+ this.wait(wait);
+ }
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ ((DroidGap)this.ctx).showWebPage(url, openExternal, clearHistory, params);
+ }
+
+ /**
+ * Cancel loadUrl before it has been loaded.
+ */
+ public void cancelLoadUrl() {
+ ((DroidGap)this.ctx).cancelLoadUrl();
+ }
+
/**
* Clear page history for the app.
*/
public void clearHistory() {
- ((DroidGap)this.ctx).clearHistory();
+ ((DroidGap)this.ctx).clearHistory();
}
-
+
/**
* Go to previous page displayed.
* This is the same as pressing the backbutton on Android device.
@@ -172,27 +172,27 @@ public class App extends Plugin {
/**
* Override the default behavior of the Android back button.
* If overridden, when the back button is pressed, the "backKeyDown" JavaScript event will be fired.
- *
+ *
* @param override T=override, F=cancel override
*/
public void overrideBackbutton(boolean override) {
- LOG.i("DroidGap", "WARNING: Back Button Default Behaviour will be overridden. The backbutton event will be fired!");
- ((DroidGap)this.ctx).bound = override;
+ LOG.i("DroidGap", "WARNING: Back Button Default Behaviour will be overridden. The backbutton event will be fired!");
+ ((DroidGap)this.ctx).bound = override;
}
/**
* Return whether the Android back button is overridden by the user.
- *
+ *
* @return boolean
*/
public boolean isBackbuttonOverridden() {
- return ((DroidGap)this.ctx).bound;
+ return ((DroidGap)this.ctx).bound;
}
/**
* Exit the Android application.
*/
public void exitApp() {
- ((DroidGap)this.ctx).endActivity();
+ ((DroidGap)this.ctx).endActivity();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/src/org/apache/cordova/AudioHandler.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/AudioHandler.java b/framework/src/org/apache/cordova/AudioHandler.java
index d7df63e..dce24cd 100755
--- a/framework/src/org/apache/cordova/AudioHandler.java
+++ b/framework/src/org/apache/cordova/AudioHandler.java
@@ -22,22 +22,20 @@ import android.content.Context;
import android.media.AudioManager;
import java.util.ArrayList;
-import org.apache.cordova.api.LOG;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import java.util.HashMap;
-import java.util.Map.Entry;
/**
- * This class called by CordovaActivity to play and record audio.
+ * This class called by CordovaActivity to play and record audio.
* The file can be local or over a network using http.
- *
+ *
* Audio formats supported (tested):
* .mp3, .wav
- *
+ *
* Local audio files must reside in one of two places:
* android_asset: file name must start with /android_asset/sound.mp3
* sdcard: file name is just sound.mp3
@@ -45,112 +43,112 @@ import java.util.Map.Entry;
public class AudioHandler extends Plugin {
public static String TAG = "AudioHandler";
- HashMap<String,AudioPlayer> players; // Audio player object
- ArrayList<AudioPlayer> pausedForPhone; // Audio players that were paused when phone call came in
-
- /**
- * Constructor.
- */
- public AudioHandler() {
- this.players = new HashMap<String,AudioPlayer>();
- this.pausedForPhone = new ArrayList<AudioPlayer>();
- }
-
- /**
- * Executes the request and returns PluginResult.
- *
- * @param action The action to execute.
- * @param args JSONArry of arguments for the plugin.
- * @param callbackId The callback id used when calling back into JavaScript.
- * @return A PluginResult object with a status and message.
- */
- public PluginResult execute(String action, JSONArray args, String callbackId) {
- PluginResult.Status status = PluginResult.Status.OK;
- String result = "";
-
- try {
- if (action.equals("startRecordingAudio")) {
- this.startRecordingAudio(args.getString(0), args.getString(1));
- }
- else if (action.equals("stopRecordingAudio")) {
- this.stopRecordingAudio(args.getString(0));
- }
- else if (action.equals("startPlayingAudio")) {
- this.startPlayingAudio(args.getString(0), args.getString(1));
- }
- else if (action.equals("seekToAudio")) {
- this.seekToAudio(args.getString(0), args.getInt(1));
- }
- else if (action.equals("pausePlayingAudio")) {
- this.pausePlayingAudio(args.getString(0));
- }
- else if (action.equals("stopPlayingAudio")) {
- this.stopPlayingAudio(args.getString(0));
- } else if (action.equals("setVolume")) {
- try {
- this.setVolume(args.getString(0), Float.parseFloat(args.getString(1)));
- } catch (NumberFormatException nfe) {
- //no-op
- }
- } else if (action.equals("getCurrentPositionAudio")) {
- float f = this.getCurrentPositionAudio(args.getString(0));
- return new PluginResult(status, f);
- }
- else if (action.equals("getDurationAudio")) {
- float f = this.getDurationAudio(args.getString(0), args.getString(1));
- return new PluginResult(status, f);
- }
- else if (action.equals("release")) {
- boolean b = this.release(args.getString(0));
- return new PluginResult(status, b);
- }
- return new PluginResult(status, result);
- } catch (JSONException e) {
- e.printStackTrace();
- return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
- }
- }
-
- /**
- * Identifies if action to be executed returns a value and should be run synchronously.
- *
- * @param action The action to execute
- * @return T=returns value
- */
- public boolean isSynch(String action) {
- if (action.equals("getCurrentPositionAudio")) {
- return true;
- }
- else if (action.equals("getDurationAudio")) {
- return true;
- }
- return false;
- }
-
- /**
- * Stop all audio players and recorders.
- */
- public void onDestroy() {
+ HashMap<String,AudioPlayer> players; // Audio player object
+ ArrayList<AudioPlayer> pausedForPhone; // Audio players that were paused when phone call came in
+
+ /**
+ * Constructor.
+ */
+ public AudioHandler() {
+ this.players = new HashMap<String,AudioPlayer>();
+ this.pausedForPhone = new ArrayList<AudioPlayer>();
+ }
+
+ /**
+ * Executes the request and returns PluginResult.
+ *
+ * @param action The action to execute.
+ * @param args JSONArry of arguments for the plugin.
+ * @param callbackId The callback id used when calling back into JavaScript.
+ * @return A PluginResult object with a status and message.
+ */
+ public PluginResult execute(String action, JSONArray args, String callbackId) {
+ PluginResult.Status status = PluginResult.Status.OK;
+ String result = "";
+
+ try {
+ if (action.equals("startRecordingAudio")) {
+ this.startRecordingAudio(args.getString(0), args.getString(1));
+ }
+ else if (action.equals("stopRecordingAudio")) {
+ this.stopRecordingAudio(args.getString(0));
+ }
+ else if (action.equals("startPlayingAudio")) {
+ this.startPlayingAudio(args.getString(0), args.getString(1));
+ }
+ else if (action.equals("seekToAudio")) {
+ this.seekToAudio(args.getString(0), args.getInt(1));
+ }
+ else if (action.equals("pausePlayingAudio")) {
+ this.pausePlayingAudio(args.getString(0));
+ }
+ else if (action.equals("stopPlayingAudio")) {
+ this.stopPlayingAudio(args.getString(0));
+ } else if (action.equals("setVolume")) {
+ try {
+ this.setVolume(args.getString(0), Float.parseFloat(args.getString(1)));
+ } catch (NumberFormatException nfe) {
+ //no-op
+ }
+ } else if (action.equals("getCurrentPositionAudio")) {
+ float f = this.getCurrentPositionAudio(args.getString(0));
+ return new PluginResult(status, f);
+ }
+ else if (action.equals("getDurationAudio")) {
+ float f = this.getDurationAudio(args.getString(0), args.getString(1));
+ return new PluginResult(status, f);
+ }
+ else if (action.equals("release")) {
+ boolean b = this.release(args.getString(0));
+ return new PluginResult(status, b);
+ }
+ return new PluginResult(status, result);
+ } catch (JSONException e) {
+ e.printStackTrace();
+ return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
+ }
+ }
+
+ /**
+ * Identifies if action to be executed returns a value and should be run synchronously.
+ *
+ * @param action The action to execute
+ * @return T=returns value
+ */
+ public boolean isSynch(String action) {
+ if (action.equals("getCurrentPositionAudio")) {
+ return true;
+ }
+ else if (action.equals("getDurationAudio")) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Stop all audio players and recorders.
+ */
+ public void onDestroy() {
for (AudioPlayer audio : this.players.values()) {
audio.destroy();
}
this.players.clear();
- }
-
+ }
+
/**
- * Called when a message is sent to plugin.
- *
+ * Called when a message is sent to plugin.
+ *
* @param id The message id
* @param data The message data
*/
public void onMessage(String id, Object data) {
-
+
// If phone message
if (id.equals("telephone")) {
-
+
// If phone ringing, then pause playing
if ("ringing".equals(data) || "offhook".equals(data)) {
-
+
// Get all audio players and pause them
for (AudioPlayer audio : this.players.values()) {
if (audio.getState() == AudioPlayer.MEDIA_RUNNING) {
@@ -160,7 +158,7 @@ public class AudioHandler extends Plugin {
}
}
-
+
// If phone idle, then resume playing those players we paused
else if ("idle".equals(data)) {
for (AudioPlayer audio : this.pausedForPhone) {
@@ -174,177 +172,177 @@ public class AudioHandler extends Plugin {
//--------------------------------------------------------------------------
// LOCAL METHODS
//--------------------------------------------------------------------------
-
- /**
- * Release the audio player instance to save memory.
- *
- * @param id The id of the audio player
- */
- private boolean release(String id) {
- if (!this.players.containsKey(id)) {
- return false;
- }
- AudioPlayer audio = this.players.get(id);
- this.players.remove(id);
- audio.destroy();
- return true;
- }
-
- /**
- * Start recording and save the specified file.
- *
- * @param id The id of the audio player
- * @param file The name of the file
- */
+
+ /**
+ * Release the audio player instance to save memory.
+ *
+ * @param id The id of the audio player
+ */
+ private boolean release(String id) {
+ if (!this.players.containsKey(id)) {
+ return false;
+ }
+ AudioPlayer audio = this.players.get(id);
+ this.players.remove(id);
+ audio.destroy();
+ return true;
+ }
+
+ /**
+ * Start recording and save the specified file.
+ *
+ * @param id The id of the audio player
+ * @param file The name of the file
+ */
public void startRecordingAudio(String id, String file) {
- // If already recording, then just return;
- if (this.players.containsKey(id)) {
- return;
- }
- AudioPlayer audio = new AudioPlayer(this, id);
- this.players.put(id, audio);
- audio.startRecording(file);
+ // If already recording, then just return;
+ if (this.players.containsKey(id)) {
+ return;
+ }
+ AudioPlayer audio = new AudioPlayer(this, id);
+ this.players.put(id, audio);
+ audio.startRecording(file);
}
/**
* Stop recording and save to the file specified when recording started.
- *
- * @param id The id of the audio player
+ *
+ * @param id The id of the audio player
*/
public void stopRecordingAudio(String id) {
- AudioPlayer audio = this.players.get(id);
- if (audio != null) {
- audio.stopRecording();
- this.players.remove(id);
- }
+ AudioPlayer audio = this.players.get(id);
+ if (audio != null) {
+ audio.stopRecording();
+ this.players.remove(id);
+ }
}
-
+
/**
* Start or resume playing audio file.
- *
- * @param id The id of the audio player
+ *
+ * @param id The id of the audio player
* @param file The name of the audio file.
*/
public void startPlayingAudio(String id, String file) {
- AudioPlayer audio = this.players.get(id);
- if (audio == null) {
- audio = new AudioPlayer(this, id);
- this.players.put(id, audio);
- }
- audio.startPlaying(file);
+ AudioPlayer audio = this.players.get(id);
+ if (audio == null) {
+ audio = new AudioPlayer(this, id);
+ this.players.put(id, audio);
+ }
+ audio.startPlaying(file);
}
/**
* Seek to a location.
- *
- *
- * @param id The id of the audio player
- * @param miliseconds int: number of milliseconds to skip 1000 = 1 second
+ *
+ *
+ * @param id The id of the audio player
+ * @param miliseconds int: number of milliseconds to skip 1000 = 1 second
*/
public void seekToAudio(String id, int milliseconds) {
- AudioPlayer audio = this.players.get(id);
- if (audio != null) {
- audio.seekToPlaying(milliseconds);
- }
+ AudioPlayer audio = this.players.get(id);
+ if (audio != null) {
+ audio.seekToPlaying(milliseconds);
+ }
}
-
+
/**
* Pause playing.
- *
- * @param id The id of the audio player
+ *
+ * @param id The id of the audio player
*/
public void pausePlayingAudio(String id) {
- AudioPlayer audio = this.players.get(id);
- if (audio != null) {
- audio.pausePlaying();
- }
+ AudioPlayer audio = this.players.get(id);
+ if (audio != null) {
+ audio.pausePlaying();
+ }
}
/**
* Stop playing the audio file.
- *
- * @param id The id of the audio player
+ *
+ * @param id The id of the audio player
*/
public void stopPlayingAudio(String id) {
- AudioPlayer audio = this.players.get(id);
- if (audio != null) {
- audio.stopPlaying();
- //audio.destroy();
- //this.players.remove(id);
- }
+ AudioPlayer audio = this.players.get(id);
+ if (audio != null) {
+ audio.stopPlaying();
+ //audio.destroy();
+ //this.players.remove(id);
+ }
}
-
+
/**
* Get current position of playback.
- *
- * @param id The id of the audio player
+ *
+ * @param id The id of the audio player
* @return position in msec
*/
public float getCurrentPositionAudio(String id) {
- AudioPlayer audio = this.players.get(id);
- if (audio != null) {
- return(audio.getCurrentPosition()/1000.0f);
- }
- return -1;
+ AudioPlayer audio = this.players.get(id);
+ if (audio != null) {
+ return(audio.getCurrentPosition()/1000.0f);
+ }
+ return -1;
}
-
+
/**
* Get the duration of the audio file.
- *
- * @param id The id of the audio player
+ *
+ * @param id The id of the audio player
* @param file The name of the audio file.
* @return The duration in msec.
*/
public float getDurationAudio(String id, String file) {
-
- // Get audio file
- AudioPlayer audio = this.players.get(id);
- if (audio != null) {
- return(audio.getDuration(file));
- }
-
- // If not already open, then open the file
- else {
- audio = new AudioPlayer(this, id);
- this.players.put(id, audio);
- return(audio.getDuration(file));
- }
- }
-
+
+ // Get audio file
+ AudioPlayer audio = this.players.get(id);
+ if (audio != null) {
+ return(audio.getDuration(file));
+ }
+
+ // If not already open, then open the file
+ else {
+ audio = new AudioPlayer(this, id);
+ this.players.put(id, audio);
+ return(audio.getDuration(file));
+ }
+ }
+
/**
* Set the audio device to be used for playback.
- *
+ *
* @param output 1=earpiece, 2=speaker
*/
public void setAudioOutputDevice(int output) {
- AudioManager audiMgr = (AudioManager) this.ctx.getSystemService(Context.AUDIO_SERVICE);
- if (output == 2) {
- audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
- }
- else if (output == 1) {
- audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
- }
- else {
- System.out.println("AudioHandler.setAudioOutputDevice() Error: Unknown output device.");
- }
+ AudioManager audiMgr = (AudioManager) this.ctx.getSystemService(Context.AUDIO_SERVICE);
+ if (output == 2) {
+ audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL);
+ }
+ else if (output == 1) {
+ audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL);
+ }
+ else {
+ System.out.println("AudioHandler.setAudioOutputDevice() Error: Unknown output device.");
+ }
}
-
+
/**
* Get the audio device to be used for playback.
- *
+ *
* @return 1=earpiece, 2=speaker
*/
public int getAudioOutputDevice() {
- AudioManager audiMgr = (AudioManager) this.ctx.getSystemService(Context.AUDIO_SERVICE);
- if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_EARPIECE) {
- return 1;
- }
- else if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_SPEAKER) {
- return 2;
- }
- else {
- return -1;
- }
+ AudioManager audiMgr = (AudioManager) this.ctx.getSystemService(Context.AUDIO_SERVICE);
+ if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_EARPIECE) {
+ return 1;
+ }
+ else if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_SPEAKER) {
+ return 2;
+ }
+ else {
+ return -1;
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/src/org/apache/cordova/AudioPlayer.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/AudioPlayer.java b/framework/src/org/apache/cordova/AudioPlayer.java
index 9397ec7..675161f 100755
--- a/framework/src/org/apache/cordova/AudioPlayer.java
+++ b/framework/src/org/apache/cordova/AudioPlayer.java
@@ -35,7 +35,7 @@ import java.io.IOException;
* This class implements the audio playback and recording capabilities used by Cordova.
* It is called by the AudioHandler Cordova class.
* Only one file can be played or recorded per class instance.
- *
+ *
* Local audio files must reside in one of two places:
* android_asset: file name must start with /android_asset/sound.mp3
* sdcard: file name is just sound.mp3
@@ -45,422 +45,422 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
private static final String LOG_TAG = "AudioPlayer";
// AudioPlayer states
- public static int MEDIA_NONE = 0;
- public static int MEDIA_STARTING = 1;
- public static int MEDIA_RUNNING = 2;
- public static int MEDIA_PAUSED = 3;
- public static int MEDIA_STOPPED = 4;
-
- // AudioPlayer message ids
- private static int MEDIA_STATE = 1;
- private static int MEDIA_DURATION = 2;
+ public static int MEDIA_NONE = 0;
+ public static int MEDIA_STARTING = 1;
+ public static int MEDIA_RUNNING = 2;
+ public static int MEDIA_PAUSED = 3;
+ public static int MEDIA_STOPPED = 4;
+
+ // AudioPlayer message ids
+ private static int MEDIA_STATE = 1;
+ private static int MEDIA_DURATION = 2;
private static int MEDIA_POSITION = 3;
- private static int MEDIA_ERROR = 9;
-
- // Media error codes
+ private static int MEDIA_ERROR = 9;
+
+ // Media error codes
private static int MEDIA_ERR_NONE_ACTIVE = 0;
private static int MEDIA_ERR_ABORTED = 1;
private static int MEDIA_ERR_NETWORK = 2;
private static int MEDIA_ERR_DECODE = 3;
private static int MEDIA_ERR_NONE_SUPPORTED = 4;
-
- private AudioHandler handler; // The AudioHandler object
- private String id; // The id of this player (used to identify Media object in JavaScript)
- private int state = MEDIA_NONE; // State of recording or playback
- private String audioFile = null; // File name to play or record to
- private float duration = -1; // Duration of audio
-
- private MediaRecorder recorder = null; // Audio recording object
- private String tempFile = null; // Temporary recording file name
-
- private MediaPlayer mPlayer = null; // Audio player object
- private boolean prepareOnly = false;
-
- /**
- * Constructor.
- *
- * @param handler The audio handler object
- * @param id The id of this audio player
- */
- public AudioPlayer(AudioHandler handler, String id) {
- this.handler = handler;
- this.id = id;
+
+ private AudioHandler handler; // The AudioHandler object
+ private String id; // The id of this player (used to identify Media object in JavaScript)
+ private int state = MEDIA_NONE; // State of recording or playback
+ private String audioFile = null; // File name to play or record to
+ private float duration = -1; // Duration of audio
+
+ private MediaRecorder recorder = null; // Audio recording object
+ private String tempFile = null; // Temporary recording file name
+
+ private MediaPlayer mPlayer = null; // Audio player object
+ private boolean prepareOnly = false;
+
+ /**
+ * Constructor.
+ *
+ * @param handler The audio handler object
+ * @param id The id of this audio player
+ */
+ public AudioPlayer(AudioHandler handler, String id) {
+ this.handler = handler;
+ this.id = id;
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
this.tempFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/tmprecording.mp3";
} else {
this.tempFile = "/data/data/" + handler.ctx.getPackageName() + "/cache/tmprecording.mp3";
}
- }
-
- /**
- * Destroy player and stop audio playing or recording.
- */
- public void destroy() {
-
- // Stop any play or record
- if (this.mPlayer != null) {
- if ((this.state == MEDIA_RUNNING) || (this.state == MEDIA_PAUSED)) {
- this.mPlayer.stop();
- this.setState(MEDIA_STOPPED);
- }
- this.mPlayer.release();
- this.mPlayer = null;
- }
- if (this.recorder != null) {
- this.stopRecording();
- this.recorder.release();
- this.recorder = null;
- }
- }
-
- /**
- * Start recording the specified file.
- *
- * @param file The name of the file
- */
- public void startRecording(String file) {
- if (this.mPlayer != null) {
- Log.d(LOG_TAG, "AudioPlayer Error: Can't record in play mode.");
- this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
- }
-
- // Make sure we're not already recording
- else if (this.recorder == null) {
- this.audioFile = file;
- this.recorder = new MediaRecorder();
- this.recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
- this.recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); // THREE_GPP);
- this.recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); //AMR_NB);
- this.recorder.setOutputFile(this.tempFile);
- try {
- this.recorder.prepare();
- this.recorder.start();
- this.setState(MEDIA_RUNNING);
- return;
- } catch (IllegalStateException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
- }
- else {
- Log.d(LOG_TAG, "AudioPlayer Error: Already recording.");
- this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
- }
- }
-
- /**
- * Save temporary recorded file to specified name
- *
- * @param file
- */
- public void moveFile(String file) {
- /* this is a hack to save the file as the specified name */
- File f = new File(this.tempFile);
+ }
+
+ /**
+ * Destroy player and stop audio playing or recording.
+ */
+ public void destroy() {
+
+ // Stop any play or record
+ if (this.mPlayer != null) {
+ if ((this.state == MEDIA_RUNNING) || (this.state == MEDIA_PAUSED)) {
+ this.mPlayer.stop();
+ this.setState(MEDIA_STOPPED);
+ }
+ this.mPlayer.release();
+ this.mPlayer = null;
+ }
+ if (this.recorder != null) {
+ this.stopRecording();
+ this.recorder.release();
+ this.recorder = null;
+ }
+ }
+
+ /**
+ * Start recording the specified file.
+ *
+ * @param file The name of the file
+ */
+ public void startRecording(String file) {
+ if (this.mPlayer != null) {
+ Log.d(LOG_TAG, "AudioPlayer Error: Can't record in play mode.");
+ this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
+ }
+
+ // Make sure we're not already recording
+ else if (this.recorder == null) {
+ this.audioFile = file;
+ this.recorder = new MediaRecorder();
+ this.recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
+ this.recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); // THREE_GPP);
+ this.recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); //AMR_NB);
+ this.recorder.setOutputFile(this.tempFile);
+ try {
+ this.recorder.prepare();
+ this.recorder.start();
+ this.setState(MEDIA_RUNNING);
+ return;
+ } catch (IllegalStateException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
+ }
+ else {
+ Log.d(LOG_TAG, "AudioPlayer Error: Already recording.");
+ this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
+ }
+ }
+
+ /**
+ * Save temporary recorded file to specified name
+ *
+ * @param file
+ */
+ public void moveFile(String file) {
+ /* this is a hack to save the file as the specified name */
+ File f = new File(this.tempFile);
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- f.renameTo(new File(Environment.getExternalStorageDirectory().getAbsolutePath()
+ f.renameTo(new File(Environment.getExternalStorageDirectory().getAbsolutePath()
+ File.separator + file));
} else {
f.renameTo(new File("/data/data/" + handler.ctx.getPackageName() + "/cache/" + file));
}
-
- }
-
+
+ }
+
/**
* Stop recording and save to the file specified when recording started.
*/
- public void stopRecording() {
- if (this.recorder != null) {
- try{
- if (this.state == MEDIA_RUNNING) {
- this.recorder.stop();
- this.setState(MEDIA_STOPPED);
- }
- this.moveFile(this.audioFile);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
+ public void stopRecording() {
+ if (this.recorder != null) {
+ try{
+ if (this.state == MEDIA_RUNNING) {
+ this.recorder.stop();
+ this.setState(MEDIA_STOPPED);
+ }
+ this.moveFile(this.audioFile);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
/**
* Start or resume playing audio file.
- *
+ *
* @param file The name of the audio file.
*/
- public void startPlaying(String file) {
- if (this.recorder != null) {
- Log.d(LOG_TAG, "AudioPlayer Error: Can't play in record mode.");
- this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
- }
-
- // If this is a new request to play audio, or stopped
- else if ((this.mPlayer == null) || (this.state == MEDIA_STOPPED)) {
- try {
- // If stopped, then reset player
- if (this.mPlayer != null) {
- this.mPlayer.reset();
- }
- // Otherwise, create a new one
- else {
- this.mPlayer = new MediaPlayer();
- }
- this.audioFile = file;
-
- // If streaming file
- if (this.isStreaming(file)) {
- this.mPlayer.setDataSource(file);
- this.mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
- this.setState(MEDIA_STARTING);
- this.mPlayer.setOnPreparedListener(this);
- this.mPlayer.prepareAsync();
- }
-
- // If local file
- else {
- if (file.startsWith("/android_asset/")) {
- String f = file.substring(15);
- android.content.res.AssetFileDescriptor fd = this.handler.ctx.getBaseContext().getAssets().openFd(f);
- this.mPlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
- }
+ public void startPlaying(String file) {
+ if (this.recorder != null) {
+ Log.d(LOG_TAG, "AudioPlayer Error: Can't play in record mode.");
+ this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
+ }
+
+ // If this is a new request to play audio, or stopped
+ else if ((this.mPlayer == null) || (this.state == MEDIA_STOPPED)) {
+ try {
+ // If stopped, then reset player
+ if (this.mPlayer != null) {
+ this.mPlayer.reset();
+ }
+ // Otherwise, create a new one
+ else {
+ this.mPlayer = new MediaPlayer();
+ }
+ this.audioFile = file;
+
+ // If streaming file
+ if (this.isStreaming(file)) {
+ this.mPlayer.setDataSource(file);
+ this.mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
+ this.setState(MEDIA_STARTING);
+ this.mPlayer.setOnPreparedListener(this);
+ this.mPlayer.prepareAsync();
+ }
+
+ // If local file
+ else {
+ if (file.startsWith("/android_asset/")) {
+ String f = file.substring(15);
+ android.content.res.AssetFileDescriptor fd = this.handler.ctx.getBaseContext().getAssets().openFd(f);
+ this.mPlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
+ }
else {
File fp = new File(file);
if (fp.exists()) {
FileInputStream fileInputStream = new FileInputStream(file);
this.mPlayer.setDataSource(fileInputStream.getFD());
- }
+ }
else {
this.mPlayer.setDataSource("/sdcard/" + file);
}
}
- this.setState(MEDIA_STARTING);
- this.mPlayer.setOnPreparedListener(this);
- this.mPlayer.prepare();
-
- // Get duration
- this.duration = getDurationInSeconds();
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
- }
- }
-
- // If we have already have created an audio player
- else {
-
- // If player has been paused, then resume playback
- if ((this.state == MEDIA_PAUSED) || (this.state == MEDIA_STARTING)) {
- this.mPlayer.start();
- this.setState(MEDIA_RUNNING);
- }
- else {
- Log.d(LOG_TAG, "AudioPlayer Error: startPlaying() called during invalid state: "+this.state);
- this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
- }
- }
- }
-
- /**
- * Seek or jump to a new time in the track.
- */
- public void seekToPlaying(int milliseconds) {
- if (this.mPlayer != null) {
- this.mPlayer.seekTo(milliseconds);
- Log.d(LOG_TAG, "Send a onStatus update for the new seek");
- this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_POSITION+", "+milliseconds/1000.0f+");");
- }
- }
-
- /**
- * Pause playing.
- */
- public void pausePlaying() {
-
- // If playing, then pause
- if (this.state == MEDIA_RUNNING) {
- this.mPlayer.pause();
- this.setState(MEDIA_PAUSED);
- }
- else {
- Log.d(LOG_TAG, "AudioPlayer Error: pausePlaying() called during invalid state: "+this.state);
- this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_NONE_ACTIVE+"});");
- }
- }
+ this.setState(MEDIA_STARTING);
+ this.mPlayer.setOnPreparedListener(this);
+ this.mPlayer.prepare();
+
+ // Get duration
+ this.duration = getDurationInSeconds();
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
+ }
+ }
+
+ // If we have already have created an audio player
+ else {
+
+ // If player has been paused, then resume playback
+ if ((this.state == MEDIA_PAUSED) || (this.state == MEDIA_STARTING)) {
+ this.mPlayer.start();
+ this.setState(MEDIA_RUNNING);
+ }
+ else {
+ Log.d(LOG_TAG, "AudioPlayer Error: startPlaying() called during invalid state: "+this.state);
+ this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_ABORTED+"});");
+ }
+ }
+ }
+
+ /**
+ * Seek or jump to a new time in the track.
+ */
+ public void seekToPlaying(int milliseconds) {
+ if (this.mPlayer != null) {
+ this.mPlayer.seekTo(milliseconds);
+ Log.d(LOG_TAG, "Send a onStatus update for the new seek");
+ this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_POSITION+", "+milliseconds/1000.0f+");");
+ }
+ }
+
+ /**
+ * Pause playing.
+ */
+ public void pausePlaying() {
+
+ // If playing, then pause
+ if (this.state == MEDIA_RUNNING) {
+ this.mPlayer.pause();
+ this.setState(MEDIA_PAUSED);
+ }
+ else {
+ Log.d(LOG_TAG, "AudioPlayer Error: pausePlaying() called during invalid state: "+this.state);
+ this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_NONE_ACTIVE+"});");
+ }
+ }
/**
* Stop playing the audio file.
*/
- public void stopPlaying() {
- if ((this.state == MEDIA_RUNNING) || (this.state == MEDIA_PAUSED)) {
- this.mPlayer.stop();
- this.setState(MEDIA_STOPPED);
- }
- else {
- Log.d(LOG_TAG, "AudioPlayer Error: stopPlaying() called during invalid state: "+this.state);
- this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_NONE_ACTIVE+"});");
- }
- }
-
- /**
- * Callback to be invoked when playback of a media source has completed.
- *
- * @param mPlayer The MediaPlayer that reached the end of the file
- */
- public void onCompletion(MediaPlayer mPlayer) {
- this.setState(MEDIA_STOPPED);
- }
-
+ public void stopPlaying() {
+ if ((this.state == MEDIA_RUNNING) || (this.state == MEDIA_PAUSED)) {
+ this.mPlayer.stop();
+ this.setState(MEDIA_STOPPED);
+ }
+ else {
+ Log.d(LOG_TAG, "AudioPlayer Error: stopPlaying() called during invalid state: "+this.state);
+ this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", { \"code\":"+MEDIA_ERR_NONE_ACTIVE+"});");
+ }
+ }
+
+ /**
+ * Callback to be invoked when playback of a media source has completed.
+ *
+ * @param mPlayer The MediaPlayer that reached the end of the file
+ */
+ public void onCompletion(MediaPlayer mPlayer) {
+ this.setState(MEDIA_STOPPED);
+ }
+
/**
* Get current position of playback.
- *
+ *
* @return position in msec or -1 if not playing
*/
- public long getCurrentPosition() {
- if ((this.state == MEDIA_RUNNING) || (this.state == MEDIA_PAUSED)) {
- int curPos = this.mPlayer.getCurrentPosition();
- this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_POSITION+", "+curPos/1000.0f+");");
- return curPos;
- }
- else {
- return -1;
- }
- }
-
- /**
- * Determine if playback file is streaming or local.
- * It is streaming if file name starts with "http://"
- *
- * @param file The file name
- * @return T=streaming, F=local
- */
- public boolean isStreaming(String file) {
- if (file.contains("http://") || file.contains("https://")) {
- return true;
- }
- else {
- return false;
- }
- }
-
+ public long getCurrentPosition() {
+ if ((this.state == MEDIA_RUNNING) || (this.state == MEDIA_PAUSED)) {
+ int curPos = this.mPlayer.getCurrentPosition();
+ this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_POSITION+", "+curPos/1000.0f+");");
+ return curPos;
+ }
+ else {
+ return -1;
+ }
+ }
+
+ /**
+ * Determine if playback file is streaming or local.
+ * It is streaming if file name starts with "http://"
+ *
+ * @param file The file name
+ * @return T=streaming, F=local
+ */
+ public boolean isStreaming(String file) {
+ if (file.contains("http://") || file.contains("https://")) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+
/**
* Get the duration of the audio file.
- *
+ *
* @param file The name of the audio file.
* @return The duration in msec.
* -1=can't be determined
* -2=not allowed
*/
- public float getDuration(String file) {
-
- // Can't get duration of recording
- if (this.recorder != null) {
- return(-2); // not allowed
- }
-
- // If audio file already loaded and started, then return duration
- if (this.mPlayer != null) {
- return this.duration;
- }
-
- // If no player yet, then create one
- else {
- this.prepareOnly = true;
- this.startPlaying(file);
-
- // This will only return value for local, since streaming
- // file hasn't been read yet.
- return this.duration;
- }
- }
-
- /**
- * Callback to be invoked when the media source is ready for playback.
- *
- * @param mPlayer The MediaPlayer that is ready for playback
- */
- public void onPrepared(MediaPlayer mPlayer) {
- // Listen for playback completion
- this.mPlayer.setOnCompletionListener(this);
-
- // If start playing after prepared
- if (!this.prepareOnly) {
-
- // Start playing
- this.mPlayer.start();
-
- // Set player init flag
- this.setState(MEDIA_RUNNING);
- }
-
- // Save off duration
- this.duration = getDurationInSeconds();
- this.prepareOnly = false;
-
- // Send status notification to JavaScript
- this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_DURATION+","+this.duration+");");
-
- }
-
- /**
- * By default Android returns the length of audio in mills but we want seconds
- *
- * @return length of clip in seconds
- */
- private float getDurationInSeconds() {
- return (this.mPlayer.getDuration() / 1000.0f);
- }
-
- /**
- * Callback to be invoked when there has been an error during an asynchronous operation
- * (other errors will throw exceptions at method call time).
- *
- * @param mPlayer the MediaPlayer the error pertains to
- * @param arg1 the type of error that has occurred: (MEDIA_ERROR_UNKNOWN, MEDIA_ERROR_SERVER_DIED)
- * @param arg2 an extra code, specific to the error.
- */
- public boolean onError(MediaPlayer mPlayer, int arg1, int arg2) {
- Log.d(LOG_TAG, "AudioPlayer.onError(" + arg1 + ", " + arg2+")");
-
- // TODO: Not sure if this needs to be sent?
- this.mPlayer.stop();
- this.mPlayer.release();
-
- // Send error notification to JavaScript
- this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', { \"code\":"+arg1+"});");
- return false;
- }
-
- /**
- * Set the state and send it to JavaScript.
- *
- * @param state
- */
- private void setState(int state) {
- if (this.state != state) {
- this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_STATE+", "+state+");");
- }
-
- this.state = state;
- }
-
- /**
- * Get the audio state.
- *
- * @return int
- */
- public int getState() {
- return this.state;
- }
-
- /**
- * Set the volume for audio player
- *
- * @param volume
- */
+ public float getDuration(String file) {
+
+ // Can't get duration of recording
+ if (this.recorder != null) {
+ return(-2); // not allowed
+ }
+
+ // If audio file already loaded and started, then return duration
+ if (this.mPlayer != null) {
+ return this.duration;
+ }
+
+ // If no player yet, then create one
+ else {
+ this.prepareOnly = true;
+ this.startPlaying(file);
+
+ // This will only return value for local, since streaming
+ // file hasn't been read yet.
+ return this.duration;
+ }
+ }
+
+ /**
+ * Callback to be invoked when the media source is ready for playback.
+ *
+ * @param mPlayer The MediaPlayer that is ready for playback
+ */
+ public void onPrepared(MediaPlayer mPlayer) {
+ // Listen for playback completion
+ this.mPlayer.setOnCompletionListener(this);
+
+ // If start playing after prepared
+ if (!this.prepareOnly) {
+
+ // Start playing
+ this.mPlayer.start();
+
+ // Set player init flag
+ this.setState(MEDIA_RUNNING);
+ }
+
+ // Save off duration
+ this.duration = getDurationInSeconds();
+ this.prepareOnly = false;
+
+ // Send status notification to JavaScript
+ this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_DURATION+","+this.duration+");");
+
+ }
+
+ /**
+ * By default Android returns the length of audio in mills but we want seconds
+ *
+ * @return length of clip in seconds
+ */
+ private float getDurationInSeconds() {
+ return (this.mPlayer.getDuration() / 1000.0f);
+ }
+
+ /**
+ * Callback to be invoked when there has been an error during an asynchronous operation
+ * (other errors will throw exceptions at method call time).
+ *
+ * @param mPlayer the MediaPlayer the error pertains to
+ * @param arg1 the type of error that has occurred: (MEDIA_ERROR_UNKNOWN, MEDIA_ERROR_SERVER_DIED)
+ * @param arg2 an extra code, specific to the error.
+ */
+ public boolean onError(MediaPlayer mPlayer, int arg1, int arg2) {
+ Log.d(LOG_TAG, "AudioPlayer.onError(" + arg1 + ", " + arg2+")");
+
+ // TODO: Not sure if this needs to be sent?
+ this.mPlayer.stop();
+ this.mPlayer.release();
+
+ // Send error notification to JavaScript
+ this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', { \"code\":"+arg1+"});");
+ return false;
+ }
+
+ /**
+ * Set the state and send it to JavaScript.
+ *
+ * @param state
+ */
+ private void setState(int state) {
+ if (this.state != state) {
+ this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_STATE+", "+state+");");
+ }
+
+ this.state = state;
+ }
+
+ /**
+ * Get the audio state.
+ *
+ * @return int
+ */
+ public int getState() {
+ return this.state;
+ }
+
+ /**
+ * Set the volume for audio player
+ *
+ * @param volume
+ */
public void setVolume(float volume) {
this.mPlayer.setVolume(volume, volume);
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/src/org/apache/cordova/AuthenticationToken.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/AuthenticationToken.java b/framework/src/org/apache/cordova/AuthenticationToken.java
index 60965a3..d3a231a 100644
--- a/framework/src/org/apache/cordova/AuthenticationToken.java
+++ b/framework/src/org/apache/cordova/AuthenticationToken.java
@@ -24,46 +24,46 @@ package org.apache.cordova;
public class AuthenticationToken {
private String userName;
private String password;
-
+
/**
* Gets the user name.
- *
+ *
* @return the user name
*/
public String getUserName() {
return userName;
}
-
+
/**
* Sets the user name.
- *
+ *
* @param userName
* the new user name
*/
public void setUserName(String userName) {
this.userName = userName;
}
-
+
/**
* Gets the password.
- *
+ *
* @return the password
*/
public String getPassword() {
return password;
}
-
+
/**
* Sets the password.
- *
+ *
* @param password
* the new password
*/
public void setPassword(String password) {
this.password = password;
}
-
-
-
-
+
+
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/6d1e0356/framework/src/org/apache/cordova/BatteryListener.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/BatteryListener.java b/framework/src/org/apache/cordova/BatteryListener.java
index 84024b2..22b1b94 100755
--- a/framework/src/org/apache/cordova/BatteryListener.java
+++ b/framework/src/org/apache/cordova/BatteryListener.java
@@ -32,23 +32,23 @@ import android.content.IntentFilter;
import android.util.Log;
public class BatteryListener extends Plugin {
-
+
private static final String LOG_TAG = "BatteryManager";
BroadcastReceiver receiver;
private String batteryCallbackId = null;
-
+
/**
* Constructor.
*/
public BatteryListener() {
this.receiver = null;
}
-
+
/**
* Executes the request and returns PluginResult.
- *
+ *
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @param callbackId The callback id used when calling back into JavaScript.
@@ -56,12 +56,12 @@ public class BatteryListener extends Plugin {
*/
public PluginResult execute(String action, JSONArray args, String callbackId) {
PluginResult.Status status = PluginResult.Status.INVALID_ACTION;
- String result = "Unsupported Operation: " + action;
-
+ String result = "Unsupported Operation: " + action;
+
if (action.equals("start")) {
- if (this.batteryCallbackId != null) {
- return new PluginResult(PluginResult.Status.ERROR, "Battery listener already running.");
- }
+ if (this.batteryCallbackId != null) {
+ return new PluginResult(PluginResult.Status.ERROR, "Battery listener already running.");
+ }
this.batteryCallbackId = callbackId;
// We need to listen to power events to update battery status
@@ -70,29 +70,29 @@ public class BatteryListener extends Plugin {
if (this.receiver == null) {
this.receiver = new BroadcastReceiver() {
@Override
- public void onReceive(Context context, Intent intent) {
- updateBatteryInfo(intent);
+ public void onReceive(Context context, Intent intent) {
+ updateBatteryInfo(intent);
}
};
ctx.registerReceiver(this.receiver, intentFilter);
}
- // Don't return any result now, since status results will be sent when events come in from broadcast receiver
+ // Don't return any result now, since status results will be sent when events come in from broadcast receiver
PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
pluginResult.setKeepCallback(true);
return pluginResult;
- }
-
+ }
+
else if (action.equals("stop")) {
removeBatteryListener();
this.sendUpdate(new JSONObject(), false); // release status callback in JS side
this.batteryCallbackId = null;
return new PluginResult(PluginResult.Status.OK);
}
-
+
return new PluginResult(status, result);
}
-
+
/**
* Stop battery receiver.
*/
@@ -116,7 +116,7 @@ public class BatteryListener extends Plugin {
/**
* Creates a JSONObject with the current battery information
- *
+ *
* @param batteryIntent the current battery information
* @return a JSONObject containing the battery status information
*/
@@ -133,24 +133,24 @@ public class BatteryListener extends Plugin {
/**
* Updates the JavaScript side whenever the battery changes
- *
+ *
* @param batteryIntent the current battery information
* @return
*/
- private void updateBatteryInfo(Intent batteryIntent) {
+ private void updateBatteryInfo(Intent batteryIntent) {
sendUpdate(this.getBatteryInfo(batteryIntent), true);
}
-
+
/**
* Create a new plugin result and send it back to JavaScript
- *
+ *
* @param connection the network info to set as navigator.connection
*/
private void sendUpdate(JSONObject info, boolean keepCallback) {
- if (this.batteryCallbackId != null) {
- PluginResult result = new PluginResult(PluginResult.Status.OK, info);
- result.setKeepCallback(keepCallback);
- this.success(result, this.batteryCallbackId);
- }
+ if (this.batteryCallbackId != null) {
+ PluginResult result = new PluginResult(PluginResult.Status.OK, info);
+ result.setKeepCallback(keepCallback);
+ this.success(result, this.batteryCallbackId);
+ }
}
}