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,165 @@
|
|
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.HashMap;
|
22
|
+
import java.util.Map.Entry;
|
23
|
+
|
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
|
+
|
29
|
+
|
30
|
+
/*
|
31
|
+
* This class is the interface to the Geolocation. It's bound to the geo object.
|
32
|
+
*
|
33
|
+
* This class only starts and stops various GeoListeners, which consist of a GPS and a Network Listener
|
34
|
+
*/
|
35
|
+
|
36
|
+
public class GeoBroker extends Plugin {
|
37
|
+
|
38
|
+
// List of gGeolocation listeners
|
39
|
+
private HashMap<String, GeoListener> geoListeners;
|
40
|
+
private GeoListener global;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Constructor.
|
44
|
+
*/
|
45
|
+
public GeoBroker() {
|
46
|
+
this.geoListeners = new HashMap<String, GeoListener>();
|
47
|
+
}
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Executes the request and returns PluginResult.
|
51
|
+
*
|
52
|
+
* @param action The action to execute.
|
53
|
+
* @param args JSONArry of arguments for the plugin.
|
54
|
+
* @param callbackId The callback id used when calling back into JavaScript.
|
55
|
+
* @return A PluginResult object with a status and message.
|
56
|
+
*/
|
57
|
+
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
58
|
+
PluginResult.Status status = PluginResult.Status.OK;
|
59
|
+
String result = "";
|
60
|
+
|
61
|
+
try {
|
62
|
+
if (action.equals("getCurrentLocation")) {
|
63
|
+
this.getCurrentLocation(args.getBoolean(0), args.getInt(1), args.getInt(2));
|
64
|
+
}
|
65
|
+
else if (action.equals("start")) {
|
66
|
+
String s = this.start(args.getString(0), args.getBoolean(1), args.getInt(2), args.getInt(3));
|
67
|
+
return new PluginResult(status, s);
|
68
|
+
}
|
69
|
+
else if (action.equals("stop")) {
|
70
|
+
this.stop(args.getString(0));
|
71
|
+
}
|
72
|
+
return new PluginResult(status, result);
|
73
|
+
} catch (JSONException e) {
|
74
|
+
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Identifies if action to be executed returns a value and should be run synchronously.
|
80
|
+
*
|
81
|
+
* @param action The action to execute
|
82
|
+
* @return T=returns value
|
83
|
+
*/
|
84
|
+
public boolean isSynch(String action) {
|
85
|
+
// Starting listeners is easier to run on main thread, so don't run async.
|
86
|
+
return true;
|
87
|
+
}
|
88
|
+
|
89
|
+
/**
|
90
|
+
* Called when the activity is to be shut down.
|
91
|
+
* Stop listener.
|
92
|
+
*/
|
93
|
+
public void onDestroy() {
|
94
|
+
java.util.Set<Entry<String,GeoListener>> s = this.geoListeners.entrySet();
|
95
|
+
java.util.Iterator<Entry<String,GeoListener>> it = s.iterator();
|
96
|
+
while (it.hasNext()) {
|
97
|
+
Entry<String,GeoListener> entry = it.next();
|
98
|
+
GeoListener listener = entry.getValue();
|
99
|
+
listener.destroy();
|
100
|
+
}
|
101
|
+
this.geoListeners.clear();
|
102
|
+
if (this.global != null) {
|
103
|
+
this.global.destroy();
|
104
|
+
}
|
105
|
+
this.global = null;
|
106
|
+
}
|
107
|
+
|
108
|
+
//--------------------------------------------------------------------------
|
109
|
+
// LOCAL METHODS
|
110
|
+
//--------------------------------------------------------------------------
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Get current location.
|
114
|
+
* The result is returned to JavaScript via a callback.
|
115
|
+
*
|
116
|
+
* @param enableHighAccuracy
|
117
|
+
* @param timeout
|
118
|
+
* @param maximumAge
|
119
|
+
*/
|
120
|
+
public void getCurrentLocation(boolean enableHighAccuracy, int timeout, int maximumAge) {
|
121
|
+
|
122
|
+
// Create a geolocation listener just for getCurrentLocation and call it "global"
|
123
|
+
if (this.global == null) {
|
124
|
+
this.global = new GeoListener(this, "global", maximumAge);
|
125
|
+
}
|
126
|
+
else {
|
127
|
+
this.global.start(maximumAge);
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Start geolocation listener and add to listener list.
|
133
|
+
*
|
134
|
+
* @param key The listener id
|
135
|
+
* @param enableHighAccuracy
|
136
|
+
* @param timeout
|
137
|
+
* @param maximumAge
|
138
|
+
* @return
|
139
|
+
*/
|
140
|
+
public String start(String key, boolean enableHighAccuracy, int timeout, int maximumAge) {
|
141
|
+
|
142
|
+
// Make sure this listener doesn't already exist
|
143
|
+
GeoListener listener = geoListeners.get(key);
|
144
|
+
if (listener == null) {
|
145
|
+
listener = new GeoListener(this, key, maximumAge);
|
146
|
+
geoListeners.put(key, listener);
|
147
|
+
}
|
148
|
+
|
149
|
+
// Start it
|
150
|
+
listener.start(maximumAge);
|
151
|
+
return key;
|
152
|
+
}
|
153
|
+
|
154
|
+
/**
|
155
|
+
* Stop geolocation listener and remove from listener list.
|
156
|
+
*
|
157
|
+
* @param key The listener id
|
158
|
+
*/
|
159
|
+
public void stop(String key) {
|
160
|
+
GeoListener listener = geoListeners.remove(key);
|
161
|
+
if (listener != null) {
|
162
|
+
listener.stop();
|
163
|
+
}
|
164
|
+
}
|
165
|
+
}
|
@@ -0,0 +1,133 @@
|
|
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 android.content.Context;
|
22
|
+
import android.location.Location;
|
23
|
+
import android.location.LocationManager;
|
24
|
+
import android.webkit.WebView;
|
25
|
+
|
26
|
+
public class GeoListener {
|
27
|
+
public static int PERMISSION_DENIED = 1;
|
28
|
+
public static int POSITION_UNAVAILABLE = 2;
|
29
|
+
public static int TIMEOUT = 3;
|
30
|
+
|
31
|
+
String id; // Listener ID
|
32
|
+
String successCallback; //
|
33
|
+
String failCallback;
|
34
|
+
GpsListener mGps; // GPS listener
|
35
|
+
NetworkListener mNetwork; // Network listener
|
36
|
+
LocationManager mLocMan; // Location manager
|
37
|
+
|
38
|
+
private GeoBroker broker; // GeoBroker object
|
39
|
+
|
40
|
+
int interval;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Constructor.
|
44
|
+
*
|
45
|
+
* @param id Listener id
|
46
|
+
* @param ctx
|
47
|
+
* @param time Sampling period in msec
|
48
|
+
* @param appView
|
49
|
+
*/
|
50
|
+
GeoListener(GeoBroker broker, String id, int time) {
|
51
|
+
this.id = id;
|
52
|
+
this.interval = time;
|
53
|
+
this.broker = broker;
|
54
|
+
this.mGps = null;
|
55
|
+
this.mNetwork = null;
|
56
|
+
this.mLocMan = (LocationManager) broker.ctx.getSystemService(Context.LOCATION_SERVICE);
|
57
|
+
|
58
|
+
// If GPS provider, then create and start GPS listener
|
59
|
+
if (this.mLocMan.getProvider(LocationManager.GPS_PROVIDER) != null) {
|
60
|
+
this.mGps = new GpsListener(broker.ctx, time, this);
|
61
|
+
}
|
62
|
+
|
63
|
+
// If network provider, then create and start network listener
|
64
|
+
if (this.mLocMan.getProvider(LocationManager.NETWORK_PROVIDER) != null) {
|
65
|
+
this.mNetwork = new NetworkListener(broker.ctx, time, this);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Destroy listener.
|
71
|
+
*/
|
72
|
+
public void destroy() {
|
73
|
+
this.stop();
|
74
|
+
}
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Location found. Send location back to JavaScript.
|
78
|
+
*
|
79
|
+
* @param loc
|
80
|
+
*/
|
81
|
+
void success(Location loc) {
|
82
|
+
|
83
|
+
String params = loc.getLatitude() + "," + loc.getLongitude() + ", " + loc.getAltitude() +
|
84
|
+
"," + loc.getAccuracy() + "," + loc.getBearing() +
|
85
|
+
"," + loc.getSpeed() + "," + loc.getTime();
|
86
|
+
|
87
|
+
if (id == "global") {
|
88
|
+
this.stop();
|
89
|
+
}
|
90
|
+
this.broker.sendJavascript("navigator._geo.success('" + id + "'," + params + ");");
|
91
|
+
}
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Location failed. Send error back to JavaScript.
|
95
|
+
*
|
96
|
+
* @param code The error code
|
97
|
+
* @param msg The error message
|
98
|
+
*/
|
99
|
+
void fail(int code, String msg) {
|
100
|
+
this.broker.sendJavascript("navigator._geo.fail('" + this.id + "', '" + code + "', '" + msg + "');");
|
101
|
+
this.stop();
|
102
|
+
}
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Start retrieving location.
|
106
|
+
*
|
107
|
+
* @param interval
|
108
|
+
*/
|
109
|
+
void start(int interval) {
|
110
|
+
if (this.mGps != null) {
|
111
|
+
this.mGps.start(interval);
|
112
|
+
}
|
113
|
+
if (this.mNetwork != null) {
|
114
|
+
this.mNetwork.start(interval);
|
115
|
+
}
|
116
|
+
if (this.mNetwork == null && this.mGps == null) {
|
117
|
+
this.fail(POSITION_UNAVAILABLE, "No location providers available.");
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
/**
|
122
|
+
* Stop listening for location.
|
123
|
+
*/
|
124
|
+
void stop() {
|
125
|
+
if (this.mGps != null) {
|
126
|
+
this.mGps.stop();
|
127
|
+
}
|
128
|
+
if (this.mNetwork != null) {
|
129
|
+
this.mNetwork.stop();
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
}
|
@@ -0,0 +1,163 @@
|
|
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.CordovaInterface;
|
23
|
+
|
24
|
+
import android.content.Context;
|
25
|
+
import android.location.Location;
|
26
|
+
import android.location.LocationManager;
|
27
|
+
import android.location.LocationListener;
|
28
|
+
import android.os.Bundle;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* This class handles requests for GPS location services.
|
32
|
+
*
|
33
|
+
*/
|
34
|
+
public class GpsListener implements LocationListener {
|
35
|
+
|
36
|
+
private CordovaInterface mCtx; // CordovaActivity object
|
37
|
+
|
38
|
+
private LocationManager mLocMan; // Location manager object
|
39
|
+
private GeoListener owner; // Geolistener object (parent)
|
40
|
+
private boolean hasData = false; // Flag indicates if location data is available in cLoc
|
41
|
+
private Location cLoc; // Last recieved location
|
42
|
+
private boolean running = false; // Flag indicates if listener is running
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Constructor.
|
46
|
+
* Automatically starts listening.
|
47
|
+
*
|
48
|
+
* @param ctx
|
49
|
+
* @param interval
|
50
|
+
* @param m
|
51
|
+
*/
|
52
|
+
public GpsListener(CordovaInterface ctx, int interval, GeoListener m) {
|
53
|
+
this.owner = m;
|
54
|
+
this.mCtx = ctx;
|
55
|
+
this.mLocMan = (LocationManager) this.mCtx.getSystemService(Context.LOCATION_SERVICE);
|
56
|
+
this.running = false;
|
57
|
+
this.start(interval);
|
58
|
+
}
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Get last location.
|
62
|
+
*
|
63
|
+
* @return Location object
|
64
|
+
*/
|
65
|
+
public Location getLocation() {
|
66
|
+
this.cLoc = this.mLocMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
67
|
+
if (this.cLoc != null) {
|
68
|
+
this.hasData = true;
|
69
|
+
}
|
70
|
+
return this.cLoc;
|
71
|
+
}
|
72
|
+
|
73
|
+
/**
|
74
|
+
* Called when the provider is disabled by the user.
|
75
|
+
*
|
76
|
+
* @param provider
|
77
|
+
*/
|
78
|
+
public void onProviderDisabled(String provider) {
|
79
|
+
this.owner.fail(GeoListener.POSITION_UNAVAILABLE, "GPS provider disabled.");
|
80
|
+
}
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Called when the provider is enabled by the user.
|
84
|
+
*
|
85
|
+
* @param provider
|
86
|
+
*/
|
87
|
+
public void onProviderEnabled(String provider) {
|
88
|
+
System.out.println("GpsListener: The provider "+ provider + " is enabled");
|
89
|
+
}
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Called when the provider status changes. This method is called when a
|
93
|
+
* provider is unable to fetch a location or if the provider has recently
|
94
|
+
* become available after a period of unavailability.
|
95
|
+
*
|
96
|
+
* @param provider
|
97
|
+
* @param status
|
98
|
+
* @param extras
|
99
|
+
*/
|
100
|
+
public void onStatusChanged(String provider, int status, Bundle extras) {
|
101
|
+
System.out.println("GpsListener: The status of the provider " + provider + " has changed");
|
102
|
+
if (status == 0) {
|
103
|
+
System.out.println("GpsListener: " + provider + " is OUT OF SERVICE");
|
104
|
+
this.owner.fail(GeoListener.POSITION_UNAVAILABLE, "GPS out of service.");
|
105
|
+
}
|
106
|
+
else if (status == 1) {
|
107
|
+
System.out.println("GpsListener: " + provider + " is TEMPORARILY_UNAVAILABLE");
|
108
|
+
}
|
109
|
+
else {
|
110
|
+
System.out.println("GpsListener: " + provider + " is Available");
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
/**
|
115
|
+
* Called when the location has changed.
|
116
|
+
*
|
117
|
+
* @param location
|
118
|
+
*/
|
119
|
+
public void onLocationChanged(Location location) {
|
120
|
+
System.out.println("GpsListener: The location has been updated!");
|
121
|
+
this.hasData = true;
|
122
|
+
this.cLoc = location;
|
123
|
+
this.owner.success(location);
|
124
|
+
}
|
125
|
+
|
126
|
+
/**
|
127
|
+
* Determine if location data is available.
|
128
|
+
*
|
129
|
+
* @return
|
130
|
+
*/
|
131
|
+
public boolean hasLocation() {
|
132
|
+
return this.hasData;
|
133
|
+
}
|
134
|
+
|
135
|
+
/**
|
136
|
+
* Start requesting location updates.
|
137
|
+
*
|
138
|
+
* @param interval
|
139
|
+
*/
|
140
|
+
public void start(int interval) {
|
141
|
+
if (!this.running) {
|
142
|
+
this.running = true;
|
143
|
+
this.mLocMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, interval, 0, this);
|
144
|
+
this.getLocation();
|
145
|
+
|
146
|
+
// If GPS provider has data, then send now
|
147
|
+
if (this.hasData) {
|
148
|
+
this.owner.success(this.cLoc);
|
149
|
+
}
|
150
|
+
}
|
151
|
+
}
|
152
|
+
|
153
|
+
/**
|
154
|
+
* Stop receiving location updates.
|
155
|
+
*/
|
156
|
+
public void stop() {
|
157
|
+
if (this.running) {
|
158
|
+
this.mLocMan.removeUpdates(this);
|
159
|
+
}
|
160
|
+
this.running = false;
|
161
|
+
}
|
162
|
+
|
163
|
+
}
|
@@ -0,0 +1,80 @@
|
|
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.io.FileOutputStream;
|
22
|
+
import java.io.IOException;
|
23
|
+
import java.io.InputStream;
|
24
|
+
|
25
|
+
import org.apache.http.HttpEntity;
|
26
|
+
import org.apache.http.HttpResponse;
|
27
|
+
import org.apache.http.client.methods.HttpGet;
|
28
|
+
import org.apache.http.impl.client.DefaultHttpClient;
|
29
|
+
|
30
|
+
public class HttpHandler {
|
31
|
+
|
32
|
+
protected Boolean get(String url, String file)
|
33
|
+
{
|
34
|
+
HttpEntity entity = getHttpEntity(url);
|
35
|
+
try {
|
36
|
+
writeToDisk(entity, file);
|
37
|
+
} catch (Exception e) { e.printStackTrace(); return false; }
|
38
|
+
try {
|
39
|
+
entity.consumeContent();
|
40
|
+
} catch (Exception e) { e.printStackTrace(); return false; }
|
41
|
+
return true;
|
42
|
+
}
|
43
|
+
|
44
|
+
private HttpEntity getHttpEntity(String url)
|
45
|
+
/**
|
46
|
+
* get the http entity at a given url
|
47
|
+
*/
|
48
|
+
{
|
49
|
+
HttpEntity entity=null;
|
50
|
+
try {
|
51
|
+
DefaultHttpClient httpclient = new DefaultHttpClient();
|
52
|
+
HttpGet httpget = new HttpGet(url);
|
53
|
+
HttpResponse response = httpclient.execute(httpget);
|
54
|
+
entity = response.getEntity();
|
55
|
+
} catch (Exception e) { e.printStackTrace(); return null; }
|
56
|
+
return entity;
|
57
|
+
}
|
58
|
+
|
59
|
+
private void writeToDisk(HttpEntity entity, String file) throws IllegalStateException, IOException
|
60
|
+
/**
|
61
|
+
* writes a HTTP entity to the specified filename and location on disk
|
62
|
+
*/
|
63
|
+
{
|
64
|
+
int i=0;
|
65
|
+
String FilePath="/sdcard/" + file;
|
66
|
+
InputStream in = entity.getContent();
|
67
|
+
byte buff[] = new byte[1024];
|
68
|
+
FileOutputStream out=
|
69
|
+
new FileOutputStream(FilePath);
|
70
|
+
do {
|
71
|
+
int numread = in.read(buff);
|
72
|
+
if (numread <= 0)
|
73
|
+
break;
|
74
|
+
out.write(buff, 0, numread);
|
75
|
+
i++;
|
76
|
+
} while (true);
|
77
|
+
out.flush();
|
78
|
+
out.close();
|
79
|
+
}
|
80
|
+
}
|
data/templates/cordova_android/framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java
ADDED
@@ -0,0 +1,104 @@
|
|
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
|
+
import org.apache.cordova.api.LOG;
|
21
|
+
|
22
|
+
import android.content.Context;
|
23
|
+
import android.view.View.MeasureSpec;
|
24
|
+
import android.widget.LinearLayout;
|
25
|
+
|
26
|
+
/**
|
27
|
+
* This class is used to detect when the soft keyboard is shown and hidden in the web view.
|
28
|
+
*/
|
29
|
+
public class LinearLayoutSoftKeyboardDetect extends LinearLayout {
|
30
|
+
|
31
|
+
private static final String TAG = "SoftKeyboardDetect";
|
32
|
+
|
33
|
+
private int oldHeight = 0; // Need to save the old height as not to send redundant events
|
34
|
+
private int oldWidth = 0; // Need to save old width for orientation change
|
35
|
+
private int screenWidth = 0;
|
36
|
+
private int screenHeight = 0;
|
37
|
+
private DroidGap app = null;
|
38
|
+
|
39
|
+
public LinearLayoutSoftKeyboardDetect(Context context, int width, int height) {
|
40
|
+
super(context);
|
41
|
+
screenWidth = width;
|
42
|
+
screenHeight = height;
|
43
|
+
app = (DroidGap) context;
|
44
|
+
}
|
45
|
+
|
46
|
+
@Override
|
47
|
+
/**
|
48
|
+
* Start listening to new measurement events. Fire events when the height
|
49
|
+
* gets smaller fire a show keyboard event and when height gets bigger fire
|
50
|
+
* a hide keyboard event.
|
51
|
+
*
|
52
|
+
* Note: We are using app.postMessage so that this is more compatible with the API
|
53
|
+
*
|
54
|
+
* @param widthMeasureSpec
|
55
|
+
* @param heightMeasureSpec
|
56
|
+
*/
|
57
|
+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
58
|
+
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
59
|
+
|
60
|
+
LOG.v(TAG, "We are in our onMeasure method");
|
61
|
+
|
62
|
+
// Get the current height of the visible part of the screen.
|
63
|
+
// This height will not included the status bar.\
|
64
|
+
int width, height;
|
65
|
+
|
66
|
+
height = MeasureSpec.getSize(heightMeasureSpec);
|
67
|
+
width = MeasureSpec.getSize(widthMeasureSpec);
|
68
|
+
LOG.v(TAG, "Old Height = %d", oldHeight);
|
69
|
+
LOG.v(TAG, "Height = %d", height);
|
70
|
+
LOG.v(TAG, "Old Width = %d", oldWidth);
|
71
|
+
LOG.v(TAG, "Width = %d", width);
|
72
|
+
|
73
|
+
// If the oldHeight = 0 then this is the first measure event as the app starts up.
|
74
|
+
// If oldHeight == height then we got a measurement change that doesn't affect us.
|
75
|
+
if (oldHeight == 0 || oldHeight == height) {
|
76
|
+
LOG.d(TAG, "Ignore this event");
|
77
|
+
}
|
78
|
+
// Account for orientation change and ignore this event/Fire orientation change
|
79
|
+
else if(screenHeight == width)
|
80
|
+
{
|
81
|
+
int tmp_var = screenHeight;
|
82
|
+
screenHeight = screenWidth;
|
83
|
+
screenWidth = tmp_var;
|
84
|
+
LOG.v(TAG, "Orientation Change");
|
85
|
+
}
|
86
|
+
// If the height as gotten bigger then we will assume the soft keyboard has
|
87
|
+
// gone away.
|
88
|
+
else if (height > oldHeight) {
|
89
|
+
if(app != null)
|
90
|
+
app.sendJavascript("require('cordova').fireDocumentEvent('hidekeyboard');");
|
91
|
+
}
|
92
|
+
// If the height as gotten smaller then we will assume the soft keyboard has
|
93
|
+
// been displayed.
|
94
|
+
else if (height < oldHeight) {
|
95
|
+
if(app != null)
|
96
|
+
app.sendJavascript("require('cordova').fireDocumentEvent('showkeyboard');");
|
97
|
+
}
|
98
|
+
|
99
|
+
// Update the old height for the next event
|
100
|
+
oldHeight = height;
|
101
|
+
oldWidth = width;
|
102
|
+
}
|
103
|
+
|
104
|
+
}
|