You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/05/30 22:22:02 UTC

[1/3] git commit: Fix HarnessServer menu command

Repository: cordova-app-harness
Updated Branches:
  refs/heads/master a40bfa310 -> 3879ccfb4


Fix HarnessServer menu command


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/3c31ce48
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/3c31ce48
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/3c31ce48

Branch: refs/heads/master
Commit: 3c31ce488ccf75dccb39751276a495a82559ee94
Parents: c95b39a
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri May 30 10:24:40 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri May 30 10:39:39 2014 -0400

----------------------------------------------------------------------
 www/cdvah/js/AppHarnessUI.js  | 11 ++++++++++-
 www/cdvah/js/HarnessServer.js |  2 +-
 www/cdvah/js/InAppMenuCtrl.js | 16 +++++++---------
 3 files changed, 18 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/3c31ce48/www/cdvah/js/AppHarnessUI.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/AppHarnessUI.js b/www/cdvah/js/AppHarnessUI.js
index 01abf65..9413255 100644
--- a/www/cdvah/js/AppHarnessUI.js
+++ b/www/cdvah/js/AppHarnessUI.js
@@ -37,7 +37,16 @@
                 return deferred.promise;
             },
             setEventHandler: function(f) {
-                cordova.plugins.appharnessui.onEvent = f;
+                cordova.plugins.appharnessui.onEvent = f && function(type) {
+                    $q.when().then(function() {
+                        f(type);
+                    });
+                };
+            },
+            fireEvent: function(type) {
+                if (cordova.plugins.appharnessui.onEvent) {
+                    cordova.plugins.appharnessui.onEvent(type);
+                }
             },
             evalJs: function(code) {
                 var deferred = $q.defer();

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/3c31ce48/www/cdvah/js/HarnessServer.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/HarnessServer.js b/www/cdvah/js/HarnessServer.js
index 326944b..911babb 100644
--- a/www/cdvah/js/HarnessServer.js
+++ b/www/cdvah/js/HarnessServer.js
@@ -104,7 +104,7 @@
 
         function handleMenu(req, resp) {
             resp.sendTextResponse(200, '');
-            return AppHarnessUI.createOverlay();
+            return AppHarnessUI.fireEvent('showMenu');
         }
 
         function handleLaunch(req, resp) {

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/3c31ce48/www/cdvah/js/InAppMenuCtrl.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/InAppMenuCtrl.js b/www/cdvah/js/InAppMenuCtrl.js
index 1527d92..bbcab49 100644
--- a/www/cdvah/js/InAppMenuCtrl.js
+++ b/www/cdvah/js/InAppMenuCtrl.js
@@ -49,15 +49,13 @@
         };
 
         AppHarnessUI.setEventHandler(function(eventName) {
-            $scope.$apply(function() {
-                if (eventName == 'showMenu') {
-                    AppHarnessUI.setVisible(false);
-                } else if (eventName == 'destroyed') {
-                    $window.history.back();
-                } else {
-                    console.warn('Unknown message from AppHarnessUI: ' + eventName);
-                }
-            });
+            if (eventName == 'showMenu') {
+                AppHarnessUI.setVisible(false);
+            } else if (eventName == 'destroyed') {
+                $window.history.back();
+            } else {
+                console.warn('Unknown message from AppHarnessUI: ' + eventName);
+            }
         });
     }]);
 })();


[3/3] git commit: Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/cordova-app-harness

Posted by ag...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/cordova-app-harness


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/3879ccfb
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/3879ccfb
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/3879ccfb

Branch: refs/heads/master
Commit: 3879ccfb48c732f33189270a792877b09f7e1d67
Parents: f1a8fab a40bfa3
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri May 30 16:21:53 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri May 30 16:21:53 2014 -0400

----------------------------------------------------------------------
 CONTRIBUTING.md | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
----------------------------------------------------------------------



[2/3] git commit: Make view shrink to reveal in-app-menu

Posted by ag...@apache.org.
Make view shrink to reveal in-app-menu


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/f1a8fab7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/tree/f1a8fab7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-app-harness/diff/f1a8fab7

Branch: refs/heads/master
Commit: f1a8fab759e20d937d88ffb64c346d2cbfbf7b16
Parents: 3c31ce4
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri May 30 16:18:26 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri May 30 16:18:26 2014 -0400

----------------------------------------------------------------------
 AppHarnessUI/AppHarnessUI.java | 55 +++++++++++++++++++++++++++++--------
 AppHarnessUI/AppHarnessUI.m    | 50 +++++++++++++++++++++++++++------
 www/cdvah/js/InAppMenuCtrl.js  |  2 ++
 3 files changed, 86 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/f1a8fab7/AppHarnessUI/AppHarnessUI.java
----------------------------------------------------------------------
diff --git a/AppHarnessUI/AppHarnessUI.java b/AppHarnessUI/AppHarnessUI.java
index 9e6eb82..624a159 100644
--- a/AppHarnessUI/AppHarnessUI.java
+++ b/AppHarnessUI/AppHarnessUI.java
@@ -31,13 +31,18 @@ import org.apache.cordova.PluginResult;
 import org.json.JSONException;
 
 import android.annotation.SuppressLint;
+import android.annotation.TargetApi;
 import android.content.Context;
 import android.os.Build;
 import android.util.Log;
+import android.view.Gravity;
 import android.view.MotionEvent;
 import android.view.View;
 import android.view.ViewConfiguration;
 import android.view.ViewGroup;
+import android.view.ViewPropertyAnimator;
+import android.view.animation.DecelerateInterpolator;
+import android.widget.FrameLayout;
 import android.widget.LinearLayout;
 
 public class AppHarnessUI extends CordovaPlugin {
@@ -117,7 +122,12 @@ public class AppHarnessUI extends CordovaPlugin {
                 slaveWebView.setOverScrollMode(CordovaWebView.OVER_SCROLL_NEVER);
             }
             slaveWebView.loadUrl(url);
-            setSlaveVisible(true, null);
+            View newView = (View)slaveWebView.getParent();
+            contentView.addView(newView);
+            slaveVisible = true;
+            // Back button capturing breaks without these:
+            newView.requestFocus();
+
         }
         callbackContext.success();
     }
@@ -126,9 +136,11 @@ public class AppHarnessUI extends CordovaPlugin {
         if (slaveWebView == null) {
             Log.w(LOG_TAG, "destroy: already destroyed");
         } else {
-            setSlaveVisible(false, null);
+            contentView.removeView((View)slaveWebView.getParent());
             slaveWebView.destroy();
+            origMainView.requestFocus();
             slaveWebView = null;
+            slaveVisible = false;
             sendEvent("destroyed");
         }
         if (eventsCallback != null) {
@@ -138,6 +150,7 @@ public class AppHarnessUI extends CordovaPlugin {
         callbackContext.success();
     }
 
+    @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
     private void setSlaveVisible(boolean value, CallbackContext callbackContext) {
         if (value == slaveVisible) {
             return;
@@ -146,19 +159,24 @@ public class AppHarnessUI extends CordovaPlugin {
             Log.w(LOG_TAG, "setSlaveVisible: slave not created");
         } else {
             slaveVisible = value;
-            contentView.removeAllViews();
-            View newView = value ? (View)slaveWebView.getParent() : origMainView;
-            // Back button capturing breaks without these:
-            contentView.addView(newView);
-            newView.requestFocus();
-
+            ViewPropertyAnimator anim = slaveWebView.animate();
+            // Note: Pivot is set in onSizeChanged.
+            if (value) {
+                anim.scaleX(1.0f).scaleY(1.0f);
+                ((View)slaveWebView.getParent()).requestFocus();
+            } else {
+                anim.scaleX(.25f).scaleY(.25f);
+                origMainView.requestFocus();
+            }
+            slaveWebView.stealTapEvents = !value;
+            anim.setDuration(300).setInterpolator(new DecelerateInterpolator(2.0f)).start();
         }
         if (callbackContext != null) {
             callbackContext.success();
         }
     }
 
-    private void initWebView(CordovaWebView newWebView) {
+    private void initWebView(final CordovaWebView newWebView) {
         CordovaActivity activity = (CordovaActivity)cordova.getActivity();
         if (contentView == null) {
             contentView = (ViewGroup)activity.findViewById(android.R.id.content);
@@ -167,10 +185,9 @@ public class AppHarnessUI extends CordovaPlugin {
 
         LinearLayoutSoftKeyboardDetect layoutView = new LinearLayoutSoftKeyboardDetect(activity, contentView.getWidth(), contentView.getHeight());
         layoutView.setOrientation(LinearLayout.VERTICAL);
-//        layoutView.setBackground(origRootView.getBackground());
-        layoutView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
-                ViewGroup.LayoutParams.MATCH_PARENT, 0.0F));
 
+//        layoutView.setBackground(origRootView.getBackground());
+        layoutView.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.BOTTOM | Gravity.LEFT));
 
         if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
             newWebView.setWebViewClient(new CordovaWebViewClient(cordova, newWebView));
@@ -228,6 +245,7 @@ public class AppHarnessUI extends CordovaPlugin {
 
     private class CustomCordovaWebView extends CordovaWebView {
         TwoFingerDoubleTapGestureDetector twoFingerTapDetector;
+        boolean stealTapEvents;
 
         public CustomCordovaWebView(Context context) {
             super(context);
@@ -236,8 +254,21 @@ public class AppHarnessUI extends CordovaPlugin {
 
         @Override
         public boolean onTouchEvent(MotionEvent e) {
+            if (stealTapEvents) {
+                if (e.getAction() == MotionEvent.ACTION_UP) {
+                    sendEvent("hideMenu");
+                }
+                return true;
+            }
             twoFingerTapDetector.onTouchEvent(e);
             return super.onTouchEvent(e);
         }
+
+        @SuppressLint("NewApi")
+        protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+            super.onSizeChanged(w, h, oldw, oldh);
+            // Needed for the view to stay in the bottom when rotating.
+            setPivotY(h);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/f1a8fab7/AppHarnessUI/AppHarnessUI.m
----------------------------------------------------------------------
diff --git a/AppHarnessUI/AppHarnessUI.m b/AppHarnessUI/AppHarnessUI.m
index 00bcb78..3d7dafc 100644
--- a/AppHarnessUI/AppHarnessUI.m
+++ b/AppHarnessUI/AppHarnessUI.m
@@ -26,6 +26,7 @@
 @interface AHUIViewController : CDVViewController<UIGestureRecognizerDelegate> {
 @public
     __weak AppHarnessUI* _parentPlugin;
+    UITapGestureRecognizer* _singleTapRecognizer;
 }
 @end
 
@@ -50,9 +51,20 @@
     tapRecognizer.numberOfTapsRequired = 2;
     tapRecognizer.numberOfTouchesRequired = 2;
     tapRecognizer.delegate = self;
- 
-    // Add the tap gesture recognizer to the view
     [self.view addGestureRecognizer:tapRecognizer];
+
+    // Single-tap
+    _singleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
+
+}
+
+- (void)setCaptureSingleTap:(BOOL)value {
+    [self.webView setUserInteractionEnabled:!value];
+    if (value) {
+        [self.view addGestureRecognizer:_singleTapRecognizer];
+    } else {
+        [self.view removeGestureRecognizer:_singleTapRecognizer];
+    }
 }
 
 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
@@ -60,6 +72,10 @@
     return YES;
 }
 
+- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer {
+    [_parentPlugin sendEvent:@"hideMenu"];
+}
+
 - (void)handleTap:(UITapGestureRecognizer *)recognizer {
     [_parentPlugin sendEvent:@"showMenu"];
 }
@@ -97,7 +113,14 @@
         _slaveCordovaViewController = [[AHUIViewController alloc] init];
         _slaveCordovaViewController.startPage = url;
         _slaveCordovaViewController->_parentPlugin = self;
-        [self setVisibleHelper:YES];
+        UIView* newView = _slaveCordovaViewController.view;
+        UIView* superView = self.viewController.view;
+        [self.viewController addChildViewController:_slaveCordovaViewController];
+        [newView layer].anchorPoint = CGPointMake(0.0f, 1.0f);
+        [newView setFrame:superView.bounds];
+        [superView addSubview:newView];
+        [_slaveCordovaViewController didMoveToParentViewController:self.viewController];
+        _slaveVisible = YES;
     } else {
         NSLog(@"AppHarnessUI.create: already exists");
     }
@@ -109,8 +132,10 @@
     if (_slaveCordovaViewController == nil) {
         NSLog(@"AppHarnessUI.destroy: already destroyed.");
     } else {
-        [self setVisibleHelper:NO];
+        [_slaveCordovaViewController removeFromParentViewController];
+        [_slaveCordovaViewController.view removeFromSuperview];
         _slaveCordovaViewController = nil;
+        _slaveVisible = NO;
         [self sendEvent:@"destroyed"];
     }
     CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
@@ -126,11 +151,18 @@
     if (_slaveCordovaViewController == nil) {
         NSLog(@"AppHarnessUI.setVisible: slave doesn't exist");
     } else {
-        UIView* newView = value ? _slaveCordovaViewController.view : self.viewController.view;
-        UIView* oldView = !value ? _slaveCordovaViewController.view : self.viewController.view;
-        UIView* superView = oldView.superview;
-        [oldView removeFromSuperview];
-        [superView addSubview:newView];
+        [UIView animateWithDuration:.3
+                              delay:0
+                            options:UIViewAnimationOptionCurveEaseOut
+                         animations:^{
+             [_slaveCordovaViewController setCaptureSingleTap:!value];
+             UIView* view = _slaveCordovaViewController.view;
+             if (value) {
+                 [view setTransform:CGAffineTransformIdentity];
+             } else {
+                 [view setTransform:CGAffineTransformMakeScale(.25, .25)];
+             }
+         } completion:nil];
     }
 }
 

http://git-wip-us.apache.org/repos/asf/cordova-app-harness/blob/f1a8fab7/www/cdvah/js/InAppMenuCtrl.js
----------------------------------------------------------------------
diff --git a/www/cdvah/js/InAppMenuCtrl.js b/www/cdvah/js/InAppMenuCtrl.js
index bbcab49..ee21620 100644
--- a/www/cdvah/js/InAppMenuCtrl.js
+++ b/www/cdvah/js/InAppMenuCtrl.js
@@ -51,6 +51,8 @@
         AppHarnessUI.setEventHandler(function(eventName) {
             if (eventName == 'showMenu') {
                 AppHarnessUI.setVisible(false);
+            } else if (eventName == 'hideMenu') {
+                AppHarnessUI.setVisible(true);
             } else if (eventName == 'destroyed') {
                 $window.history.back();
             } else {