Methods Summary |
---|
public final void | addBatch(long eventTime, float x, float y, float pressure, float size, int metaState)Add a new movement to the batch of movements in this event. The event's
current location, position and size is updated to the new values. In
the future, the current values in the event will be added to a list of
historic values.
float[] history = mHistory;
long[] historyTimes = mHistoryTimes;
int N;
int avail;
if (history == null) {
mHistory = history = new float[8*4];
mHistoryTimes = historyTimes = new long[8];
mNumHistory = N = 0;
avail = 8;
} else {
N = mNumHistory;
avail = history.length/4;
if (N == avail) {
avail += 8;
float[] newHistory = new float[avail*4];
System.arraycopy(history, 0, newHistory, 0, N*4);
mHistory = history = newHistory;
long[] newHistoryTimes = new long[avail];
System.arraycopy(historyTimes, 0, newHistoryTimes, 0, N);
mHistoryTimes = historyTimes = newHistoryTimes;
}
}
historyTimes[N] = mEventTime;
final int pos = N*4;
history[pos] = mX;
history[pos+1] = mY;
history[pos+2] = mPressure;
history[pos+3] = mSize;
mNumHistory = N+1;
mEventTime = eventTime;
mX = mRawX = x;
mY = mRawY = y;
mPressure = pressure;
mSize = size;
mMetaState |= metaState;
|
public int | describeContents()
return 0;
|
public final int | getAction()Return the kind of action being performed -- one of either
{@link #ACTION_DOWN}, {@link #ACTION_MOVE}, {@link #ACTION_UP}, or
{@link #ACTION_CANCEL}.
return mAction;
|
public final int | getDeviceId()Return the id for the device that this event came from. An id of
zero indicates that the event didn't come from a physical device; other
numbers are arbitrary and you shouldn't depend on the values.
return mDeviceId;
|
public final long | getDownTime()Returns the time (in ms) when the user originally pressed down to start
a stream of position events.
return mDownTime;
|
public final int | getEdgeFlags()Returns a bitfield indicating which edges, if any, where touched by this
MotionEvent. For touch events, clients can use this to determine if the
user's finger was touching the edge of the display.
return mEdgeFlags;
|
public final long | getEventTime()Returns the time (in ms) when this specific event was generated.
return mEventTime;
|
public final long | getHistoricalEventTime(int pos)Returns the time that a historical movement occurred between this event
and the previous event. Only applies to ACTION_MOVE events.
return mHistoryTimes[pos];
|
public final float | getHistoricalPressure(int pos)Returns a historical pressure coordinate that occurred between this event
and the previous event. Only applies to ACTION_MOVE events.
return mHistory[pos*4 + 2];
|
public final float | getHistoricalSize(int pos)Returns a historical size coordinate that occurred between this event
and the previous event. Only applies to ACTION_MOVE events.
return mHistory[pos*4 + 3];
|
public final float | getHistoricalX(int pos)Returns a historical X coordinate that occurred between this event
and the previous event. Only applies to ACTION_MOVE events.
return mHistory[pos*4];
|
public final float | getHistoricalY(int pos)Returns a historical Y coordinate that occurred between this event
and the previous event. Only applies to ACTION_MOVE events.
return mHistory[pos*4 + 1];
|
public final int | getHistorySize()Returns the number of historical points in this event. These are
movements that have occurred between this event and the previous event.
This only applies to ACTION_MOVE events -- all other actions will have
a size of 0.
return mNumHistory;
|
public final int | getMetaState()Returns the state of any meta / modifier keys that were in effect when
the event was generated. This is the same values as those
returned by {@link KeyEvent#getMetaState() KeyEvent.getMetaState}.
return mMetaState;
|
public final float | getPressure()Returns the current pressure of this event. The pressure generally
ranges from 0 (no pressure at all) to 1 (normal pressure), however
values higher than 1 may be generated depending on the calibration of
the input device.
return mPressure;
|
public final float | getRawX()Returns the original raw X coordinate of this event. For touch
events on the screen, this is the original location of the event
on the screen, before it had been adjusted for the containing window
and views.
return mRawX;
|
public final float | getRawY()Returns the original raw Y coordinate of this event. For touch
events on the screen, this is the original location of the event
on the screen, before it had been adjusted for the containing window
and views.
return mRawY;
|
public final float | getSize()Returns a scaled value of the approximate size, of the area being pressed when
touched with the finger. The actual value in pixels corresponding to the finger
touch is normalized with the device specific range of values
and scaled to a value between 0 and 1. The value of size can be used to
determine fat touch events.
return mSize;
|
public final float | getX()Returns the X coordinate of this event. Whole numbers are pixels; the
value may have a fraction for input devices that are sub-pixel precise.
return mX;
|
public final float | getXPrecision()Return the precision of the X coordinates being reported. You can
multiple this number with {@link #getX} to find the actual hardware
value of the X coordinate.
return mXPrecision;
|
public final float | getY()Returns the Y coordinate of this event. Whole numbers are pixels; the
value may have a fraction for input devices that are sub-pixel precise.
return mY;
|
public final float | getYPrecision()Return the precision of the Y coordinates being reported. You can
multiple this number with {@link #getY} to find the actual hardware
value of the Y coordinate.
return mYPrecision;
|
private static android.view.MotionEvent | obtain()
synchronized (gRecyclerLock) {
if (gRecyclerTop == null) {
return new MotionEvent();
}
MotionEvent ev = gRecyclerTop;
gRecyclerTop = ev.mNext;
gRecyclerUsed--;
ev.mRecycledLocation = null;
ev.mRecycled = false;
return ev;
}
|
public static android.view.MotionEvent | obtain(long downTime, long eventTime, int action, float x, float y, float pressure, float size, int metaState, float xPrecision, float yPrecision, int deviceId, int edgeFlags)Create a new MotionEvent, filling in all of the basic values that
define the motion.
MotionEvent ev = obtain();
ev.mDeviceId = deviceId;
ev.mEdgeFlags = edgeFlags;
ev.mDownTime = downTime;
ev.mEventTime = eventTime;
ev.mAction = action;
ev.mX = ev.mRawX = x;
ev.mY = ev.mRawY = y;
ev.mPressure = pressure;
ev.mSize = size;
ev.mMetaState = metaState;
ev.mXPrecision = xPrecision;
ev.mYPrecision = yPrecision;
return ev;
|
public static android.view.MotionEvent | obtain(long downTime, long eventTime, int action, float x, float y, int metaState)Create a new MotionEvent, filling in a subset of the basic motion
values. Those not specified here are: device id (always 0), pressure
and size (always 1), x and y precision (always 1), and edgeFlags (always 0).
MotionEvent ev = obtain();
ev.mDeviceId = 0;
ev.mEdgeFlags = 0;
ev.mDownTime = downTime;
ev.mEventTime = eventTime;
ev.mAction = action;
ev.mX = ev.mRawX = x;
ev.mY = ev.mRawY = y;
ev.mPressure = 1.0f;
ev.mSize = 1.0f;
ev.mMetaState = metaState;
ev.mXPrecision = 1.0f;
ev.mYPrecision = 1.0f;
return ev;
|
public static android.view.MotionEvent | obtain(android.view.MotionEvent o)Create a new MotionEvent, copying from an existing one.
MotionEvent ev = obtain();
ev.mDeviceId = o.mDeviceId;
ev.mEdgeFlags = o.mEdgeFlags;
ev.mDownTime = o.mDownTime;
ev.mEventTime = o.mEventTime;
ev.mAction = o.mAction;
ev.mX = o.mX;
ev.mRawX = o.mRawX;
ev.mY = o.mY;
ev.mRawY = o.mRawY;
ev.mPressure = o.mPressure;
ev.mSize = o.mSize;
ev.mMetaState = o.mMetaState;
ev.mXPrecision = o.mXPrecision;
ev.mYPrecision = o.mYPrecision;
final int N = o.mNumHistory;
ev.mNumHistory = N;
if (N > 0) {
// could be more efficient about this...
ev.mHistory = (float[])o.mHistory.clone();
ev.mHistoryTimes = (long[])o.mHistoryTimes.clone();
}
return ev;
|
public final void | offsetLocation(float deltaX, float deltaY)Adjust this event's location.
mX += deltaX;
mY += deltaY;
final int N = mNumHistory*4;
if (N <= 0) {
return;
}
final float[] pos = mHistory;
for (int i=0; i<N; i+=4) {
pos[i] += deltaX;
pos[i+1] += deltaY;
}
|
private void | readFromParcel(android.os.Parcel in)
mDownTime = in.readLong();
mEventTime = in.readLong();
mAction = in.readInt();
mX = in.readFloat();
mY = in.readFloat();
mPressure = in.readFloat();
mSize = in.readFloat();
mMetaState = in.readInt();
mRawX = in.readFloat();
mRawY = in.readFloat();
final int N = in.readInt();
if ((mNumHistory=N) > 0) {
final int N4 = N*4;
float[] history = mHistory;
if (history == null || history.length < N4) {
mHistory = history = new float[N4 + (4*4)];
}
for (int i=0; i<N4; i++) {
history[i] = in.readFloat();
}
long[] times = mHistoryTimes;
if (times == null || times.length < N) {
mHistoryTimes = times = new long[N + 4];
}
for (int i=0; i<N; i++) {
times[i] = in.readLong();
}
}
mXPrecision = in.readFloat();
mYPrecision = in.readFloat();
mDeviceId = in.readInt();
mEdgeFlags = in.readInt();
|
public void | recycle()Recycle the MotionEvent, to be re-used by a later caller. After calling
this function you must not ever touch the event again.
// Ensure recycle is only called once!
if (TRACK_RECYCLED_LOCATION) {
if (mRecycledLocation != null) {
throw new RuntimeException(toString() + " recycled twice!", mRecycledLocation);
}
mRecycledLocation = new RuntimeException("Last recycled here");
} else if (mRecycled) {
throw new RuntimeException(toString() + " recycled twice!");
}
//Log.w("MotionEvent", "Recycling event " + this, mRecycledLocation);
synchronized (gRecyclerLock) {
if (gRecyclerUsed < MAX_RECYCLED) {
gRecyclerUsed++;
mNumHistory = 0;
mNext = gRecyclerTop;
gRecyclerTop = this;
}
}
|
public final void | setAction(int action)Sets this event's action.
mAction = action;
|
public final void | setEdgeFlags(int flags)Sets the bitfield indicating which edges, if any, where touched by this
MotionEvent.
mEdgeFlags = flags;
|
public final void | setLocation(float x, float y)Set this event's location. Applies {@link #offsetLocation} with a
delta from the current location to the given new location.
float deltaX = x-mX;
float deltaY = y-mY;
if (deltaX != 0 || deltaY != 0) {
offsetLocation(deltaX, deltaY);
}
|
public java.lang.String | toString()
return "MotionEvent{" + Integer.toHexString(System.identityHashCode(this))
+ " action=" + mAction + " x=" + mX
+ " y=" + mY + " pressure=" + mPressure + " size=" + mSize + "}";
|
public void | writeToParcel(android.os.Parcel out, int flags)
out.writeLong(mDownTime);
out.writeLong(mEventTime);
out.writeInt(mAction);
out.writeFloat(mX);
out.writeFloat(mY);
out.writeFloat(mPressure);
out.writeFloat(mSize);
out.writeInt(mMetaState);
out.writeFloat(mRawX);
out.writeFloat(mRawY);
final int N = mNumHistory;
out.writeInt(N);
if (N > 0) {
final int N4 = N*4;
int i;
float[] history = mHistory;
for (i=0; i<N4; i++) {
out.writeFloat(history[i]);
}
long[] times = mHistoryTimes;
for (i=0; i<N; i++) {
out.writeLong(times[i]);
}
}
out.writeFloat(mXPrecision);
out.writeFloat(mYPrecision);
out.writeInt(mDeviceId);
out.writeInt(mEdgeFlags);
|