Merge "Fix magnification unit test"
This commit is contained in:
@@ -229,7 +229,7 @@ class MagnificationGestureHandler extends BaseEventStreamTransformation {
|
||||
}
|
||||
|
||||
void clearAndTransitionToStateDetecting() {
|
||||
mCurrentState = mDelegatingState;
|
||||
mCurrentState = mDetectingState;
|
||||
mDetectingState.clear();
|
||||
mViewportDraggingState.clear();
|
||||
mPanningScalingState.clear();
|
||||
@@ -649,14 +649,19 @@ class MagnificationGestureHandler extends BaseEventStreamTransformation {
|
||||
break;
|
||||
case ACTION_MOVE: {
|
||||
if (isFingerDown()
|
||||
&& distance(mLastDown, /* move */ event) > mSwipeMinDistance
|
||||
// For convenience, viewport dragging on 3tap&hold takes precedence
|
||||
// over insta-delegating on 3tap&swipe
|
||||
// (which is a rare combo to be used aside from magnification)
|
||||
&& !isMultiTapTriggered(2 /* taps */)) {
|
||||
&& distance(mLastDown, /* move */ event) > mSwipeMinDistance) {
|
||||
|
||||
// Swipe detected - delegate skipping timeout
|
||||
transitionToDelegatingStateAndClear();
|
||||
// Swipe detected - transition immediately
|
||||
|
||||
// For convenience, viewport dragging takes precedence
|
||||
// over insta-delegating on 3tap&swipe
|
||||
// (which is a rare combo to be used aside from magnification)
|
||||
if (isMultiTapTriggered(2 /* taps */)) {
|
||||
transitionTo(mViewportDraggingState);
|
||||
clear();
|
||||
} else {
|
||||
transitionToDelegatingStateAndClear();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -32,6 +32,7 @@ import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.content.Context;
|
||||
import android.os.Message;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.util.DebugUtils;
|
||||
@@ -76,6 +77,8 @@ public class MagnificationGestureHandlerTest {
|
||||
private MagnificationGestureHandler mMgh;
|
||||
private TestHandler mHandler;
|
||||
|
||||
private long mLastDownTime = Integer.MIN_VALUE;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mContext = InstrumentationRegistry.getContext();
|
||||
@@ -104,7 +107,13 @@ public class MagnificationGestureHandlerTest {
|
||||
MagnificationGestureHandler h = new MagnificationGestureHandler(
|
||||
mContext, mMagnificationController,
|
||||
detectTripleTap, detectShortcutTrigger);
|
||||
mHandler = new TestHandler(h.mDetectingState, mClock);
|
||||
mHandler = new TestHandler(h.mDetectingState, mClock) {
|
||||
@Override
|
||||
protected String messageToString(Message m) {
|
||||
return DebugUtils.valueToString(
|
||||
MagnificationGestureHandler.DetectingState.class, "MESSAGE_", m.what);
|
||||
}
|
||||
};
|
||||
h.mDetectingState.mHandler = mHandler;
|
||||
h.setNext(strictMock(EventStreamTransformation.class));
|
||||
return h;
|
||||
@@ -184,11 +193,11 @@ public class MagnificationGestureHandlerTest {
|
||||
fastForward1sec();
|
||||
}, STATE_ZOOMED);
|
||||
|
||||
// tap+tap+swipe gets delegated
|
||||
assertTransition(STATE_2TAPS, () -> {
|
||||
allowEventDelegation();
|
||||
swipe();
|
||||
}, STATE_IDLE);
|
||||
// tap+tap+swipe doesn't get delegated
|
||||
assertTransition(STATE_2TAPS, () -> swipe(), STATE_IDLE);
|
||||
|
||||
// tap+tap+swipe initiates viewport dragging immediately
|
||||
assertTransition(STATE_2TAPS, () -> swipeAndHold(), STATE_DRAGGING_TMP);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -439,23 +448,24 @@ public class MagnificationGestureHandlerTest {
|
||||
}
|
||||
|
||||
private void tap() {
|
||||
MotionEvent downEvent = downEvent();
|
||||
send(downEvent);
|
||||
send(upEvent(downEvent.getDownTime()));
|
||||
send(downEvent());
|
||||
send(upEvent());
|
||||
}
|
||||
|
||||
private void swipe() {
|
||||
MotionEvent downEvent = downEvent();
|
||||
send(downEvent);
|
||||
swipeAndHold();
|
||||
send(upEvent());
|
||||
}
|
||||
|
||||
private void swipeAndHold() {
|
||||
send(downEvent());
|
||||
send(moveEvent(DEFAULT_X * 2, DEFAULT_Y * 2));
|
||||
send(upEvent(downEvent.getDownTime()));
|
||||
}
|
||||
|
||||
private void longTap() {
|
||||
MotionEvent downEvent = downEvent();
|
||||
send(downEvent);
|
||||
send(downEvent());
|
||||
fastForward(2000);
|
||||
send(upEvent(downEvent.getDownTime()));
|
||||
send(upEvent());
|
||||
}
|
||||
|
||||
private void triggerShortcut() {
|
||||
@@ -473,16 +483,17 @@ public class MagnificationGestureHandlerTest {
|
||||
}
|
||||
|
||||
private MotionEvent moveEvent(float x, float y) {
|
||||
return MotionEvent.obtain(defaultDownTime(), mClock.now(), ACTION_MOVE, x, y, 0);
|
||||
return MotionEvent.obtain(mLastDownTime, mClock.now(), ACTION_MOVE, x, y, 0);
|
||||
}
|
||||
|
||||
private MotionEvent downEvent() {
|
||||
return MotionEvent.obtain(mClock.now(), mClock.now(),
|
||||
mLastDownTime = mClock.now();
|
||||
return MotionEvent.obtain(mLastDownTime, mLastDownTime,
|
||||
ACTION_DOWN, DEFAULT_X, DEFAULT_Y, 0);
|
||||
}
|
||||
|
||||
private MotionEvent upEvent() {
|
||||
return upEvent(defaultDownTime());
|
||||
return upEvent(mLastDownTime);
|
||||
}
|
||||
|
||||
private MotionEvent upEvent(long downTime) {
|
||||
@@ -490,11 +501,6 @@ public class MagnificationGestureHandlerTest {
|
||||
MotionEvent.ACTION_UP, DEFAULT_X, DEFAULT_Y, 0);
|
||||
}
|
||||
|
||||
private long defaultDownTime() {
|
||||
MotionEvent lastDown = mMgh.mDetectingState.mLastDown;
|
||||
return lastDown == null ? mClock.now() - 1 : lastDown.getDownTime();
|
||||
}
|
||||
|
||||
private MotionEvent pointerEvent(int action, float x, float y) {
|
||||
MotionEvent.PointerProperties defPointerProperties = new MotionEvent.PointerProperties();
|
||||
defPointerProperties.id = 0;
|
||||
|
||||
@@ -104,6 +104,15 @@ public class TestHandler extends Handler {
|
||||
return new PriorityQueue<>(mMessages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optionally-overridable to allow deciphering message types
|
||||
*
|
||||
* @see android.util.DebugUtils#valueToString - a handy utility to use when overriding this
|
||||
*/
|
||||
protected String messageToString(Message message) {
|
||||
return message.toString();
|
||||
}
|
||||
|
||||
private void dispatch(MsgInfo msg) {
|
||||
int msgId = msg.message.what;
|
||||
|
||||
@@ -148,7 +157,7 @@ public class TestHandler extends Handler {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MsgInfo{" +
|
||||
"message=" + message +
|
||||
"message=" + messageToString(message) +
|
||||
", sendTime=" + sendTime +
|
||||
'}';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user