mobile_template 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +28 -0
- data/Rakefile +3 -0
- data/bin/mobile_template +71 -0
- data/lib/mobile_template/version.rb +4 -0
- data/lib/mobile_template.rb +5 -0
- data/mobile_template.gemspec +21 -0
- data/templates/assets/Gemfile +4 -0
- data/templates/assets/config.rb +96 -0
- data/templates/assets/config.ru +4 -0
- data/templates/assets/source/images/vendor/ajax-loader.gif +0 -0
- data/templates/assets/source/images/vendor/ajax-loader.png +0 -0
- data/templates/assets/source/images/vendor/icons-18-black.png +0 -0
- data/templates/assets/source/images/vendor/icons-18-white.png +0 -0
- data/templates/assets/source/images/vendor/icons-36-black.png +0 -0
- data/templates/assets/source/images/vendor/icons-36-white.png +0 -0
- data/templates/assets/source/index.html.erb +2 -0
- data/templates/assets/source/javascripts/app/index.js.coffee +2 -0
- data/templates/assets/source/javascripts/application.js.coffee +5 -0
- data/templates/assets/source/javascripts/vendor/cordova.js +4841 -0
- data/templates/assets/source/javascripts/vendor/jquery.js +9267 -0
- data/templates/assets/source/javascripts/vendor/jquery.mobile.js +7410 -0
- data/templates/assets/source/layout.erb +24 -0
- data/templates/assets/source/stylesheets/application.css.scss +2 -0
- data/templates/assets/source/stylesheets/vendor/jquery.mobile.css.scss +1872 -0
- data/templates/cordova_android/.gitignore +18 -0
- data/templates/cordova_android/LICENSE +202 -0
- data/templates/cordova_android/NOTICE +5 -0
- data/templates/cordova_android/README.md +95 -0
- data/templates/cordova_android/VERSION +1 -0
- data/templates/cordova_android/bin/BOOM +4 -0
- data/templates/cordova_android/bin/autotest +2 -0
- data/templates/cordova_android/bin/bench +29 -0
- data/templates/cordova_android/bin/create +46 -0
- data/templates/cordova_android/bin/create.bat +1 -0
- data/templates/cordova_android/bin/create.js +88 -0
- data/templates/cordova_android/bin/create.xml +79 -0
- data/templates/cordova_android/bin/node_modules/.bin/cake +7 -0
- data/templates/cordova_android/bin/node_modules/.bin/coffee +7 -0
- data/templates/cordova_android/bin/node_modules/.bin/nodeunit +120 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/.npmignore +11 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/LICENSE +22 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/README +48 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/Rakefile +78 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/bin/cake +7 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/bin/coffee +7 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/extras/jsl.conf +44 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/browser.js +75 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/cake.js +76 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/coffee-script.js +135 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/command.js +301 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/grammar.js +591 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/helpers.js +66 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/index.js +8 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/lexer.js +656 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/nodes.js +2289 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/optparse.js +111 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/parser.js +676 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/repl.js +123 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/rewriter.js +363 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/lib/scope.js +120 -0
- data/templates/cordova_android/bin/node_modules/coffee-script/package.json +27 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/.gitignore +5 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/.npmignore +3 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/CONTRIBUTORS.md +60 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/LICENSE +19 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/Makefile +126 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/README.md +432 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/bin/nodeunit +120 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/bin/nodeunit.json +10 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/deps/async.js +623 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/deps/console.log.js +55 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/deps/ejs.js +125 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/deps/json2.js +483 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/nodeunit.js +1757 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/suite1.js +12 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/suite2.js +13 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/examples/browser/test.html +16 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/img/example_fail.png +0 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/img/example_pass.png +0 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/index.js +3 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/assert.js +316 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/core.js +260 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/nodeunit.js +82 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/browser.js +119 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/default.js +123 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/html.js +107 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/index.js +9 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/junit.js +183 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/minimal.js +112 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/reporters/skip_passed.js +105 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/track.js +48 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/types.js +187 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/lib/utils.js +209 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/man1/nodeunit.1 +95 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/nodelint.cfg +4 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/package.json +56 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/share/junit.xml.ejs +19 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/share/license.js +11 -0
- data/templates/cordova_android/bin/node_modules/nodeunit/share/nodeunit.css +70 -0
- data/templates/cordova_android/bin/templates/project/.cordova/android/readme.md +1 -0
- data/templates/cordova_android/bin/templates/project/.cordova/readme.md +3 -0
- data/templates/cordova_android/bin/templates/project/cordova/create +36 -0
- data/templates/cordova_android/bin/templates/project/cordova/debug +9 -0
- data/templates/cordova_android/bin/templates/project/cordova/emulate +12 -0
- data/templates/cordova_android/bin/templates/project/cordova/log +3 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/Activity.java +16 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/AndroidManifest.xml +50 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/index.html +42 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/main.js +146 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/assets/www/master.css +96 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/drawable/icon.png +0 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/xml/cordova.xml +5 -0
- data/templates/cordova_android/bin/templates/project/cordova/templates/project/res/xml/plugins.xml +19 -0
- data/templates/cordova_android/bin/test +26 -0
- data/templates/cordova_android/bin/tests/autotest.coffee +4 -0
- data/templates/cordova_android/bin/tests/create.coffee +21 -0
- data/templates/cordova_android/bin/tests/debug.coffee +0 -0
- data/templates/cordova_android/bin/tests/test.coffee +0 -0
- data/templates/cordova_android/framework/.classpath +8 -0
- data/templates/cordova_android/framework/.project +33 -0
- data/templates/cordova_android/framework/AndroidManifest.xml +68 -0
- data/templates/cordova_android/framework/ant.properties +34 -0
- data/templates/cordova_android/framework/assets/js/accelerometer.js +137 -0
- data/templates/cordova_android/framework/assets/js/app.js +89 -0
- data/templates/cordova_android/framework/assets/js/battery.js +134 -0
- data/templates/cordova_android/framework/assets/js/camera.js +168 -0
- data/templates/cordova_android/framework/assets/js/capture.js +203 -0
- data/templates/cordova_android/framework/assets/js/compass.js +168 -0
- data/templates/cordova_android/framework/assets/js/contact.js +310 -0
- data/templates/cordova_android/framework/assets/js/cordova.android.js +4841 -0
- data/templates/cordova_android/framework/assets/js/cordova.js.base +924 -0
- data/templates/cordova_android/framework/assets/js/crypto.js +54 -0
- data/templates/cordova_android/framework/assets/js/device.js +83 -0
- data/templates/cordova_android/framework/assets/js/file.js +1082 -0
- data/templates/cordova_android/framework/assets/js/filetransfer.js +125 -0
- data/templates/cordova_android/framework/assets/js/geolocation.js +209 -0
- data/templates/cordova_android/framework/assets/js/header.txt +19 -0
- data/templates/cordova_android/framework/assets/js/media.js +233 -0
- data/templates/cordova_android/framework/assets/js/network.js +100 -0
- data/templates/cordova_android/framework/assets/js/notification.js +133 -0
- data/templates/cordova_android/framework/assets/js/position.js +100 -0
- data/templates/cordova_android/framework/assets/js/storage.js +439 -0
- data/templates/cordova_android/framework/assets/www/index.html +27 -0
- data/templates/cordova_android/framework/build.xml +216 -0
- data/templates/cordova_android/framework/libs/commons-codec-1.3.jar +0 -0
- data/templates/cordova_android/framework/proguard-project.txt +20 -0
- data/templates/cordova_android/framework/project.properties +14 -0
- data/templates/cordova_android/framework/res/drawable/icon.png +0 -0
- data/templates/cordova_android/framework/res/drawable/splash.png +0 -0
- data/templates/cordova_android/framework/res/layout/main.xml +29 -0
- data/templates/cordova_android/framework/res/values/strings.xml +23 -0
- data/templates/cordova_android/framework/res/xml/cordova.xml +37 -0
- data/templates/cordova_android/framework/res/xml/plugins.xml +37 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/IPlugin.java +27 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/LOG.java +28 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/PhonegapActivity.java +28 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/Plugin.java +27 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/PluginManager.java +35 -0
- data/templates/cordova_android/framework/src/com/phonegap/api/PluginResult.java +53 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/AccelListener.java +311 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/App.java +198 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/AudioHandler.java +364 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/AudioPlayer.java +450 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/AuthenticationToken.java +69 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/BatteryListener.java +156 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CallbackServer.java +431 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CameraLauncher.java +500 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/Capture.java +400 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CompassListener.java +308 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessor.java +198 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/ContactAccessorSdk5.java +1934 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/ContactManager.java +113 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CordovaChromeClient.java +314 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/CordovaWebViewClient.java +306 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/Device.java +219 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/DirectoryManager.java +161 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/DroidGap.java +1417 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/ExifHelper.java +165 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/FileTransfer.java +458 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/FileUploadResult.java +63 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/FileUtils.java +1048 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/GeoBroker.java +165 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/GeoListener.java +133 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/GpsListener.java +163 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/HttpHandler.java +80 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java +104 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/NetworkListener.java +153 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/NetworkManager.java +248 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/Notification.java +366 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/PreferenceNode.java +34 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/PreferenceSet.java +62 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/StandAlone.java +35 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/Storage.java +239 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/TempListener.java +112 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/CordovaInterface.java +145 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/IPlugin.java +116 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/LOG.java +234 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/Plugin.java +210 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginManager.java +359 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/api/PluginResult.java +119 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/file/EncodingException.java +28 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/file/FileExistsException.java +28 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/file/InvalidModificationException.java +29 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/file/NoModificationAllowedException.java +28 -0
- data/templates/cordova_android/framework/src/org/apache/cordova/file/TypeMismatchException.java +29 -0
- data/templates/cordova_android/framework/test/org/apache/cordova/PreferenceNodeTest.java +53 -0
- data/templates/cordova_android/framework/test/org/apache/cordova/PreferenceSetTest.java +73 -0
- metadata +279 -0
@@ -0,0 +1,311 @@
|
|
1
|
+
/*
|
2
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
or more contributor license agreements. See the NOTICE file
|
4
|
+
distributed with this work for additional information
|
5
|
+
regarding copyright ownership. The ASF licenses this file
|
6
|
+
to you under the Apache License, Version 2.0 (the
|
7
|
+
"License"); you may not use this file except in compliance
|
8
|
+
with the License. You may obtain a copy of the License at
|
9
|
+
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
|
12
|
+
Unless required by applicable law or agreed to in writing,
|
13
|
+
software distributed under the License is distributed on an
|
14
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
KIND, either express or implied. See the License for the
|
16
|
+
specific language governing permissions and limitations
|
17
|
+
under the License.
|
18
|
+
*/
|
19
|
+
package org.apache.cordova;
|
20
|
+
|
21
|
+
import java.util.List;
|
22
|
+
|
23
|
+
import org.apache.cordova.api.CordovaInterface;
|
24
|
+
import org.apache.cordova.api.Plugin;
|
25
|
+
import org.apache.cordova.api.PluginResult;
|
26
|
+
import org.json.JSONArray;
|
27
|
+
import org.json.JSONException;
|
28
|
+
import org.json.JSONObject;
|
29
|
+
|
30
|
+
|
31
|
+
import android.hardware.Sensor;
|
32
|
+
import android.hardware.SensorEvent;
|
33
|
+
import android.hardware.SensorEventListener;
|
34
|
+
import android.hardware.SensorManager;
|
35
|
+
import android.content.Context;
|
36
|
+
|
37
|
+
/**
|
38
|
+
* This class listens to the accelerometer sensor and stores the latest
|
39
|
+
* acceleration values x,y,z.
|
40
|
+
*/
|
41
|
+
public class AccelListener extends Plugin implements SensorEventListener {
|
42
|
+
|
43
|
+
public static int STOPPED = 0;
|
44
|
+
public static int STARTING = 1;
|
45
|
+
public static int RUNNING = 2;
|
46
|
+
public static int ERROR_FAILED_TO_START = 3;
|
47
|
+
|
48
|
+
public float TIMEOUT = 30000; // Timeout in msec to shut off listener
|
49
|
+
|
50
|
+
float x,y,z; // most recent acceleration values
|
51
|
+
long timestamp; // time of most recent value
|
52
|
+
int status; // status of listener
|
53
|
+
long lastAccessTime; // time the value was last retrieved
|
54
|
+
|
55
|
+
private SensorManager sensorManager;// Sensor manager
|
56
|
+
Sensor mSensor; // Acceleration sensor returned by sensor manager
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Create an accelerometer listener.
|
60
|
+
*/
|
61
|
+
public AccelListener() {
|
62
|
+
this.x = 0;
|
63
|
+
this.y = 0;
|
64
|
+
this.z = 0;
|
65
|
+
this.timestamp = 0;
|
66
|
+
this.setStatus(AccelListener.STOPPED);
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Sets the context of the Command. This can then be used to do things like
|
71
|
+
* get file paths associated with the Activity.
|
72
|
+
*
|
73
|
+
* @param ctx The context of the main Activity.
|
74
|
+
*/
|
75
|
+
public void setContext(CordovaInterface ctx) {
|
76
|
+
super.setContext(ctx);
|
77
|
+
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
78
|
+
}
|
79
|
+
|
80
|
+
/**
|
81
|
+
* Executes the request and returns PluginResult.
|
82
|
+
*
|
83
|
+
* @param action The action to execute.
|
84
|
+
* @param args JSONArry of arguments for the plugin.
|
85
|
+
* @param callbackId The callback id used when calling back into JavaScript.
|
86
|
+
* @return A PluginResult object with a status and message.
|
87
|
+
*/
|
88
|
+
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
89
|
+
PluginResult.Status status = PluginResult.Status.OK;
|
90
|
+
String result = "";
|
91
|
+
|
92
|
+
try {
|
93
|
+
if (action.equals("getStatus")) {
|
94
|
+
int i = this.getStatus();
|
95
|
+
return new PluginResult(status, i);
|
96
|
+
}
|
97
|
+
else if (action.equals("start")) {
|
98
|
+
int i = this.start();
|
99
|
+
return new PluginResult(status, i);
|
100
|
+
}
|
101
|
+
else if (action.equals("stop")) {
|
102
|
+
this.stop();
|
103
|
+
return new PluginResult(status, 0);
|
104
|
+
}
|
105
|
+
else if (action.equals("getAcceleration")) {
|
106
|
+
// If not running, then this is an async call, so don't worry about waiting
|
107
|
+
if (this.status != AccelListener.RUNNING) {
|
108
|
+
int r = this.start();
|
109
|
+
if (r == AccelListener.ERROR_FAILED_TO_START) {
|
110
|
+
return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START);
|
111
|
+
}
|
112
|
+
// Wait until running
|
113
|
+
long timeout = 2000;
|
114
|
+
while ((this.status == STARTING) && (timeout > 0)) {
|
115
|
+
timeout = timeout - 100;
|
116
|
+
try {
|
117
|
+
Thread.sleep(100);
|
118
|
+
} catch (InterruptedException e) {
|
119
|
+
e.printStackTrace();
|
120
|
+
}
|
121
|
+
}
|
122
|
+
if (timeout == 0) {
|
123
|
+
return new PluginResult(PluginResult.Status.IO_EXCEPTION, AccelListener.ERROR_FAILED_TO_START);
|
124
|
+
}
|
125
|
+
}
|
126
|
+
this.lastAccessTime = System.currentTimeMillis();
|
127
|
+
JSONObject r = new JSONObject();
|
128
|
+
r.put("x", this.x);
|
129
|
+
r.put("y", this.y);
|
130
|
+
r.put("z", this.z);
|
131
|
+
// TODO: Should timestamp be sent?
|
132
|
+
r.put("timestamp", this.timestamp);
|
133
|
+
return new PluginResult(status, r);
|
134
|
+
}
|
135
|
+
else if (action.equals("setTimeout")) {
|
136
|
+
try {
|
137
|
+
float timeout = Float.parseFloat(args.getString(0));
|
138
|
+
this.setTimeout(timeout);
|
139
|
+
return new PluginResult(status, 0);
|
140
|
+
} catch (NumberFormatException e) {
|
141
|
+
status = PluginResult.Status.INVALID_ACTION;
|
142
|
+
e.printStackTrace();
|
143
|
+
} catch (JSONException e) {
|
144
|
+
status = PluginResult.Status.JSON_EXCEPTION;
|
145
|
+
e.printStackTrace();
|
146
|
+
}
|
147
|
+
}
|
148
|
+
else if (action.equals("getTimeout")) {
|
149
|
+
float f = this.getTimeout();
|
150
|
+
return new PluginResult(status, f);
|
151
|
+
} else {
|
152
|
+
// Unsupported action
|
153
|
+
return new PluginResult(PluginResult.Status.INVALID_ACTION);
|
154
|
+
}
|
155
|
+
return new PluginResult(status, result);
|
156
|
+
} catch (JSONException e) {
|
157
|
+
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
/**
|
162
|
+
* Identifies if action to be executed returns a value and should be run synchronously.
|
163
|
+
*
|
164
|
+
* @param action The action to execute
|
165
|
+
* @return T=returns value
|
166
|
+
*/
|
167
|
+
public boolean isSynch(String action) {
|
168
|
+
if (action.equals("getStatus")) {
|
169
|
+
return true;
|
170
|
+
}
|
171
|
+
else if (action.equals("getAcceleration")) {
|
172
|
+
// Can only return value if RUNNING
|
173
|
+
if (this.status == AccelListener.RUNNING) {
|
174
|
+
return true;
|
175
|
+
}
|
176
|
+
}
|
177
|
+
else if (action.equals("getTimeout")) {
|
178
|
+
return true;
|
179
|
+
}
|
180
|
+
return false;
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Called by AccelBroker when listener is to be shut down.
|
185
|
+
* Stop listener.
|
186
|
+
*/
|
187
|
+
public void onDestroy() {
|
188
|
+
this.stop();
|
189
|
+
}
|
190
|
+
|
191
|
+
//--------------------------------------------------------------------------
|
192
|
+
// LOCAL METHODS
|
193
|
+
//--------------------------------------------------------------------------
|
194
|
+
|
195
|
+
/**
|
196
|
+
* Start listening for acceleration sensor.
|
197
|
+
*
|
198
|
+
* @return status of listener
|
199
|
+
*/
|
200
|
+
public int start() {
|
201
|
+
|
202
|
+
// If already starting or running, then just return
|
203
|
+
if ((this.status == AccelListener.RUNNING) || (this.status == AccelListener.STARTING)) {
|
204
|
+
return this.status;
|
205
|
+
}
|
206
|
+
|
207
|
+
// Get accelerometer from sensor manager
|
208
|
+
List<Sensor> list = this.sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
|
209
|
+
|
210
|
+
// If found, then register as listener
|
211
|
+
if ((list != null) && (list.size() > 0)) {
|
212
|
+
this.mSensor = list.get(0);
|
213
|
+
this.sensorManager.registerListener(this, this.mSensor, SensorManager.SENSOR_DELAY_FASTEST);
|
214
|
+
this.setStatus(AccelListener.STARTING);
|
215
|
+
this.lastAccessTime = System.currentTimeMillis();
|
216
|
+
}
|
217
|
+
|
218
|
+
// If error, then set status to error
|
219
|
+
else {
|
220
|
+
this.setStatus(AccelListener.ERROR_FAILED_TO_START);
|
221
|
+
}
|
222
|
+
|
223
|
+
return this.status;
|
224
|
+
}
|
225
|
+
|
226
|
+
/**
|
227
|
+
* Stop listening to acceleration sensor.
|
228
|
+
*/
|
229
|
+
public void stop() {
|
230
|
+
if (this.status != AccelListener.STOPPED) {
|
231
|
+
this.sensorManager.unregisterListener(this);
|
232
|
+
}
|
233
|
+
this.setStatus(AccelListener.STOPPED);
|
234
|
+
}
|
235
|
+
|
236
|
+
/**
|
237
|
+
* Called when the accuracy of the sensor has changed.
|
238
|
+
*
|
239
|
+
* @param sensor
|
240
|
+
* @param accuracy
|
241
|
+
*/
|
242
|
+
public void onAccuracyChanged(Sensor sensor, int accuracy) {
|
243
|
+
}
|
244
|
+
|
245
|
+
/**
|
246
|
+
* Sensor listener event.
|
247
|
+
*
|
248
|
+
* @param SensorEvent event
|
249
|
+
*/
|
250
|
+
public void onSensorChanged(SensorEvent event) {
|
251
|
+
|
252
|
+
// Only look at accelerometer events
|
253
|
+
if (event.sensor.getType() != Sensor.TYPE_ACCELEROMETER) {
|
254
|
+
return;
|
255
|
+
}
|
256
|
+
|
257
|
+
// If not running, then just return
|
258
|
+
if (this.status == AccelListener.STOPPED) {
|
259
|
+
return;
|
260
|
+
}
|
261
|
+
|
262
|
+
// Save time that event was received
|
263
|
+
this.timestamp = System.currentTimeMillis();
|
264
|
+
this.x = event.values[0];
|
265
|
+
this.y = event.values[1];
|
266
|
+
this.z = event.values[2];
|
267
|
+
|
268
|
+
this.setStatus(AccelListener.RUNNING);
|
269
|
+
|
270
|
+
// If values haven't been read for TIMEOUT time, then turn off accelerometer sensor to save power
|
271
|
+
if ((this.timestamp - this.lastAccessTime) > this.TIMEOUT) {
|
272
|
+
this.stop();
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
/**
|
277
|
+
* Get status of accelerometer sensor.
|
278
|
+
*
|
279
|
+
* @return status
|
280
|
+
*/
|
281
|
+
public int getStatus() {
|
282
|
+
return this.status;
|
283
|
+
}
|
284
|
+
|
285
|
+
/**
|
286
|
+
* Set the timeout to turn off accelerometer sensor if getX() hasn't been called.
|
287
|
+
*
|
288
|
+
* @param timeout Timeout in msec.
|
289
|
+
*/
|
290
|
+
public void setTimeout(float timeout) {
|
291
|
+
this.TIMEOUT = timeout;
|
292
|
+
}
|
293
|
+
|
294
|
+
/**
|
295
|
+
* Get the timeout to turn off accelerometer sensor if getX() hasn't been called.
|
296
|
+
*
|
297
|
+
* @return timeout in msec
|
298
|
+
*/
|
299
|
+
public float getTimeout() {
|
300
|
+
return this.TIMEOUT;
|
301
|
+
}
|
302
|
+
|
303
|
+
/**
|
304
|
+
* Set the status and send it to JavaScript.
|
305
|
+
* @param status
|
306
|
+
*/
|
307
|
+
private void setStatus(int status) {
|
308
|
+
this.status = status;
|
309
|
+
}
|
310
|
+
|
311
|
+
}
|
@@ -0,0 +1,198 @@
|
|
1
|
+
/*
|
2
|
+
Licensed to the Apache Software Foundation (ASF) under one
|
3
|
+
or more contributor license agreements. See the NOTICE file
|
4
|
+
distributed with this work for additional information
|
5
|
+
regarding copyright ownership. The ASF licenses this file
|
6
|
+
to you under the Apache License, Version 2.0 (the
|
7
|
+
"License"); you may not use this file except in compliance
|
8
|
+
with the License. You may obtain a copy of the License at
|
9
|
+
|
10
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
|
12
|
+
Unless required by applicable law or agreed to in writing,
|
13
|
+
software distributed under the License is distributed on an
|
14
|
+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
15
|
+
KIND, either express or implied. See the License for the
|
16
|
+
specific language governing permissions and limitations
|
17
|
+
under the License.
|
18
|
+
*/
|
19
|
+
|
20
|
+
package org.apache.cordova;
|
21
|
+
|
22
|
+
import org.apache.cordova.api.LOG;
|
23
|
+
import org.apache.cordova.api.Plugin;
|
24
|
+
import org.apache.cordova.api.PluginResult;
|
25
|
+
import org.json.JSONArray;
|
26
|
+
import org.json.JSONException;
|
27
|
+
import org.json.JSONObject;
|
28
|
+
import java.util.HashMap;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* This class exposes methods in DroidGap that can be called from JavaScript.
|
32
|
+
*/
|
33
|
+
public class App extends Plugin {
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Executes the request and returns PluginResult.
|
37
|
+
*
|
38
|
+
* @param action The action to execute.
|
39
|
+
* @param args JSONArry of arguments for the plugin.
|
40
|
+
* @param callbackId The callback id used when calling back into JavaScript.
|
41
|
+
* @return A PluginResult object with a status and message.
|
42
|
+
*/
|
43
|
+
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
44
|
+
PluginResult.Status status = PluginResult.Status.OK;
|
45
|
+
String result = "";
|
46
|
+
|
47
|
+
try {
|
48
|
+
if (action.equals("clearCache")) {
|
49
|
+
this.clearCache();
|
50
|
+
}
|
51
|
+
else if (action.equals("loadUrl")) {
|
52
|
+
this.loadUrl(args.getString(0), args.optJSONObject(1));
|
53
|
+
}
|
54
|
+
else if (action.equals("cancelLoadUrl")) {
|
55
|
+
this.cancelLoadUrl();
|
56
|
+
}
|
57
|
+
else if (action.equals("clearHistory")) {
|
58
|
+
this.clearHistory();
|
59
|
+
}
|
60
|
+
else if (action.equals("backHistory")) {
|
61
|
+
this.backHistory();
|
62
|
+
}
|
63
|
+
else if (action.equals("overrideBackbutton")) {
|
64
|
+
this.overrideBackbutton(args.getBoolean(0));
|
65
|
+
}
|
66
|
+
else if (action.equals("isBackbuttonOverridden")) {
|
67
|
+
boolean b = this.isBackbuttonOverridden();
|
68
|
+
return new PluginResult(status, b);
|
69
|
+
}
|
70
|
+
else if (action.equals("exitApp")) {
|
71
|
+
this.exitApp();
|
72
|
+
}
|
73
|
+
return new PluginResult(status, result);
|
74
|
+
} catch (JSONException e) {
|
75
|
+
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
//--------------------------------------------------------------------------
|
80
|
+
// LOCAL METHODS
|
81
|
+
//--------------------------------------------------------------------------
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Clear the resource cache.
|
85
|
+
*/
|
86
|
+
public void clearCache() {
|
87
|
+
((DroidGap)this.ctx).clearCache();
|
88
|
+
}
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Load the url into the webview.
|
92
|
+
*
|
93
|
+
* @param url
|
94
|
+
* @param props Properties that can be passed in to the DroidGap activity (i.e. loadingDialog, wait, ...)
|
95
|
+
* @throws JSONException
|
96
|
+
*/
|
97
|
+
public void loadUrl(String url, JSONObject props) throws JSONException {
|
98
|
+
LOG.d("App", "App.loadUrl("+url+","+props+")");
|
99
|
+
int wait = 0;
|
100
|
+
boolean openExternal = false;
|
101
|
+
boolean clearHistory = false;
|
102
|
+
|
103
|
+
// If there are properties, then set them on the Activity
|
104
|
+
HashMap<String, Object> params = new HashMap<String, Object>();
|
105
|
+
if (props != null) {
|
106
|
+
JSONArray keys = props.names();
|
107
|
+
for (int i=0; i<keys.length(); i++) {
|
108
|
+
String key = keys.getString(i);
|
109
|
+
if (key.equals("wait")) {
|
110
|
+
wait = props.getInt(key);
|
111
|
+
}
|
112
|
+
else if (key.equalsIgnoreCase("openexternal")) {
|
113
|
+
openExternal = props.getBoolean(key);
|
114
|
+
}
|
115
|
+
else if (key.equalsIgnoreCase("clearhistory")) {
|
116
|
+
clearHistory = props.getBoolean(key);
|
117
|
+
}
|
118
|
+
else {
|
119
|
+
Object value = props.get(key);
|
120
|
+
if (value == null) {
|
121
|
+
|
122
|
+
}
|
123
|
+
else if (value.getClass().equals(String.class)) {
|
124
|
+
params.put(key, (String)value);
|
125
|
+
}
|
126
|
+
else if (value.getClass().equals(Boolean.class)) {
|
127
|
+
params.put(key, (Boolean)value);
|
128
|
+
}
|
129
|
+
else if (value.getClass().equals(Integer.class)) {
|
130
|
+
params.put(key, (Integer)value);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
// If wait property, then delay loading
|
137
|
+
|
138
|
+
if (wait > 0) {
|
139
|
+
try {
|
140
|
+
synchronized(this) {
|
141
|
+
this.wait(wait);
|
142
|
+
}
|
143
|
+
} catch (InterruptedException e) {
|
144
|
+
e.printStackTrace();
|
145
|
+
}
|
146
|
+
}
|
147
|
+
((DroidGap)this.ctx).showWebPage(url, openExternal, clearHistory, params);
|
148
|
+
}
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Cancel loadUrl before it has been loaded.
|
152
|
+
*/
|
153
|
+
public void cancelLoadUrl() {
|
154
|
+
((DroidGap)this.ctx).cancelLoadUrl();
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* Clear page history for the app.
|
159
|
+
*/
|
160
|
+
public void clearHistory() {
|
161
|
+
((DroidGap)this.ctx).clearHistory();
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
* Go to previous page displayed.
|
166
|
+
* This is the same as pressing the backbutton on Android device.
|
167
|
+
*/
|
168
|
+
public void backHistory() {
|
169
|
+
((DroidGap)this.ctx).backHistory();
|
170
|
+
}
|
171
|
+
|
172
|
+
/**
|
173
|
+
* Override the default behavior of the Android back button.
|
174
|
+
* If overridden, when the back button is pressed, the "backKeyDown" JavaScript event will be fired.
|
175
|
+
*
|
176
|
+
* @param override T=override, F=cancel override
|
177
|
+
*/
|
178
|
+
public void overrideBackbutton(boolean override) {
|
179
|
+
LOG.i("DroidGap", "WARNING: Back Button Default Behaviour will be overridden. The backbutton event will be fired!");
|
180
|
+
((DroidGap)this.ctx).bound = override;
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Return whether the Android back button is overridden by the user.
|
185
|
+
*
|
186
|
+
* @return boolean
|
187
|
+
*/
|
188
|
+
public boolean isBackbuttonOverridden() {
|
189
|
+
return ((DroidGap)this.ctx).bound;
|
190
|
+
}
|
191
|
+
|
192
|
+
/**
|
193
|
+
* Exit the Android application.
|
194
|
+
*/
|
195
|
+
public void exitApp() {
|
196
|
+
((DroidGap)this.ctx).endActivity();
|
197
|
+
}
|
198
|
+
}
|