mobile_template 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,306 @@
|
|
|
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 org.apache.cordova.api.LOG;
|
|
22
|
+
|
|
23
|
+
import android.content.Intent;
|
|
24
|
+
import android.content.pm.ApplicationInfo;
|
|
25
|
+
import android.content.pm.PackageManager;
|
|
26
|
+
import android.content.pm.PackageManager.NameNotFoundException;
|
|
27
|
+
import android.graphics.Bitmap;
|
|
28
|
+
import android.net.Uri;
|
|
29
|
+
import android.net.http.SslError;
|
|
30
|
+
import android.util.Log;
|
|
31
|
+
import android.view.View;
|
|
32
|
+
import android.webkit.HttpAuthHandler;
|
|
33
|
+
import android.webkit.SslErrorHandler;
|
|
34
|
+
import android.webkit.WebView;
|
|
35
|
+
import android.webkit.WebViewClient;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* This class is the WebViewClient that implements callbacks for our web view.
|
|
39
|
+
*/
|
|
40
|
+
public class CordovaWebViewClient extends WebViewClient {
|
|
41
|
+
|
|
42
|
+
private static final String TAG = "Cordova";
|
|
43
|
+
DroidGap ctx;
|
|
44
|
+
private boolean doClearHistory = false;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Constructor.
|
|
48
|
+
*
|
|
49
|
+
* @param ctx
|
|
50
|
+
*/
|
|
51
|
+
public CordovaWebViewClient(DroidGap ctx) {
|
|
52
|
+
this.ctx = ctx;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Give the host application a chance to take over the control when a new url
|
|
57
|
+
* is about to be loaded in the current WebView.
|
|
58
|
+
*
|
|
59
|
+
* @param view The WebView that is initiating the callback.
|
|
60
|
+
* @param url The url to be loaded.
|
|
61
|
+
* @return true to override, false for default behavior
|
|
62
|
+
*/
|
|
63
|
+
@Override
|
|
64
|
+
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
65
|
+
|
|
66
|
+
// First give any plugins the chance to handle the url themselves
|
|
67
|
+
if (this.ctx.pluginManager.onOverrideUrlLoading(url)) {
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// If dialing phone (tel:5551212)
|
|
71
|
+
else if (url.startsWith(WebView.SCHEME_TEL)) {
|
|
72
|
+
try {
|
|
73
|
+
Intent intent = new Intent(Intent.ACTION_DIAL);
|
|
74
|
+
intent.setData(Uri.parse(url));
|
|
75
|
+
ctx.startActivity(intent);
|
|
76
|
+
} catch (android.content.ActivityNotFoundException e) {
|
|
77
|
+
LOG.e(TAG, "Error dialing "+url+": "+ e.toString());
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// If displaying map (geo:0,0?q=address)
|
|
82
|
+
else if (url.startsWith("geo:")) {
|
|
83
|
+
try {
|
|
84
|
+
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
85
|
+
intent.setData(Uri.parse(url));
|
|
86
|
+
ctx.startActivity(intent);
|
|
87
|
+
} catch (android.content.ActivityNotFoundException e) {
|
|
88
|
+
LOG.e(TAG, "Error showing map "+url+": "+ e.toString());
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// If sending email (mailto:abc@corp.com)
|
|
93
|
+
else if (url.startsWith(WebView.SCHEME_MAILTO)) {
|
|
94
|
+
try {
|
|
95
|
+
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
96
|
+
intent.setData(Uri.parse(url));
|
|
97
|
+
ctx.startActivity(intent);
|
|
98
|
+
} catch (android.content.ActivityNotFoundException e) {
|
|
99
|
+
LOG.e(TAG, "Error sending email "+url+": "+ e.toString());
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// If sms:5551212?body=This is the message
|
|
104
|
+
else if (url.startsWith("sms:")) {
|
|
105
|
+
try {
|
|
106
|
+
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
107
|
+
|
|
108
|
+
// Get address
|
|
109
|
+
String address = null;
|
|
110
|
+
int parmIndex = url.indexOf('?');
|
|
111
|
+
if (parmIndex == -1) {
|
|
112
|
+
address = url.substring(4);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
address = url.substring(4, parmIndex);
|
|
116
|
+
|
|
117
|
+
// If body, then set sms body
|
|
118
|
+
Uri uri = Uri.parse(url);
|
|
119
|
+
String query = uri.getQuery();
|
|
120
|
+
if (query != null) {
|
|
121
|
+
if (query.startsWith("body=")) {
|
|
122
|
+
intent.putExtra("sms_body", query.substring(5));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
intent.setData(Uri.parse("sms:"+address));
|
|
127
|
+
intent.putExtra("address", address);
|
|
128
|
+
intent.setType("vnd.android-dir/mms-sms");
|
|
129
|
+
ctx.startActivity(intent);
|
|
130
|
+
} catch (android.content.ActivityNotFoundException e) {
|
|
131
|
+
LOG.e(TAG, "Error sending sms "+url+":"+ e.toString());
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// All else
|
|
136
|
+
else {
|
|
137
|
+
|
|
138
|
+
// If our app or file:, then load into a new Cordova webview container by starting a new instance of our activity.
|
|
139
|
+
// Our app continues to run. When BACK is pressed, our app is redisplayed.
|
|
140
|
+
if (url.startsWith("file://") || url.indexOf(this.ctx.baseUrl) == 0 || ctx.isUrlWhiteListed(url)) {
|
|
141
|
+
this.ctx.loadUrl(url);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// If not our application, let default viewer handle
|
|
145
|
+
else {
|
|
146
|
+
try {
|
|
147
|
+
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
148
|
+
intent.setData(Uri.parse(url));
|
|
149
|
+
ctx.startActivity(intent);
|
|
150
|
+
} catch (android.content.ActivityNotFoundException e) {
|
|
151
|
+
LOG.e(TAG, "Error loading url "+url, e);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* On received http auth request.
|
|
160
|
+
* The method reacts on all registered authentication tokens. There is one and only one authentication token for any host + realm combination
|
|
161
|
+
*
|
|
162
|
+
* @param view
|
|
163
|
+
* the view
|
|
164
|
+
* @param handler
|
|
165
|
+
* the handler
|
|
166
|
+
* @param host
|
|
167
|
+
* the host
|
|
168
|
+
* @param realm
|
|
169
|
+
* the realm
|
|
170
|
+
*/
|
|
171
|
+
@Override
|
|
172
|
+
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host,
|
|
173
|
+
String realm) {
|
|
174
|
+
|
|
175
|
+
// get the authentication token
|
|
176
|
+
AuthenticationToken token = ctx.getAuthenticationToken(host,realm);
|
|
177
|
+
|
|
178
|
+
if(token != null) {
|
|
179
|
+
handler.proceed(token.getUserName(), token.getPassword());
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
@Override
|
|
185
|
+
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
|
186
|
+
// Clear history so history.back() doesn't do anything.
|
|
187
|
+
// So we can reinit() native side CallbackServer & PluginManager.
|
|
188
|
+
view.clearHistory();
|
|
189
|
+
this.doClearHistory = true;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Notify the host application that a page has finished loading.
|
|
194
|
+
*
|
|
195
|
+
* @param view The webview initiating the callback.
|
|
196
|
+
* @param url The url of the page.
|
|
197
|
+
*/
|
|
198
|
+
@Override
|
|
199
|
+
public void onPageFinished(WebView view, String url) {
|
|
200
|
+
super.onPageFinished(view, url);
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Because of a timing issue we need to clear this history in onPageFinished as well as
|
|
204
|
+
* onPageStarted. However we only want to do this if the doClearHistory boolean is set to
|
|
205
|
+
* true. You see when you load a url with a # in it which is common in jQuery applications
|
|
206
|
+
* onPageStared is not called. Clearing the history at that point would break jQuery apps.
|
|
207
|
+
*/
|
|
208
|
+
if (this.doClearHistory) {
|
|
209
|
+
view.clearHistory();
|
|
210
|
+
this.doClearHistory = false;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Clear timeout flag
|
|
214
|
+
this.ctx.loadUrlTimeout++;
|
|
215
|
+
|
|
216
|
+
// Try firing the onNativeReady event in JS. If it fails because the JS is
|
|
217
|
+
// not loaded yet then just set a flag so that the onNativeReady can be fired
|
|
218
|
+
// from the JS side when the JS gets to that code.
|
|
219
|
+
if (!url.equals("about:blank")) {
|
|
220
|
+
ctx.appView.loadUrl("javascript:try{ require('cordova/channel').onNativeReady.fire();}catch(e){_nativeReady = true;}");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Make app visible after 2 sec in case there was a JS error and Cordova JS never initialized correctly
|
|
224
|
+
if (ctx.appView.getVisibility() == View.INVISIBLE) {
|
|
225
|
+
Thread t = new Thread(new Runnable() {
|
|
226
|
+
public void run() {
|
|
227
|
+
try {
|
|
228
|
+
Thread.sleep(2000);
|
|
229
|
+
ctx.runOnUiThread(new Runnable() {
|
|
230
|
+
public void run() {
|
|
231
|
+
ctx.appView.setVisibility(View.VISIBLE);
|
|
232
|
+
ctx.spinnerStop();
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
} catch (InterruptedException e) {
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
t.start();
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
// Shutdown if blank loaded
|
|
244
|
+
if (url.equals("about:blank")) {
|
|
245
|
+
if (this.ctx.callbackServer != null) {
|
|
246
|
+
this.ctx.callbackServer.destroy();
|
|
247
|
+
}
|
|
248
|
+
this.ctx.endActivity();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
|
|
254
|
+
* The errorCode parameter corresponds to one of the ERROR_* constants.
|
|
255
|
+
*
|
|
256
|
+
* @param view The WebView that is initiating the callback.
|
|
257
|
+
* @param errorCode The error code corresponding to an ERROR_* value.
|
|
258
|
+
* @param description A String describing the error.
|
|
259
|
+
* @param failingUrl The url that failed to load.
|
|
260
|
+
*/
|
|
261
|
+
@Override
|
|
262
|
+
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
|
263
|
+
LOG.d(TAG, "DroidGap: GapViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);
|
|
264
|
+
|
|
265
|
+
// Clear timeout flag
|
|
266
|
+
this.ctx.loadUrlTimeout++;
|
|
267
|
+
|
|
268
|
+
// Stop "app loading" spinner if showing
|
|
269
|
+
this.ctx.spinnerStop();
|
|
270
|
+
|
|
271
|
+
// Handle error
|
|
272
|
+
this.ctx.onReceivedError(errorCode, description, failingUrl);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
|
|
276
|
+
|
|
277
|
+
final String packageName = this.ctx.getPackageName();
|
|
278
|
+
final PackageManager pm = this.ctx.getPackageManager();
|
|
279
|
+
ApplicationInfo appInfo;
|
|
280
|
+
try {
|
|
281
|
+
appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
|
|
282
|
+
if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
|
|
283
|
+
// debug = true
|
|
284
|
+
handler.proceed();
|
|
285
|
+
return;
|
|
286
|
+
} else {
|
|
287
|
+
// debug = false
|
|
288
|
+
super.onReceivedSslError(view, handler, error);
|
|
289
|
+
}
|
|
290
|
+
} catch (NameNotFoundException e) {
|
|
291
|
+
// When it doubt, lock it out!
|
|
292
|
+
super.onReceivedSslError(view, handler, error);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
@Override
|
|
297
|
+
public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) {
|
|
298
|
+
/*
|
|
299
|
+
* If you do a document.location.href the url does not get pushed on the stack
|
|
300
|
+
* so we do a check here to see if the url should be pushed.
|
|
301
|
+
*/
|
|
302
|
+
if (!this.ctx.peekAtUrlStack().equals(url)) {
|
|
303
|
+
this.ctx.pushUrl(url);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
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.TimeZone;
|
|
22
|
+
|
|
23
|
+
import org.apache.cordova.api.LOG;
|
|
24
|
+
import org.apache.cordova.api.CordovaInterface;
|
|
25
|
+
import org.apache.cordova.api.Plugin;
|
|
26
|
+
import org.apache.cordova.api.PluginResult;
|
|
27
|
+
import org.json.JSONArray;
|
|
28
|
+
import org.json.JSONException;
|
|
29
|
+
import org.json.JSONObject;
|
|
30
|
+
|
|
31
|
+
import android.content.BroadcastReceiver;
|
|
32
|
+
import android.content.Context;
|
|
33
|
+
import android.content.Intent;
|
|
34
|
+
import android.content.IntentFilter;
|
|
35
|
+
import android.provider.Settings;
|
|
36
|
+
import android.telephony.TelephonyManager;
|
|
37
|
+
|
|
38
|
+
public class Device extends Plugin {
|
|
39
|
+
public static final String TAG = "Device";
|
|
40
|
+
|
|
41
|
+
public static String cordovaVersion = "1.5.0"; // Cordova version
|
|
42
|
+
public static String platform = "Android"; // Device OS
|
|
43
|
+
public static String uuid; // Device UUID
|
|
44
|
+
|
|
45
|
+
BroadcastReceiver telephonyReceiver = null;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Constructor.
|
|
49
|
+
*/
|
|
50
|
+
public Device() {
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Sets the context of the Command. This can then be used to do things like
|
|
55
|
+
* get file paths associated with the Activity.
|
|
56
|
+
*
|
|
57
|
+
* @param ctx The context of the main Activity.
|
|
58
|
+
*/
|
|
59
|
+
public void setContext(CordovaInterface ctx) {
|
|
60
|
+
super.setContext(ctx);
|
|
61
|
+
Device.uuid = getUuid();
|
|
62
|
+
this.initTelephonyReceiver();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Executes the request and returns PluginResult.
|
|
67
|
+
*
|
|
68
|
+
* @param action The action to execute.
|
|
69
|
+
* @param args JSONArry of arguments for the plugin.
|
|
70
|
+
* @param callbackId The callback id used when calling back into JavaScript.
|
|
71
|
+
* @return A PluginResult object with a status and message.
|
|
72
|
+
*/
|
|
73
|
+
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
|
74
|
+
PluginResult.Status status = PluginResult.Status.OK;
|
|
75
|
+
String result = "";
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
if (action.equals("getDeviceInfo")) {
|
|
79
|
+
JSONObject r = new JSONObject();
|
|
80
|
+
r.put("uuid", Device.uuid);
|
|
81
|
+
r.put("version", this.getOSVersion());
|
|
82
|
+
r.put("platform", Device.platform);
|
|
83
|
+
r.put("name", this.getProductName());
|
|
84
|
+
r.put("cordova", Device.cordovaVersion);
|
|
85
|
+
//JSONObject pg = new JSONObject();
|
|
86
|
+
//pg.put("version", Device.CordovaVersion);
|
|
87
|
+
//r.put("cordova", pg);
|
|
88
|
+
return new PluginResult(status, r);
|
|
89
|
+
}
|
|
90
|
+
return new PluginResult(status, result);
|
|
91
|
+
} catch (JSONException e) {
|
|
92
|
+
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Identifies if action to be executed returns a value and should be run synchronously.
|
|
98
|
+
*
|
|
99
|
+
* @param action The action to execute
|
|
100
|
+
* @return T=returns value
|
|
101
|
+
*/
|
|
102
|
+
public boolean isSynch(String action) {
|
|
103
|
+
if (action.equals("getDeviceInfo")) {
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Unregister receiver.
|
|
111
|
+
*/
|
|
112
|
+
public void onDestroy() {
|
|
113
|
+
this.ctx.unregisterReceiver(this.telephonyReceiver);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
//--------------------------------------------------------------------------
|
|
117
|
+
// LOCAL METHODS
|
|
118
|
+
//--------------------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Listen for telephony events: RINGING, OFFHOOK and IDLE
|
|
122
|
+
* Send these events to all plugins using
|
|
123
|
+
* DroidGap.onMessage("telephone", "ringing" | "offhook" | "idle")
|
|
124
|
+
*/
|
|
125
|
+
private void initTelephonyReceiver() {
|
|
126
|
+
IntentFilter intentFilter = new IntentFilter() ;
|
|
127
|
+
intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
|
|
128
|
+
final CordovaInterface myctx = this.ctx;
|
|
129
|
+
this.telephonyReceiver = new BroadcastReceiver() {
|
|
130
|
+
|
|
131
|
+
@Override
|
|
132
|
+
public void onReceive(Context context, Intent intent) {
|
|
133
|
+
|
|
134
|
+
// If state has changed
|
|
135
|
+
if ((intent != null) && intent.getAction().equals(TelephonyManager.ACTION_PHONE_STATE_CHANGED)) {
|
|
136
|
+
if (intent.hasExtra(TelephonyManager.EXTRA_STATE)) {
|
|
137
|
+
String extraData = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
|
|
138
|
+
if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
|
|
139
|
+
LOG.i(TAG, "Telephone RINGING");
|
|
140
|
+
myctx.postMessage("telephone", "ringing");
|
|
141
|
+
}
|
|
142
|
+
else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
|
|
143
|
+
LOG.i(TAG, "Telephone OFFHOOK");
|
|
144
|
+
myctx.postMessage("telephone", "offhook");
|
|
145
|
+
}
|
|
146
|
+
else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
|
|
147
|
+
LOG.i(TAG, "Telephone IDLE");
|
|
148
|
+
myctx.postMessage("telephone", "idle");
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// Register the receiver
|
|
156
|
+
this.ctx.registerReceiver(this.telephonyReceiver, intentFilter);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Get the OS name.
|
|
161
|
+
*
|
|
162
|
+
* @return
|
|
163
|
+
*/
|
|
164
|
+
public String getPlatform() {
|
|
165
|
+
return Device.platform;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Get the device's Universally Unique Identifier (UUID).
|
|
170
|
+
*
|
|
171
|
+
* @return
|
|
172
|
+
*/
|
|
173
|
+
public String getUuid() {
|
|
174
|
+
String uuid = Settings.Secure.getString(this.ctx.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
|
|
175
|
+
return uuid;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Get the Cordova version.
|
|
180
|
+
*
|
|
181
|
+
* @return
|
|
182
|
+
*/
|
|
183
|
+
public String getCordovaVersion() {
|
|
184
|
+
return Device.cordovaVersion;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public String getModel() {
|
|
188
|
+
String model = android.os.Build.MODEL;
|
|
189
|
+
return model;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
public String getProductName() {
|
|
193
|
+
String productname = android.os.Build.PRODUCT;
|
|
194
|
+
return productname;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Get the OS version.
|
|
199
|
+
*
|
|
200
|
+
* @return
|
|
201
|
+
*/
|
|
202
|
+
public String getOSVersion() {
|
|
203
|
+
String osversion = android.os.Build.VERSION.RELEASE;
|
|
204
|
+
return osversion;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
public String getSDKVersion() {
|
|
208
|
+
String sdkversion = android.os.Build.VERSION.SDK;
|
|
209
|
+
return sdkversion;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
public String getTimeZoneID() {
|
|
214
|
+
TimeZone tz = TimeZone.getDefault();
|
|
215
|
+
return(tz.getID());
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
}
|
|
219
|
+
|
|
@@ -0,0 +1,161 @@
|
|
|
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.File;
|
|
22
|
+
|
|
23
|
+
import android.content.Context;
|
|
24
|
+
import android.os.Environment;
|
|
25
|
+
import android.os.StatFs;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* This class provides file directory utilities.
|
|
29
|
+
* All file operations are performed on the SD card.
|
|
30
|
+
*
|
|
31
|
+
* It is used by the FileUtils class.
|
|
32
|
+
*/
|
|
33
|
+
public class DirectoryManager {
|
|
34
|
+
|
|
35
|
+
private static final String LOG_TAG = "DirectoryManager";
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Determine if a file or directory exists.
|
|
39
|
+
*
|
|
40
|
+
* @param name The name of the file to check.
|
|
41
|
+
* @return T=exists, F=not found
|
|
42
|
+
*/
|
|
43
|
+
protected static boolean testFileExists(String name) {
|
|
44
|
+
boolean status;
|
|
45
|
+
|
|
46
|
+
// If SD card exists
|
|
47
|
+
if ((testSaveLocationExists()) && (!name.equals(""))) {
|
|
48
|
+
File path = Environment.getExternalStorageDirectory();
|
|
49
|
+
File newPath = constructFilePaths(path.toString(), name);
|
|
50
|
+
status = newPath.exists();
|
|
51
|
+
}
|
|
52
|
+
// If no SD card
|
|
53
|
+
else{
|
|
54
|
+
status = false;
|
|
55
|
+
}
|
|
56
|
+
return status;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get the free disk space
|
|
61
|
+
*
|
|
62
|
+
* @return Size in KB or -1 if not available
|
|
63
|
+
*/
|
|
64
|
+
protected static long getFreeDiskSpace(boolean checkInternal) {
|
|
65
|
+
String status = Environment.getExternalStorageState();
|
|
66
|
+
long freeSpace = 0;
|
|
67
|
+
|
|
68
|
+
// If SD card exists
|
|
69
|
+
if (status.equals(Environment.MEDIA_MOUNTED)) {
|
|
70
|
+
freeSpace = freeSpaceCalculation(Environment.getExternalStorageDirectory().getPath());
|
|
71
|
+
}
|
|
72
|
+
else if (checkInternal) {
|
|
73
|
+
freeSpace = freeSpaceCalculation("/");
|
|
74
|
+
}
|
|
75
|
+
// If no SD card and we haven't been asked to check the internal directory then return -1
|
|
76
|
+
else {
|
|
77
|
+
return -1;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return freeSpace;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Given a path return the number of free KB
|
|
85
|
+
*
|
|
86
|
+
* @param path to the file system
|
|
87
|
+
* @return free space in KB
|
|
88
|
+
*/
|
|
89
|
+
private static long freeSpaceCalculation(String path) {
|
|
90
|
+
StatFs stat = new StatFs(path);
|
|
91
|
+
long blockSize = stat.getBlockSize();
|
|
92
|
+
long availableBlocks = stat.getAvailableBlocks();
|
|
93
|
+
return availableBlocks*blockSize/1024;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Determine if SD card exists.
|
|
98
|
+
*
|
|
99
|
+
* @return T=exists, F=not found
|
|
100
|
+
*/
|
|
101
|
+
protected static boolean testSaveLocationExists() {
|
|
102
|
+
String sDCardStatus = Environment.getExternalStorageState();
|
|
103
|
+
boolean status;
|
|
104
|
+
|
|
105
|
+
// If SD card is mounted
|
|
106
|
+
if (sDCardStatus.equals(Environment.MEDIA_MOUNTED)) {
|
|
107
|
+
status = true;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// If no SD card
|
|
111
|
+
else {
|
|
112
|
+
status = false;
|
|
113
|
+
}
|
|
114
|
+
return status;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Create a new file object from two file paths.
|
|
119
|
+
*
|
|
120
|
+
* @param file1 Base file path
|
|
121
|
+
* @param file2 Remaining file path
|
|
122
|
+
* @return File object
|
|
123
|
+
*/
|
|
124
|
+
private static File constructFilePaths (String file1, String file2) {
|
|
125
|
+
File newPath;
|
|
126
|
+
if (file2.startsWith(file1)) {
|
|
127
|
+
newPath = new File(file2);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
newPath = new File(file1+"/"+file2);
|
|
131
|
+
}
|
|
132
|
+
return newPath;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Determine if we can use the SD Card to store the temporary file. If not then use
|
|
137
|
+
* the internal cache directory.
|
|
138
|
+
*
|
|
139
|
+
* @return the absolute path of where to store the file
|
|
140
|
+
*/
|
|
141
|
+
protected static String getTempDirectoryPath(Context ctx) {
|
|
142
|
+
File cache = null;
|
|
143
|
+
|
|
144
|
+
// SD Card Mounted
|
|
145
|
+
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
|
|
146
|
+
cache = new File(Environment.getExternalStorageDirectory().getAbsolutePath() +
|
|
147
|
+
"/Android/data/" + ctx.getPackageName() + "/cache/");
|
|
148
|
+
}
|
|
149
|
+
// Use internal storage
|
|
150
|
+
else {
|
|
151
|
+
cache = ctx.getCacheDir();
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Create the cache directory if it doesn't exist
|
|
155
|
+
if (!cache.exists()) {
|
|
156
|
+
cache.mkdirs();
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return cache.getAbsolutePath();
|
|
160
|
+
}
|
|
161
|
+
}
|