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 unkown and send a TOUCH timeout event to detect single taps
149  mCurrentMode = MODE_UNKNOWN;
150  mHandler.sendEmptyMessageDelayed(TAP, SINGLE_DOUBLE_TOUCH_TIMEOUT);
151 
152  handled |= mListener.onDoubleTouchDown(ev);
153  break;
154 
155  case MotionEvent.ACTION_MOVE:
156 
157  // detection cancelled or not active?
158  if (mCancelDetection || !mDoubleInProgress || ev.getPointerCount() != 2)
159  break;
160 
161  // determine mode
162  if (mCurrentMode == MODE_UNKNOWN)
163  {
164  // did the pointer distance change?
165  if (pointerDistanceChanged(mCurrentDoubleDownEvent, ev))
166  {
167  handled |= scaleGestureDetector.onTouchEvent(mCurrentDownEvent);
168  MotionEvent e = MotionEvent.obtain(ev);
169  e.setAction(mCurrentDoubleDownEvent.getAction());
170  handled |= scaleGestureDetector.onTouchEvent(e);
171  mCurrentMode = MODE_PINCH_ZOOM;
172  break;
173  }
174  else
175  {
176  mScrollDetectionScore++;
177  if (mScrollDetectionScore >= SCROLL_SCORE_TO_REACH)
178  mCurrentMode = MODE_SCROLL;
179  }
180  }
181 
182  switch (mCurrentMode)
183  {
184  case MODE_PINCH_ZOOM:
185  if (scaleGestureDetector != null)
186  handled |= scaleGestureDetector.onTouchEvent(ev);
187  break;
188 
189  case MODE_SCROLL:
190  handled = mListener.onDoubleTouchScroll(mCurrentDownEvent, ev);
191  break;
192 
193  default:
194  handled = true;
195  break;
196  }
197 
198  break;
199 
200  case MotionEvent.ACTION_UP:
201  // fingers were not removed equally? cancel
202  if (mPreviousPointerUpEvent != null &&
203  (ev.getEventTime() - mPreviousPointerUpEvent.getEventTime()) >
204  DOUBLE_TOUCH_TIMEOUT)
205  {
206  mPreviousPointerUpEvent.recycle();
207  mPreviousPointerUpEvent = null;
208  cancel();
209  break;
210  }
211 
212  // detection cancelled or not active?
213  if (mCancelDetection || !mDoubleInProgress)
214  break;
215 
216  boolean hasTapEvent = mHandler.hasMessages(TAP);
217  MotionEvent currentUpEvent = MotionEvent.obtain(ev);
218  if (mCurrentMode == MODE_UNKNOWN && hasTapEvent)
219  handled = mListener.onDoubleTouchSingleTap(mCurrentDoubleDownEvent);
220  else if (mCurrentMode == MODE_PINCH_ZOOM)
221  handled = scaleGestureDetector.onTouchEvent(ev);
222 
223  if (mPreviousUpEvent != null)
224  mPreviousUpEvent.recycle();
225 
226  // Hold the event we obtained above - listeners may have changed the original.
227  mPreviousUpEvent = currentUpEvent;
228  handled |= mListener.onDoubleTouchUp(ev);
229  break;
230 
231  case MotionEvent.ACTION_CANCEL:
232  cancel();
233  break;
234  }
235 
236  if ((action == MotionEvent.ACTION_MOVE) && handled == false)
237  handled = true;
238 
239  return handled;
240  }

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: