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

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

Issue 2023133002: Use Event to render feedback animations. (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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
Lambros 2016/06/01 23:51:36 These bug-fixes and cleanups seem unrelated to thi
Hzj_jie 2016/06/02 02:21:37 Sure.
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;
11 import android.util.SparseArray; 11 import android.util.SparseArray;
(...skipping 23 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;
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.
(...skipping 15 matching lines...) Expand all
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);
105 // Cause a long-press notification to be triggered after the tim eout. 107 // Cause a long-press notification to be triggered after the tim eout.
Lambros 2016/06/01 23:51:37 Blank line before comment.
Hzj_jie 2016/06/02 02:21:37 Done.
106 mHandler.sendEmptyMessageDelayed(0, ViewConfiguration.getLongPre ssTimeout()); 108 mHandler.sendEmptyMessageDelayed(0, ViewConfiguration.getLongPre ssTimeout());
107 trackDownEvent(event);
108 mPointerCount = 1; 109 mPointerCount = 1;
109 break; 110 break;
110 111
111 case MotionEvent.ACTION_POINTER_DOWN: 112 case MotionEvent.ACTION_POINTER_DOWN:
112 trackDownEvent(event); 113 trackDownEvent(event);
113 mPointerCount = Math.max(mPointerCount, event.getPointerCount()) ; 114 mPointerCount = Math.max(mPointerCount, event.getPointerCount()) ;
114 break; 115 break;
115 116
116 case MotionEvent.ACTION_MOVE: 117 case MotionEvent.ACTION_MOVE:
117 if (!mTapCancelled) { 118 if (!mTapCancelled) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 mPointerCount = 0; 205 mPointerCount = 0;
205 mInitialPositions.clear(); 206 mInitialPositions.clear();
206 mTapCancelled = false; 207 mTapCancelled = false;
207 } 208 }
208 209
209 /** Cancels any pending long-touch notifications from the message-queue. */ 210 /** Cancels any pending long-touch notifications from the message-queue. */
210 private void cancelLongTouchNotification() { 211 private void cancelLongTouchNotification() {
211 mHandler.removeMessages(0); 212 mHandler.removeMessages(0);
212 } 213 }
213 } 214 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698