Reputation: 615
I want to automate the touch events like ontouch and double tap.
long downTime = SystemClock.uptimeMillis();
long eventTime = SystemClock.uptimeMillis() + 100;
this.getWindow().getDecorView().dispatchTouchEvent(getMotionEvent(downTime, eventTime, MotionEvent.ACTION_DOWN));
.
public static MotionEvent getMotionEvent(long downTime,long eventTime,int eventType){
float x = 0.0f;
float y = 0.0f;
// List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
int metaState = 0;
MotionEvent motionEvent = MotionEvent.obtain(
downTime,
eventTime,
eventType,
x,
y,
metaState
);
return motionEvent;
}
. It is working fine and when I called this in background service this is what I got
{ action=ACTION_DOWN, id[0]=0, x[0]=0.0, y[0]=0.0, toolType[0]=TOOL_TYPE_UNKNOWN, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=4827157, downTime=4827057, deviceId=0, source=0x0 }
ToolType is TOOL_TYPE_UNKNOWN . I want to set it to TOOL_TYPE_FINGER . I have gone thourgh widgetevent.java file i fount getToolType method but there is
no setToolType method . My question is Is it possible to set the tooltype if so how?
Remove - unwanted code formatter
Upvotes: 3
Views: 653
Reputation: 615
I found the answer myself. There is no direct method to update or change tooltype.But we can make one of the obtain to get motionevent object with desired tooltype.
public static MotionEvent obtain (long downTime, long eventTime, int action, int pointerCount, PointerProperties[] pointerProperties, PointerCoords[] pointerCoords, int metaState, int buttonState, float xPrecision, float yPrecision, int deviceId, int edgeFlags, int source, int flags)
we can make use of pointerproperties to change properties of motion event object. ref.
Upvotes: 3