Skip to content

Commit

Permalink
Fixed a bug where the swipes to show the nav bar in the new
Browse files Browse the repository at this point in the history
immersive mode were moving the pointer or causing panning depending
on input mode.
  • Loading branch information
iiordanov committed Aug 15, 2016
1 parent ff1a70f commit 7c21bbe
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 10 deletions.
4 changes: 2 additions & 2 deletions eclipse_projects/Opaque/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.undatech.opaque"
android:versionCode="1339"
android:versionName="1.3.9" >
android:versionCode="1340"
android:versionName="1.4.0" >

<uses-sdk
android:minSdkVersion="9"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ abstract class InputHandlerGeneric extends GestureDetector.SimpleOnGestureListen
// 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;

// Some variables indicating what kind of a gesture we're currently in or just finished.
boolean inScrolling = false;
boolean inScaling = false;
Expand Down Expand Up @@ -351,13 +355,15 @@ protected boolean endDragModesAndScrolling () {
inScaling = false;
inSwiping = false;
inScrolling = false;
immersiveSwipe = false;
if (dragMode || rightDragMode || middleDragMode) {
dragMode = false;
rightDragMode = false;
middleDragMode = false;
return true;
} else
} else {
return false;
}
}

/**
Expand All @@ -369,7 +375,18 @@ protected boolean endDragModesAndScrolling () {
private void setEventCoordinates(MotionEvent e, float x, float y) {
e.setLocation(x, y);
}


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;
}
}

/*
* @see com.undatech.opaque.input.InputHandler#onTouchEvent(android.view.MotionEvent)
*/
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
*/
Expand Down
2 changes: 1 addition & 1 deletion eclipse_projects/bVNC/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.iiordanov.bVNC" android:installLocation="auto"
android:versionCode="3830" android:versionName="v3.8.3">
android:versionCode="3840" android:versionName="v3.8.4">

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="10"></uses-sdk>
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7c21bbe

Please sign in to comment.