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

Data Structures

interface  OnDoubleTapListener
 
interface  OnGestureListener
 
class  SimpleOnGestureListener
 

Public Member Functions

 GestureDetector (Context context, OnGestureListener listener)
 
 GestureDetector (Context context, OnGestureListener listener, Handler handler)
 
 GestureDetector (Context context, OnGestureListener listener, Handler handler, boolean ignoreMultitouch)
 
void setOnDoubleTapListener (OnDoubleTapListener onDoubleTapListener)
 
void setIsLongpressEnabled (boolean isLongpressEnabled)
 
boolean isLongpressEnabled ()
 
void setLongPressTimeout (int timeout)
 
boolean onTouchEvent (MotionEvent ev)
 

Detailed Description

Definition at line 29 of file GestureDetector.java.

Constructor & Destructor Documentation

◆ GestureDetector() [1/3]

com.freerdp.freerdpcore.utils.GestureDetector.GestureDetector ( Context  context,
OnGestureListener  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 80 of file GestureDetector.java.

81  {
82  this(context, listener, null);
83  }

◆ GestureDetector() [2/3]

com.freerdp.freerdpcore.utils.GestureDetector.GestureDetector ( Context  context,
OnGestureListener  listener,
Handler  handler 
)
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.
handlerthe handler to use
Exceptions
NullPointerExceptionif
listener
is null.
See also
android.os.Handler::Handler()

Definition at line 96 of file GestureDetector.java.

97  {
98  this(context, listener, handler,
99  context != null &&
100  context.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.FROYO);
101  }

◆ GestureDetector() [3/3]

com.freerdp.freerdpcore.utils.GestureDetector.GestureDetector ( Context  context,
OnGestureListener  listener,
Handler  handler,
boolean  ignoreMultitouch 
)
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.
handlerthe handler to use
ignoreMultitouchwhether events involving more than one pointer should be ignored.
Exceptions
NullPointerExceptionif
listener
is null.
See also
android.os.Handler::Handler()

Definition at line 116 of file GestureDetector.java.

118  {
119  if (handler != null)
120  {
121  mHandler = new GestureHandler(handler);
122  }
123  else
124  {
125  mHandler = new GestureHandler();
126  }
127  mListener = listener;
128  if (listener instanceof OnDoubleTapListener)
129  {
130  setOnDoubleTapListener((OnDoubleTapListener)listener);
131  }
132  init(context, ignoreMultitouch);
133  }
void setOnDoubleTapListener(OnDoubleTapListener onDoubleTapListener)

References com.freerdp.freerdpcore.utils.GestureDetector.setOnDoubleTapListener().

Here is the call graph for this function:

Member Function Documentation

◆ isLongpressEnabled()

boolean com.freerdp.freerdpcore.utils.GestureDetector.isLongpressEnabled ( )
inline
Returns
true if longpress is enabled, else false.

Definition at line 196 of file GestureDetector.java.

197  {
198  return mIsLongpressEnabled;
199  }

Referenced by com.freerdp.freerdpcore.utils.GestureDetector.setIsLongpressEnabled().

Here is the caller graph for this function:

◆ onTouchEvent()

boolean com.freerdp.freerdpcore.utils.GestureDetector.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 214 of file GestureDetector.java.

215  {
216  final int action = ev.getAction();
217  final float y = ev.getY();
218  final float x = ev.getX();
219 
220  boolean handled = false;
221 
222  switch (action & MotionEvent.ACTION_MASK)
223  {
224  case MotionEvent.ACTION_POINTER_DOWN:
225  if (mIgnoreMultitouch)
226  {
227  // Multitouch event - abort.
228  cancel();
229  }
230  break;
231 
232  case MotionEvent.ACTION_POINTER_UP:
233  // Ending a multitouch gesture and going back to 1 finger
234  if (mIgnoreMultitouch && ev.getPointerCount() == 2)
235  {
236  int index = (((action & MotionEvent.ACTION_POINTER_INDEX_MASK) >>
237  MotionEvent.ACTION_POINTER_INDEX_SHIFT) == 0)
238  ? 1
239  : 0;
240  mLastMotionX = ev.getX(index);
241  mLastMotionY = ev.getY(index);
242  }
243  break;
244 
245  case MotionEvent.ACTION_DOWN:
246  if (mDoubleTapListener != null)
247  {
248  boolean hadTapMessage = mHandler.hasMessages(TAP);
249  if (hadTapMessage)
250  mHandler.removeMessages(TAP);
251  if ((mCurrentDownEvent != null) && (mPreviousUpEvent != null) &&
252  hadTapMessage &&
253  isConsideredDoubleTap(mCurrentDownEvent, mPreviousUpEvent, ev))
254  {
255  // This is a second tap
256  mIsDoubleTapping = true;
257  // Give a callback with the first tap of the double-tap
258  handled |= mDoubleTapListener.onDoubleTap(mCurrentDownEvent);
259  // Give a callback with down event of the double-tap
260  handled |= mDoubleTapListener.onDoubleTapEvent(ev);
261  }
262  else
263  {
264  // This is a first tap
265  mHandler.sendEmptyMessageDelayed(TAP, DOUBLE_TAP_TIMEOUT);
266  }
267  }
268 
269  mLastMotionX = x;
270  mLastMotionY = y;
271  if (mCurrentDownEvent != null)
272  {
273  mCurrentDownEvent.recycle();
274  }
275  mCurrentDownEvent = MotionEvent.obtain(ev);
276  mAlwaysInTapRegion = true;
277  mAlwaysInBiggerTapRegion = true;
278  mStillDown = true;
279  mInLongPress = false;
280 
281  if (mIsLongpressEnabled)
282  {
283  mHandler.removeMessages(LONG_PRESS);
284  mHandler.sendEmptyMessageAtTime(LONG_PRESS, mCurrentDownEvent.getDownTime() +
285  TAP_TIMEOUT +
286  mLongpressTimeout);
287  }
288  mHandler.sendEmptyMessageAtTime(SHOW_PRESS,
289  mCurrentDownEvent.getDownTime() + TAP_TIMEOUT);
290  handled |= mListener.onDown(ev);
291  break;
292 
293  case MotionEvent.ACTION_MOVE:
294  if (mIgnoreMultitouch && ev.getPointerCount() > 1)
295  {
296  break;
297  }
298  final float scrollX = mLastMotionX - x;
299  final float scrollY = mLastMotionY - y;
300  if (mIsDoubleTapping)
301  {
302  // Give the move events of the double-tap
303  handled |= mDoubleTapListener.onDoubleTapEvent(ev);
304  }
305  else if (mAlwaysInTapRegion)
306  {
307  final int deltaX = (int)(x - mCurrentDownEvent.getX());
308  final int deltaY = (int)(y - mCurrentDownEvent.getY());
309  int distance = (deltaX * deltaX) + (deltaY * deltaY);
310  if (distance > mTouchSlopSquare)
311  {
312  mLastMotionX = x;
313  mLastMotionY = y;
314  mAlwaysInTapRegion = false;
315  mHandler.removeMessages(TAP);
316  mHandler.removeMessages(SHOW_PRESS);
317  mHandler.removeMessages(LONG_PRESS);
318  }
319  if (distance > mLargeTouchSlopSquare)
320  {
321  mAlwaysInBiggerTapRegion = false;
322  }
323  handled = mListener.onScroll(mCurrentDownEvent, ev, scrollX, scrollY);
324  }
325  else if ((Math.abs(scrollX) >= 1) || (Math.abs(scrollY) >= 1))
326  {
327  handled = mListener.onScroll(mCurrentDownEvent, ev, scrollX, scrollY);
328  mLastMotionX = x;
329  mLastMotionY = y;
330  }
331  break;
332 
333  case MotionEvent.ACTION_UP:
334  mStillDown = false;
335  MotionEvent currentUpEvent = MotionEvent.obtain(ev);
336  if (mIsDoubleTapping)
337  {
338  // Finally, give the up event of the double-tap
339  handled |= mDoubleTapListener.onDoubleTapEvent(ev);
340  }
341  else if (mInLongPress)
342  {
343  mHandler.removeMessages(TAP);
344  mListener.onLongPressUp(ev);
345  mInLongPress = false;
346  }
347  else if (mAlwaysInTapRegion)
348  {
349  handled = mListener.onSingleTapUp(mCurrentDownEvent);
350  }
351  else
352  {
353  // A fling must travel the minimum tap distance
354  }
355  if (mPreviousUpEvent != null)
356  {
357  mPreviousUpEvent.recycle();
358  }
359  // Hold the event we obtained above - listeners may have changed the original.
360  mPreviousUpEvent = currentUpEvent;
361  mIsDoubleTapping = false;
362  mHandler.removeMessages(SHOW_PRESS);
363  mHandler.removeMessages(LONG_PRESS);
364  handled |= mListener.onUp(ev);
365  break;
366  case MotionEvent.ACTION_CANCEL:
367  cancel();
368  break;
369  }
370  return handled;
371  }
boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)

References com.freerdp.freerdpcore.utils.GestureDetector.OnDoubleTapListener.onDoubleTap(), com.freerdp.freerdpcore.utils.GestureDetector.OnDoubleTapListener.onDoubleTapEvent(), com.freerdp.freerdpcore.utils.GestureDetector.OnGestureListener.onDown(), com.freerdp.freerdpcore.utils.GestureDetector.OnGestureListener.onLongPressUp(), com.freerdp.freerdpcore.utils.GestureDetector.OnGestureListener.onScroll(), com.freerdp.freerdpcore.utils.GestureDetector.OnGestureListener.onSingleTapUp(), and com.freerdp.freerdpcore.utils.GestureDetector.OnGestureListener.onUp().

Here is the call graph for this function:

◆ setIsLongpressEnabled()

void com.freerdp.freerdpcore.utils.GestureDetector.setIsLongpressEnabled ( boolean  isLongpressEnabled)
inline

Set whether longpress is enabled, if this is enabled when a user presses and holds down you get a longpress event and nothing further. If it's disabled the user can press and hold down and then later moved their finger and you will get scroll events. By default longpress is enabled.

Parameters
isLongpressEnabledwhether longpress should be enabled.

Definition at line 188 of file GestureDetector.java.

189  {
190  mIsLongpressEnabled = isLongpressEnabled;
191  }

References com.freerdp.freerdpcore.utils.GestureDetector.isLongpressEnabled().

Here is the call graph for this function:

◆ setOnDoubleTapListener()

void com.freerdp.freerdpcore.utils.GestureDetector.setOnDoubleTapListener ( OnDoubleTapListener  onDoubleTapListener)
inline

Sets the listener which will be called for double-tap and related gestures.

Parameters
onDoubleTapListenerthe listener invoked for all the callbacks, or null to stop listening for double-tap gestures.

Definition at line 174 of file GestureDetector.java.

175  {
176  mDoubleTapListener = onDoubleTapListener;
177  }

Referenced by com.freerdp.freerdpcore.utils.GestureDetector.GestureDetector().

Here is the caller graph for this function:

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