FreeRDP
Loading...
Searching...
No Matches
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 28 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 79 of file GestureDetector.java.

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

◆ 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 95 of file GestureDetector.java.

96 {
97 this(context, listener, handler, context != null);
98 }

◆ 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 113 of file GestureDetector.java.

115 {
116 if (handler != null)
117 {
118 mHandler = new GestureHandler(handler);
119 }
120 else
121 {
122 mHandler = new GestureHandler();
123 }
124 mListener = listener;
125 if (listener instanceof OnDoubleTapListener)
126 {
127 setOnDoubleTapListener((OnDoubleTapListener)listener);
128 }
129 init(context, ignoreMultitouch);
130 }
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 193 of file GestureDetector.java.

194 {
195 return mIsLongpressEnabled;
196 }

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 211 of file GestureDetector.java.

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

186 {
187 mIsLongpressEnabled = isLongpressEnabled;
188 }

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

Here is the call graph for this function:

◆ setLongPressTimeout()

void com.freerdp.freerdpcore.utils.GestureDetector.setLongPressTimeout ( int  timeout)
inline

Definition at line 198 of file GestureDetector.java.

199 {
200 mLongpressTimeout = timeout;
201 }

◆ 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 171 of file GestureDetector.java.

172 {
173 mDoubleTapListener = onDoubleTapListener;
174 }

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: