use of android.view.MotionEvent.PointerProperties in project robotium by RobotiumTech.
the class Zoomer method generateZoomGesture.
public void generateZoomGesture(PointF startPoint1, PointF startPoint2, PointF endPoint1, PointF endPoint2) {
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis();
float startX1 = startPoint1.x;
float startY1 = startPoint1.y;
float startX2 = startPoint2.x;
float startY2 = startPoint2.y;
float endX1 = endPoint1.x;
float endY1 = endPoint1.y;
float endX2 = endPoint2.x;
float endY2 = endPoint2.y;
//pointer 1
float x1 = startX1;
float y1 = startY1;
//pointer 2
float x2 = startX2;
float y2 = startY2;
PointerCoords[] pointerCoords = new PointerCoords[2];
PointerCoords pc1 = new PointerCoords();
PointerCoords pc2 = new PointerCoords();
pc1.x = x1;
pc1.y = y1;
pc1.pressure = 1;
pc1.size = 1;
pc2.x = x2;
pc2.y = y2;
pc2.pressure = 1;
pc2.size = 1;
pointerCoords[0] = pc1;
pointerCoords[1] = pc2;
PointerProperties[] pointerProperties = new PointerProperties[2];
PointerProperties pp1 = new PointerProperties();
PointerProperties pp2 = new PointerProperties();
pp1.id = 0;
pp1.toolType = MotionEvent.TOOL_TYPE_FINGER;
pp2.id = 1;
pp2.toolType = MotionEvent.TOOL_TYPE_FINGER;
pointerProperties[0] = pp1;
pointerProperties[1] = pp2;
MotionEvent event;
// send the initial touches
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, 1, pointerProperties, pointerCoords, // metaState, buttonState
0, // metaState, buttonState
0, // x precision
1, // y precision
1, 0, 0, 0, // deviceId, edgeFlags, source, flags
0);
_instrument.sendPointerSync(event);
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_POINTER_DOWN + (pp2.id << MotionEvent.ACTION_POINTER_INDEX_SHIFT), 2, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, 0, 0);
_instrument.sendPointerSync(event);
int numMoves = GESTURE_DURATION_MS / EVENT_TIME_INTERVAL_MS;
float stepX1 = (endX1 - startX1) / numMoves;
float stepY1 = (endY1 - startY1) / numMoves;
float stepX2 = (endX2 - startX2) / numMoves;
float stepY2 = (endY2 - startY2) / numMoves;
// send the zoom
for (int i = 0; i < numMoves; i++) {
eventTime += EVENT_TIME_INTERVAL_MS;
pointerCoords[0].x += stepX1;
pointerCoords[0].y += stepY1;
pointerCoords[1].x += stepX2;
pointerCoords[1].y += stepY2;
event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_MOVE, 2, pointerProperties, pointerCoords, 0, 0, 1, 1, 0, 0, 0, 0);
_instrument.sendPointerSync(event);
}
}
use of android.view.MotionEvent.PointerProperties in project android_frameworks_base by ResurrectionRemix.
the class DocumentHolderTest method createEvent.
public MotionEvent createEvent(int tooltype) {
long time = SystemClock.uptimeMillis();
PointerProperties[] properties = new PointerProperties[] { new PointerProperties() };
properties[0].toolType = tooltype;
PointerCoords[] coords = new PointerCoords[] { new PointerCoords() };
Rect rect = new Rect();
mHolder.itemView.getHitRect(rect);
coords[0].x = rect.left;
coords[0].y = rect.top;
return MotionEvent.obtain(// down time
time, // event time
time, // action
MotionEvent.ACTION_UP, // pointer count
1, // pointer properties
properties, // pointer coords
coords, // metastate
0, // button state
0, // xprecision
0, // yprecision
0, // deviceid
0, // edgeflags
0, // source
0, // flags
0);
}
use of android.view.MotionEvent.PointerProperties in project android_frameworks_base by ResurrectionRemix.
the class TouchExplorer method offsetEvent.
/**
* Offsets all pointers in the given event by adding the specified X and Y
* offsets.
*
* @param event The event to offset.
* @param offsetX The X offset.
* @param offsetY The Y offset.
* @return An event with the offset pointers or the original event if both
* offsets are zero.
*/
private MotionEvent offsetEvent(MotionEvent event, int offsetX, int offsetY) {
if (offsetX == 0 && offsetY == 0) {
return event;
}
final int remappedIndex = event.findPointerIndex(mLongPressingPointerId);
final int pointerCount = event.getPointerCount();
PointerProperties[] props = PointerProperties.createArray(pointerCount);
PointerCoords[] coords = PointerCoords.createArray(pointerCount);
for (int i = 0; i < pointerCount; i++) {
event.getPointerProperties(i, props[i]);
event.getPointerCoords(i, coords[i]);
if (i == remappedIndex) {
coords[i].x += offsetX;
coords[i].y += offsetY;
}
}
return MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event.getAction(), event.getPointerCount(), props, coords, event.getMetaState(), event.getButtonState(), 1.0f, 1.0f, event.getDeviceId(), event.getEdgeFlags(), event.getSource(), event.getFlags());
}
use of android.view.MotionEvent.PointerProperties in project android_frameworks_base by ResurrectionRemix.
the class TouchExplorer method onDoubleTap.
@Override
public boolean onDoubleTap(MotionEvent event, int policyFlags) {
// Ignore the event if we aren't touch exploring.
if (mCurrentState != STATE_TOUCH_EXPLORING) {
return false;
}
// Remove pending event deliveries.
mSendHoverEnterAndMoveDelayed.cancel();
mSendHoverExitDelayed.cancel();
if (mSendTouchExplorationEndDelayed.isPending()) {
mSendTouchExplorationEndDelayed.forceSendAndRemove();
}
if (mSendTouchInteractionEndDelayed.isPending()) {
mSendTouchInteractionEndDelayed.forceSendAndRemove();
}
final int pointerIndex = event.getActionIndex();
final int pointerId = event.getPointerId(pointerIndex);
Point clickLocation = mTempPoint;
final int result = computeClickLocation(clickLocation);
if (result == CLICK_LOCATION_NONE) {
// consumed.
return true;
}
// Do the click.
PointerProperties[] properties = new PointerProperties[1];
properties[0] = new PointerProperties();
event.getPointerProperties(pointerIndex, properties[0]);
PointerCoords[] coords = new PointerCoords[1];
coords[0] = new PointerCoords();
coords[0].x = clickLocation.x;
coords[0].y = clickLocation.y;
MotionEvent click_event = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), MotionEvent.ACTION_DOWN, 1, properties, coords, 0, 0, 1.0f, 1.0f, event.getDeviceId(), 0, event.getSource(), event.getFlags());
final boolean targetAccessibilityFocus = (result == CLICK_LOCATION_ACCESSIBILITY_FOCUS);
sendActionDownAndUp(click_event, policyFlags, targetAccessibilityFocus);
click_event.recycle();
return true;
}
use of android.view.MotionEvent.PointerProperties in project android_frameworks_base by ResurrectionRemix.
the class InteractionController method performMultiPointerGesture.
/**
* Performs a multi-touch gesture
*
* Takes a series of touch coordinates for at least 2 pointers. Each pointer must have
* all of its touch steps defined in an array of {@link PointerCoords}. By having the ability
* to specify the touch points along the path of a pointer, the caller is able to specify
* complex gestures like circles, irregular shapes etc, where each pointer may take a
* different path.
*
* To create a single point on a pointer's touch path
* <code>
* PointerCoords p = new PointerCoords();
* p.x = stepX;
* p.y = stepY;
* p.pressure = 1;
* p.size = 1;
* </code>
* @param touches each array of {@link PointerCoords} constitute a single pointer's touch path.
* Multiple {@link PointerCoords} arrays constitute multiple pointers, each with its own
* path. Each {@link PointerCoords} in an array constitute a point on a pointer's path.
* @return <code>true</code> if all points on all paths are injected successfully, <code>false
* </code>otherwise
* @since API Level 18
*/
public boolean performMultiPointerGesture(PointerCoords[]... touches) {
boolean ret = true;
if (touches.length < 2) {
throw new IllegalArgumentException("Must provide coordinates for at least 2 pointers");
}
// Get the pointer with the max steps to inject.
int maxSteps = 0;
for (int x = 0; x < touches.length; x++) maxSteps = (maxSteps < touches[x].length) ? touches[x].length : maxSteps;
// specify the properties for each pointer as finger touch
PointerProperties[] properties = new PointerProperties[touches.length];
PointerCoords[] pointerCoords = new PointerCoords[touches.length];
for (int x = 0; x < touches.length; x++) {
PointerProperties prop = new PointerProperties();
prop.id = x;
prop.toolType = MotionEvent.TOOL_TYPE_FINGER;
properties[x] = prop;
// for each pointer set the first coordinates for touch down
pointerCoords[x] = touches[x][0];
}
// Touch down all pointers
long downTime = SystemClock.uptimeMillis();
MotionEvent event;
event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_DOWN, 1, properties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
ret &= injectEventSync(event);
for (int x = 1; x < touches.length; x++) {
event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), getPointerAction(MotionEvent.ACTION_POINTER_DOWN, x), x + 1, properties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
ret &= injectEventSync(event);
}
// Move all pointers
for (int i = 1; i < maxSteps - 1; i++) {
// for each pointer
for (int x = 0; x < touches.length; x++) {
// check if it has coordinates to move
if (touches[x].length > i)
pointerCoords[x] = touches[x][i];
else
pointerCoords[x] = touches[x][touches[x].length - 1];
}
event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_MOVE, touches.length, properties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
ret &= injectEventSync(event);
SystemClock.sleep(MOTION_EVENT_INJECTION_DELAY_MILLIS);
}
// For each pointer get the last coordinates
for (int x = 0; x < touches.length; x++) pointerCoords[x] = touches[x][touches[x].length - 1];
// touch up
for (int x = 1; x < touches.length; x++) {
event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), getPointerAction(MotionEvent.ACTION_POINTER_UP, x), x + 1, properties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
ret &= injectEventSync(event);
}
Log.i(LOG_TAG, "x " + pointerCoords[0].x);
// first to touch down is last up
event = MotionEvent.obtain(downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, 1, properties, pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN, 0);
ret &= injectEventSync(event);
return ret;
}
Aggregations