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,400 @@
|
|
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
|
+
import java.io.IOException;
|
23
|
+
import java.io.OutputStream;
|
24
|
+
|
25
|
+
import org.apache.cordova.api.LOG;
|
26
|
+
import org.apache.cordova.api.Plugin;
|
27
|
+
import org.apache.cordova.api.PluginResult;
|
28
|
+
import org.json.JSONArray;
|
29
|
+
import org.json.JSONException;
|
30
|
+
import org.json.JSONObject;
|
31
|
+
|
32
|
+
import android.app.Activity;
|
33
|
+
import android.content.ContentValues;
|
34
|
+
import android.content.Intent;
|
35
|
+
import android.graphics.Bitmap;
|
36
|
+
import android.graphics.BitmapFactory;
|
37
|
+
import android.media.MediaPlayer;
|
38
|
+
import android.net.Uri;
|
39
|
+
import android.util.Log;
|
40
|
+
|
41
|
+
|
42
|
+
public class Capture extends Plugin {
|
43
|
+
|
44
|
+
private static final String VIDEO_3GPP = "video/3gpp";
|
45
|
+
private static final String VIDEO_MP4 = "video/mp4";
|
46
|
+
private static final String AUDIO_3GPP = "audio/3gpp";
|
47
|
+
private static final String IMAGE_JPEG = "image/jpeg";
|
48
|
+
|
49
|
+
private static final int CAPTURE_AUDIO = 0; // Constant for capture audio
|
50
|
+
private static final int CAPTURE_IMAGE = 1; // Constant for capture image
|
51
|
+
private static final int CAPTURE_VIDEO = 2; // Constant for capture video
|
52
|
+
private static final String LOG_TAG = "Capture";
|
53
|
+
|
54
|
+
private static final int CAPTURE_INTERNAL_ERR = 0;
|
55
|
+
private static final int CAPTURE_APPLICATION_BUSY = 1;
|
56
|
+
private static final int CAPTURE_INVALID_ARGUMENT = 2;
|
57
|
+
private static final int CAPTURE_NO_MEDIA_FILES = 3;
|
58
|
+
private static final int CAPTURE_NOT_SUPPORTED = 20;
|
59
|
+
|
60
|
+
private String callbackId; // The ID of the callback to be invoked with our result
|
61
|
+
private long limit; // the number of pics/vids/clips to take
|
62
|
+
private double duration; // optional duration parameter for video recording
|
63
|
+
private JSONArray results; // The array of results to be returned to the user
|
64
|
+
private Uri imageUri; // Uri of captured image
|
65
|
+
|
66
|
+
@Override
|
67
|
+
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
68
|
+
this.callbackId = callbackId;
|
69
|
+
this.limit = 1;
|
70
|
+
this.duration = 0.0f;
|
71
|
+
this.results = new JSONArray();
|
72
|
+
|
73
|
+
JSONObject options = args.optJSONObject(0);
|
74
|
+
if (options != null) {
|
75
|
+
limit = options.optLong("limit", 1);
|
76
|
+
duration = options.optDouble("duration", 0.0f);
|
77
|
+
}
|
78
|
+
|
79
|
+
if (action.equals("getFormatData")) {
|
80
|
+
try {
|
81
|
+
JSONObject obj = getFormatData(args.getString(0), args.getString(1));
|
82
|
+
return new PluginResult(PluginResult.Status.OK, obj);
|
83
|
+
} catch (JSONException e) {
|
84
|
+
return new PluginResult(PluginResult.Status.ERROR);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
else if (action.equals("captureAudio")) {
|
88
|
+
this.captureAudio();
|
89
|
+
}
|
90
|
+
else if (action.equals("captureImage")) {
|
91
|
+
this.captureImage();
|
92
|
+
}
|
93
|
+
else if (action.equals("captureVideo")) {
|
94
|
+
this.captureVideo(duration);
|
95
|
+
}
|
96
|
+
|
97
|
+
PluginResult r = new PluginResult(PluginResult.Status.NO_RESULT);
|
98
|
+
r.setKeepCallback(true);
|
99
|
+
return r;
|
100
|
+
}
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Provides the media data file data depending on it's mime type
|
104
|
+
*
|
105
|
+
* @param filePath path to the file
|
106
|
+
* @param mimeType of the file
|
107
|
+
* @return a MediaFileData object
|
108
|
+
*/
|
109
|
+
private JSONObject getFormatData(String filePath, String mimeType) {
|
110
|
+
JSONObject obj = new JSONObject();
|
111
|
+
try {
|
112
|
+
// setup defaults
|
113
|
+
obj.put("height", 0);
|
114
|
+
obj.put("width", 0);
|
115
|
+
obj.put("bitrate", 0);
|
116
|
+
obj.put("duration", 0);
|
117
|
+
obj.put("codecs", "");
|
118
|
+
|
119
|
+
// If the mimeType isn't set the rest will fail
|
120
|
+
// so let's see if we can determine it.
|
121
|
+
if (mimeType == null || mimeType.equals("")) {
|
122
|
+
mimeType = FileUtils.getMimeType(filePath);
|
123
|
+
}
|
124
|
+
Log.d(LOG_TAG, "Mime type = " + mimeType);
|
125
|
+
|
126
|
+
if (mimeType.equals(IMAGE_JPEG) || filePath.endsWith(".jpg")) {
|
127
|
+
obj = getImageData(filePath, obj);
|
128
|
+
}
|
129
|
+
else if (mimeType.endsWith(AUDIO_3GPP)) {
|
130
|
+
obj = getAudioVideoData(filePath, obj, false);
|
131
|
+
}
|
132
|
+
else if (mimeType.equals(VIDEO_3GPP) || mimeType.equals(VIDEO_MP4)) {
|
133
|
+
obj = getAudioVideoData(filePath, obj, true);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
catch (JSONException e) {
|
137
|
+
Log.d(LOG_TAG, "Error: setting media file data object");
|
138
|
+
}
|
139
|
+
return obj;
|
140
|
+
}
|
141
|
+
|
142
|
+
/**
|
143
|
+
* Get the Image specific attributes
|
144
|
+
*
|
145
|
+
* @param filePath path to the file
|
146
|
+
* @param obj represents the Media File Data
|
147
|
+
* @return a JSONObject that represents the Media File Data
|
148
|
+
* @throws JSONException
|
149
|
+
*/
|
150
|
+
private JSONObject getImageData(String filePath, JSONObject obj) throws JSONException {
|
151
|
+
Bitmap bitmap = BitmapFactory.decodeFile(filePath);
|
152
|
+
obj.put("height", bitmap.getHeight());
|
153
|
+
obj.put("width", bitmap.getWidth());
|
154
|
+
return obj;
|
155
|
+
}
|
156
|
+
|
157
|
+
/**
|
158
|
+
* Get the Image specific attributes
|
159
|
+
*
|
160
|
+
* @param filePath path to the file
|
161
|
+
* @param obj represents the Media File Data
|
162
|
+
* @param video if true get video attributes as well
|
163
|
+
* @return a JSONObject that represents the Media File Data
|
164
|
+
* @throws JSONException
|
165
|
+
*/
|
166
|
+
private JSONObject getAudioVideoData(String filePath, JSONObject obj, boolean video) throws JSONException {
|
167
|
+
MediaPlayer player = new MediaPlayer();
|
168
|
+
try {
|
169
|
+
player.setDataSource(filePath);
|
170
|
+
player.prepare();
|
171
|
+
obj.put("duration", player.getDuration()/1000);
|
172
|
+
if (video) {
|
173
|
+
obj.put("height", player.getVideoHeight());
|
174
|
+
obj.put("width", player.getVideoWidth());
|
175
|
+
}
|
176
|
+
}
|
177
|
+
catch (IOException e) {
|
178
|
+
Log.d(LOG_TAG, "Error: loading video file");
|
179
|
+
}
|
180
|
+
return obj;
|
181
|
+
}
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Sets up an intent to capture audio. Result handled by onActivityResult()
|
185
|
+
*/
|
186
|
+
private void captureAudio() {
|
187
|
+
Intent intent = new Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION);
|
188
|
+
|
189
|
+
this.ctx.startActivityForResult((Plugin) this, intent, CAPTURE_AUDIO);
|
190
|
+
}
|
191
|
+
|
192
|
+
/**
|
193
|
+
* Sets up an intent to capture images. Result handled by onActivityResult()
|
194
|
+
*/
|
195
|
+
private void captureImage() {
|
196
|
+
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
197
|
+
|
198
|
+
// Specify file so that large image is captured and returned
|
199
|
+
File photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()), "Capture.jpg");
|
200
|
+
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
|
201
|
+
this.imageUri = Uri.fromFile(photo);
|
202
|
+
|
203
|
+
this.ctx.startActivityForResult((Plugin) this, intent, CAPTURE_IMAGE);
|
204
|
+
}
|
205
|
+
|
206
|
+
/**
|
207
|
+
* Sets up an intent to capture video. Result handled by onActivityResult()
|
208
|
+
*/
|
209
|
+
private void captureVideo(double duration) {
|
210
|
+
Intent intent = new Intent(android.provider.MediaStore.ACTION_VIDEO_CAPTURE);
|
211
|
+
// Introduced in API 8
|
212
|
+
//intent.putExtra(android.provider.MediaStore.EXTRA_DURATION_LIMIT, duration);
|
213
|
+
|
214
|
+
this.ctx.startActivityForResult((Plugin) this, intent, CAPTURE_VIDEO);
|
215
|
+
}
|
216
|
+
|
217
|
+
/**
|
218
|
+
* Called when the video view exits.
|
219
|
+
*
|
220
|
+
* @param requestCode The request code originally supplied to startActivityForResult(),
|
221
|
+
* allowing you to identify who this result came from.
|
222
|
+
* @param resultCode The integer result code returned by the child activity through its setResult().
|
223
|
+
* @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
|
224
|
+
* @throws JSONException
|
225
|
+
*/
|
226
|
+
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
227
|
+
|
228
|
+
// Result received okay
|
229
|
+
if (resultCode == Activity.RESULT_OK) {
|
230
|
+
// An audio clip was requested
|
231
|
+
if (requestCode == CAPTURE_AUDIO) {
|
232
|
+
// Get the uri of the audio clip
|
233
|
+
Uri data = intent.getData();
|
234
|
+
// create a file object from the uri
|
235
|
+
results.put(createMediaFile(data));
|
236
|
+
|
237
|
+
if (results.length() >= limit) {
|
238
|
+
// Send Uri back to JavaScript for listening to audio
|
239
|
+
this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
|
240
|
+
} else {
|
241
|
+
// still need to capture more audio clips
|
242
|
+
captureAudio();
|
243
|
+
}
|
244
|
+
} else if (requestCode == CAPTURE_IMAGE) {
|
245
|
+
// For some reason if I try to do:
|
246
|
+
// Uri data = intent.getData();
|
247
|
+
// It crashes in the emulator and on my phone with a null pointer exception
|
248
|
+
// To work around it I had to grab the code from CameraLauncher.java
|
249
|
+
try {
|
250
|
+
// Create an ExifHelper to save the exif data that is lost during compression
|
251
|
+
ExifHelper exif = new ExifHelper();
|
252
|
+
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/Capture.jpg");
|
253
|
+
exif.readExifData();
|
254
|
+
|
255
|
+
// Read in bitmap of captured image
|
256
|
+
Bitmap bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getContentResolver(), imageUri);
|
257
|
+
|
258
|
+
// Create entry in media store for image
|
259
|
+
// (Don't use insertImage() because it uses default compression setting of 50 - no way to change it)
|
260
|
+
ContentValues values = new ContentValues();
|
261
|
+
values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, IMAGE_JPEG);
|
262
|
+
Uri uri = null;
|
263
|
+
try {
|
264
|
+
uri = this.ctx.getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
265
|
+
} catch (UnsupportedOperationException e) {
|
266
|
+
LOG.d(LOG_TAG, "Can't write to external media storage.");
|
267
|
+
try {
|
268
|
+
uri = this.ctx.getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
|
269
|
+
} catch (UnsupportedOperationException ex) {
|
270
|
+
LOG.d(LOG_TAG, "Can't write to internal media storage.");
|
271
|
+
this.fail(createErrorObject(CAPTURE_INTERNAL_ERR, "Error capturing image - no media storage found."));
|
272
|
+
return;
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
// Add compressed version of captured image to returned media store Uri
|
277
|
+
OutputStream os = this.ctx.getContentResolver().openOutputStream(uri);
|
278
|
+
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
|
279
|
+
os.close();
|
280
|
+
|
281
|
+
bitmap.recycle();
|
282
|
+
bitmap = null;
|
283
|
+
System.gc();
|
284
|
+
|
285
|
+
// Restore exif data to file
|
286
|
+
exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx));
|
287
|
+
exif.writeExifData();
|
288
|
+
|
289
|
+
// Add image to results
|
290
|
+
results.put(createMediaFile(uri));
|
291
|
+
|
292
|
+
if (results.length() >= limit) {
|
293
|
+
// Send Uri back to JavaScript for viewing image
|
294
|
+
this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
|
295
|
+
} else {
|
296
|
+
// still need to capture more images
|
297
|
+
captureImage();
|
298
|
+
}
|
299
|
+
} catch (IOException e) {
|
300
|
+
e.printStackTrace();
|
301
|
+
this.fail(createErrorObject(CAPTURE_INTERNAL_ERR, "Error capturing image."));
|
302
|
+
}
|
303
|
+
} else if (requestCode == CAPTURE_VIDEO) {
|
304
|
+
// Get the uri of the video clip
|
305
|
+
Uri data = intent.getData();
|
306
|
+
// create a file object from the uri
|
307
|
+
results.put(createMediaFile(data));
|
308
|
+
|
309
|
+
if (results.length() >= limit) {
|
310
|
+
// Send Uri back to JavaScript for viewing video
|
311
|
+
this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
|
312
|
+
} else {
|
313
|
+
// still need to capture more video clips
|
314
|
+
captureVideo(duration);
|
315
|
+
}
|
316
|
+
}
|
317
|
+
}
|
318
|
+
// If canceled
|
319
|
+
else if (resultCode == Activity.RESULT_CANCELED) {
|
320
|
+
// If we have partial results send them back to the user
|
321
|
+
if (results.length() > 0) {
|
322
|
+
this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
|
323
|
+
}
|
324
|
+
// user canceled the action
|
325
|
+
else {
|
326
|
+
this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Canceled."));
|
327
|
+
}
|
328
|
+
}
|
329
|
+
// If something else
|
330
|
+
else {
|
331
|
+
// If we have partial results send them back to the user
|
332
|
+
if (results.length() > 0) {
|
333
|
+
this.success(new PluginResult(PluginResult.Status.OK, results), this.callbackId);
|
334
|
+
}
|
335
|
+
// something bad happened
|
336
|
+
else {
|
337
|
+
this.fail(createErrorObject(CAPTURE_NO_MEDIA_FILES, "Did not complete!"));
|
338
|
+
}
|
339
|
+
}
|
340
|
+
}
|
341
|
+
|
342
|
+
/**
|
343
|
+
* Creates a JSONObject that represents a File from the Uri
|
344
|
+
*
|
345
|
+
* @param data the Uri of the audio/image/video
|
346
|
+
* @return a JSONObject that represents a File
|
347
|
+
* @throws IOException
|
348
|
+
*/
|
349
|
+
private JSONObject createMediaFile(Uri data){
|
350
|
+
File fp = new File(FileUtils.getRealPathFromURI(data, this.ctx));
|
351
|
+
JSONObject obj = new JSONObject();
|
352
|
+
|
353
|
+
try {
|
354
|
+
// File properties
|
355
|
+
obj.put("name", fp.getName());
|
356
|
+
obj.put("fullPath", fp.getAbsolutePath());
|
357
|
+
|
358
|
+
// Because of an issue with MimeTypeMap.getMimeTypeFromExtension() all .3gpp files
|
359
|
+
// are reported as video/3gpp. I'm doing this hacky check of the URI to see if it
|
360
|
+
// is stored in the audio or video content store.
|
361
|
+
if (fp.getAbsoluteFile().toString().endsWith(".3gp") || fp.getAbsoluteFile().toString().endsWith(".3gpp")) {
|
362
|
+
if (data.toString().contains("/audio/")) {
|
363
|
+
obj.put("type", AUDIO_3GPP);
|
364
|
+
} else {
|
365
|
+
obj.put("type", VIDEO_3GPP);
|
366
|
+
}
|
367
|
+
} else {
|
368
|
+
obj.put("type", FileUtils.getMimeType(fp.getAbsolutePath()));
|
369
|
+
}
|
370
|
+
|
371
|
+
obj.put("lastModifiedDate", fp.lastModified());
|
372
|
+
obj.put("size", fp.length());
|
373
|
+
} catch (JSONException e) {
|
374
|
+
// this will never happen
|
375
|
+
e.printStackTrace();
|
376
|
+
}
|
377
|
+
|
378
|
+
return obj;
|
379
|
+
}
|
380
|
+
|
381
|
+
private JSONObject createErrorObject(int code, String message) {
|
382
|
+
JSONObject obj = new JSONObject();
|
383
|
+
try {
|
384
|
+
obj.put("code", code);
|
385
|
+
obj.put("message", message);
|
386
|
+
} catch (JSONException e) {
|
387
|
+
// This will never happen
|
388
|
+
}
|
389
|
+
return obj;
|
390
|
+
}
|
391
|
+
|
392
|
+
/**
|
393
|
+
* Send error message to JavaScript.
|
394
|
+
*
|
395
|
+
* @param err
|
396
|
+
*/
|
397
|
+
public void fail(JSONObject err) {
|
398
|
+
this.error(new PluginResult(PluginResult.Status.ERROR, err), this.callbackId);
|
399
|
+
}
|
400
|
+
}
|