Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: remoting/android/javatests/src/org/chromium/chromoting/TouchEventBuilder.java

Issue 2066683003: [Chromoting] Add InputInjector and InputInjectorWrapper for easy unittesting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix FindBugs errors Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.chromoting;
6
7 import org.chromium.chromoting.jni.TouchEventData;
8
9 import java.util.ArrayList;
10
11 /** 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
12 public final class TouchEventBuilder {
13 private final ArrayList<TouchEventData> mData;
14 private TouchEventData.EventType mEventType;
15 // Following fields are the of the pending TouchEventData. They will be adde d to {@link #data}
Lambros 2016/06/17 23:00:11 Blank line.
Hzj_jie 2016/06/19 23:41:40 Done.
16 // by calling appendData().
17 private int mId;
18 private float mX;
19 private float mY;
20 private float mRadiusX;
21 private float mRadiusY;
22 private float mAngleInRadians;
23 private float mPressure;
24
25 public TouchEventBuilder() {
26 mData = new ArrayList<>();
27 clear();
28 }
29
30 public TouchEventBuilder withEventType(TouchEventData.EventType eventType) {
31 mEventType = eventType;
32 return this;
33 }
34
35 public TouchEventBuilder withId(int id) {
36 mId = id;
37 return this;
38 }
39
40 public TouchEventBuilder withX(float x) {
41 mX = x;
42 return this;
43 }
44
45 public TouchEventBuilder withY(float y) {
46 mY = y;
47 return this;
48 }
49
50 public TouchEventBuilder withRadiusX(float radiusX) {
51 mRadiusX = radiusX;
52 return this;
53 }
54
55 public TouchEventBuilder withRadiusY(float radiusY) {
56 mRadiusY = radiusY;
57 return this;
58 }
59
60 public TouchEventBuilder withAngleInRadians(float angleInRadians) {
61 mAngleInRadians = angleInRadians;
62 return this;
63 }
64
65 public TouchEventBuilder withPressure(float pressure) {
66 mPressure = pressure;
67 return this;
68 }
69
70 public TouchEventBuilder append() {
71 mData.add(new TouchEventData(mId, mX, mY, mRadiusX, mRadiusY, mAngleInRa dians, mPressure));
72 resetPending();
73 return this;
74 }
75
76 public MockInputInjector.TouchEvent build() {
77 return new MockInputInjector.TouchEvent(mEventType, mData.toArray(new To uchEventData[] {}));
78 }
79
80 private void clear() {
81 mEventType = TouchEventData.EventType.TOUCH_EVENT_UNKNOWN;
82 mData.clear();
83 resetPending();
84 }
85
86 private void resetPending() {
87 mId = MockInputInjector.TouchEvent.INVALID_ID;
88 mX = MockInputInjector.TouchEvent.INVALID_POSITION;
89 mY = MockInputInjector.TouchEvent.INVALID_POSITION;
90 mRadiusX = MockInputInjector.TouchEvent.INVALID_POSITION;
91 mRadiusY = MockInputInjector.TouchEvent.INVALID_POSITION;
92 mAngleInRadians = MockInputInjector.TouchEvent.INVALID_RADIANS;
93 mPressure = MockInputInjector.TouchEvent.INVALID_POSITION;
94 }
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698