forked from github/cordova-android
Massive refactor of CordovaInterface. Deprecation and Exception throwing to notify the user that we're changing things
This commit is contained in:
parent
b99e9abb5f
commit
1794f2e047
@ -30,7 +30,7 @@ import android.webkit.WebView;
|
|||||||
*/
|
*/
|
||||||
public class PluginManager extends org.apache.cordova.api.PluginManager {
|
public class PluginManager extends org.apache.cordova.api.PluginManager {
|
||||||
|
|
||||||
public PluginManager(WebView app, CordovaInterface ctx) {
|
public PluginManager(WebView app, CordovaInterface ctx) throws Exception {
|
||||||
super(app, ctx);
|
super(app, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,10 +72,10 @@ public class AccelListener extends Plugin implements SensorEventListener {
|
|||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(CordovaInterface ctx) {
|
|
||||||
super.setContext(ctx);
|
public void setContext(Context ctx) {
|
||||||
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the request and returns PluginResult.
|
* Executes the request and returns PluginResult.
|
||||||
|
@ -25,6 +25,9 @@ import org.apache.cordova.api.PluginResult;
|
|||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -195,4 +198,5 @@ public class App extends Plugin {
|
|||||||
public void exitApp() {
|
public void exitApp() {
|
||||||
((DroidGap)this.ctx).endActivity();
|
((DroidGap)this.ctx).endActivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -213,7 +213,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
|
|||||||
else {
|
else {
|
||||||
if (file.startsWith("/android_asset/")) {
|
if (file.startsWith("/android_asset/")) {
|
||||||
String f = file.substring(15);
|
String f = file.substring(15);
|
||||||
android.content.res.AssetFileDescriptor fd = this.handler.ctx.getBaseContext().getAssets().openFd(f);
|
android.content.res.AssetFileDescriptor fd = this.handler.ctx.getAssets().openFd(f);
|
||||||
this.mPlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
|
this.mPlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -26,6 +26,7 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import org.apache.cordova.api.CordovaInterface;
|
||||||
import org.apache.cordova.api.LOG;
|
import org.apache.cordova.api.LOG;
|
||||||
import org.apache.cordova.api.Plugin;
|
import org.apache.cordova.api.Plugin;
|
||||||
import org.apache.cordova.api.PluginResult;
|
import org.apache.cordova.api.PluginResult;
|
||||||
@ -34,6 +35,7 @@ import org.json.JSONException;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
@ -78,12 +80,23 @@ public class CameraLauncher extends Plugin {
|
|||||||
public String callbackId;
|
public String callbackId;
|
||||||
private int numPics;
|
private int numPics;
|
||||||
|
|
||||||
|
//This should never be null!
|
||||||
|
private CordovaInterface cordova;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public CameraLauncher() {
|
public CameraLauncher() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setContext(Context mCtx) {
|
||||||
|
super.setContext(mCtx);
|
||||||
|
if(CordovaInterface.class.isInstance(mCtx))
|
||||||
|
cordova = (CordovaInterface) mCtx;
|
||||||
|
else
|
||||||
|
LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the request and returns PluginResult.
|
* Executes the request and returns PluginResult.
|
||||||
*
|
*
|
||||||
@ -163,7 +176,10 @@ public class CameraLauncher extends Plugin {
|
|||||||
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
|
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
|
||||||
this.imageUri = Uri.fromFile(photo);
|
this.imageUri = Uri.fromFile(photo);
|
||||||
|
|
||||||
this.ctx.startActivityForResult((Plugin) this, intent, (CAMERA+1)*16 + returnType+1);
|
if(cordova != null)
|
||||||
|
cordova.startActivityForResult((Plugin) this, intent, (CAMERA+1)*16 + returnType+1);
|
||||||
|
else
|
||||||
|
LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -175,9 +191,9 @@ public class CameraLauncher extends Plugin {
|
|||||||
private File createCaptureFile(int encodingType) {
|
private File createCaptureFile(int encodingType) {
|
||||||
File photo = null;
|
File photo = null;
|
||||||
if (encodingType == JPEG) {
|
if (encodingType == JPEG) {
|
||||||
photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()), "Pic.jpg");
|
photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Pic.jpg");
|
||||||
} else if (encodingType == PNG) {
|
} else if (encodingType == PNG) {
|
||||||
photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()), "Pic.png");
|
photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Pic.png");
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Invalid Encoding Type: " + encodingType);
|
throw new IllegalArgumentException("Invalid Encoding Type: " + encodingType);
|
||||||
}
|
}
|
||||||
@ -211,7 +227,7 @@ public class CameraLauncher extends Plugin {
|
|||||||
|
|
||||||
intent.setAction(Intent.ACTION_GET_CONTENT);
|
intent.setAction(Intent.ACTION_GET_CONTENT);
|
||||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
this.ctx.startActivityForResult((Plugin) this, Intent.createChooser(intent,
|
cordova.startActivityForResult((Plugin) this, Intent.createChooser(intent,
|
||||||
new String(title)), (srcType+1)*16 + returnType + 1);
|
new String(title)), (srcType+1)*16 + returnType + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +294,7 @@ public class CameraLauncher extends Plugin {
|
|||||||
ExifHelper exif = new ExifHelper();
|
ExifHelper exif = new ExifHelper();
|
||||||
try {
|
try {
|
||||||
if (this.encodingType == JPEG) {
|
if (this.encodingType == JPEG) {
|
||||||
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/Pic.jpg");
|
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx) + "/Pic.jpg");
|
||||||
exif.readExifData();
|
exif.readExifData();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@ -335,7 +351,7 @@ public class CameraLauncher extends Plugin {
|
|||||||
|
|
||||||
// Restore exif data to file
|
// Restore exif data to file
|
||||||
if (this.encodingType == JPEG) {
|
if (this.encodingType == JPEG) {
|
||||||
exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx));
|
exif.createOutFile(FileUtils.getRealPathFromURI(uri, ((Activity) this.ctx)));
|
||||||
exif.writeExifData();
|
exif.writeExifData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,14 +429,14 @@ public class CameraLauncher extends Plugin {
|
|||||||
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
|
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
|
||||||
bitmap = scaleBitmap(bitmap);
|
bitmap = scaleBitmap(bitmap);
|
||||||
|
|
||||||
String fileName = DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/resize.jpg";
|
String fileName = DirectoryManager.getTempDirectoryPath(ctx) + "/resize.jpg";
|
||||||
OutputStream os = new FileOutputStream(fileName);
|
OutputStream os = new FileOutputStream(fileName);
|
||||||
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
|
bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
|
||||||
os.close();
|
os.close();
|
||||||
|
|
||||||
// Restore exif data to file
|
// Restore exif data to file
|
||||||
if (this.encodingType == JPEG) {
|
if (this.encodingType == JPEG) {
|
||||||
exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx));
|
exif.createOutFile(FileUtils.getRealPathFromURI(uri, ((Activity) ctx)));
|
||||||
exif.writeExifData();
|
exif.writeExifData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import org.apache.cordova.api.CordovaInterface;
|
||||||
import org.apache.cordova.api.LOG;
|
import org.apache.cordova.api.LOG;
|
||||||
import org.apache.cordova.api.Plugin;
|
import org.apache.cordova.api.Plugin;
|
||||||
import org.apache.cordova.api.PluginResult;
|
import org.apache.cordova.api.PluginResult;
|
||||||
@ -31,6 +32,7 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
@ -62,6 +64,15 @@ public class Capture extends Plugin {
|
|||||||
private double duration; // optional duration parameter for video recording
|
private double duration; // optional duration parameter for video recording
|
||||||
private JSONArray results; // The array of results to be returned to the user
|
private JSONArray results; // The array of results to be returned to the user
|
||||||
private Uri imageUri; // Uri of captured image
|
private Uri imageUri; // Uri of captured image
|
||||||
|
private CordovaInterface cordova;
|
||||||
|
|
||||||
|
public void setContext(Context mCtx)
|
||||||
|
{
|
||||||
|
if(CordovaInterface.class.isInstance(mCtx))
|
||||||
|
cordova = (CordovaInterface) mCtx;
|
||||||
|
else
|
||||||
|
LOG.d(LOG_TAG, "ERROR: You must use the CordovaInterface for this to work correctly. Please implement it in your activity");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
public PluginResult execute(String action, JSONArray args, String callbackId) {
|
||||||
@ -186,7 +197,7 @@ public class Capture extends Plugin {
|
|||||||
private void captureAudio() {
|
private void captureAudio() {
|
||||||
Intent intent = new Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION);
|
Intent intent = new Intent(android.provider.MediaStore.Audio.Media.RECORD_SOUND_ACTION);
|
||||||
|
|
||||||
this.ctx.startActivityForResult((Plugin) this, intent, CAPTURE_AUDIO);
|
cordova.startActivityForResult((Plugin) this, intent, CAPTURE_AUDIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -196,11 +207,11 @@ public class Capture extends Plugin {
|
|||||||
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
|
|
||||||
// Specify file so that large image is captured and returned
|
// Specify file so that large image is captured and returned
|
||||||
File photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()), "Capture.jpg");
|
File photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Capture.jpg");
|
||||||
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
|
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
|
||||||
this.imageUri = Uri.fromFile(photo);
|
this.imageUri = Uri.fromFile(photo);
|
||||||
|
|
||||||
this.ctx.startActivityForResult((Plugin) this, intent, CAPTURE_IMAGE);
|
cordova.startActivityForResult((Plugin) this, intent, CAPTURE_IMAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -211,7 +222,7 @@ public class Capture extends Plugin {
|
|||||||
// Introduced in API 8
|
// Introduced in API 8
|
||||||
//intent.putExtra(android.provider.MediaStore.EXTRA_DURATION_LIMIT, duration);
|
//intent.putExtra(android.provider.MediaStore.EXTRA_DURATION_LIMIT, duration);
|
||||||
|
|
||||||
this.ctx.startActivityForResult((Plugin) this, intent, CAPTURE_VIDEO);
|
cordova.startActivityForResult((Plugin) this, intent, CAPTURE_VIDEO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -249,7 +260,7 @@ public class Capture extends Plugin {
|
|||||||
try {
|
try {
|
||||||
// Create an ExifHelper to save the exif data that is lost during compression
|
// Create an ExifHelper to save the exif data that is lost during compression
|
||||||
ExifHelper exif = new ExifHelper();
|
ExifHelper exif = new ExifHelper();
|
||||||
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/Capture.jpg");
|
exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx) + "/Capture.jpg");
|
||||||
exif.readExifData();
|
exif.readExifData();
|
||||||
|
|
||||||
// Read in bitmap of captured image
|
// Read in bitmap of captured image
|
||||||
@ -283,7 +294,7 @@ public class Capture extends Plugin {
|
|||||||
System.gc();
|
System.gc();
|
||||||
|
|
||||||
// Restore exif data to file
|
// Restore exif data to file
|
||||||
exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx));
|
exif.createOutFile(FileUtils.getRealPathFromURI(uri, ((Activity) this.ctx)));
|
||||||
exif.writeExifData();
|
exif.writeExifData();
|
||||||
|
|
||||||
// Add image to results
|
// Add image to results
|
||||||
@ -347,7 +358,7 @@ public class Capture extends Plugin {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
private JSONObject createMediaFile(Uri data){
|
private JSONObject createMediaFile(Uri data){
|
||||||
File fp = new File(FileUtils.getRealPathFromURI(data, this.ctx));
|
File fp = new File(FileUtils.getRealPathFromURI(data, ((Activity) this.ctx)));
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -70,7 +70,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
|
|||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(CordovaInterface ctx) {
|
public void setContext(Context ctx) {
|
||||||
super.setContext(ctx);
|
super.setContext(ctx);
|
||||||
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ public class ContactManager extends Plugin {
|
|||||||
* older phones.
|
* older phones.
|
||||||
*/
|
*/
|
||||||
if (this.contactAccessor == null) {
|
if (this.contactAccessor == null) {
|
||||||
this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx.getContext());
|
this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Stack;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ import android.util.AttributeSet;
|
|||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebSettings.LayoutAlgorithm;
|
import android.webkit.WebSettings.LayoutAlgorithm;
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
public class CordovaWebView extends WebView {
|
public class CordovaWebView extends WebView {
|
||||||
|
|
||||||
@ -38,6 +40,15 @@ public class CordovaWebView extends WebView {
|
|||||||
private CordovaWebViewClient viewClient;
|
private CordovaWebViewClient viewClient;
|
||||||
private CordovaChromeClient chromeClient;
|
private CordovaChromeClient chromeClient;
|
||||||
|
|
||||||
|
//This is for the polyfil history
|
||||||
|
private String url;
|
||||||
|
private String baseUrl;
|
||||||
|
private Stack<String> urls = new Stack<String>();
|
||||||
|
|
||||||
|
protected int loadUrlTimeout;
|
||||||
|
|
||||||
|
protected long loadUrlTimeoutValue;
|
||||||
|
|
||||||
public CordovaWebView(Context context) {
|
public CordovaWebView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
mCtx = context;
|
mCtx = context;
|
||||||
@ -94,9 +105,23 @@ public class CordovaWebView extends WebView {
|
|||||||
settings.setGeolocationEnabled(true);
|
settings.setGeolocationEnabled(true);
|
||||||
|
|
||||||
//Start up the plugin manager
|
//Start up the plugin manager
|
||||||
this.pluginManager = new PluginManager(this, (DroidGap) mCtx);
|
this.pluginManager = new PluginManager(this, mCtx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//This sets it up so that we can save copies of the clients that we might need later.
|
||||||
|
public void setWebViewClient(CordovaWebViewClient client)
|
||||||
|
{
|
||||||
|
viewClient = client;
|
||||||
|
super.setWebViewClient(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setWebChromeClient(CordovaChromeClient client)
|
||||||
|
{
|
||||||
|
chromeClient = client;
|
||||||
|
super.setWebChromeClient(client);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Sets the authentication token.
|
* Sets the authentication token.
|
||||||
*
|
*
|
||||||
@ -245,4 +270,21 @@ public class CordovaWebView extends WebView {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void loadUrl(String url)
|
||||||
|
{
|
||||||
|
if (!url.startsWith("javascript:")) {
|
||||||
|
this.urls.push(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
super.loadUrl(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendJavascript(String statement) {
|
||||||
|
callbackServer.sendJavascript(statement);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void postMessage(String id, String data) {
|
||||||
|
pluginManager.postMessage(id, data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class Device extends Plugin {
|
|||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(CordovaInterface ctx) {
|
public void setContext(Context ctx) {
|
||||||
super.setContext(ctx);
|
super.setContext(ctx);
|
||||||
Device.uuid = getUuid();
|
Device.uuid = getUuid();
|
||||||
this.initTelephonyReceiver();
|
this.initTelephonyReceiver();
|
||||||
@ -125,7 +125,7 @@ public class Device extends Plugin {
|
|||||||
private void initTelephonyReceiver() {
|
private void initTelephonyReceiver() {
|
||||||
IntentFilter intentFilter = new IntentFilter() ;
|
IntentFilter intentFilter = new IntentFilter() ;
|
||||||
intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
|
intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
|
||||||
final CordovaInterface myctx = this.ctx;
|
final Context myctx = this.ctx;
|
||||||
this.telephonyReceiver = new BroadcastReceiver() {
|
this.telephonyReceiver = new BroadcastReceiver() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -137,15 +137,15 @@ public class Device extends Plugin {
|
|||||||
String extraData = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
|
String extraData = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
|
||||||
if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
|
if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
|
||||||
LOG.i(TAG, "Telephone RINGING");
|
LOG.i(TAG, "Telephone RINGING");
|
||||||
myctx.postMessage("telephone", "ringing");
|
webView.postMessage("telephone", "ringing");
|
||||||
}
|
}
|
||||||
else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
|
else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
|
||||||
LOG.i(TAG, "Telephone OFFHOOK");
|
LOG.i(TAG, "Telephone OFFHOOK");
|
||||||
myctx.postMessage("telephone", "offhook");
|
webView.postMessage("telephone", "offhook");
|
||||||
}
|
}
|
||||||
else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
|
else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
|
||||||
LOG.i(TAG, "Telephone IDLE");
|
LOG.i(TAG, "Telephone IDLE");
|
||||||
myctx.postMessage("telephone", "idle");
|
webView.postMessage("telephone", "idle");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -416,7 +416,7 @@ public class FileTransfer extends Plugin {
|
|||||||
file.getParentFile().mkdirs();
|
file.getParentFile().mkdirs();
|
||||||
|
|
||||||
// connect to server
|
// connect to server
|
||||||
if(this.ctx.isUrlWhiteListed(source))
|
if(webView.isUrlWhiteListed(source))
|
||||||
{
|
{
|
||||||
URL url = new URL(source);
|
URL url = new URL(source);
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
@ -37,12 +37,14 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.webkit.MimeTypeMap;
|
import android.webkit.MimeTypeMap;
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -242,7 +244,7 @@ public class FileUtils extends Plugin {
|
|||||||
|
|
||||||
// Handle the special case where you get an Android content:// uri.
|
// Handle the special case where you get an Android content:// uri.
|
||||||
if (decoded.startsWith("content:")) {
|
if (decoded.startsWith("content:")) {
|
||||||
Cursor cursor = this.ctx.managedQuery(Uri.parse(decoded), new String[] { MediaStore.Images.Media.DATA }, null, null, null);
|
Cursor cursor = ((Activity) this.ctx).managedQuery(Uri.parse(decoded), new String[] { MediaStore.Images.Media.DATA }, null, null, null);
|
||||||
// Note: MediaStore.Images/Audio/Video.Media.DATA is always "_data"
|
// Note: MediaStore.Images/Audio/Video.Media.DATA is always "_data"
|
||||||
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
@ -1035,12 +1037,12 @@ public class FileUtils extends Plugin {
|
|||||||
* Queries the media store to find out what the file path is for the Uri we supply
|
* 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 contentUri the Uri of the audio/image/video
|
||||||
* @param ctx the current applicaiton context
|
* @param ctx) the current applicaiton context
|
||||||
* @return the full path to the file
|
* @return the full path to the file
|
||||||
*/
|
*/
|
||||||
protected static String getRealPathFromURI(Uri contentUri, CordovaInterface ctx) {
|
protected static String getRealPathFromURI(Uri contentUri, Activity ctx) {
|
||||||
String[] proj = { _DATA };
|
String[] proj = { _DATA };
|
||||||
Cursor cursor = ctx.managedQuery(contentUri, proj, null, null, null);
|
Cursor cursor = ctx.managedQuery(contentUri, proj, null, null, null);
|
||||||
int column_index = cursor.getColumnIndexOrThrow(_DATA);
|
int column_index = cursor.getColumnIndexOrThrow(_DATA);
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
return cursor.getString(column_index);
|
return cursor.getString(column_index);
|
||||||
|
@ -33,7 +33,7 @@ import android.os.Bundle;
|
|||||||
*/
|
*/
|
||||||
public class GpsListener implements LocationListener {
|
public class GpsListener implements LocationListener {
|
||||||
|
|
||||||
private CordovaInterface mCtx; // CordovaActivity object
|
private Context mCtx; // CordovaActivity object
|
||||||
|
|
||||||
private LocationManager mLocMan; // Location manager object
|
private LocationManager mLocMan; // Location manager object
|
||||||
private GeoListener owner; // Geolistener object (parent)
|
private GeoListener owner; // Geolistener object (parent)
|
||||||
@ -49,7 +49,7 @@ public class GpsListener implements LocationListener {
|
|||||||
* @param interval
|
* @param interval
|
||||||
* @param m
|
* @param m
|
||||||
*/
|
*/
|
||||||
public GpsListener(CordovaInterface ctx, int interval, GeoListener m) {
|
public GpsListener(Context ctx, int interval, GeoListener m) {
|
||||||
this.owner = m;
|
this.owner = m;
|
||||||
this.mCtx = ctx;
|
this.mCtx = ctx;
|
||||||
this.mLocMan = (LocationManager) this.mCtx.getSystemService(Context.LOCATION_SERVICE);
|
this.mLocMan = (LocationManager) this.mCtx.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
@ -28,7 +28,7 @@ import android.os.Bundle;
|
|||||||
|
|
||||||
public class NetworkListener implements LocationListener {
|
public class NetworkListener implements LocationListener {
|
||||||
|
|
||||||
private CordovaInterface mCtx; // CordovaActivity object
|
private Context mCtx; // CordovaActivity object
|
||||||
|
|
||||||
private LocationManager mLocMan; // Location manager object
|
private LocationManager mLocMan; // Location manager object
|
||||||
private GeoListener owner; // Geolistener object (parent)
|
private GeoListener owner; // Geolistener object (parent)
|
||||||
@ -44,7 +44,7 @@ public class NetworkListener implements LocationListener {
|
|||||||
* @param interval
|
* @param interval
|
||||||
* @param m
|
* @param m
|
||||||
*/
|
*/
|
||||||
public NetworkListener(CordovaInterface ctx, int interval, GeoListener m) {
|
public NetworkListener(Context ctx, int interval, GeoListener m) {
|
||||||
this.owner = m;
|
this.owner = m;
|
||||||
this.mCtx = ctx;
|
this.mCtx = ctx;
|
||||||
this.mLocMan = (LocationManager) this.mCtx.getSystemService(Context.LOCATION_SERVICE);
|
this.mLocMan = (LocationManager) this.mCtx.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
@ -87,7 +87,7 @@ public class NetworkManager extends Plugin {
|
|||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(CordovaInterface ctx) {
|
public void setContext(Context ctx) {
|
||||||
super.setContext(ctx);
|
super.setContext(ctx);
|
||||||
this.sockMan = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
|
this.sockMan = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
this.connectionCallbackId = null;
|
this.connectionCallbackId = null;
|
||||||
@ -201,7 +201,7 @@ public class NetworkManager extends Plugin {
|
|||||||
this.success(result, this.connectionCallbackId);
|
this.success(result, this.connectionCallbackId);
|
||||||
|
|
||||||
// Send to all plugins
|
// Send to all plugins
|
||||||
this.ctx.postMessage("networkconnection", type);
|
webView.postMessage("networkconnection", type);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,6 +31,7 @@ import android.media.Ringtone;
|
|||||||
import android.media.RingtoneManager;
|
import android.media.RingtoneManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
|
import android.app.Activity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provides access to notifications on the device.
|
* This class provides access to notifications on the device.
|
||||||
@ -143,7 +144,7 @@ public class Notification extends Plugin {
|
|||||||
*/
|
*/
|
||||||
public void beep(long count) {
|
public void beep(long count) {
|
||||||
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
||||||
Ringtone notification = RingtoneManager.getRingtone(this.ctx.getContext(), ringtone);
|
Ringtone notification = RingtoneManager.getRingtone(this.ctx, ringtone);
|
||||||
|
|
||||||
// If phone is not set to silent mode
|
// If phone is not set to silent mode
|
||||||
if (notification != null) {
|
if (notification != null) {
|
||||||
@ -184,13 +185,13 @@ public class Notification extends Plugin {
|
|||||||
*/
|
*/
|
||||||
public synchronized void alert(final String message, final String title, final String buttonLabel, final String callbackId) {
|
public synchronized void alert(final String message, final String title, final String buttonLabel, final String callbackId) {
|
||||||
|
|
||||||
final CordovaInterface ctx = this.ctx;
|
final Context ctx = this.ctx;
|
||||||
final Notification notification = this;
|
final Notification notification = this;
|
||||||
|
|
||||||
Runnable runnable = new Runnable() {
|
Runnable runnable = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
|
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
|
||||||
dlg.setMessage(message);
|
dlg.setMessage(message);
|
||||||
dlg.setTitle(title);
|
dlg.setTitle(title);
|
||||||
dlg.setCancelable(false);
|
dlg.setCancelable(false);
|
||||||
@ -205,7 +206,7 @@ public class Notification extends Plugin {
|
|||||||
dlg.show();
|
dlg.show();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
this.ctx.runOnUiThread(runnable);
|
((Activity) this.ctx).runOnUiThread(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -220,13 +221,13 @@ public class Notification extends Plugin {
|
|||||||
*/
|
*/
|
||||||
public synchronized void confirm(final String message, final String title, String buttonLabels, final String callbackId) {
|
public synchronized void confirm(final String message, final String title, String buttonLabels, final String callbackId) {
|
||||||
|
|
||||||
final CordovaInterface ctx = this.ctx;
|
final Context ctx = this.ctx;
|
||||||
final Notification notification = this;
|
final Notification notification = this;
|
||||||
final String[] fButtons = buttonLabels.split(",");
|
final String[] fButtons = buttonLabels.split(",");
|
||||||
|
|
||||||
Runnable runnable = new Runnable() {
|
Runnable runnable = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
|
AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
|
||||||
dlg.setMessage(message);
|
dlg.setMessage(message);
|
||||||
dlg.setTitle(title);
|
dlg.setTitle(title);
|
||||||
dlg.setCancelable(false);
|
dlg.setCancelable(false);
|
||||||
@ -269,7 +270,7 @@ public class Notification extends Plugin {
|
|||||||
dlg.show();
|
dlg.show();
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
this.ctx.runOnUiThread(runnable);
|
((Activity) this.ctx).runOnUiThread(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -284,10 +285,10 @@ public class Notification extends Plugin {
|
|||||||
this.spinnerDialog = null;
|
this.spinnerDialog = null;
|
||||||
}
|
}
|
||||||
final Notification notification = this;
|
final Notification notification = this;
|
||||||
final CordovaInterface ctx = this.ctx;
|
final Activity ctx = (Activity) this.ctx;
|
||||||
Runnable runnable = new Runnable() {
|
Runnable runnable = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
notification.spinnerDialog = ProgressDialog.show(ctx.getContext(), title , message, true, true,
|
notification.spinnerDialog = ProgressDialog.show(ctx, title , message, true, true,
|
||||||
new DialogInterface.OnCancelListener() {
|
new DialogInterface.OnCancelListener() {
|
||||||
public void onCancel(DialogInterface dialog) {
|
public void onCancel(DialogInterface dialog) {
|
||||||
notification.spinnerDialog = null;
|
notification.spinnerDialog = null;
|
||||||
@ -295,7 +296,7 @@ public class Notification extends Plugin {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.ctx.runOnUiThread(runnable);
|
ctx.runOnUiThread(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -320,10 +321,10 @@ public class Notification extends Plugin {
|
|||||||
this.progressDialog = null;
|
this.progressDialog = null;
|
||||||
}
|
}
|
||||||
final Notification notification = this;
|
final Notification notification = this;
|
||||||
final CordovaInterface ctx = this.ctx;
|
final Activity ctx = (Activity) this.ctx;
|
||||||
Runnable runnable = new Runnable() {
|
Runnable runnable = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
notification.progressDialog = new ProgressDialog(ctx.getContext());
|
notification.progressDialog = new ProgressDialog(ctx);
|
||||||
notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||||
notification.progressDialog.setTitle(title);
|
notification.progressDialog.setTitle(title);
|
||||||
notification.progressDialog.setMessage(message);
|
notification.progressDialog.setMessage(message);
|
||||||
@ -339,7 +340,7 @@ public class Notification extends Plugin {
|
|||||||
notification.progressDialog.show();
|
notification.progressDialog.show();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
this.ctx.runOnUiThread(runnable);
|
ctx.runOnUiThread(runnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,7 +49,7 @@ public class TempListener extends Plugin implements SensorEventListener {
|
|||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(CordovaInterface ctx) {
|
public void setContext(Context ctx) {
|
||||||
super.setContext(ctx);
|
super.setContext(ctx);
|
||||||
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,37 @@ import android.net.Uri;
|
|||||||
*/
|
*/
|
||||||
public interface CordovaInterface {
|
public interface CordovaInterface {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Launch an activity for which you would like a result when it finished. When this activity exits,
|
||||||
|
* your onActivityResult() method will be called.
|
||||||
|
*
|
||||||
|
* @param command The command object
|
||||||
|
* @param intent The intent to start
|
||||||
|
* @param requestCode The request code that is passed to callback to identify the activity
|
||||||
|
*/
|
||||||
|
abstract public void startActivityForResult(IPlugin command, Intent intent, int requestCode);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the plugin to be called when a sub-activity exits.
|
||||||
|
*
|
||||||
|
* @param plugin The plugin on which onActivityResult is to be called
|
||||||
|
*/
|
||||||
|
abstract public void setActivityResultCallback(IPlugin plugin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Causes the Activity to override the back button behaviour
|
||||||
|
* @param override
|
||||||
|
*/
|
||||||
|
public abstract void bindBackButton(boolean override);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook required to check if the Back Button is bound
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public abstract boolean isBackButtonBound();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated
|
* @deprecated
|
||||||
* Add services to res/xml/plugins.xml instead.
|
* Add services to res/xml/plugins.xml instead.
|
||||||
@ -53,95 +84,100 @@ public interface CordovaInterface {
|
|||||||
abstract public void addService(String serviceType, String className);
|
abstract public void addService(String serviceType, String className);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @deprecated
|
||||||
* Send JavaScript statement back to JavaScript.
|
* Send JavaScript statement back to JavaScript.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
abstract public void sendJavascript(String statement);
|
abstract public void sendJavascript(String statement);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launch an activity for which you would like a result when it finished. When this activity exits,
|
* @deprecated
|
||||||
* your onActivityResult() method will be called.
|
|
||||||
*
|
|
||||||
* @param command The command object
|
|
||||||
* @param intent The intent to start
|
|
||||||
* @param requestCode The request code that is passed to callback to identify the activity
|
|
||||||
*/
|
|
||||||
abstract public void startActivityForResult(IPlugin command, Intent intent, int requestCode);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Launch an activity for which you would not like a result when it finished.
|
* Launch an activity for which you would not like a result when it finished.
|
||||||
*
|
*
|
||||||
* @param intent The intent to start
|
* @param intent The intent to start
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
abstract public void startActivity(Intent intent);
|
abstract public void startActivity(Intent intent);
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the plugin to be called when a sub-activity exits.
|
|
||||||
*
|
|
||||||
* @param plugin The plugin on which onActivityResult is to be called
|
|
||||||
*/
|
|
||||||
abstract public void setActivityResultCallback(IPlugin plugin);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @deprecated
|
||||||
* Load the specified URL in the Cordova webview.
|
* Load the specified URL in the Cordova webview.
|
||||||
*
|
*
|
||||||
* @param url The URL to load.
|
* @param url The URL to load.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
abstract public void loadUrl(String url);
|
abstract public void loadUrl(String url);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @deprecated
|
||||||
* Send a message to all plugins.
|
* Send a message to all plugins.
|
||||||
*
|
*
|
||||||
* @param id The message id
|
* @param id The message id
|
||||||
* @param data The message data
|
* @param data The message data
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
abstract public void postMessage(String id, Object data);
|
abstract public void postMessage(String id, Object data);
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract Resources getResources();
|
public abstract Resources getResources();
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract String getPackageName();
|
public abstract String getPackageName();
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract Object getSystemService(String service);
|
public abstract Object getSystemService(String service);
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract Context getContext();
|
public abstract Context getContext();
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract Context getBaseContext();
|
public abstract Context getBaseContext();
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract Intent registerReceiver(BroadcastReceiver receiver,
|
public abstract Intent registerReceiver(BroadcastReceiver receiver,
|
||||||
IntentFilter intentFilter);
|
IntentFilter intentFilter);
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract ContentResolver getContentResolver();
|
public abstract ContentResolver getContentResolver();
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract void unregisterReceiver(BroadcastReceiver receiver);
|
public abstract void unregisterReceiver(BroadcastReceiver receiver);
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract Cursor managedQuery(Uri uri, String[] projection, String selection,
|
public abstract Cursor managedQuery(Uri uri, String[] projection, String selection,
|
||||||
String[] selectionArgs, String sortOrder);
|
String[] selectionArgs, String sortOrder);
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract void runOnUiThread(Runnable runnable);
|
public abstract void runOnUiThread(Runnable runnable);
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract AssetManager getAssets();
|
public abstract AssetManager getAssets();
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract void clearCache();
|
public abstract void clearCache();
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract void clearHistory();
|
public abstract void clearHistory();
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract boolean backHistory();
|
public abstract boolean backHistory();
|
||||||
|
|
||||||
//public abstract void addWhiteListEntry(String origin, boolean subdomains);
|
//public abstract void addWhiteListEntry(String origin, boolean subdomains);
|
||||||
|
|
||||||
public abstract void bindBackButton(boolean override);
|
@Deprecated
|
||||||
|
|
||||||
public abstract boolean isBackButtonBound();
|
|
||||||
|
|
||||||
public abstract void cancelLoadUrl();
|
public abstract void cancelLoadUrl();
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract void showWebPage(String url, boolean openExternal,
|
public abstract void showWebPage(String url, boolean openExternal,
|
||||||
boolean clearHistory, HashMap<String, Object> params);
|
boolean clearHistory, HashMap<String, Object> params);
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract Context getApplicationContext();
|
public abstract Context getApplicationContext();
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public abstract boolean isUrlWhiteListed(String source);
|
public abstract boolean isUrlWhiteListed(String source);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cordova.api;
|
package org.apache.cordova.api;
|
||||||
|
|
||||||
|
import org.apache.cordova.CordovaWebView;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
@ -53,7 +56,7 @@ public interface IPlugin {
|
|||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
void setContext(CordovaInterface ctx);
|
void setContext(Context ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the main View of the application, this is the WebView within which
|
* Sets the main View of the application, this is the WebView within which
|
||||||
@ -61,7 +64,7 @@ public interface IPlugin {
|
|||||||
*
|
*
|
||||||
* @param webView The Cordova WebView
|
* @param webView The Cordova WebView
|
||||||
*/
|
*/
|
||||||
void setView(WebView webView);
|
void setView(CordovaWebView webView);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the system is about to start resuming a previous activity.
|
* Called when the system is about to start resuming a previous activity.
|
||||||
|
@ -18,9 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cordova.api;
|
package org.apache.cordova.api;
|
||||||
|
|
||||||
|
import org.apache.cordova.CordovaWebView;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
@ -32,8 +34,8 @@ import android.webkit.WebView;
|
|||||||
public abstract class Plugin implements IPlugin {
|
public abstract class Plugin implements IPlugin {
|
||||||
|
|
||||||
public String id;
|
public String id;
|
||||||
public WebView webView; // WebView object
|
public CordovaWebView webView; // WebView object
|
||||||
public CordovaInterface ctx; // CordovaActivity object
|
public Context ctx; // CordovaActivity object
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the request and returns PluginResult.
|
* Executes the request and returns PluginResult.
|
||||||
@ -61,7 +63,7 @@ public abstract class Plugin implements IPlugin {
|
|||||||
*
|
*
|
||||||
* @param ctx The context of the main Activity.
|
* @param ctx The context of the main Activity.
|
||||||
*/
|
*/
|
||||||
public void setContext(CordovaInterface ctx) {
|
public void setContext(Context ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +73,7 @@ public abstract class Plugin implements IPlugin {
|
|||||||
*
|
*
|
||||||
* @param webView The Cordova WebView
|
* @param webView The Cordova WebView
|
||||||
*/
|
*/
|
||||||
public void setView(WebView webView) {
|
public void setView(CordovaWebView webView) {
|
||||||
this.webView = webView;
|
this.webView = webView;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +143,7 @@ public abstract class Plugin implements IPlugin {
|
|||||||
* @param statement
|
* @param statement
|
||||||
*/
|
*/
|
||||||
public void sendJavascript(String statement) {
|
public void sendJavascript(String statement) {
|
||||||
this.ctx.sendJavascript(statement);
|
webView.sendJavascript(statement);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -155,7 +157,7 @@ public abstract class Plugin implements IPlugin {
|
|||||||
* @param callbackId The callback id used when calling back into JavaScript.
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
*/
|
*/
|
||||||
public void success(PluginResult pluginResult, String callbackId) {
|
public void success(PluginResult pluginResult, String callbackId) {
|
||||||
this.ctx.sendJavascript(pluginResult.toSuccessCallbackString(callbackId));
|
webView.sendJavascript(pluginResult.toSuccessCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,7 +167,7 @@ public abstract class Plugin implements IPlugin {
|
|||||||
* @param callbackId The callback id used when calling back into JavaScript.
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
*/
|
*/
|
||||||
public void success(JSONObject message, String callbackId) {
|
public void success(JSONObject message, String callbackId) {
|
||||||
this.ctx.sendJavascript(new PluginResult(PluginResult.Status.OK, message).toSuccessCallbackString(callbackId));
|
webView.sendJavascript(new PluginResult(PluginResult.Status.OK, message).toSuccessCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -175,7 +177,7 @@ public abstract class Plugin implements IPlugin {
|
|||||||
* @param callbackId The callback id used when calling back into JavaScript.
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
*/
|
*/
|
||||||
public void success(String message, String callbackId) {
|
public void success(String message, String callbackId) {
|
||||||
this.ctx.sendJavascript(new PluginResult(PluginResult.Status.OK, message).toSuccessCallbackString(callbackId));
|
webView.sendJavascript(new PluginResult(PluginResult.Status.OK, message).toSuccessCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -185,7 +187,7 @@ public abstract class Plugin implements IPlugin {
|
|||||||
* @param callbackId The callback id used when calling back into JavaScript.
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
*/
|
*/
|
||||||
public void error(PluginResult pluginResult, String callbackId) {
|
public void error(PluginResult pluginResult, String callbackId) {
|
||||||
this.ctx.sendJavascript(pluginResult.toErrorCallbackString(callbackId));
|
webView.sendJavascript(pluginResult.toErrorCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -195,7 +197,7 @@ public abstract class Plugin implements IPlugin {
|
|||||||
* @param callbackId The callback id used when calling back into JavaScript.
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
*/
|
*/
|
||||||
public void error(JSONObject message, String callbackId) {
|
public void error(JSONObject message, String callbackId) {
|
||||||
this.ctx.sendJavascript(new PluginResult(PluginResult.Status.ERROR, message).toErrorCallbackString(callbackId));
|
webView.sendJavascript(new PluginResult(PluginResult.Status.ERROR, message).toErrorCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -205,6 +207,6 @@ public abstract class Plugin implements IPlugin {
|
|||||||
* @param callbackId The callback id used when calling back into JavaScript.
|
* @param callbackId The callback id used when calling back into JavaScript.
|
||||||
*/
|
*/
|
||||||
public void error(String message, String callbackId) {
|
public void error(String message, String callbackId) {
|
||||||
this.ctx.sendJavascript(new PluginResult(PluginResult.Status.ERROR, message).toErrorCallbackString(callbackId));
|
webView.sendJavascript(new PluginResult(PluginResult.Status.ERROR, message).toErrorCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.apache.cordova.api;
|
package org.apache.cordova.api;
|
||||||
|
|
||||||
|
import org.apache.cordova.CordovaWebView;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,7 +70,7 @@ public class PluginEntry {
|
|||||||
* @return The plugin object
|
* @return The plugin object
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public IPlugin createPlugin(WebView webView, CordovaInterface ctx) {
|
public IPlugin createPlugin(CordovaWebView webView, Context ctx) {
|
||||||
if (this.plugin != null) {
|
if (this.plugin != null) {
|
||||||
return this.plugin;
|
return this.plugin;
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,12 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
import org.apache.cordova.CordovaWebView;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
@ -43,8 +45,8 @@ public class PluginManager {
|
|||||||
// List of service entries
|
// List of service entries
|
||||||
private final HashMap<String, PluginEntry> entries = new HashMap<String, PluginEntry>();
|
private final HashMap<String, PluginEntry> entries = new HashMap<String, PluginEntry>();
|
||||||
|
|
||||||
private final CordovaInterface ctx;
|
private final Context ctx;
|
||||||
private final WebView app;
|
private final CordovaWebView app;
|
||||||
|
|
||||||
// Flag to track first time through
|
// Flag to track first time through
|
||||||
private boolean firstRun;
|
private boolean firstRun;
|
||||||
@ -59,12 +61,27 @@ public class PluginManager {
|
|||||||
* @param app
|
* @param app
|
||||||
* @param ctx
|
* @param ctx
|
||||||
*/
|
*/
|
||||||
public PluginManager(WebView app, CordovaInterface ctx) {
|
public PluginManager(CordovaWebView app, Context ctx) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.firstRun = true;
|
this.firstRun = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public PluginManager(WebView mApp, CordovaInterface mCtx) throws Exception {
|
||||||
|
this.ctx = mCtx.getContext();
|
||||||
|
if(CordovaWebView.class.isInstance(mApp))
|
||||||
|
{
|
||||||
|
this.app = (CordovaWebView) mApp;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Throw an exception here
|
||||||
|
throw new Exception();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init when loading a new HTML page into webview.
|
* Init when loading a new HTML page into webview.
|
||||||
*/
|
*/
|
||||||
@ -174,7 +191,7 @@ public class PluginManager {
|
|||||||
try {
|
try {
|
||||||
final JSONArray args = new JSONArray(jsonArgs);
|
final JSONArray args = new JSONArray(jsonArgs);
|
||||||
final IPlugin plugin = this.getPlugin(service);
|
final IPlugin plugin = this.getPlugin(service);
|
||||||
final CordovaInterface ctx = this.ctx;
|
final Context ctx = this.ctx;
|
||||||
if (plugin != null) {
|
if (plugin != null) {
|
||||||
runAsync = async && !plugin.isSynch(action);
|
runAsync = async && !plugin.isSynch(action);
|
||||||
if (runAsync) {
|
if (runAsync) {
|
||||||
@ -192,16 +209,16 @@ public class PluginManager {
|
|||||||
|
|
||||||
// Check the success (OK, NO_RESULT & !KEEP_CALLBACK)
|
// Check the success (OK, NO_RESULT & !KEEP_CALLBACK)
|
||||||
else if ((status == PluginResult.Status.OK.ordinal()) || (status == PluginResult.Status.NO_RESULT.ordinal())) {
|
else if ((status == PluginResult.Status.OK.ordinal()) || (status == PluginResult.Status.NO_RESULT.ordinal())) {
|
||||||
ctx.sendJavascript(cr.toSuccessCallbackString(callbackId));
|
app.sendJavascript(cr.toSuccessCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If error
|
// If error
|
||||||
else {
|
else {
|
||||||
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
app.sendJavascript(cr.toErrorCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
PluginResult cr = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
|
PluginResult cr = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
|
||||||
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
app.sendJavascript(cr.toErrorCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -226,7 +243,7 @@ public class PluginManager {
|
|||||||
if (cr == null) {
|
if (cr == null) {
|
||||||
cr = new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION);
|
cr = new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION);
|
||||||
}
|
}
|
||||||
ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
|
app.sendJavascript(cr.toErrorCallbackString(callbackId));
|
||||||
}
|
}
|
||||||
return (cr != null ? cr.getJSONString() : "{ status: 0, message: 'all good' }");
|
return (cr != null ? cr.getJSONString() : "{ status: 0, message: 'all good' }");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user