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

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

Issue 2032883002: [Chromoting] Minor changes to TapGestureDetector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chromoting; 5 package org.chromium.chromoting;
6 6
7 import android.content.Context; 7 import android.content.Context;
8 import android.graphics.PointF; 8 import android.graphics.PointF;
9 import android.os.Handler; 9 import android.os.Handler;
10 import android.os.Message; 10 import android.os.Message;
(...skipping 24 matching lines...) Expand all
35 * Notified when a long-touch event occurs. 35 * Notified when a long-touch event occurs.
36 * 36 *
37 * @param pointerCount The number of fingers held down. 37 * @param pointerCount The number of fingers held down.
38 * @param x The x coordinate of the initial finger tapped. 38 * @param x The x coordinate of the initial finger tapped.
39 * @param y The y coordinate of the initial finger tapped. 39 * @param y The y coordinate of the initial finger tapped.
40 */ 40 */
41 void onLongPress(int pointerCount, float x, float y); 41 void onLongPress(int pointerCount, float x, float y);
42 } 42 }
43 43
44 /** The listener to which notifications are sent. */ 44 /** The listener to which notifications are sent. */
45 private OnTapListener mListener; 45 private final OnTapListener mListener;
Lambros 2016/06/02 18:11:30 Are you adding 'final' simply because this impleme
Hzj_jie 2016/06/02 22:20:04 In my opinion -- it's similar as the 'final' of Se
46 46
47 /** Handler used for posting tasks to be executed in the future. */ 47 /** Handler used for posting tasks to be executed in the future. */
48 private Handler mHandler; 48 private final Handler mHandler;
49 49
50 /** The maximum number of fingers seen in the gesture. */ 50 /** The maximum number of fingers seen in the gesture. */
51 private int mPointerCount = 0; 51 private int mPointerCount = 0;
52 52
53 /** The coordinates of the first finger down seen in the gesture. */ 53 /** The coordinates of the first finger down seen in the gesture. */
54 private PointF mInitialPoint; 54 private PointF mInitialPoint;
55 55
56 /** 56 /**
57 * Stores the location of each down MotionEvent (by pointer ID), for detecti ng motion of any 57 * Stores the location of each down MotionEvent (by pointer ID), for detecti ng motion of any
58 * pointer beyond the TouchSlop region. 58 * pointer beyond the TouchSlop region.
59 */ 59 */
60 private SparseArray<PointF> mInitialPositions = new SparseArray<PointF>(); 60 private SparseArray<PointF> mInitialPositions = new SparseArray<PointF>();
Lambros 2016/06/02 18:11:30 This could be final as well?
Hzj_jie 2016/06/02 22:20:04 Done.
61 61
62 /** 62 /**
63 * Threshold squared-distance, in pixels, to use for motion-detection. If a finger moves less 63 * Threshold squared-distance, in pixels, to use for motion-detection. If a finger moves less
64 * than this distance, the gesture is still eligible to be a tap event. 64 * than this distance, the gesture is still eligible to be a tap event.
65 */ 65 */
66 private int mTouchSlopSquare; 66 private int mTouchSlopSquare;
Lambros 2016/06/02 18:11:30 And this?
Hzj_jie 2016/06/02 22:20:04 Done.
67 67
68 /** Set to true whenever motion is detected in the gesture, or a long-touch is triggered. */ 68 /** Set to true whenever motion is detected in the gesture, or a long-touch is triggered. */
69 private boolean mTapCancelled = false; 69 private boolean mTapCancelled = false;
70 70
71 // This static inner class holds a WeakReference to the outer object, to avo id triggering the 71 // This static inner class holds a WeakReference to the outer object, to avo id triggering the
72 // lint HandlerLeak warning. 72 // lint HandlerLeak warning.
73 private static class EventHandler extends Handler { 73 private static class EventHandler extends Handler {
74 private final WeakReference<TapGestureDetector> mDetector; 74 private final WeakReference<TapGestureDetector> mDetector;
75 75
76 public EventHandler(TapGestureDetector detector) { 76 public EventHandler(TapGestureDetector detector) {
77 mDetector = new WeakReference<TapGestureDetector>(detector); 77 mDetector = new WeakReference<TapGestureDetector>(detector);
78 } 78 }
79 79
80 @Override 80 @Override
81 public void handleMessage(Message message) { 81 public void handleMessage(Message message) {
82 TapGestureDetector detector = mDetector.get(); 82 TapGestureDetector detector = mDetector.get();
83 if (detector != null) { 83 if (detector != null) {
84 detector.mTapCancelled = true;
84 detector.mListener.onLongPress( 85 detector.mListener.onLongPress(
85 detector.mPointerCount, detector.mInitialPoint.x, detect or.mInitialPoint.y); 86 detector.mPointerCount, detector.mInitialPoint.x, detect or.mInitialPoint.y);
86 detector.mTapCancelled = true; 87 detector.mInitialPoint = null;
87 } 88 }
88 } 89 }
89 } 90 }
90 91
91 public TapGestureDetector(Context context, OnTapListener listener) { 92 public TapGestureDetector(Context context, OnTapListener listener) {
92 mListener = listener; 93 mListener = listener;
93 mHandler = new EventHandler(this); 94 mHandler = new EventHandler(this);
94 ViewConfiguration config = ViewConfiguration.get(context); 95 ViewConfiguration config = ViewConfiguration.get(context);
95 int touchSlop = config.getScaledTouchSlop(); 96 int touchSlop = config.getScaledTouchSlop();
96 mTouchSlopSquare = touchSlop * touchSlop; 97 mTouchSlopSquare = touchSlop * touchSlop;
97 } 98 }
98 99
99 /** Analyzes the touch event to determine whether to notify the listener. */ 100 /** Analyzes the touch event to determine whether to notify the listener. */
100 public boolean onTouchEvent(MotionEvent event) { 101 public boolean onTouchEvent(MotionEvent event) {
101 boolean handled = false; 102 boolean handled = false;
102 switch (event.getActionMasked()) { 103 switch (event.getActionMasked()) {
103 case MotionEvent.ACTION_DOWN: 104 case MotionEvent.ACTION_DOWN:
104 reset(); 105 reset();
106 trackDownEvent(event);
107
105 // Cause a long-press notification to be triggered after the tim eout. 108 // Cause a long-press notification to be triggered after the tim eout.
106 mHandler.sendEmptyMessageDelayed(0, ViewConfiguration.getLongPre ssTimeout()); 109 mHandler.sendEmptyMessageDelayed(0, ViewConfiguration.getLongPre ssTimeout());
107 trackDownEvent(event);
108 mPointerCount = 1; 110 mPointerCount = 1;
109 break; 111 break;
110 112
111 case MotionEvent.ACTION_POINTER_DOWN: 113 case MotionEvent.ACTION_POINTER_DOWN:
112 trackDownEvent(event); 114 trackDownEvent(event);
113 mPointerCount = Math.max(mPointerCount, event.getPointerCount()) ; 115 mPointerCount = Math.max(mPointerCount, event.getPointerCount()) ;
114 break; 116 break;
115 117
116 case MotionEvent.ACTION_MOVE: 118 case MotionEvent.ACTION_MOVE:
117 if (!mTapCancelled) { 119 if (!mTapCancelled) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 mPointerCount = 0; 206 mPointerCount = 0;
205 mInitialPositions.clear(); 207 mInitialPositions.clear();
206 mTapCancelled = false; 208 mTapCancelled = false;
207 } 209 }
208 210
209 /** Cancels any pending long-touch notifications from the message-queue. */ 211 /** Cancels any pending long-touch notifications from the message-queue. */
210 private void cancelLongTouchNotification() { 212 private void cancelLongTouchNotification() {
211 mHandler.removeMessages(0); 213 mHandler.removeMessages(0);
212 } 214 }
213 } 215 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698