Tweak the Gestures Overlay demo. This shortens the fade duration to make it more usable and also adds a longer pause before the fade. This change also introduce a new compile-time setting to decide whether or not the overlay should steal the events from the underlying ListView. It is now off by default, per discussion with hackbod. It feel a little bit better but it may vary from user to user so studies will be necessary.
This commit is contained in:
@@ -41,8 +41,10 @@ public class GestureOverlay extends View {
|
||||
// TODO: Move all these values into XML attributes
|
||||
private static final int TRANSPARENT_BACKGROUND = 0x00000000;
|
||||
|
||||
private static final float FADING_ALPHA_CHANGE = 0.03f;
|
||||
private static final long FADING_REFRESHING_RATE = 100;
|
||||
// TODO: SHOULD BE A TOTAL DURATION
|
||||
private static final float FADING_ALPHA_CHANGE = 0.15f;
|
||||
private static final long FADING_OFFSET = 300;
|
||||
private static final long FADING_REFRESHING_RATE = 16;
|
||||
|
||||
private static final int GESTURE_STROKE_WIDTH = 12;
|
||||
private static final boolean GESTURE_RENDERING_ANTIALIAS = true;
|
||||
@@ -235,7 +237,7 @@ public class GestureOverlay extends View {
|
||||
mFadingAlpha = 1;
|
||||
mIsFadingOut = true;
|
||||
mHandler.removeCallbacks(mFadingOut);
|
||||
mHandler.postDelayed(mFadingOut, FADING_REFRESHING_RATE);
|
||||
mHandler.postDelayed(mFadingOut, FADING_OFFSET);
|
||||
} else {
|
||||
mPath = null;
|
||||
mCurrentGesture = null;
|
||||
|
||||
@@ -37,6 +37,8 @@ public class TouchThroughGesturing implements GestureListener {
|
||||
private static final float SQUARENESS_THRESHOLD = 0.275f;
|
||||
private static final float ANGLE_THRESHOLD = 40;
|
||||
|
||||
private static final boolean STEAL_EVENTS = false;
|
||||
|
||||
public static final int DEFAULT_UNCERTAIN_GESTURE_COLOR = Color.argb(60, 255, 255, 0);
|
||||
|
||||
private boolean mIsGesturing = false;
|
||||
@@ -91,6 +93,11 @@ public class TouchThroughGesturing implements GestureListener {
|
||||
}
|
||||
|
||||
public void onGesture(GestureOverlay overlay, MotionEvent event) {
|
||||
//noinspection PointlessBooleanExpression
|
||||
if (!STEAL_EVENTS) {
|
||||
mModel.dispatchTouchEvent(event);
|
||||
}
|
||||
|
||||
if (mIsGesturing) {
|
||||
return;
|
||||
}
|
||||
@@ -114,14 +121,18 @@ public class TouchThroughGesturing implements GestureListener {
|
||||
if (box.squareness > SQUARENESS_THRESHOLD || angle < ANGLE_THRESHOLD) {
|
||||
mIsGesturing = true;
|
||||
overlay.setGestureColor(GestureOverlay.DEFAULT_GESTURE_COLOR);
|
||||
event = MotionEvent.obtain(event.getDownTime(), System.currentTimeMillis(),
|
||||
MotionEvent.ACTION_UP, x, y, event.getPressure(), event.getSize(),
|
||||
event.getMetaState(), event.getXPrecision(), event.getYPrecision(),
|
||||
event.getDeviceId(), event.getEdgeFlags());
|
||||
if (STEAL_EVENTS) {
|
||||
event = MotionEvent.obtain(event.getDownTime(), System.currentTimeMillis(),
|
||||
MotionEvent.ACTION_UP, x, y, event.getPressure(), event.getSize(),
|
||||
event.getMetaState(), event.getXPrecision(), event.getYPrecision(),
|
||||
event.getDeviceId(), event.getEdgeFlags());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mModel.dispatchTouchEvent(event);
|
||||
if (STEAL_EVENTS) {
|
||||
mModel.dispatchTouchEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
public void onFinishGesture(GestureOverlay overlay, MotionEvent event) {
|
||||
|
||||
@@ -50,8 +50,6 @@ public class ContactListGestureOverlay extends Activity {
|
||||
People.DISPLAY_NAME, // 1
|
||||
};
|
||||
|
||||
private GestureOverlay mOverlay;
|
||||
|
||||
private ContactAdapter mContactAdapter;
|
||||
|
||||
private TouchThroughGesturing mGestureProcessor;
|
||||
@@ -97,7 +95,7 @@ public class ContactListGestureOverlay extends Activity {
|
||||
setProgressBarIndeterminateVisibility(false);
|
||||
|
||||
// add a gesture overlay on top of the ListView
|
||||
mOverlay = new GestureOverlay(this);
|
||||
GestureOverlay overlay = new GestureOverlay(this);
|
||||
mGestureProcessor = new TouchThroughGesturing(mContactList);
|
||||
mGestureProcessor.setGestureType(TouchThroughGesturing.MULTIPLE_STROKE);
|
||||
mGestureProcessor.addGestureActionListener(new GestureActionListener() {
|
||||
@@ -114,9 +112,9 @@ public class ContactListGestureOverlay extends Activity {
|
||||
}
|
||||
}
|
||||
});
|
||||
mOverlay.addGestureListener(mGestureProcessor);
|
||||
overlay.addGestureListener(mGestureProcessor);
|
||||
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(
|
||||
ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
|
||||
this.addContentView(mOverlay, params);
|
||||
this.addContentView(overlay, params);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user