mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-22 00:32:55 +08:00
Merge branch 'master' of github.com:phonegap/phonegap-android
This commit is contained in:
commit
e2acd1af33
@ -25,6 +25,7 @@
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
|
||||
|
||||
<uses-feature android:name="android.hardware.camera" />
|
||||
<uses-feature android:name="android.hardware.camera.autofocus" />
|
||||
|
124
framework/assets/js/battery.js
Executable file
124
framework/assets/js/battery.js
Executable file
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||
*
|
||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||
* Copyright (c) 2010-2011, IBM Corporation
|
||||
*/
|
||||
|
||||
if (!PhoneGap.hasResource("battery")) {
|
||||
PhoneGap.addResource("battery");
|
||||
|
||||
/**
|
||||
* This class contains information about the current battery status.
|
||||
* @constructor
|
||||
*/
|
||||
var Battery = function() {
|
||||
this._level = null;
|
||||
this._isPlugged = null;
|
||||
this._batteryListener = [];
|
||||
this._lowListener = [];
|
||||
this._criticalListener = [];
|
||||
};
|
||||
|
||||
/**
|
||||
* Registers as an event producer for battery events.
|
||||
*
|
||||
* @param {Object} eventType
|
||||
* @param {Object} handler
|
||||
* @param {Object} add
|
||||
*/
|
||||
Battery.prototype.eventHandler = function(eventType, handler, add) {
|
||||
var me = navigator.battery;
|
||||
if (add) {
|
||||
// If there are no current registered event listeners start the battery listener on native side.
|
||||
if (me._batteryListener.length === 0 && me._lowListener.length === 0 && me._criticalListener.length === 0) {
|
||||
PhoneGap.exec(me._status, me._error, "Battery", "start", []);
|
||||
}
|
||||
|
||||
// Register the event listener in the proper array
|
||||
if (eventType === "batterystatus") {
|
||||
var pos = me._batteryListener.indexOf(handler);
|
||||
if (pos === -1) {
|
||||
me._batteryListener.push(handler);
|
||||
}
|
||||
} else if (eventType === "batterylow") {
|
||||
var pos = me._lowListener.indexOf(handler);
|
||||
if (pos === -1) {
|
||||
me._lowListener.push(handler);
|
||||
}
|
||||
} else if (eventType === "batterycritical") {
|
||||
var pos = me._criticalListener.indexOf(handler);
|
||||
if (pos === -1) {
|
||||
me._criticalListener.push(handler);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Remove the event listener from the proper array
|
||||
if (eventType === "batterystatus") {
|
||||
var pos = me._batteryListener.indexOf(handler);
|
||||
if (pos > -1) {
|
||||
me._batteryListener.splice(pos, 1);
|
||||
}
|
||||
} else if (eventType === "batterylow") {
|
||||
var pos = me._lowListener.indexOf(handler);
|
||||
if (pos > -1) {
|
||||
me._lowListener.splice(pos, 1);
|
||||
}
|
||||
} else if (eventType === "batterycritical") {
|
||||
var pos = me._criticalListener.indexOf(handler);
|
||||
if (pos > -1) {
|
||||
me._criticalListener.splice(pos, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// If there are no more registered event listeners stop the battery listener on native side.
|
||||
if (me._batteryListener.length === 0 && me._lowListener.length === 0 && me._criticalListener.length === 0) {
|
||||
PhoneGap.exec(null, null, "Battery", "stop", []);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback for battery status
|
||||
*
|
||||
* @param {Object} info keys: level, isPlugged
|
||||
*/
|
||||
Battery.prototype._status = function(info) {
|
||||
if (info) {
|
||||
var me = this;
|
||||
if (me._level != info.level || me._isPlugged != info.isPlugged) {
|
||||
// Fire batterystatus event
|
||||
PhoneGap.fireWindowEvent("batterystatus", info);
|
||||
|
||||
// Fire low battery event
|
||||
if (info.level == 20 || info.level == 5) {
|
||||
if (info.level == 20) {
|
||||
PhoneGap.fireWindowEvent("batterylow", info);
|
||||
}
|
||||
else {
|
||||
PhoneGap.fireWindowEvent("batterycritical", info);
|
||||
}
|
||||
}
|
||||
}
|
||||
me._level = info.level;
|
||||
me._isPlugged = info.isPlugged;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Error callback for battery start
|
||||
*/
|
||||
Battery.prototype._error = function(e) {
|
||||
console.log("Error initializing Battery: " + e);
|
||||
};
|
||||
|
||||
PhoneGap.addConstructor(function() {
|
||||
if (typeof navigator.battery === "undefined") {
|
||||
navigator.battery = new Battery();
|
||||
PhoneGap.addWindowEventHandler("batterystatus", navigator.battery.eventHandler);
|
||||
PhoneGap.addWindowEventHandler("batterylow", navigator.battery.eventHandler);
|
||||
PhoneGap.addWindowEventHandler("batterycritical", navigator.battery.eventHandler);
|
||||
}
|
||||
});
|
||||
}
|
@ -155,6 +155,13 @@ Media.prototype.release = function() {
|
||||
PhoneGap.exec(null, null, "Media", "release", [this.id]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Adjust the volume.
|
||||
*/
|
||||
Media.prototype.setVolume = function(volume) {
|
||||
PhoneGap.exec(null, null, "Media", "setVolume", [this.id, volume]);
|
||||
};
|
||||
|
||||
/**
|
||||
* List of media objects.
|
||||
* PRIVATE
|
||||
|
@ -27,7 +27,7 @@ var Connection = function() {
|
||||
// set a timer if still offline at the end of timer send the offline event
|
||||
me._timer = setTimeout(function(){
|
||||
me.type = type;
|
||||
PhoneGap.fireEvent('offline');
|
||||
PhoneGap.fireDocumentEvent('offline');
|
||||
me._timer = null;
|
||||
}, me.timeout);
|
||||
} else {
|
||||
@ -37,7 +37,7 @@ var Connection = function() {
|
||||
me._timer = null;
|
||||
}
|
||||
me.type = type;
|
||||
PhoneGap.fireEvent('online');
|
||||
PhoneGap.fireDocumentEvent('online');
|
||||
}
|
||||
|
||||
// should only fire this once
|
||||
@ -47,6 +47,12 @@ var Connection = function() {
|
||||
}
|
||||
},
|
||||
function(e) {
|
||||
// If we can't get the network info we should still tell PhoneGap
|
||||
// to fire the deviceready event.
|
||||
if (me._firstRun) {
|
||||
me._firstRun = false;
|
||||
PhoneGap.onPhoneGapConnectionReady.fire();
|
||||
}
|
||||
console.log("Error initializing Network Connection: " + e);
|
||||
});
|
||||
};
|
||||
|
@ -46,7 +46,9 @@ var PhoneGap = {
|
||||
ready: true,
|
||||
commands: [],
|
||||
timer: null
|
||||
}
|
||||
},
|
||||
documentEventHandler: {}, // Collection of custom document event handlers
|
||||
windowEventHandler: {} // Collection of custom window event handlers
|
||||
};
|
||||
|
||||
/**
|
||||
@ -365,6 +367,9 @@ PhoneGap.Channel.join(function() {
|
||||
// Fire onDeviceReady event once all constructors have run and PhoneGap info has been
|
||||
// received from native side, and any user defined initialization channels.
|
||||
PhoneGap.Channel.join(function() {
|
||||
// Let native code know we are inited on JS side
|
||||
prompt("", "gap_init:");
|
||||
|
||||
PhoneGap.onDeviceReady.fire();
|
||||
|
||||
// Fire the onresume event, since first one happens before JavaScript is loaded
|
||||
@ -381,6 +386,36 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
// Intercept calls to document.addEventListener and watch for deviceready
|
||||
PhoneGap.m_document_addEventListener = document.addEventListener;
|
||||
|
||||
// Intercept calls to window.addEventListener
|
||||
PhoneGap.m_window_addEventListener = window.addEventListener;
|
||||
|
||||
/**
|
||||
* Add a custom window event handler.
|
||||
*
|
||||
* @param {String} event The event name that callback handles
|
||||
* @param {Function} callback The event handler
|
||||
*/
|
||||
PhoneGap.addWindowEventHandler = function(event, callback) {
|
||||
PhoneGap.windowEventHandler[event] = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a custom document event handler.
|
||||
*
|
||||
* @param {String} event The event name that callback handles
|
||||
* @param {Function} callback The event handler
|
||||
*/
|
||||
PhoneGap.addDocumentEventHandler = function(event, callback) {
|
||||
PhoneGap.documentEventHandler[event] = callback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Intercept adding document event listeners and handle our own
|
||||
*
|
||||
* @param {Object} evt
|
||||
* @param {Function} handler
|
||||
* @param capture
|
||||
*/
|
||||
document.addEventListener = function(evt, handler, capture) {
|
||||
var e = evt.toLowerCase();
|
||||
if (e === 'deviceready') {
|
||||
@ -399,14 +434,51 @@ document.addEventListener = function(evt, handler, capture) {
|
||||
PhoneGap.exec(null, null, "App", "overrideBackbutton", [true]);
|
||||
}
|
||||
|
||||
// If subscribing to an event that is handled by a plugin
|
||||
else if (typeof PhoneGap.documentEventHandler[e] !== "undefined") {
|
||||
if (PhoneGap.documentEventHandler[e](e, handler, true)) {
|
||||
return; // Stop default behavior
|
||||
}
|
||||
}
|
||||
|
||||
PhoneGap.m_document_addEventListener.call(document, evt, handler, capture);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Intercept adding window event listeners and handle our own
|
||||
*
|
||||
* @param {Object} evt
|
||||
* @param {Function} handler
|
||||
* @param capture
|
||||
*/
|
||||
window.addEventListener = function(evt, handler, capture) {
|
||||
var e = evt.toLowerCase();
|
||||
|
||||
// If subscribing to an event that is handled by a plugin
|
||||
if (typeof PhoneGap.windowEventHandler[e] !== "undefined") {
|
||||
if (PhoneGap.windowEventHandler[e](e, handler, true)) {
|
||||
return; // Stop default behavior
|
||||
}
|
||||
}
|
||||
|
||||
PhoneGap.m_window_addEventListener.call(window, evt, handler, capture);
|
||||
};
|
||||
|
||||
// Intercept calls to document.removeEventListener and watch for events that
|
||||
// are generated by PhoneGap native code
|
||||
PhoneGap.m_document_removeEventListener = document.removeEventListener;
|
||||
|
||||
// Intercept calls to window.removeEventListener
|
||||
PhoneGap.m_window_removeEventListener = window.removeEventListener;
|
||||
|
||||
/**
|
||||
* Intercept removing document event listeners and handle our own
|
||||
*
|
||||
* @param {Object} evt
|
||||
* @param {Function} handler
|
||||
* @param capture
|
||||
*/
|
||||
document.removeEventListener = function(evt, handler, capture) {
|
||||
var e = evt.toLowerCase();
|
||||
|
||||
@ -415,18 +487,70 @@ document.removeEventListener = function(evt, handler, capture) {
|
||||
PhoneGap.exec(null, null, "App", "overrideBackbutton", [false]);
|
||||
}
|
||||
|
||||
// If unsubcribing from an event that is handled by a plugin
|
||||
if (typeof PhoneGap.documentEventHandler[e] !== "undefined") {
|
||||
if (PhoneGap.documentEventHandler[e](e, handler, false)) {
|
||||
return; // Stop default behavior
|
||||
}
|
||||
}
|
||||
|
||||
PhoneGap.m_document_removeEventListener.call(document, evt, handler, capture);
|
||||
};
|
||||
|
||||
/**
|
||||
* Method to fire event from native code
|
||||
* Intercept removing window event listeners and handle our own
|
||||
*
|
||||
* @param {Object} evt
|
||||
* @param {Function} handler
|
||||
* @param capture
|
||||
*/
|
||||
PhoneGap.fireEvent = function(type) {
|
||||
window.removeEventListener = function(evt, handler, capture) {
|
||||
var e = evt.toLowerCase();
|
||||
|
||||
// If unsubcribing from an event that is handled by a plugin
|
||||
if (typeof PhoneGap.windowEventHandler[e] !== "undefined") {
|
||||
if (PhoneGap.windowEventHandler[e](e, handler, false)) {
|
||||
return; // Stop default behavior
|
||||
}
|
||||
}
|
||||
|
||||
PhoneGap.m_window_removeEventListener.call(window, evt, handler, capture);
|
||||
};
|
||||
|
||||
/**
|
||||
* Method to fire document event
|
||||
*
|
||||
* @param {String} type The event type to fire
|
||||
* @param {Object} data Data to send with event
|
||||
*/
|
||||
PhoneGap.fireDocumentEvent = function(type, data) {
|
||||
var e = document.createEvent('Events');
|
||||
e.initEvent(type);
|
||||
if (data) {
|
||||
for (var i in data) {
|
||||
e[i] = data[i];
|
||||
}
|
||||
}
|
||||
document.dispatchEvent(e);
|
||||
};
|
||||
|
||||
/**
|
||||
* Method to fire window event
|
||||
*
|
||||
* @param {String} type The event type to fire
|
||||
* @param {Object} data Data to send with event
|
||||
*/
|
||||
PhoneGap.fireWindowEvent = function(type, data) {
|
||||
var e = document.createEvent('Events');
|
||||
e.initEvent(type);
|
||||
if (data) {
|
||||
for (var i in data) {
|
||||
e[i] = data[i];
|
||||
}
|
||||
}
|
||||
window.dispatchEvent(e);
|
||||
};
|
||||
|
||||
/**
|
||||
* If JSON not included, use our own stringify. (Android 1.6)
|
||||
* The restriction on ours is that it must be an array of simple types.
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -16,4 +16,5 @@
|
||||
<plugin name="Temperature" value="com.phonegap.TempListener"/>
|
||||
<plugin name="FileTransfer" value="com.phonegap.FileTransfer"/>
|
||||
<plugin name="Capture" value="com.phonegap.Capture"/>
|
||||
<plugin name="Battery" value="com.phonegap.BatteryListener"/>
|
||||
</plugins>
|
@ -7,17 +7,15 @@
|
||||
*/
|
||||
package com.phonegap;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
|
||||
import android.content.Context;
|
||||
import android.media.AudioManager;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* This class called by PhonegapActivity to play and record audio.
|
||||
@ -71,8 +69,13 @@ public class AudioHandler extends Plugin {
|
||||
}
|
||||
else if (action.equals("stopPlayingAudio")) {
|
||||
this.stopPlayingAudio(args.getString(0));
|
||||
} else if (action.equals("setVolume")) {
|
||||
try {
|
||||
this.setVolume(args.getString(0), Float.parseFloat(args.getString(1)));
|
||||
} catch (NumberFormatException nfe) {
|
||||
//no-op
|
||||
}
|
||||
else if (action.equals("getCurrentPositionAudio")) {
|
||||
} else if (action.equals("getCurrentPositionAudio")) {
|
||||
float f = this.getCurrentPositionAudio(args.getString(0));
|
||||
return new PluginResult(status, f);
|
||||
}
|
||||
@ -296,4 +299,19 @@ public class AudioHandler extends Plugin {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the volume for an audio device
|
||||
*
|
||||
* @param id The id of the audio player
|
||||
* @param volume Volume to adjust to 0.0f - 1.0f
|
||||
*/
|
||||
public void setVolume(String id, float volume) {
|
||||
AudioPlayer audio = this.players.get(id);
|
||||
if (audio != null) {
|
||||
audio.setVolume(volume);
|
||||
} else {
|
||||
System.out.println("AudioHandler.setVolume() Error: Unknown Audio Player " + id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,8 +7,6 @@
|
||||
*/
|
||||
package com.phonegap;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import android.media.AudioManager;
|
||||
import android.media.MediaPlayer;
|
||||
import android.media.MediaPlayer.OnCompletionListener;
|
||||
@ -18,6 +16,9 @@ import android.media.MediaRecorder;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This class implements the audio playback and recording capabilities used by PhoneGap.
|
||||
* It is called by the AudioHandler PhoneGap class.
|
||||
@ -85,7 +86,10 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
|
||||
// Stop any play or record
|
||||
if (this.mPlayer != null) {
|
||||
this.stopPlaying();
|
||||
if ((this.state == MEDIA_RUNNING) || (this.state == MEDIA_PAUSED)) {
|
||||
this.mPlayer.stop();
|
||||
this.setState(MEDIA_STOPPED);
|
||||
}
|
||||
this.mPlayer.release();
|
||||
this.mPlayer = null;
|
||||
}
|
||||
@ -417,4 +421,13 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
||||
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the volume for audio player
|
||||
*
|
||||
* @param volume
|
||||
*/
|
||||
public void setVolume(float volume) {
|
||||
this.mPlayer.setVolume(volume, volume);
|
||||
}
|
||||
}
|
||||
|
145
framework/src/com/phonegap/BatteryListener.java
Executable file
145
framework/src/com/phonegap/BatteryListener.java
Executable file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||
*
|
||||
* Copyright (c) 2005-2010, Nitobi Software Inc.
|
||||
* Copyright (c) 2010-2011, IBM Corporation
|
||||
*/
|
||||
package com.phonegap;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.util.Log;
|
||||
|
||||
public class BatteryListener extends Plugin {
|
||||
|
||||
private static final String LOG_TAG = "BatteryManager";
|
||||
|
||||
BroadcastReceiver receiver;
|
||||
|
||||
private String batteryCallbackId = null;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public BatteryListener() {
|
||||
this.receiver = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
* @param action The action to execute.
|
||||
* @param args JSONArry of arguments for the plugin.
|
||||
* @param callbackId The callback id used when calling back into JavaScript.
|
||||
* @return A PluginResult object with a status and message.
|
||||
*/
|
||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||
PluginResult.Status status = PluginResult.Status.INVALID_ACTION;
|
||||
String result = "Unsupported Operation: " + action;
|
||||
|
||||
if (action.equals("start")) {
|
||||
if (this.batteryCallbackId != null) {
|
||||
return new PluginResult(PluginResult.Status.ERROR, "Battery listener already running.");
|
||||
}
|
||||
this.batteryCallbackId = callbackId;
|
||||
|
||||
// We need to listen to power events to update battery status
|
||||
IntentFilter intentFilter = new IntentFilter() ;
|
||||
intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
|
||||
if (this.receiver == null) {
|
||||
this.receiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
updateBatteryInfo(intent);
|
||||
}
|
||||
};
|
||||
ctx.registerReceiver(this.receiver, intentFilter);
|
||||
}
|
||||
|
||||
// Don't return any result now, since status results will be sent when events come in from broadcast receiver
|
||||
PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
|
||||
pluginResult.setKeepCallback(true);
|
||||
return pluginResult;
|
||||
}
|
||||
|
||||
else if (action.equals("stop")) {
|
||||
removeBatteryListener();
|
||||
this.sendUpdate(new JSONObject(), false); // release status callback in JS side
|
||||
this.batteryCallbackId = null;
|
||||
return new PluginResult(PluginResult.Status.OK);
|
||||
}
|
||||
|
||||
return new PluginResult(status, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop battery receiver.
|
||||
*/
|
||||
public void onDestroy() {
|
||||
removeBatteryListener();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the battery receiver and set it to null.
|
||||
*/
|
||||
private void removeBatteryListener() {
|
||||
if (this.receiver != null) {
|
||||
try {
|
||||
this.ctx.unregisterReceiver(this.receiver);
|
||||
this.receiver = null;
|
||||
} catch (Exception e) {
|
||||
Log.e(LOG_TAG, "Error unregistering battery receiver: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a JSONObject with the current battery information
|
||||
*
|
||||
* @param batteryIntent the current battery information
|
||||
* @return a JSONObject containing the battery status information
|
||||
*/
|
||||
private JSONObject getBatteryInfo(Intent batteryIntent) {
|
||||
JSONObject obj = new JSONObject();
|
||||
try {
|
||||
obj.put("level", batteryIntent.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, 0));
|
||||
obj.put("isPlugged", batteryIntent.getIntExtra(android.os.BatteryManager.EXTRA_PLUGGED, -1) > 0 ? true : false);
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOG_TAG, e.getMessage(), e);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the JavaScript side whenever the battery changes
|
||||
*
|
||||
* @param batteryIntent the current battery information
|
||||
* @return
|
||||
*/
|
||||
private void updateBatteryInfo(Intent batteryIntent) {
|
||||
sendUpdate(this.getBatteryInfo(batteryIntent), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new plugin result and send it back to JavaScript
|
||||
*
|
||||
* @param connection the network info to set as navigator.connection
|
||||
*/
|
||||
private void sendUpdate(JSONObject info, boolean keepCallback) {
|
||||
if (this.batteryCallbackId != null) {
|
||||
PluginResult result = new PluginResult(PluginResult.Status.OK, info);
|
||||
result.setKeepCallback(keepCallback);
|
||||
this.success(result, this.batteryCallbackId);
|
||||
}
|
||||
}
|
||||
}
|
@ -48,7 +48,9 @@ public class CameraLauncher extends Plugin {
|
||||
private int mQuality; // Compression quality hint (0-100: 0=low quality & high compression, 100=compress of max quality)
|
||||
private int targetWidth; // desired width of the image
|
||||
private int targetHeight; // desired height of the image
|
||||
private Uri imageUri; // Uri of captured image
|
||||
private Uri imageUri;
|
||||
private int encodingType;
|
||||
// Uri of captured image
|
||||
public String callbackId;
|
||||
|
||||
/**
|
||||
@ -86,9 +88,9 @@ public class CameraLauncher extends Plugin {
|
||||
if (args.length() > 4) {
|
||||
this.targetHeight = args.getInt(4);
|
||||
}
|
||||
int encodingType = JPEG;
|
||||
this.encodingType = JPEG;
|
||||
if (args.length() > 5) {
|
||||
encodingType = args.getInt(5);
|
||||
this.encodingType = args.getInt(5);
|
||||
}
|
||||
if (srcType == CAMERA) {
|
||||
this.takePicture(args.getInt(0), destType, encodingType);
|
||||
@ -238,6 +240,13 @@ public class CameraLauncher extends Plugin {
|
||||
// If image available
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
try {
|
||||
// Create an ExifHelper to save the exif data that is lost during compression
|
||||
ExifHelper exif = new ExifHelper();
|
||||
if (this.encodingType == JPEG) {
|
||||
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx) + "/Pic.jpg");
|
||||
exif.readExifData();
|
||||
}
|
||||
|
||||
// Read in bitmap of captured image
|
||||
Bitmap bitmap;
|
||||
try {
|
||||
@ -280,6 +289,12 @@ public class CameraLauncher extends Plugin {
|
||||
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
|
||||
os.close();
|
||||
|
||||
// Restore exif data to file
|
||||
if (this.encodingType == JPEG) {
|
||||
exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx));
|
||||
exif.writeExifData();
|
||||
}
|
||||
|
||||
// Send Uri back to JavaScript for viewing image
|
||||
this.success(new PluginResult(PluginResult.Status.OK, uri.toString()), this.callbackId);
|
||||
}
|
||||
|
@ -18,12 +18,10 @@ import org.json.JSONObject;
|
||||
import android.app.Activity;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.media.MediaPlayer;
|
||||
import android.net.Uri;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
import com.phonegap.api.Plugin;
|
||||
@ -31,7 +29,6 @@ import com.phonegap.api.PluginResult;
|
||||
|
||||
public class Capture extends Plugin {
|
||||
|
||||
private static final String _DATA = "_data"; // The column name where the file path is stored
|
||||
private static final int CAPTURE_AUDIO = 0; // Constant for capture audio
|
||||
private static final int CAPTURE_IMAGE = 1; // Constant for capture image
|
||||
private static final int CAPTURE_VIDEO = 2; // Constant for capture video
|
||||
@ -225,6 +222,11 @@ public class Capture extends Plugin {
|
||||
// It crashes in the emulator and on my phone with a null pointer exception
|
||||
// To work around it I had to grab the code from CameraLauncher.java
|
||||
try {
|
||||
// Create an ExifHelper to save the exif data that is lost during compression
|
||||
ExifHelper exif = new ExifHelper();
|
||||
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx) + "/Capture.jpg");
|
||||
exif.readExifData();
|
||||
|
||||
// Read in bitmap of captured image
|
||||
Bitmap bitmap = android.provider.MediaStore.Images.Media.getBitmap(this.ctx.getContentResolver(), imageUri);
|
||||
|
||||
@ -255,6 +257,10 @@ public class Capture extends Plugin {
|
||||
bitmap = null;
|
||||
System.gc();
|
||||
|
||||
// Restore exif data to file
|
||||
exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx));
|
||||
exif.writeExifData();
|
||||
|
||||
// Add image to results
|
||||
results.put(createMediaFile(uri));
|
||||
|
||||
@ -313,10 +319,10 @@ public class Capture extends Plugin {
|
||||
*
|
||||
* @param data the Uri of the audio/image/video
|
||||
* @return a JSONObject that represents a File
|
||||
* @throws IOException
|
||||
*/
|
||||
private JSONObject createMediaFile(Uri data) {
|
||||
File fp = new File(getRealPathFromURI(data));
|
||||
|
||||
private JSONObject createMediaFile(Uri data){
|
||||
File fp = new File(FileUtils.getRealPathFromURI(data, this.ctx));
|
||||
JSONObject obj = new JSONObject();
|
||||
|
||||
try {
|
||||
@ -334,20 +340,6 @@ public class Capture extends Plugin {
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the media store to find out what the file path is for the Uri we supply
|
||||
*
|
||||
* @param contentUri the Uri of the audio/image/video
|
||||
* @return the full path to the file
|
||||
*/
|
||||
private String getRealPathFromURI(Uri contentUri) {
|
||||
String[] proj = { _DATA };
|
||||
Cursor cursor = this.ctx.managedQuery(contentUri, proj, null, null, null);
|
||||
int column_index = cursor.getColumnIndexOrThrow(_DATA);
|
||||
cursor.moveToFirst();
|
||||
return cursor.getString(column_index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send error message to JavaScript.
|
||||
*
|
||||
|
73
framework/src/com/phonegap/DroidGap.java
Normal file → Executable file
73
framework/src/com/phonegap/DroidGap.java
Normal file → Executable file
@ -95,6 +95,10 @@ import com.phonegap.api.PluginManager;
|
||||
* // (String - default=null)
|
||||
* super.setStringProperty("loadingDialog", "Wait,Loading Demo...");
|
||||
*
|
||||
* // Display a native loading dialog when loading sub-pages. Format for value = "Title,Message".
|
||||
* // (String - default=null)
|
||||
* super.setStringProperty("loadingPageDialog", "Loading page...");
|
||||
*
|
||||
* // Cause all links on web page to be loaded into existing web view,
|
||||
* // instead of being loaded into new browser. (Boolean - default=false)
|
||||
* super.setBooleanProperty("loadInWebView", true);
|
||||
@ -103,6 +107,10 @@ import com.phonegap.api.PluginManager;
|
||||
* // (Integer - default=0)
|
||||
* super.setIntegerProperty("splashscreen", R.drawable.splash);
|
||||
*
|
||||
* // Set the background color.
|
||||
* // (Integer - default=0 or BLACK)
|
||||
* super.setIntegerProperty("backgroundColor", Color.WHITE);
|
||||
*
|
||||
* // Time in msec to wait before triggering a timeout error when loading
|
||||
* // with super.loadUrl(). (Integer - default=20000)
|
||||
* super.setIntegerProperty("loadUrlTimeoutValue", 60000);
|
||||
@ -144,6 +152,10 @@ public class DroidGap extends PhonegapActivity {
|
||||
// Flag indicates that a loadUrl timeout occurred
|
||||
private int loadUrlTimeout = 0;
|
||||
|
||||
// Default background color for activity
|
||||
// (this is not the color for the webview, which is set in HTML)
|
||||
private int backgroundColor = Color.BLACK;
|
||||
|
||||
/*
|
||||
* The variables below are used to cache some of the activity properties.
|
||||
*/
|
||||
@ -183,7 +195,7 @@ public class DroidGap extends PhonegapActivity {
|
||||
|
||||
root = new LinearLayoutSoftKeyboardDetect(this, width, height);
|
||||
root.setOrientation(LinearLayout.VERTICAL);
|
||||
root.setBackgroundColor(Color.BLACK);
|
||||
root.setBackgroundColor(this.backgroundColor);
|
||||
root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
|
||||
ViewGroup.LayoutParams.FILL_PARENT, 0.0F));
|
||||
|
||||
@ -297,6 +309,10 @@ public class DroidGap extends PhonegapActivity {
|
||||
this.init();
|
||||
}
|
||||
|
||||
// If backgroundColor
|
||||
this.backgroundColor = this.getIntegerProperty("backgroundColor", Color.BLACK);
|
||||
this.root.setBackgroundColor(this.backgroundColor);
|
||||
|
||||
// If spashscreen
|
||||
this.splashscreen = this.getIntegerProperty("splashscreen", 0);
|
||||
if (this.splashscreen != 0) {
|
||||
@ -712,7 +728,8 @@ public class DroidGap extends PhonegapActivity {
|
||||
public void showWebPage(String url, boolean usePhoneGap, boolean clearPrev, HashMap<String, Object> params) throws android.content.ActivityNotFoundException {
|
||||
Intent intent = null;
|
||||
if (usePhoneGap) {
|
||||
intent = new Intent().setClass(this, com.phonegap.DroidGap.class);
|
||||
try {
|
||||
intent = new Intent().setClass(this, Class.forName(this.getComponentName().getClassName()));
|
||||
intent.putExtra("url", url);
|
||||
|
||||
// Add parameters
|
||||
@ -737,6 +754,11 @@ public class DroidGap extends PhonegapActivity {
|
||||
}
|
||||
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(url));
|
||||
}
|
||||
}
|
||||
else {
|
||||
intent = new Intent(Intent.ACTION_VIEW);
|
||||
@ -892,13 +914,13 @@ public class DroidGap extends PhonegapActivity {
|
||||
}
|
||||
|
||||
// Polling for JavaScript messages
|
||||
else if (reqOk && defaultValue.equals("gap_poll:")) {
|
||||
else if (reqOk && defaultValue != null && defaultValue.equals("gap_poll:")) {
|
||||
String r = callbackServer.getJavascript();
|
||||
result.confirm(r);
|
||||
}
|
||||
|
||||
// Calling into CallbackServer
|
||||
else if (reqOk && defaultValue.equals("gap_callbackServer:")) {
|
||||
else if (reqOk && defaultValue != null && defaultValue.equals("gap_callbackServer:")) {
|
||||
String r = "";
|
||||
if (message.equals("usePolling")) {
|
||||
r = ""+callbackServer.usePolling();
|
||||
@ -915,6 +937,14 @@ public class DroidGap extends PhonegapActivity {
|
||||
result.confirm(r);
|
||||
}
|
||||
|
||||
// PhoneGap JS has initialized, so show webview
|
||||
// (This solves white flash seen when rendering HTML)
|
||||
else if (reqOk && defaultValue != null && defaultValue.equals("gap_init:")) {
|
||||
appView.setVisibility(View.VISIBLE);
|
||||
ctx.spinnerStop();
|
||||
result.confirm("OK");
|
||||
}
|
||||
|
||||
// Show dialog
|
||||
else {
|
||||
final JsPromptResult res = result;
|
||||
@ -1123,7 +1153,11 @@ public class DroidGap extends PhonegapActivity {
|
||||
try {
|
||||
// Init parameters to new DroidGap activity and propagate existing parameters
|
||||
HashMap<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("loadingDialog", null);
|
||||
String loadingPage = this.ctx.getStringProperty("loadingPageDialog", null);
|
||||
if (loadingPage != null) {
|
||||
params.put("loadingDialog", loadingPage);
|
||||
params.put("loadingPageDialog", loadingPage);
|
||||
}
|
||||
if (this.ctx.loadInWebView) {
|
||||
params.put("loadInWebView", true);
|
||||
}
|
||||
@ -1133,6 +1167,7 @@ public class DroidGap extends PhonegapActivity {
|
||||
if (errorUrl != null) {
|
||||
params.put("errorUrl", errorUrl);
|
||||
}
|
||||
params.put("backgroundColor", this.ctx.backgroundColor);
|
||||
|
||||
this.ctx.showWebPage(url, true, false, params);
|
||||
} catch (android.content.ActivityNotFoundException e) {
|
||||
@ -1174,11 +1209,23 @@ public class DroidGap extends PhonegapActivity {
|
||||
appView.loadUrl("javascript:try{ PhoneGap.onNativeReady.fire();}catch(e){_nativeReady = true;}");
|
||||
}
|
||||
|
||||
// Make app view visible
|
||||
// Make app visible after 2 sec in case there was a JS error and PhoneGap JS never initialized correctly
|
||||
Thread t = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
ctx.runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
appView.setVisibility(View.VISIBLE);
|
||||
ctx.spinnerStop();
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
|
||||
// Stop "app loading" spinner if showing
|
||||
this.ctx.spinnerStop();
|
||||
|
||||
// Clear history, so that previous screen isn't there when Back button is pressed
|
||||
if (this.ctx.clearHistory) {
|
||||
@ -1256,7 +1303,7 @@ public class DroidGap extends PhonegapActivity {
|
||||
|
||||
// If back key is bound, then send event to JavaScript
|
||||
if (this.bound) {
|
||||
this.appView.loadUrl("javascript:PhoneGap.fireEvent('backbutton');");
|
||||
this.appView.loadUrl("javascript:PhoneGap.fireDocumentEvent('backbutton');");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1278,13 +1325,13 @@ public class DroidGap extends PhonegapActivity {
|
||||
|
||||
// If menu key
|
||||
else if (keyCode == KeyEvent.KEYCODE_MENU) {
|
||||
this.appView.loadUrl("javascript:PhoneGap.fireEvent('menubutton');");
|
||||
this.appView.loadUrl("javascript:PhoneGap.fireDocumentEvent('menubutton');");
|
||||
return true;
|
||||
}
|
||||
|
||||
// If search key
|
||||
else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
|
||||
this.appView.loadUrl("javascript:PhoneGap.fireEvent('searchbutton');");
|
||||
this.appView.loadUrl("javascript:PhoneGap.fireDocumentEvent('searchbutton');");
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -1478,13 +1525,13 @@ public class DroidGap extends PhonegapActivity {
|
||||
// gone away.
|
||||
else if (height > oldHeight) {
|
||||
Log.d(LOG_TAG, "Throw hide keyboard event");
|
||||
callbackServer.sendJavascript("PhoneGap.fireEvent('hidekeyboard');");
|
||||
callbackServer.sendJavascript("PhoneGap.fireDocumentEvent('hidekeyboard');");
|
||||
}
|
||||
// If the height as gotten smaller then we will assume the soft keyboard has
|
||||
// been displayed.
|
||||
else if (height < oldHeight) {
|
||||
Log.d(LOG_TAG, "Throw show keyboard event");
|
||||
callbackServer.sendJavascript("PhoneGap.fireEvent('showkeyboard');");
|
||||
callbackServer.sendJavascript("PhoneGap.fireDocumentEvent('showkeyboard');");
|
||||
}
|
||||
|
||||
// Update the old height for the next event
|
||||
|
153
framework/src/com/phonegap/ExifHelper.java
Normal file
153
framework/src/com/phonegap/ExifHelper.java
Normal file
@ -0,0 +1,153 @@
|
||||
/*
|
||||
* PhoneGap is available under *either* the terms of the modified BSD license *or* the
|
||||
* MIT License (2008). See http://opensource.org/licenses/alphabetical for full text.
|
||||
*
|
||||
* Copyright (c) 2011, IBM Corporation
|
||||
*/
|
||||
package com.phonegap;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import android.media.ExifInterface;
|
||||
|
||||
public class ExifHelper {
|
||||
private String aperature = null;
|
||||
private String datetime = null;
|
||||
private String exposureTime = null;
|
||||
private String flash = null;
|
||||
private String focalLength = null;
|
||||
private String gpsAltitude = null;
|
||||
private String gpsAltitudeRef = null;
|
||||
private String gpsDateStamp = null;
|
||||
private String gpsLatitude = null;
|
||||
private String gpsLatitudeRef = null;
|
||||
private String gpsLongitude = null;
|
||||
private String gpsLongitudeRef = null;
|
||||
private String gpsProcessingMethod = null;
|
||||
private String gpsTimestamp = null;
|
||||
private String iso = null;
|
||||
private String make = null;
|
||||
private String model = null;
|
||||
private String orientation = null;
|
||||
private String whiteBalance = null;
|
||||
|
||||
private ExifInterface inFile = null;
|
||||
private ExifInterface outFile = null;
|
||||
|
||||
/**
|
||||
* The file before it is compressed
|
||||
*
|
||||
* @param filePath
|
||||
* @throws IOException
|
||||
*/
|
||||
public void createInFile(String filePath) throws IOException {
|
||||
this.inFile = new ExifInterface(filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* The file after it has been compressed
|
||||
*
|
||||
* @param filePath
|
||||
* @throws IOException
|
||||
*/
|
||||
public void createOutFile(String filePath) throws IOException {
|
||||
this.outFile = new ExifInterface(filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads all the EXIF data from the input file.
|
||||
*/
|
||||
public void readExifData() {
|
||||
this.aperature = inFile.getAttribute(ExifInterface.TAG_APERTURE);
|
||||
this.datetime = inFile.getAttribute(ExifInterface.TAG_DATETIME);
|
||||
this.exposureTime = inFile.getAttribute(ExifInterface.TAG_EXPOSURE_TIME);
|
||||
this.flash = inFile.getAttribute(ExifInterface.TAG_FLASH);
|
||||
this.focalLength = inFile.getAttribute(ExifInterface.TAG_FOCAL_LENGTH);
|
||||
this.gpsAltitude = inFile.getAttribute(ExifInterface.TAG_GPS_ALTITUDE);
|
||||
this.gpsAltitudeRef = inFile.getAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF);
|
||||
this.gpsDateStamp = inFile.getAttribute(ExifInterface.TAG_GPS_DATESTAMP);
|
||||
this.gpsLatitude = inFile.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
|
||||
this.gpsLatitudeRef = inFile.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
|
||||
this.gpsLongitude = inFile.getAttribute(ExifInterface.TAG_GPS_LONGITUDE);
|
||||
this.gpsLongitudeRef = inFile.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
|
||||
this.gpsProcessingMethod = inFile.getAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD);
|
||||
this.gpsTimestamp = inFile.getAttribute(ExifInterface.TAG_GPS_TIMESTAMP);
|
||||
this.iso = inFile.getAttribute(ExifInterface.TAG_ISO);
|
||||
this.make = inFile.getAttribute(ExifInterface.TAG_MAKE);
|
||||
this.model = inFile.getAttribute(ExifInterface.TAG_MODEL);
|
||||
this.orientation = inFile.getAttribute(ExifInterface.TAG_ORIENTATION);
|
||||
this.whiteBalance = inFile.getAttribute(ExifInterface.TAG_WHITE_BALANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the previously stored EXIF data to the output file.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
public void writeExifData() throws IOException {
|
||||
// Don't try to write to a null file
|
||||
if (this.outFile == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.aperature != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_APERTURE, this.aperature);
|
||||
}
|
||||
if (this.datetime != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_DATETIME, this.datetime);
|
||||
}
|
||||
if (this.exposureTime != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_EXPOSURE_TIME, this.exposureTime);
|
||||
}
|
||||
if (this.flash != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_FLASH, this.flash);
|
||||
}
|
||||
if (this.focalLength != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_FOCAL_LENGTH, this.focalLength);
|
||||
}
|
||||
if (this.gpsAltitude != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_GPS_ALTITUDE, this.gpsAltitude);
|
||||
}
|
||||
if (this.gpsAltitudeRef != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF, this.gpsAltitudeRef);
|
||||
}
|
||||
if (this.gpsDateStamp != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_GPS_DATESTAMP, this.gpsDateStamp);
|
||||
}
|
||||
if (this.gpsLatitude != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_GPS_LATITUDE, this.gpsLatitude);
|
||||
}
|
||||
if (this.gpsLatitudeRef != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, this.gpsLatitudeRef);
|
||||
}
|
||||
if (this.gpsLongitude != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, this.gpsLongitude);
|
||||
}
|
||||
if (this.gpsLongitudeRef != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, this.gpsLongitudeRef);
|
||||
}
|
||||
if (this.gpsProcessingMethod != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_GPS_PROCESSING_METHOD, this.gpsProcessingMethod);
|
||||
}
|
||||
if (this.gpsTimestamp != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_GPS_TIMESTAMP, this.gpsTimestamp);
|
||||
}
|
||||
if (this.iso != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_ISO, this.iso);
|
||||
}
|
||||
if (this.make != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_MAKE, this.make);
|
||||
}
|
||||
if (this.model != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_MODEL, this.model);
|
||||
}
|
||||
if (this.orientation != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_ORIENTATION, this.orientation);
|
||||
}
|
||||
if (this.whiteBalance != null) {
|
||||
this.outFile.setAttribute(ExifInterface.TAG_WHITE_BALANCE, this.whiteBalance);
|
||||
}
|
||||
|
||||
this.outFile.saveAttributes();
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
import android.webkit.MimeTypeMap;
|
||||
|
||||
import com.phonegap.api.PhonegapActivity;
|
||||
import com.phonegap.api.Plugin;
|
||||
import com.phonegap.api.PluginResult;
|
||||
import com.phonegap.file.EncodingException;
|
||||
@ -39,6 +40,7 @@ import com.phonegap.file.TypeMismatchException;
|
||||
*/
|
||||
public class FileUtils extends Plugin {
|
||||
private static final String LOG_TAG = "FileUtils";
|
||||
private static final String _DATA = "_data"; // The column name where the file path is stored
|
||||
|
||||
public static int NOT_FOUND_ERR = 1;
|
||||
public static int SECURITY_ERR = 2;
|
||||
@ -988,5 +990,19 @@ public class FileUtils extends Plugin {
|
||||
return new FileInputStream(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the media store to find out what the file path is for the Uri we supply
|
||||
*
|
||||
* @param contentUri the Uri of the audio/image/video
|
||||
* @param ctx the current applicaiton context
|
||||
* @return the full path to the file
|
||||
*/
|
||||
protected static String getRealPathFromURI(Uri contentUri, PhonegapActivity ctx) {
|
||||
String[] proj = { _DATA };
|
||||
Cursor cursor = ctx.managedQuery(contentUri, proj, null, null, null);
|
||||
int column_index = cursor.getColumnIndexOrThrow(_DATA);
|
||||
cursor.moveToFirst();
|
||||
return cursor.getString(column_index);
|
||||
}
|
||||
}
|
||||
|
@ -38,9 +38,13 @@ public class NetworkManager extends Plugin {
|
||||
// 3G network types
|
||||
public static final String CDMA = "cdma";
|
||||
public static final String UMTS = "umts";
|
||||
public static final String HSPA = "hspa";
|
||||
public static final String HSUPA = "hsupa";
|
||||
public static final String HSDPA = "hsdpa";
|
||||
// 4G network types
|
||||
public static final String LTE = "lte";
|
||||
public static final String UMB = "umb";
|
||||
public static final String HSPA_PLUS = "hspa+";
|
||||
// return types
|
||||
public static final String TYPE_UNKNOWN = "unknown";
|
||||
public static final String TYPE_ETHERNET = "ethernet";
|
||||
@ -205,11 +209,15 @@ public class NetworkManager extends Plugin {
|
||||
return TYPE_2G;
|
||||
}
|
||||
else if (type.toLowerCase().equals(CDMA) ||
|
||||
type.toLowerCase().equals(UMTS)) {
|
||||
type.toLowerCase().equals(UMTS) ||
|
||||
type.toLowerCase().equals(HSUPA) ||
|
||||
type.toLowerCase().equals(HSDPA) ||
|
||||
type.toLowerCase().equals(HSPA)) {
|
||||
return TYPE_3G;
|
||||
}
|
||||
else if (type.toLowerCase().equals(LTE) ||
|
||||
type.toLowerCase().equals(UMB)) {
|
||||
type.toLowerCase().equals(UMB) ||
|
||||
type.toLowerCase().equals(HSPA_PLUS)) {
|
||||
return TYPE_4G;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user