You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2012/04/12 20:27:28 UTC
android commit: Massive refactor of CordovaInterface. Deprecation and
Exception throwing to notify the user that we're changing things
Updated Branches:
refs/heads/CordovaWebView b99e9abb5 -> 1794f2e04
Massive refactor of CordovaInterface. Deprecation and Exception throwing to notify the user that we're changing things
Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/1794f2e0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/1794f2e0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/1794f2e0
Branch: refs/heads/CordovaWebView
Commit: 1794f2e0470ba8b48f7433f742d7ae1793685ab7
Parents: b99e9ab
Author: Joe Bowser <bo...@apache.org>
Authored: Thu Apr 12 11:27:08 2012 -0700
Committer: Joe Bowser <bo...@apache.org>
Committed: Thu Apr 12 11:27:08 2012 -0700
----------------------------------------------------------------------
framework/src/com/phonegap/api/PluginManager.java | 2 +-
.../src/org/apache/cordova/AccelListener.java | 6 +-
framework/src/org/apache/cordova/App.java | 4 +
framework/src/org/apache/cordova/AudioPlayer.java | 2 +-
.../src/org/apache/cordova/CameraLauncher.java | 34 +++++--
framework/src/org/apache/cordova/Capture.java | 25 ++++--
.../src/org/apache/cordova/CompassListener.java | 2 +-
.../src/org/apache/cordova/ContactManager.java | 2 +-
.../src/org/apache/cordova/CordovaWebView.java | 44 ++++++++-
framework/src/org/apache/cordova/Device.java | 10 +-
framework/src/org/apache/cordova/FileTransfer.java | 2 +-
framework/src/org/apache/cordova/FileUtils.java | 10 +-
framework/src/org/apache/cordova/GpsListener.java | 4 +-
.../src/org/apache/cordova/NetworkListener.java | 4 +-
.../src/org/apache/cordova/NetworkManager.java | 4 +-
framework/src/org/apache/cordova/Notification.java | 27 +++---
framework/src/org/apache/cordova/TempListener.java | 2 +-
.../org/apache/cordova/api/CordovaInterface.java | 78 +++++++++++----
framework/src/org/apache/cordova/api/IPlugin.java | 7 +-
framework/src/org/apache/cordova/api/Plugin.java | 24 +++--
.../src/org/apache/cordova/api/PluginEntry.java | 5 +-
.../src/org/apache/cordova/api/PluginManager.java | 33 +++++--
22 files changed, 234 insertions(+), 97 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/com/phonegap/api/PluginManager.java
----------------------------------------------------------------------
diff --git a/framework/src/com/phonegap/api/PluginManager.java b/framework/src/com/phonegap/api/PluginManager.java
index 4f0f13f..b0c0f0b 100755
--- a/framework/src/com/phonegap/api/PluginManager.java
+++ b/framework/src/com/phonegap/api/PluginManager.java
@@ -30,7 +30,7 @@ import android.webkit.WebView;
*/
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);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/AccelListener.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/AccelListener.java b/framework/src/org/apache/cordova/AccelListener.java
index f751e4e..9e62a5b 100755
--- a/framework/src/org/apache/cordova/AccelListener.java
+++ b/framework/src/org/apache/cordova/AccelListener.java
@@ -72,10 +72,10 @@ public class AccelListener extends Plugin implements SensorEventListener {
*
* @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);
- }
+ }
/**
* Executes the request and returns PluginResult.
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/App.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/App.java b/framework/src/org/apache/cordova/App.java
index 9b1c96a..5bf232e 100755
--- a/framework/src/org/apache/cordova/App.java
+++ b/framework/src/org/apache/cordova/App.java
@@ -25,6 +25,9 @@ import org.apache.cordova.api.PluginResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+
+import android.webkit.WebView;
+
import java.util.HashMap;
/**
@@ -195,4 +198,5 @@ public class App extends Plugin {
public void exitApp() {
((DroidGap)this.ctx).endActivity();
}
+
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/AudioPlayer.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/AudioPlayer.java b/framework/src/org/apache/cordova/AudioPlayer.java
index 35b408a..cb97453 100755
--- a/framework/src/org/apache/cordova/AudioPlayer.java
+++ b/framework/src/org/apache/cordova/AudioPlayer.java
@@ -213,7 +213,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
else {
if (file.startsWith("/android_asset/")) {
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());
}
else {
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/CameraLauncher.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CameraLauncher.java b/framework/src/org/apache/cordova/CameraLauncher.java
index ba5d924..5751464 100755
--- a/framework/src/org/apache/cordova/CameraLauncher.java
+++ b/framework/src/org/apache/cordova/CameraLauncher.java
@@ -26,6 +26,7 @@ import java.io.IOException;
import java.io.OutputStream;
import org.apache.commons.codec.binary.Base64;
+import org.apache.cordova.api.CordovaInterface;
import org.apache.cordova.api.LOG;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
@@ -34,6 +35,7 @@ import org.json.JSONException;
import android.app.Activity;
import android.content.ContentValues;
+import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
@@ -78,12 +80,23 @@ public class CameraLauncher extends Plugin {
public String callbackId;
private int numPics;
+ //This should never be null!
+ private CordovaInterface cordova;
+
/**
* Constructor.
*/
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.
*
@@ -162,8 +175,11 @@ public class CameraLauncher extends Plugin {
File photo = createCaptureFile(encodingType);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, 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) {
File photo = null;
if (encodingType == JPEG) {
- photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()), "Pic.jpg");
+ photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Pic.jpg");
} else if (encodingType == PNG) {
- photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()), "Pic.png");
+ photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Pic.png");
} else {
throw new IllegalArgumentException("Invalid Encoding Type: " + encodingType);
}
@@ -211,7 +227,7 @@ public class CameraLauncher extends Plugin {
intent.setAction(Intent.ACTION_GET_CONTENT);
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);
}
@@ -278,7 +294,7 @@ public class CameraLauncher extends Plugin {
ExifHelper exif = new ExifHelper();
try {
if (this.encodingType == JPEG) {
- exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/Pic.jpg");
+ exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx) + "/Pic.jpg");
exif.readExifData();
}
} catch (IOException e) {
@@ -335,7 +351,7 @@ public class CameraLauncher extends Plugin {
// Restore exif data to file
if (this.encodingType == JPEG) {
- exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx));
+ exif.createOutFile(FileUtils.getRealPathFromURI(uri, ((Activity) this.ctx)));
exif.writeExifData();
}
@@ -413,14 +429,14 @@ public class CameraLauncher extends Plugin {
Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
bitmap = scaleBitmap(bitmap);
- String fileName = DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/resize.jpg";
+ String fileName = DirectoryManager.getTempDirectoryPath(ctx) + "/resize.jpg";
OutputStream os = new FileOutputStream(fileName);
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.createOutFile(FileUtils.getRealPathFromURI(uri, ((Activity) ctx)));
exif.writeExifData();
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/Capture.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/Capture.java b/framework/src/org/apache/cordova/Capture.java
index ce7e9de..c1ee74f 100644
--- a/framework/src/org/apache/cordova/Capture.java
+++ b/framework/src/org/apache/cordova/Capture.java
@@ -22,6 +22,7 @@ import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
+import org.apache.cordova.api.CordovaInterface;
import org.apache.cordova.api.LOG;
import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
@@ -31,6 +32,7 @@ import org.json.JSONObject;
import android.app.Activity;
import android.content.ContentValues;
+import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@@ -62,7 +64,16 @@ public class Capture extends Plugin {
private double duration; // optional duration parameter for video recording
private JSONArray results; // The array of results to be returned to the user
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
public PluginResult execute(String action, JSONArray args, String callbackId) {
this.callbackId = callbackId;
@@ -186,7 +197,7 @@ public class Capture extends Plugin {
private void captureAudio() {
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);
// 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));
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
//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 {
// Create an ExifHelper to save the exif data that is lost during compression
ExifHelper exif = new ExifHelper();
- exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/Capture.jpg");
+ exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx) + "/Capture.jpg");
exif.readExifData();
// Read in bitmap of captured image
@@ -283,7 +294,7 @@ public class Capture extends Plugin {
System.gc();
// Restore exif data to file
- exif.createOutFile(FileUtils.getRealPathFromURI(uri, this.ctx));
+ exif.createOutFile(FileUtils.getRealPathFromURI(uri, ((Activity) this.ctx)));
exif.writeExifData();
// Add image to results
@@ -347,7 +358,7 @@ public class Capture extends Plugin {
* @throws IOException
*/
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();
try {
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/CompassListener.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CompassListener.java b/framework/src/org/apache/cordova/CompassListener.java
index 01d431a..65b33bb 100755
--- a/framework/src/org/apache/cordova/CompassListener.java
+++ b/framework/src/org/apache/cordova/CompassListener.java
@@ -70,7 +70,7 @@ public class CompassListener extends Plugin implements SensorEventListener {
*
* @param ctx The context of the main Activity.
*/
- public void setContext(CordovaInterface ctx) {
+ public void setContext(Context ctx) {
super.setContext(ctx);
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/ContactManager.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/ContactManager.java b/framework/src/org/apache/cordova/ContactManager.java
index ebe9ede..e0e81e5 100755
--- a/framework/src/org/apache/cordova/ContactManager.java
+++ b/framework/src/org/apache/cordova/ContactManager.java
@@ -69,7 +69,7 @@ public class ContactManager extends Plugin {
* older phones.
*/
if (this.contactAccessor == null) {
- this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx.getContext());
+ this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx);
}
try {
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/CordovaWebView.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java
index ffb0cfd..4519262 100644
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@ -5,6 +5,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
+import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -18,6 +19,7 @@ import android.util.AttributeSet;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebSettings.LayoutAlgorithm;
+import android.app.Activity;
public class CordovaWebView extends WebView {
@@ -38,6 +40,15 @@ public class CordovaWebView extends WebView {
private CordovaWebViewClient viewClient;
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) {
super(context);
mCtx = context;
@@ -94,9 +105,23 @@ public class CordovaWebView extends WebView {
settings.setGeolocationEnabled(true);
//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.
*
@@ -245,4 +270,21 @@ public class CordovaWebView extends WebView {
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);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/Device.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/Device.java b/framework/src/org/apache/cordova/Device.java
index c96c522..ebcb9ba 100644
--- a/framework/src/org/apache/cordova/Device.java
+++ b/framework/src/org/apache/cordova/Device.java
@@ -56,7 +56,7 @@ public class Device extends Plugin {
*
* @param ctx The context of the main Activity.
*/
- public void setContext(CordovaInterface ctx) {
+ public void setContext(Context ctx) {
super.setContext(ctx);
Device.uuid = getUuid();
this.initTelephonyReceiver();
@@ -125,7 +125,7 @@ public class Device extends Plugin {
private void initTelephonyReceiver() {
IntentFilter intentFilter = new IntentFilter() ;
intentFilter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED);
- final CordovaInterface myctx = this.ctx;
+ final Context myctx = this.ctx;
this.telephonyReceiver = new BroadcastReceiver() {
@Override
@@ -137,15 +137,15 @@ public class Device extends Plugin {
String extraData = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
LOG.i(TAG, "Telephone RINGING");
- myctx.postMessage("telephone", "ringing");
+ webView.postMessage("telephone", "ringing");
}
else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
LOG.i(TAG, "Telephone OFFHOOK");
- myctx.postMessage("telephone", "offhook");
+ webView.postMessage("telephone", "offhook");
}
else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
LOG.i(TAG, "Telephone IDLE");
- myctx.postMessage("telephone", "idle");
+ webView.postMessage("telephone", "idle");
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/FileTransfer.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/FileTransfer.java b/framework/src/org/apache/cordova/FileTransfer.java
index 649d3a8..059d084 100644
--- a/framework/src/org/apache/cordova/FileTransfer.java
+++ b/framework/src/org/apache/cordova/FileTransfer.java
@@ -416,7 +416,7 @@ public class FileTransfer extends Plugin {
file.getParentFile().mkdirs();
// connect to server
- if(this.ctx.isUrlWhiteListed(source))
+ if(webView.isUrlWhiteListed(source))
{
URL url = new URL(source);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/FileUtils.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/FileUtils.java b/framework/src/org/apache/cordova/FileUtils.java
index 863da5b..fb5694b 100755
--- a/framework/src/org/apache/cordova/FileUtils.java
+++ b/framework/src/org/apache/cordova/FileUtils.java
@@ -37,12 +37,14 @@ import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
+import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;
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.
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"
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
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
*
* @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
*/
- protected static String getRealPathFromURI(Uri contentUri, CordovaInterface ctx) {
+ protected static String getRealPathFromURI(Uri contentUri, Activity ctx) {
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);
cursor.moveToFirst();
return cursor.getString(column_index);
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/GpsListener.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/GpsListener.java b/framework/src/org/apache/cordova/GpsListener.java
index f000692..264c00c 100755
--- a/framework/src/org/apache/cordova/GpsListener.java
+++ b/framework/src/org/apache/cordova/GpsListener.java
@@ -33,7 +33,7 @@ import android.os.Bundle;
*/
public class GpsListener implements LocationListener {
- private CordovaInterface mCtx; // CordovaActivity object
+ private Context mCtx; // CordovaActivity object
private LocationManager mLocMan; // Location manager object
private GeoListener owner; // Geolistener object (parent)
@@ -49,7 +49,7 @@ public class GpsListener implements LocationListener {
* @param interval
* @param m
*/
- public GpsListener(CordovaInterface ctx, int interval, GeoListener m) {
+ public GpsListener(Context ctx, int interval, GeoListener m) {
this.owner = m;
this.mCtx = ctx;
this.mLocMan = (LocationManager) this.mCtx.getSystemService(Context.LOCATION_SERVICE);
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/NetworkListener.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/NetworkListener.java b/framework/src/org/apache/cordova/NetworkListener.java
index fd3fbd5..1b70cd7 100755
--- a/framework/src/org/apache/cordova/NetworkListener.java
+++ b/framework/src/org/apache/cordova/NetworkListener.java
@@ -28,7 +28,7 @@ import android.os.Bundle;
public class NetworkListener implements LocationListener {
- private CordovaInterface mCtx; // CordovaActivity object
+ private Context mCtx; // CordovaActivity object
private LocationManager mLocMan; // Location manager object
private GeoListener owner; // Geolistener object (parent)
@@ -44,7 +44,7 @@ public class NetworkListener implements LocationListener {
* @param interval
* @param m
*/
- public NetworkListener(CordovaInterface ctx, int interval, GeoListener m) {
+ public NetworkListener(Context ctx, int interval, GeoListener m) {
this.owner = m;
this.mCtx = ctx;
this.mLocMan = (LocationManager) this.mCtx.getSystemService(Context.LOCATION_SERVICE);
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/NetworkManager.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/NetworkManager.java b/framework/src/org/apache/cordova/NetworkManager.java
index 808dac1..d54b506 100755
--- a/framework/src/org/apache/cordova/NetworkManager.java
+++ b/framework/src/org/apache/cordova/NetworkManager.java
@@ -87,7 +87,7 @@ public class NetworkManager extends Plugin {
*
* @param ctx The context of the main Activity.
*/
- public void setContext(CordovaInterface ctx) {
+ public void setContext(Context ctx) {
super.setContext(ctx);
this.sockMan = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);
this.connectionCallbackId = null;
@@ -201,7 +201,7 @@ public class NetworkManager extends Plugin {
this.success(result, this.connectionCallbackId);
// Send to all plugins
- this.ctx.postMessage("networkconnection", type);
+ webView.postMessage("networkconnection", type);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/Notification.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/Notification.java b/framework/src/org/apache/cordova/Notification.java
index 9fb423a..a0778e1 100755
--- a/framework/src/org/apache/cordova/Notification.java
+++ b/framework/src/org/apache/cordova/Notification.java
@@ -31,6 +31,7 @@ import android.media.Ringtone;
import android.media.RingtoneManager;
import android.net.Uri;
import android.os.Vibrator;
+import android.app.Activity;
/**
* This class provides access to notifications on the device.
@@ -143,7 +144,7 @@ public class Notification extends Plugin {
*/
public void beep(long count) {
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 (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) {
- final CordovaInterface ctx = this.ctx;
+ final Context ctx = this.ctx;
final Notification notification = this;
Runnable runnable = new Runnable() {
public void run() {
- AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
+ AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
dlg.setMessage(message);
dlg.setTitle(title);
dlg.setCancelable(false);
@@ -205,7 +206,7 @@ public class Notification extends Plugin {
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) {
- final CordovaInterface ctx = this.ctx;
+ final Context ctx = this.ctx;
final Notification notification = this;
final String[] fButtons = buttonLabels.split(",");
Runnable runnable = new Runnable() {
public void run() {
- AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
+ AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
dlg.setMessage(message);
dlg.setTitle(title);
dlg.setCancelable(false);
@@ -269,7 +270,7 @@ public class Notification extends Plugin {
dlg.show();
};
};
- this.ctx.runOnUiThread(runnable);
+ ((Activity) this.ctx).runOnUiThread(runnable);
}
/**
@@ -284,10 +285,10 @@ public class Notification extends Plugin {
this.spinnerDialog = null;
}
final Notification notification = this;
- final CordovaInterface ctx = this.ctx;
+ final Activity ctx = (Activity) this.ctx;
Runnable runnable = new Runnable() {
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() {
public void onCancel(DialogInterface dialog) {
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;
}
final Notification notification = this;
- final CordovaInterface ctx = this.ctx;
+ final Activity ctx = (Activity) this.ctx;
Runnable runnable = new Runnable() {
public void run() {
- notification.progressDialog = new ProgressDialog(ctx.getContext());
+ notification.progressDialog = new ProgressDialog(ctx);
notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
notification.progressDialog.setTitle(title);
notification.progressDialog.setMessage(message);
@@ -339,7 +340,7 @@ public class Notification extends Plugin {
notification.progressDialog.show();
}
};
- this.ctx.runOnUiThread(runnable);
+ ctx.runOnUiThread(runnable);
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/TempListener.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/TempListener.java b/framework/src/org/apache/cordova/TempListener.java
index 93a5f82..936343a 100755
--- a/framework/src/org/apache/cordova/TempListener.java
+++ b/framework/src/org/apache/cordova/TempListener.java
@@ -49,7 +49,7 @@ public class TempListener extends Plugin implements SensorEventListener {
*
* @param ctx The context of the main Activity.
*/
- public void setContext(CordovaInterface ctx) {
+ public void setContext(Context ctx) {
super.setContext(ctx);
this.sensorManager = (SensorManager) ctx.getSystemService(Context.SENSOR_SERVICE);
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/api/CordovaInterface.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/CordovaInterface.java b/framework/src/org/apache/cordova/api/CordovaInterface.java
index 79dbe74..5af9fa8 100755
--- a/framework/src/org/apache/cordova/api/CordovaInterface.java
+++ b/framework/src/org/apache/cordova/api/CordovaInterface.java
@@ -40,6 +40,37 @@ import android.net.Uri;
*/
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
* Add services to res/xml/plugins.xml instead.
@@ -53,95 +84,100 @@ public interface CordovaInterface {
abstract public void addService(String serviceType, String className);
/**
+ * @deprecated
* Send JavaScript statement back to JavaScript.
*
* @param message
*/
+ @Deprecated
abstract public void sendJavascript(String statement);
/**
- * 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);
-
- /**
+ * @deprecated
* Launch an activity for which you would not like a result when it finished.
*
* @param intent The intent to start
*/
+ @Deprecated
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.
*
* @param url The URL to load.
*/
+ @Deprecated
abstract public void loadUrl(String url);
/**
+ * @deprecated
* Send a message to all plugins.
*
* @param id The message id
* @param data The message data
*/
+ @Deprecated
abstract public void postMessage(String id, Object data);
-
+ @Deprecated
public abstract Resources getResources();
+ @Deprecated
public abstract String getPackageName();
+ @Deprecated
public abstract Object getSystemService(String service);
+ @Deprecated
public abstract Context getContext();
+ @Deprecated
public abstract Context getBaseContext();
+ @Deprecated
public abstract Intent registerReceiver(BroadcastReceiver receiver,
IntentFilter intentFilter);
+ @Deprecated
public abstract ContentResolver getContentResolver();
+ @Deprecated
public abstract void unregisterReceiver(BroadcastReceiver receiver);
+ @Deprecated
public abstract Cursor managedQuery(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder);
+ @Deprecated
public abstract void runOnUiThread(Runnable runnable);
+ @Deprecated
public abstract AssetManager getAssets();
+ @Deprecated
public abstract void clearCache();
+ @Deprecated
public abstract void clearHistory();
+ @Deprecated
public abstract boolean backHistory();
//public abstract void addWhiteListEntry(String origin, boolean subdomains);
- public abstract void bindBackButton(boolean override);
-
- public abstract boolean isBackButtonBound();
-
+ @Deprecated
public abstract void cancelLoadUrl();
+ @Deprecated
public abstract void showWebPage(String url, boolean openExternal,
boolean clearHistory, HashMap<String, Object> params);
+ @Deprecated
public abstract Context getApplicationContext();
+ @Deprecated
public abstract boolean isUrlWhiteListed(String source);
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/api/IPlugin.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/IPlugin.java b/framework/src/org/apache/cordova/api/IPlugin.java
index 44349ee..7757963 100755
--- a/framework/src/org/apache/cordova/api/IPlugin.java
+++ b/framework/src/org/apache/cordova/api/IPlugin.java
@@ -18,7 +18,10 @@
*/
package org.apache.cordova.api;
+import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
+
+import android.content.Context;
import android.content.Intent;
import android.webkit.WebView;
@@ -53,7 +56,7 @@ public interface IPlugin {
*
* @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
@@ -61,7 +64,7 @@ public interface IPlugin {
*
* @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.
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/api/Plugin.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/Plugin.java b/framework/src/org/apache/cordova/api/Plugin.java
index 648e86d..36faa03 100755
--- a/framework/src/org/apache/cordova/api/Plugin.java
+++ b/framework/src/org/apache/cordova/api/Plugin.java
@@ -18,9 +18,11 @@
*/
package org.apache.cordova.api;
+import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONObject;
+import android.content.Context;
import android.content.Intent;
import android.webkit.WebView;
@@ -32,8 +34,8 @@ import android.webkit.WebView;
public abstract class Plugin implements IPlugin {
public String id;
- public WebView webView; // WebView object
- public CordovaInterface ctx; // CordovaActivity object
+ public CordovaWebView webView; // WebView object
+ public Context ctx; // CordovaActivity object
/**
* Executes the request and returns PluginResult.
@@ -61,7 +63,7 @@ public abstract class Plugin implements IPlugin {
*
* @param ctx The context of the main Activity.
*/
- public void setContext(CordovaInterface ctx) {
+ public void setContext(Context ctx) {
this.ctx = ctx;
}
@@ -71,7 +73,7 @@ public abstract class Plugin implements IPlugin {
*
* @param webView The Cordova WebView
*/
- public void setView(WebView webView) {
+ public void setView(CordovaWebView webView) {
this.webView = webView;
}
@@ -141,7 +143,7 @@ public abstract class Plugin implements IPlugin {
* @param 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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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.
*/
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));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/api/PluginEntry.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/PluginEntry.java b/framework/src/org/apache/cordova/api/PluginEntry.java
index 450fa4c..2c4cdb8 100755
--- a/framework/src/org/apache/cordova/api/PluginEntry.java
+++ b/framework/src/org/apache/cordova/api/PluginEntry.java
@@ -18,6 +18,9 @@
*/
package org.apache.cordova.api;
+import org.apache.cordova.CordovaWebView;
+
+import android.content.Context;
import android.webkit.WebView;
/**
@@ -67,7 +70,7 @@ public class PluginEntry {
* @return The plugin object
*/
@SuppressWarnings("unchecked")
- public IPlugin createPlugin(WebView webView, CordovaInterface ctx) {
+ public IPlugin createPlugin(CordovaWebView webView, Context ctx) {
if (this.plugin != null) {
return this.plugin;
}
http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/1794f2e0/framework/src/org/apache/cordova/api/PluginManager.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/PluginManager.java b/framework/src/org/apache/cordova/api/PluginManager.java
index b253427..d34fe92 100755
--- a/framework/src/org/apache/cordova/api/PluginManager.java
+++ b/framework/src/org/apache/cordova/api/PluginManager.java
@@ -23,10 +23,12 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
+import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONException;
import org.xmlpull.v1.XmlPullParserException;
+import android.content.Context;
import android.content.Intent;
import android.content.res.XmlResourceParser;
import android.webkit.WebView;
@@ -43,8 +45,8 @@ public class PluginManager {
// List of service entries
private final HashMap<String, PluginEntry> entries = new HashMap<String, PluginEntry>();
- private final CordovaInterface ctx;
- private final WebView app;
+ private final Context ctx;
+ private final CordovaWebView app;
// Flag to track first time through
private boolean firstRun;
@@ -59,12 +61,27 @@ public class PluginManager {
* @param app
* @param ctx
*/
- public PluginManager(WebView app, CordovaInterface ctx) {
+ public PluginManager(CordovaWebView app, Context ctx) {
this.ctx = ctx;
this.app = app;
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.
*/
@@ -174,7 +191,7 @@ public class PluginManager {
try {
final JSONArray args = new JSONArray(jsonArgs);
final IPlugin plugin = this.getPlugin(service);
- final CordovaInterface ctx = this.ctx;
+ final Context ctx = this.ctx;
if (plugin != null) {
runAsync = async && !plugin.isSynch(action);
if (runAsync) {
@@ -192,16 +209,16 @@ public class PluginManager {
// Check the success (OK, NO_RESULT & !KEEP_CALLBACK)
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
else {
- ctx.sendJavascript(cr.toErrorCallbackString(callbackId));
+ app.sendJavascript(cr.toErrorCallbackString(callbackId));
}
} catch (Exception e) {
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) {
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' }");
}