cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [03/34] git commit: Fixes to Push code. Now navigating from Javascript.
Date Tue, 06 May 2014 19:29:17 GMT
Fixes to Push code. Now navigating from Javascript.


Project: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/commit/074ca493
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/074ca493
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/074ca493

Branch: refs/heads/master
Commit: 074ca493f1ff9f6c086d9b517ac694b2c4d87f5b
Parents: f6d6d34
Author: Braden Shepherdson <braden.shepherdson@gmail.com>
Authored: Tue Jan 14 13:54:17 2014 -0500
Committer: Braden Shepherdson <braden.shepherdson@gmail.com>
Committed: Tue Jan 14 13:54:17 2014 -0500

----------------------------------------------------------------------
 src/android/Push.java | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/074ca493/src/android/Push.java
----------------------------------------------------------------------
diff --git a/src/android/Push.java b/src/android/Push.java
index 6b12b73..2845762 100644
--- a/src/android/Push.java
+++ b/src/android/Push.java
@@ -10,6 +10,7 @@ import java.util.Map;
 
 import fi.iki.elonen.NanoHTTPD;
 
+import org.apache.cordova.Config;
 import org.apache.cordova.CordovaArgs;
 import org.apache.cordova.CallbackContext;
 import org.apache.cordova.CordovaPlugin;
@@ -17,6 +18,8 @@ import org.apache.cordova.LOG;
 import org.json.JSONException;
 import org.json.JSONObject;
 
+import android.annotation.SuppressLint;
+import android.os.Build;
 import android.net.Uri;
 import android.util.Log;
 
@@ -45,6 +48,11 @@ public class Push extends CordovaPlugin {
         return false;
     }
 
+    public void onReset() {
+        Log.w(LOG_TAG, "onReset");
+
+    }
+
     private void listen(CallbackContext callbackContext) {
         // First, check that we're not already listening.
         if (listening) {
@@ -72,10 +80,25 @@ public class Push extends CordovaPlugin {
             callbackContext.success(latestPush);
             latestPush = null;
         } else {
-            callbackContext.success((JSONObject) null); // TODO: Is this legal?
+            callbackContext.success(0);
         }
     }
 
+    private void restartAppHarness() {
+        this.cordova.getActivity().runOnUiThread(new Runnable() {
+            @SuppressLint("NewApi")
+            @Override
+            public void run() {
+                String toInject = "window.location = '" + Config.getStartUrl() + "'";
+                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
+                    webView.loadUrl("javascript:" + toInject);
+                } else {
+                    webView.evaluateJavascript(toInject, null);
+                }
+            }
+        });
+    }
+
     private class PushServer extends NanoHTTPD {
         public PushServer() {
             super(Push.PORT);
@@ -105,6 +128,7 @@ public class Push extends CordovaPlugin {
                     payload.put("type", "serve");
                     payload.put("url", params.get("url").get(0));
                     Push.this.latestPush = payload;
+                    Push.this.restartAppHarness();
                     return new Response(Response.Status.OK, "text/plain", "Push successful");
                 } catch (JSONException je) {
                     Log.w(LOG_TAG, "JSONException while building 'serve' mode push data",
je);


Mime
View raw message