FreeRDP
com.freerdp.freerdpcore.utils.DoubleGestureDetector Class Reference

Data Structures

interface  OnDoubleGestureListener
 

Public Member Functions

 DoubleGestureDetector (Context context, Handler handler, OnDoubleGestureListener listener)
 
void setScaleGestureDetector (ScaleGestureDetector scaleGestureDetector)
 
boolean onTouchEvent (MotionEvent ev)
 

Detailed Description

Definition at line 20 of file DoubleGestureDetector.java.

Constructor & Destructor Documentation

◆ DoubleGestureDetector()

com.freerdp.freerdpcore.utils.DoubleGestureDetector.DoubleGestureDetector ( Context  context,
Handler  handler,
OnDoubleGestureListener  listener 
)
inline

Creates a GestureDetector with the supplied listener. You may only use this constructor from a UI thread (this is the usual situation).

Parameters
contextthe application's context
listenerthe listener invoked for all the callbacks, this must not be null.
Exceptions
NullPointerExceptionif
listener
is null.
See also
android.os.Handler::Handler()

Definition at line 56 of file DoubleGestureDetector.java.

57  {
58  mListener = listener;
59  init(context, handler);
60  }

Member Function Documentation

◆ onTouchEvent()

boolean com.freerdp.freerdpcore.utils.DoubleGestureDetector.onTouchEvent ( MotionEvent  ev)
inline

Analyzes the given motion event and if applicable triggers the appropriate callbacks on the OnGestureListener supplied.

Parameters
evThe current motion event.
Returns
true if the OnGestureListener consumed the event, else false.

Definition at line 102 of file DoubleGestureDetector.java.

103  {
104  boolean handled = false;
105  final int action = ev.getAction();
106  // dumpEvent(ev);
107 
108  switch (action & MotionEvent.ACTION_MASK)
109  {
110  case MotionEvent.ACTION_DOWN:
111  if (mCurrentDownEvent != null)
112  mCurrentDownEvent.recycle();
113 
114  mCurrentMode = MODE_UNKNOWN;
115  mCurrentDownEvent = MotionEvent.obtain(ev);
116  mCancelDetection = false;
117  mDoubleInProgress = false;
118  mScrollDetectionScore = 0;
119  handled = true;
120  break;
121 
122  case MotionEvent.ACTION_POINTER_UP:
123  if (mPreviousPointerUpEvent != null)
124  mPreviousPointerUpEvent.recycle();
125  mPreviousPointerUpEvent = MotionEvent.obtain(ev);
126  break;
127 
128  case MotionEvent.ACTION_POINTER_DOWN:
129  // more than 2 fingers down? cancel
130  // 2nd finger touched too late? cancel
131  if (ev.getPointerCount() > 2 ||
132  (ev.getEventTime() - mCurrentDownEvent.getEventTime()) > DOUBLE_TOUCH_TIMEOUT)
133  {
134  cancel();
135  break;
136  }
137 
138  // detection cancelled?
139  if (mCancelDetection)
140  break;
141 
142  // double touch gesture in progress
143  mDoubleInProgress = true;
144  if (mCurrentDoubleDownEvent != null)
145  mCurrentDoubleDownEvent.recycle();
146  mCurrentDoubleDownEvent = MotionEvent.obtain(ev);
147 
148  // set detection mode to unknown and send a TOUCH timeout event to detect single
149  // taps
150  mCurrentMode = MODE_UNKNOWN;
151  mHandler.sendEmptyMessageDelayed(TAP, SINGLE_DOUBLE_TOUCH_TIMEOUT);
152 
153  handled |= mListener.onDoubleTouchDown(ev);
154  break;
155 
156  case MotionEvent.ACTION_MOVE:
157 
158  // detection cancelled or not active?
159  if (mCancelDetection || !mDoubleInProgress || ev.getPointerCount() != 2)
160  break;
161 
162  // determine mode
163  if (mCurrentMode == MODE_UNKNOWN)
164  {
165  // did the pointer distance change?
166  if (pointerDistanceChanged(mCurrentDoubleDownEvent, ev))
167  {
168  handled |= scaleGestureDetector.onTouchEvent(mCurrentDownEvent);
169  MotionEvent e = MotionEvent.obtain(ev);
170  e.setAction(mCurrentDoubleDownEvent.getAction());
171  handled |= scaleGestureDetector.onTouchEvent(e);
172  mCurrentMode = MODE_PINCH_ZOOM;
173  break;
174  }
175  else
176  {
177  mScrollDetectionScore++;
178  if (mScrollDetectionScore >= SCROLL_SCORE_TO_REACH)
179  mCurrentMode = MODE_SCROLL;
180  }
181  }
182 
183  switch (mCurrentMode)
184  {
185  case MODE_PINCH_ZOOM:
186  if (scaleGestureDetector != null)
187  handled |= scaleGestureDetector.onTouchEvent(ev);
188  break;
189 
190  case MODE_SCROLL:
191  handled = mListener.onDoubleTouchScroll(mCurrentDownEvent, ev);
192  break;
193 
194  default:
195  handled = true;
196  break;
197  }
198 
199  break;
200 
201  case MotionEvent.ACTION_UP:
202  // fingers were not removed equally? cancel
203  if (mPreviousPointerUpEvent != null &&
204  (ev.getEventTime() - mPreviousPointerUpEvent.getEventTime()) >
205  DOUBLE_TOUCH_TIMEOUT)
206  {
207  mPreviousPointerUpEvent.recycle();
208  mPreviousPointerUpEvent = null;
209  cancel();
210  break;
211  }
212 
213  // detection cancelled or not active?
214  if (mCancelDetection || !mDoubleInProgress)
215  break;
216 
217  boolean hasTapEvent = mHandler.hasMessages(TAP);
218  MotionEvent currentUpEvent = MotionEvent.obtain(ev);
219  if (mCurrentMode == MODE_UNKNOWN && hasTapEvent)
220  handled = mListener.onDoubleTouchSingleTap(mCurrentDoubleDownEvent);
221  else if (mCurrentMode == MODE_PINCH_ZOOM)
222  handled = scaleGestureDetector.onTouchEvent(ev);
223 
224  if (mPreviousUpEvent != null)
225  mPreviousUpEvent.recycle();
226 
227  // Hold the event we obtained above - listeners may have changed the original.
228  mPreviousUpEvent = currentUpEvent;
229  handled |= mListener.onDoubleTouchUp(ev);
230  break;
231 
232  case MotionEvent.ACTION_CANCEL:
233  cancel();
234  break;
235  }
236 
237  if ((action == MotionEvent.ACTION_MOVE) && handled == false)
238  handled = true;
239 
240  return handled;
241  }

References com.freerdp.freerdpcore.utils.DoubleGestureDetector.OnDoubleGestureListener.onDoubleTouchDown(), com.freerdp.freerdpcore.utils.DoubleGestureDetector.OnDoubleGestureListener.onDoubleTouchScroll(), com.freerdp.freerdpcore.utils.DoubleGestureDetector.OnDoubleGestureListener.onDoubleTouchSingleTap(), and com.freerdp.freerdpcore.utils.DoubleGestureDetector.OnDoubleGestureListener.onDoubleTouchUp().

Here is the call graph for this function:

◆ setScaleGestureDetector()

void com.freerdp.freerdpcore.utils.DoubleGestureDetector.setScaleGestureDetector ( ScaleGestureDetector  scaleGestureDetector)
inline

Set scale gesture detector

Parameters
scaleGestureDetector

Definition at line 89 of file DoubleGestureDetector.java.

90  {
91  this.scaleGestureDetector = scaleGestureDetector;
92  }

The documentation for this class was generated from the following file: