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/02/20 22:01:01 UTC

[21/21] android commit: Moved the CordovaInterface over to master, doing this before working on CordovaJS

Moved the CordovaInterface over to master, doing this before working on CordovaJS


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/040619cd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/040619cd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/040619cd

Branch: refs/heads/master
Commit: 040619cd613b4ad0eed666b9a24683edd4559c3b
Parents: 95b9cd0
Author: Joe Bowser <bo...@apache.org>
Authored: Fri Feb 17 13:11:15 2012 -0800
Committer: Joe Bowser <bo...@apache.org>
Committed: Fri Feb 17 13:11:15 2012 -0800

----------------------------------------------------------------------
 .../src/com/phonegap/api/PhonegapActivity.java     |    4 +-
 .../src/org/apache/cordova/CameraLauncher.java     |    8 +-
 framework/src/org/apache/cordova/Capture.java      |    4 +-
 .../src/org/apache/cordova/ContactAccessor.java    |    3 +-
 .../org/apache/cordova/ContactAccessorSdk5.java    |    5 +-
 .../src/org/apache/cordova/ContactManager.java     |    2 +-
 framework/src/org/apache/cordova/DroidGap.java     |   24 ++++++-
 framework/src/org/apache/cordova/Notification.java |   10 +-
 .../org/apache/cordova/api/CordovaInterface.java   |   58 ++++++++++++++-
 9 files changed, 99 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/040619cd/framework/src/com/phonegap/api/PhonegapActivity.java
----------------------------------------------------------------------
diff --git a/framework/src/com/phonegap/api/PhonegapActivity.java b/framework/src/com/phonegap/api/PhonegapActivity.java
index d6968c3..c1b7c46 100755
--- a/framework/src/com/phonegap/api/PhonegapActivity.java
+++ b/framework/src/com/phonegap/api/PhonegapActivity.java
@@ -18,9 +18,11 @@
 */
 package com.phonegap.api;
 
+import android.app.Activity;
+
 /**
  * The Cordova activity abstract class that is extended by DroidGap.
  * It is used to isolate plugin development, and remove dependency on entire Cordova library.
  */
-public abstract class PhonegapActivity extends org.apache.cordova.api.CordovaInterface {
+public abstract class PhonegapActivity extends Activity implements org.apache.cordova.api.CordovaInterface {
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/040619cd/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 ec1cc36..facb0ab 100755
--- a/framework/src/org/apache/cordova/CameraLauncher.java
+++ b/framework/src/org/apache/cordova/CameraLauncher.java
@@ -179,9 +179,9 @@ public class CameraLauncher extends Plugin {
     private File createCaptureFile(int encodingType) {
         File photo = null;
         if (encodingType == JPEG) {
-            photo = new File(DirectoryManager.getTempDirectoryPath(ctx),  "Pic.jpg");
+            photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()),  "Pic.jpg");
         } else if (encodingType == PNG) {
-            photo = new File(DirectoryManager.getTempDirectoryPath(ctx),  "Pic.png");            
+            photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()),  "Pic.png");            
         } else {
             throw new IllegalArgumentException("Invalid Encoding Type: " + encodingType);
         }
@@ -285,7 +285,7 @@ public class CameraLauncher extends Plugin {
                     // Create an ExifHelper to save the exif data that is lost during compression
                     ExifHelper exif = new ExifHelper();
                     if (this.encodingType == JPEG) {
-                        exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx) + "/Pic.jpg");
+                        exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/Pic.jpg");
                         exif.readExifData();
                     }
 
@@ -398,7 +398,7 @@ public class CameraLauncher extends Plugin {
                                 Bitmap bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
                                 bitmap = scaleBitmap(bitmap);
     
-                                String fileName = DirectoryManager.getTempDirectoryPath(ctx) + "/resize.jpg";
+                                String fileName = DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/resize.jpg";
                                 OutputStream os = new FileOutputStream(fileName);                         
                                 bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
                                 os.close();

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/040619cd/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 34423d0..ce7e9de 100644
--- a/framework/src/org/apache/cordova/Capture.java
+++ b/framework/src/org/apache/cordova/Capture.java
@@ -196,7 +196,7 @@ 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),  "Capture.jpg");
+        File photo = new File(DirectoryManager.getTempDirectoryPath(ctx.getContext()),  "Capture.jpg");
         intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
         this.imageUri = Uri.fromFile(photo);
 
@@ -249,7 +249,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) + "/Capture.jpg");
+                    exif.createInFile(DirectoryManager.getTempDirectoryPath(ctx.getContext()) + "/Capture.jpg");
                     exif.readExifData();
                     
                     // Read in bitmap of captured image

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/040619cd/framework/src/org/apache/cordova/ContactAccessor.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/ContactAccessor.java b/framework/src/org/apache/cordova/ContactAccessor.java
index 38d4b0b..de515e9 100644
--- a/framework/src/org/apache/cordova/ContactAccessor.java
+++ b/framework/src/org/apache/cordova/ContactAccessor.java
@@ -19,6 +19,7 @@ package org.apache.cordova;
 import java.util.HashMap;
 
 import android.app.Activity;
+import android.content.Context;
 import android.util.Log;
 import android.webkit.WebView;
 
@@ -36,7 +37,7 @@ import org.json.JSONObject;
 public abstract class ContactAccessor {
   
     protected final String LOG_TAG = "ContactsAccessor";
-    protected Activity mApp;
+    protected Context mApp;
     protected WebView mView;
   
     /**

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/040619cd/framework/src/org/apache/cordova/ContactAccessorSdk5.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/ContactAccessorSdk5.java b/framework/src/org/apache/cordova/ContactAccessorSdk5.java
index ea78758..6776819 100644
--- a/framework/src/org/apache/cordova/ContactAccessorSdk5.java
+++ b/framework/src/org/apache/cordova/ContactAccessorSdk5.java
@@ -43,6 +43,7 @@ import android.content.ContentProviderOperation;
 import android.content.ContentProviderResult;
 import android.content.ContentUris;
 import android.content.ContentValues;
+import android.content.Context;
 import android.content.OperationApplicationException;
 import android.database.Cursor;
 import android.net.Uri;
@@ -121,8 +122,8 @@ public class ContactAccessorSdk5 extends ContactAccessor {
     /**
      * Create an contact accessor.
      */
-    public ContactAccessorSdk5(WebView view, Activity app) {
-    mApp = app;
+  public ContactAccessorSdk5(WebView view, Context context) {
+    mApp = context;
     mView = view;
   }
   

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/040619cd/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 1231ed0..5765634 100755
--- a/framework/src/org/apache/cordova/ContactManager.java
+++ b/framework/src/org/apache/cordova/ContactManager.java
@@ -79,7 +79,7 @@ public class ContactManager extends Plugin {
          * older phones.
          */
         if (this.contactAccessor == null) {
-            this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx);
+            this.contactAccessor = new ContactAccessorSdk5(this.webView, this.ctx.getContext());
         }
         
 		try {

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/040619cd/framework/src/org/apache/cordova/DroidGap.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java
index 61aba0d..85329b8 100755
--- a/framework/src/org/apache/cordova/DroidGap.java
+++ b/framework/src/org/apache/cordova/DroidGap.java
@@ -37,6 +37,7 @@ import org.json.JSONArray;
 import org.json.JSONException;
 import org.xmlpull.v1.XmlPullParserException;
 
+import android.app.Activity;
 import android.app.AlertDialog;
 import android.app.ProgressDialog;
 import android.content.Context;
@@ -47,6 +48,7 @@ import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
 import android.content.res.Configuration;
 import android.content.res.XmlResourceParser;
+import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.Color;
 import android.media.AudioManager;
@@ -159,7 +161,7 @@ import android.widget.LinearLayout;
  *          ...
  *      </plugins>
  */
-public class DroidGap extends CordovaInterface {
+public class DroidGap extends Activity implements CordovaInterface {
     public static String TAG = "DroidGap";
     
     // The webview for our app
@@ -1171,7 +1173,6 @@ public class DroidGap extends CordovaInterface {
          }        
      }
 
-     @Override
      public void setActivityResultCallback(IPlugin plugin) {
          this.activityResultCallback = plugin;
      }
@@ -1388,4 +1389,23 @@ public class DroidGap extends CordovaInterface {
         this.postMessage("onOptionsItemSelected", item);
         return true;
     }
+
+    public Context getContext() {
+      return this;
+    }
+
+    public Cursor managedQuery(Uri parse, String[] strings, Object object,
+        Object object2, Object object3) {
+      return this.managedQuery(parse, strings, object, object2, object3);
+    }
+
+    public void bindBackButton(boolean override) {
+      // TODO Auto-generated method stub
+      
+    }
+
+    public boolean isBackButtonBound() {
+      // TODO Auto-generated method stub
+      return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/040619cd/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 535142b..6193518 100755
--- a/framework/src/org/apache/cordova/Notification.java
+++ b/framework/src/org/apache/cordova/Notification.java
@@ -143,7 +143,7 @@ public class Notification extends Plugin {
 	 */
 	public void beep(long count) {
 		Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
-		Ringtone notification = RingtoneManager.getRingtone(this.ctx, ringtone);
+		Ringtone notification = RingtoneManager.getRingtone(this.ctx.getContext(), ringtone);
 		
 		// If phone is not set to silent mode
 		if (notification != null) {
@@ -190,7 +190,7 @@ public class Notification extends Plugin {
 		Runnable runnable = new Runnable() {
 			public void run() {
 		
-				AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
+				AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
 				dlg.setMessage(message);
 				dlg.setTitle(title);
 				dlg.setCancelable(false);
@@ -226,7 +226,7 @@ public class Notification extends Plugin {
 
 		Runnable runnable = new Runnable() {
 			public void run() {
-				AlertDialog.Builder dlg = new AlertDialog.Builder(ctx);
+				AlertDialog.Builder dlg = new AlertDialog.Builder(ctx.getContext());
 				dlg.setMessage(message);
 				dlg.setTitle(title);
 				dlg.setCancelable(false);
@@ -287,7 +287,7 @@ public class Notification extends Plugin {
 		final CordovaInterface ctx = this.ctx;
 		Runnable runnable = new Runnable() {
 			public void run() {
-				notification.spinnerDialog = ProgressDialog.show(ctx, title , message, true, true, 
+				notification.spinnerDialog = ProgressDialog.show(ctx.getContext(), title , message, true, true, 
 					new DialogInterface.OnCancelListener() { 
 						public void onCancel(DialogInterface dialog) {
 							notification.spinnerDialog = null;
@@ -323,7 +323,7 @@ public class Notification extends Plugin {
 		final CordovaInterface ctx = this.ctx;
 		Runnable runnable = new Runnable() {
 			public void run() {
-				notification.progressDialog = new ProgressDialog(ctx);
+				notification.progressDialog = new ProgressDialog(ctx.getContext());
 				notification.progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
 				notification.progressDialog.setTitle(title);
 				notification.progressDialog.setMessage(message);

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/040619cd/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 b9b4b68..f46058f 100755
--- a/framework/src/org/apache/cordova/api/CordovaInterface.java
+++ b/framework/src/org/apache/cordova/api/CordovaInterface.java
@@ -18,14 +18,27 @@
 */
 package org.apache.cordova.api;
 
+import java.util.HashMap;
+
 import android.app.Activity;
+import android.app.Service;
+import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
+import android.content.Context;
 import android.content.Intent;
+import android.content.IntentFilter;
+import android.content.res.AssetManager;
+import android.content.res.Resources;
+import android.database.Cursor;
+import android.hardware.SensorManager;
+import android.net.Uri;
+
 
 /**
  * The Cordova activity abstract class that is extended by DroidGap.
  * It is used to isolate plugin development, and remove dependency on entire Cordova library.
  */
-public abstract class CordovaInterface extends Activity {
+public interface CordovaInterface {
 
     /**
      * @deprecated
@@ -77,4 +90,47 @@ public abstract class CordovaInterface extends Activity {
      * @param data          The message data
      */
     abstract public void postMessage(String id, Object data);
+    
+    public abstract Resources getResources();
+
+    public abstract String getPackageName();
+
+    public abstract Object getSystemService(String service);
+
+    public abstract Context getContext();
+    
+    public abstract Context getBaseContext();
+
+    public abstract Intent registerReceiver(BroadcastReceiver receiver,
+            IntentFilter intentFilter);
+
+    public abstract ContentResolver getContentResolver();
+
+    public abstract void unregisterReceiver(BroadcastReceiver receiver);
+
+    public abstract Cursor managedQuery(Uri parse, String[] strings,
+            Object object, Object object2, Object object3);
+
+    public abstract void runOnUiThread(Runnable runnable);
+
+    public abstract AssetManager getAssets();
+
+    public abstract void clearCache();
+
+    public abstract void clearHistory();
+
+    public abstract boolean backHistory();
+
+    //public abstract void addWhiteListEntry(String origin, boolean subdomains);
+
+    public abstract void bindBackButton(boolean override);
+
+    public abstract boolean isBackButtonBound();
+
+    public abstract void cancelLoadUrl();
+
+    public abstract void showWebPage(String url, boolean openExternal,
+            boolean clearHistory, HashMap<String, Object> params);
+
+    public abstract Context getApplicationContext();
 }