Chromium Code Reviews| Index: remoting/android/javatests/src/org/chromium/chromoting/TouchEventBuilder.java |
| diff --git a/remoting/android/javatests/src/org/chromium/chromoting/TouchEventBuilder.java b/remoting/android/javatests/src/org/chromium/chromoting/TouchEventBuilder.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..bde8cb6667c9809e36db7d7296fdf667f96a5dd2 |
| --- /dev/null |
| +++ b/remoting/android/javatests/src/org/chromium/chromoting/TouchEventBuilder.java |
| @@ -0,0 +1,95 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chromoting; |
| + |
| +import org.chromium.chromoting.jni.TouchEventData; |
| + |
| +import java.util.ArrayList; |
| + |
| +/** A helper class to build a {@link TouchEvent}. */ |
|
Lambros
2016/06/17 23:00:10
{@link MockInputInjector.TouchEvent}
This builder
Hzj_jie
2016/06/19 23:41:40
This is also a headache to me. TouchEvent equals t
|
| +public final class TouchEventBuilder { |
| + private final ArrayList<TouchEventData> mData; |
| + private TouchEventData.EventType mEventType; |
| + // Following fields are the of the pending TouchEventData. They will be added to {@link #data} |
|
Lambros
2016/06/17 23:00:11
Blank line.
Hzj_jie
2016/06/19 23:41:40
Done.
|
| + // by calling appendData(). |
| + private int mId; |
| + private float mX; |
| + private float mY; |
| + private float mRadiusX; |
| + private float mRadiusY; |
| + private float mAngleInRadians; |
| + private float mPressure; |
| + |
| + public TouchEventBuilder() { |
| + mData = new ArrayList<>(); |
| + clear(); |
| + } |
| + |
| + public TouchEventBuilder withEventType(TouchEventData.EventType eventType) { |
| + mEventType = eventType; |
| + return this; |
| + } |
| + |
| + public TouchEventBuilder withId(int id) { |
| + mId = id; |
| + return this; |
| + } |
| + |
| + public TouchEventBuilder withX(float x) { |
| + mX = x; |
| + return this; |
| + } |
| + |
| + public TouchEventBuilder withY(float y) { |
| + mY = y; |
| + return this; |
| + } |
| + |
| + public TouchEventBuilder withRadiusX(float radiusX) { |
| + mRadiusX = radiusX; |
| + return this; |
| + } |
| + |
| + public TouchEventBuilder withRadiusY(float radiusY) { |
| + mRadiusY = radiusY; |
| + return this; |
| + } |
| + |
| + public TouchEventBuilder withAngleInRadians(float angleInRadians) { |
| + mAngleInRadians = angleInRadians; |
| + return this; |
| + } |
| + |
| + public TouchEventBuilder withPressure(float pressure) { |
| + mPressure = pressure; |
| + return this; |
| + } |
| + |
| + public TouchEventBuilder append() { |
| + mData.add(new TouchEventData(mId, mX, mY, mRadiusX, mRadiusY, mAngleInRadians, mPressure)); |
| + resetPending(); |
| + return this; |
| + } |
| + |
| + public MockInputInjector.TouchEvent build() { |
| + return new MockInputInjector.TouchEvent(mEventType, mData.toArray(new TouchEventData[] {})); |
| + } |
| + |
| + private void clear() { |
| + mEventType = TouchEventData.EventType.TOUCH_EVENT_UNKNOWN; |
| + mData.clear(); |
| + resetPending(); |
| + } |
| + |
| + private void resetPending() { |
| + mId = MockInputInjector.TouchEvent.INVALID_ID; |
| + mX = MockInputInjector.TouchEvent.INVALID_POSITION; |
| + mY = MockInputInjector.TouchEvent.INVALID_POSITION; |
| + mRadiusX = MockInputInjector.TouchEvent.INVALID_POSITION; |
| + mRadiusY = MockInputInjector.TouchEvent.INVALID_POSITION; |
| + mAngleInRadians = MockInputInjector.TouchEvent.INVALID_RADIANS; |
| + mPressure = MockInputInjector.TouchEvent.INVALID_POSITION; |
| + } |
| +} |