From 0180342dff4ce6e8f63e3d753cb1f1588c43f9f0 Mon Sep 17 00:00:00 2001 From: macdonst Date: Tue, 10 Jul 2012 16:26:52 -0400 Subject: [PATCH 1/2] CB-993: Android plugin problems upgrading to 1.9.0 --- .../org/apache/cordova/api/LegacyContext.java | 78 +++++++++++++++++++ .../src/org/apache/cordova/api/Plugin.java | 14 ++-- 2 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 framework/src/org/apache/cordova/api/LegacyContext.java diff --git a/framework/src/org/apache/cordova/api/LegacyContext.java b/framework/src/org/apache/cordova/api/LegacyContext.java new file mode 100644 index 00000000..d65d70ac --- /dev/null +++ b/framework/src/org/apache/cordova/api/LegacyContext.java @@ -0,0 +1,78 @@ +package org.apache.cordova.api; + +import android.app.Activity; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.pm.PackageManager; +import android.content.res.AssetManager; +import android.content.res.Resources; + +public class LegacyContext implements CordovaInterface { + private CordovaInterface cordova; + + public LegacyContext(CordovaInterface cordova) { + this.cordova = cordova; + } + + public void cancelLoadUrl() { + this.cordova.cancelLoadUrl(); + } + + public Activity getActivity() { + return this.cordova.getActivity(); + } + + public Context getContext() { + return this.cordova.getContext(); + } + + public Object onMessage(String arg0, Object arg1) { + return this.cordova.onMessage(arg0, arg1); + } + + public void setActivityResultCallback(IPlugin arg0) { + this.cordova.setActivityResultCallback(arg0); + } + + public void startActivityForResult(IPlugin arg0, Intent arg1, int arg2) { + this.cordova.startActivityForResult(arg0, arg1, arg2); + } + + public void startActivity(Intent intent) { + this.cordova.getActivity().startActivity(intent); + } + + public Object getSystemService(String name) { + return this.cordova.getActivity().getSystemService(name); + } + + public AssetManager getAssets() { + return this.cordova.getActivity().getAssets(); + } + + public void runOnUiThread(Runnable runnable) { + this.cordova.getActivity().runOnUiThread(runnable); + } + + public Context getApplicationContext() { + return this.cordova.getActivity().getApplicationContext(); + } + + public PackageManager getPackageManager() { + return this.cordova.getActivity().getPackageManager(); + } + + public SharedPreferences getSharedPreferences(String name, int mode) { + return this.cordova.getActivity().getSharedPreferences(name, mode); + } + + public void unregisterReceiver(BroadcastReceiver receiver) { + this.cordova.getActivity().unregisterReceiver(receiver); + } + + public Resources getResources() { + return this.cordova.getActivity().getResources(); + } +} diff --git a/framework/src/org/apache/cordova/api/Plugin.java b/framework/src/org/apache/cordova/api/Plugin.java index 1ac42f02..c7c2be79 100755 --- a/framework/src/org/apache/cordova/api/Plugin.java +++ b/framework/src/org/apache/cordova/api/Plugin.java @@ -32,12 +32,12 @@ public abstract class Plugin implements IPlugin { public String id; public CordovaWebView webView; // WebView object - public CordovaInterface ctx; // CordovaActivity object + public LegacyContext ctx; // LegacyContext object public CordovaInterface cordova; /** * Executes the request and returns PluginResult. - * + * * @param action The action to execute. * @param args JSONArry of arguments for the plugin. * @param callbackId The callback id used when calling back into JavaScript. @@ -63,13 +63,13 @@ public abstract class Plugin implements IPlugin { */ public void setContext(CordovaInterface ctx) { this.cordova = ctx; - this.ctx = cordova; + this.ctx = new LegacyContext(cordova); } /** - * 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 * a Cordova app runs. - * + * * @param webView The Cordova WebView */ public void setView(CordovaWebView webView) { @@ -77,8 +77,8 @@ public abstract class Plugin implements IPlugin { } /** - * Called when the system is about to start resuming a previous activity. - * + * Called when the system is about to start resuming a previous activity. + * * @param multitasking Flag indicating if multitasking is turned on for app */ public void onPause(boolean multitasking) { From beb9460538a9075a49f487f79d1cd66be0e87773 Mon Sep 17 00:00:00 2001 From: macdonst Date: Tue, 10 Jul 2012 20:50:28 -0400 Subject: [PATCH 2/2] CB-952: Android showSplashScreen crashes --- .gitignore | 1 + framework/src/org/apache/cordova/DroidGap.java | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 85278e2a..cf5f6cee 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ default.properties gen assets/www/cordova.js +framework/assets/www/.tmp* local.properties framework/proguard.cfg framework/cordova.jar diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java index 1a23f226..fe47df46 100755 --- a/framework/src/org/apache/cordova/DroidGap.java +++ b/framework/src/org/apache/cordova/DroidGap.java @@ -619,10 +619,12 @@ public class DroidGap extends Activity implements CordovaInterface { // If app doesn't want to run in background if (!this.keepRunning) { - // Pause JavaScript timers (including setInterval) this.appView.pauseTimers(); } + + // hide the splash screen to avoid leaking a window + this.removeSplashScreen(); } @Override @@ -684,6 +686,9 @@ public class DroidGap extends Activity implements CordovaInterface { LOG.d(TAG, "onDestroy()"); super.onDestroy(); + // hide the splash screen to avoid leaking a window + this.removeSplashScreen(); + if (this.appView != null) { // Send destroy event to JavaScript @@ -966,7 +971,7 @@ public class DroidGap extends Activity implements CordovaInterface { * Removes the Dialog that displays the splash screen */ public void removeSplashScreen() { - if (splashDialog != null) { + if (splashDialog != null && splashDialog.isShowing()) { splashDialog.dismiss(); splashDialog = null; }