6package org.mozilla.gecko.gfx;
8import android.graphics.PointF;
9import android.util.Log;
10import android.view.MotionEvent;
12import org.json.JSONException;
14import java.util.LinkedList;
15import java.util.ListIterator;
16import java.util.Stack;
54 switch (event.getAction() & MotionEvent.ACTION_MASK) {
55 case MotionEvent.ACTION_DOWN:
62 case MotionEvent.ACTION_POINTER_DOWN:
65 case MotionEvent.ACTION_MOVE:
68 case MotionEvent.ACTION_POINTER_UP:
69 case MotionEvent.ACTION_UP:
70 case MotionEvent.ACTION_CANCEL:
81 return (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
82 >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
95 for (
int i = 0;
i <
event.getPointerCount();
i++) {
97 if (pointerInfo !=
null) {
110 int action =
event.getAction() & MotionEvent.ACTION_MASK;
111 boolean isCancel = (
action == MotionEvent.ACTION_CANCEL ||
112 action == MotionEvent.ACTION_DOWN);
115 ListIterator<PointerInfo> iterator =
mPointerInfo.listIterator();
116 while (iterator.hasNext()) {
118 if (!(isCancel || pointerInfo.
getId() ==
id)) {
143 return (pointerA.
getCurrent().x + pointerB.getCurrent().x) / 2.0f;
146 Log.e(
LOGTAG,
"No gesture taking place in getFocusX()!");
160 return (pointerA.
getCurrent().y + pointerB.getCurrent().y) / 2.0f;
163 Log.e(
LOGTAG,
"No gesture taking place in getFocusY()!");
170 Log.e(
LOGTAG,
"No gesture taking place in getCurrentSpan()!");
181 Log.e(
LOGTAG,
"No gesture taking place in getPreviousSpan()!");
186 PointF
a = pointerA.
getPrevious(), b = pointerB.getPrevious();
187 if (
a ==
null || b ==
null) {
189 b = pointerB.getCurrent();
229 int id =
event.getPointerId(
index);
231 if (pointerInfo.getId() ==
id) {
277 public void populate(MotionEvent event,
int index) {
309 return "id=" +
mId +
" cur=" + currentString +
" prev=" + prevString;
310 }
catch (JSONException e) {
static JSONObject toJSON(PointF point)
static float distance(PointF point)
static Stack< PointerInfo > sPointerInfoFreeList
static PointerInfo create(MotionEvent event, int index)
void populate(MotionEvent event, int index)
A less buggy, and smoother, replacement for the built-in Android ScaleGestureDetector.
float getPreviousSpan()
Returns the second most recent distance between the two pointers.
void sendScaleGesture(EventType eventType)
boolean isInProgress()
Returns true if the scale gesture is in progress and false otherwise.
static final String LOGTAG
void onTouchStart(MotionEvent event)
PointerInfo pointerInfoForEventIndex(MotionEvent event, int index)
SimpleScaleGestureListener mListener
float getCurrentSpan()
Returns the most recent distance between the two pointers.
void onTouchMove(MotionEvent event)
float getFocusY()
Returns the Y coordinate of the focus location (the midpoint of the two fingers).
void onTouchEnd(MotionEvent event)
SimpleScaleGestureDetector(SimpleScaleGestureListener listener)
Creates a new gesture detector with the given listener.
void onTouchEvent(MotionEvent event)
Forward touch events to this function.
float getFocusX()
Returns the X coordinate of the focus location (the midpoint of the two fingers).
long getEventTime()
Returns the time of the last event related to the gesture.
int getActionIndex(MotionEvent event)
LinkedList< PointerInfo > mPointerInfo
void onScaleEnd(SimpleScaleGestureDetector detector)
boolean onScaleBegin(SimpleScaleGestureDetector detector)
boolean onScale(SimpleScaleGestureDetector detector)