From 7c21bbea25d501dba92069238e349388eece895e Mon Sep 17 00:00:00 2001 From: Iordan Iordanov Date: Sun, 14 Aug 2016 12:06:28 -0400 Subject: [PATCH] Fixed a bug where the swipes to show the nav bar in the new immersive mode were moving the pointer or causing panning depending on input mode. --- eclipse_projects/Opaque/AndroidManifest.xml | 4 +- .../opaque/input/InputHandlerGeneric.java | 36 ++++++++++++++++-- .../opaque/input/MyScaleGestureDetector.java | 4 +- eclipse_projects/bVNC/AndroidManifest.xml | 2 +- .../input/AbstractGestureInputHandler.java | 38 +++++++++++++++++-- 5 files changed, 74 insertions(+), 10 deletions(-) diff --git a/eclipse_projects/Opaque/AndroidManifest.xml b/eclipse_projects/Opaque/AndroidManifest.xml index 91562dd9c..de8048a39 100644 --- a/eclipse_projects/Opaque/AndroidManifest.xml +++ b/eclipse_projects/Opaque/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="1340" + android:versionName="1.4.0" > = android.os.Build.VERSION_CODES.KITKAT && + (y <= immersiveSwipeDistance || canvas.getHeight() - y <= immersiveSwipeDistance)) { + inSwiping = true; + immersiveSwipe = true; + } else { + inSwiping = false; + immersiveSwipe = false; + } + } + /* * @see com.undatech.opaque.input.InputHandler#onTouchEvent(android.view.MotionEvent) */ @@ -423,10 +440,20 @@ public boolean onTouchEvent(MotionEvent e) { // Indicate where we start dragging from. dragX = e.getX(); dragY = e.getY(); + + // Detect whether this is potentially the start of a gesture to show the nav bar. + detectImmersiveSwipe(dragY); break; case MotionEvent.ACTION_UP: singleHandedGesture = false; singleHandedJustEnded = true; + + // If this is the end of a swipe that showed the nav bar, consume. + if (immersiveSwipe && Math.abs(dragY - e.getY()) > immersiveSwipeDistance) { + endDragModesAndScrolling(); + return true; + } + // If any drag modes were going on, end them and send a mouse up event. if (endDragModesAndScrolling()) { p.releaseButton(getX(e), getY(e), meta); @@ -451,9 +478,12 @@ public boolean onTouchEvent(MotionEvent e) { float y = e.getY(); // Set the coordinates to where the swipe began (i.e. where scaling started). setEventCoordinates(e, xInitialFocus, yInitialFocus); - sendScrollEvents (getX(e), getY(e), meta); + sendScrollEvents (getX(e), getY(e), meta); // Restore the coordinates so that onScale doesn't get all muddled up. setEventCoordinates(e, x, y); + } else if (immersiveSwipe) { + // If this is part of swipe that shows the nav bar, consume. + return true; } } break; diff --git a/eclipse_projects/Opaque/src/com/undatech/opaque/input/MyScaleGestureDetector.java b/eclipse_projects/Opaque/src/com/undatech/opaque/input/MyScaleGestureDetector.java index 5d98bff94..f460a9915 100644 --- a/eclipse_projects/Opaque/src/com/undatech/opaque/input/MyScaleGestureDetector.java +++ b/eclipse_projects/Opaque/src/com/undatech/opaque/input/MyScaleGestureDetector.java @@ -16,6 +16,8 @@ package com.undatech.opaque.input; +import com.undatech.opaque.Constants; + import android.content.Context; import android.util.DisplayMetrics; import android.util.FloatMath; @@ -86,7 +88,7 @@ public MyScaleGestureDetector(Context context, OnScaleGestureListener listener) mListener = listener; mEdgeSlop = config.getScaledEdgeSlop(); } - + /* (non-Javadoc) * @see com.iiordanov.android.bc.IBCScaleGestureDetector#onTouchEvent(android.view.MotionEvent) */ diff --git a/eclipse_projects/bVNC/AndroidManifest.xml b/eclipse_projects/bVNC/AndroidManifest.xml index 1b7617ad4..e9a438f8d 100644 --- a/eclipse_projects/bVNC/AndroidManifest.xml +++ b/eclipse_projects/bVNC/AndroidManifest.xml @@ -1,7 +1,7 @@ + android:versionCode="3840" android:versionName="v3.8.4"> diff --git a/eclipse_projects/bVNC/src/com/iiordanov/bVNC/input/AbstractGestureInputHandler.java b/eclipse_projects/bVNC/src/com/iiordanov/bVNC/input/AbstractGestureInputHandler.java index 641ef7e6f..65b7c3e99 100644 --- a/eclipse_projects/bVNC/src/com/iiordanov/bVNC/input/AbstractGestureInputHandler.java +++ b/eclipse_projects/bVNC/src/com/iiordanov/bVNC/input/AbstractGestureInputHandler.java @@ -31,6 +31,7 @@ import com.iiordanov.android.bc.BCFactory; import com.iiordanov.android.bc.IBCScaleGestureDetector; import com.iiordanov.android.bc.OnScaleGestureListener; +import com.iiordanov.bVNC.Constants; import com.iiordanov.bVNC.RemoteCanvas; import com.iiordanov.bVNC.RemoteCanvasActivity; @@ -89,6 +90,9 @@ abstract class AbstractGestureInputHandler extends GestureDetector.SimpleOnGestu final long baseSwipeTime = 600; // This is how far the swipe has to travel before a swipe event is generated. final float baseSwipeDist = 40.f; + // This is how far from the top and bottom edge to detect immersive swipe. + final float immersiveSwipeDistance = 50.f; + boolean immersiveSwipe = false; boolean inScrolling = false; boolean inScaling = false; @@ -314,22 +318,35 @@ public void onLongPress(MotionEvent e) { dragMode = true; p.processPointerEvent(getX(e), getY(e), e.getActionMasked(), e.getMetaState(), true, false, false, false, 0); } - + protected boolean endDragModesAndScrolling () { canvas.inScrolling = false; panMode = false; inScaling = false; inSwiping = false; inScrolling = false; + immersiveSwipe = false; if (dragMode || rightDragMode || middleDragMode) { dragMode = false; rightDragMode = false; middleDragMode = false; return true; - } else + } else { return false; + } } - + + private void detectImmersiveSwipe (float y) { + if (Constants.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT && + (y <= immersiveSwipeDistance || canvas.getHeight() - y <= immersiveSwipeDistance)) { + inSwiping = true; + immersiveSwipe = true; + } else { + inSwiping = false; + immersiveSwipe = false; + } + } + /** * Modify the event so that the mouse goes where we specify. * @param e event to be modified. @@ -384,18 +401,30 @@ public boolean onTouchEvent(MotionEvent e) { // Cancel drag modes and scrolling. if (!singleHandedGesture) endDragModesAndScrolling(); + canvas.inScrolling = true; // If we are manipulating the desktop, turn off bitmap filtering for faster response. canvas.bitmapData.drawable._defaultPaint.setFilterBitmap(false); dragX = e.getX(); dragY = e.getY(); + + // Detect whether this is potentially the start of a gesture to show the nav bar. + detectImmersiveSwipe(dragY); break; case MotionEvent.ACTION_UP: singleHandedGesture = false; singleHandedJustEnded = true; + + // If this is the end of a swipe that showed the nav bar, consume. + if (immersiveSwipe && Math.abs(dragY - e.getY()) > immersiveSwipeDistance) { + endDragModesAndScrolling(); + return true; + } + // If any drag modes were going on, end them and send a mouse up event. if (endDragModesAndScrolling()) return p.processPointerEvent(getX(e), getY(e), action, meta, false, false, false, false, 0); + break; case MotionEvent.ACTION_MOVE: // Send scroll up/down events if swiping is happening. @@ -439,6 +468,9 @@ public boolean onTouchEvent(MotionEvent e) { } // Restore the coordinates so that onScale doesn't get all muddled up. setEventCoordinates(e, x, y); + } else if (immersiveSwipe) { + // If this is part of swipe that shows the nav bar, consume. + return true; } } break;