首页 > 其他 > 详细

Send MotionEvent event

时间:2017-01-24 04:21:44      阅读:388      评论:0      收藏:0      [点我收藏+]
EventCode
public static final int ACTION_DOWN             = 0;
public static final int ACTION_UP               = 1;
public static final int ACTION_MOVE             = 2;

Touch

MotionEvent event = MotionEvent.obtain(downTime, eventTime, 0, (float) x, (float) y, 0);  //dowm
inst.sendPointerSync(MotionEvent.obtain(300 + downTime, 300 + eventTime, 1, (float) x, (float) y, 0)); //up

Swipe

   xStep = (double)(upX - downX) / (double)swipeSteps;
        yStep = (double)(upY - downY) / (double)swipeSteps;
        ret = this.touchDown(downX, downY);
        if(drag) {
            SystemClock.sleep(this.mUiAutomatorBridge.getSystemLongPressTime());
        }

        for(int i = 1; i < swipeSteps; ++i) {
            ret &= this.touchMove(downX + (int)(xStep * (double)i), downY + (int)(yStep * (double)i));
            if(!ret) {
                break;
            }

            SystemClock.sleep(5L);
        }

        if(drag) {
            SystemClock.sleep(100L);
        }

        ret &= this.touchUp(upX, upY);
pinchOpen
  private static MotionEvent getMotionEvent(long downTime, long eventTime, int action, List<PointerProperties> properties, List<PointerCoords> coordinates) {
        PointerProperties[] props = (PointerProperties[])properties.toArray(new PointerProperties[properties.size()]);
        PointerCoords[] coords = (PointerCoords[])coordinates.toArray(new PointerCoords[coordinates.size()]);
        return MotionEvent.obtain(downTime, eventTime, action, props.length, props, coords, 0, 0, 1.0F, 1.0F, 0, 0, 4098, 0);
    }

 

Send Event

1.Instrumentation

Instrumentation inst = new Instrumentation();
nst.sendPointerSync

2.Uiautomation

mUiAutomation.injectInputEvent

3.IWindowManager

IWindowManager.Stub.asInterface(ServiceManager.getService("window"));

4.InputManager

MotionEvent me = getEvent();
InputManager.getInstance().injectInputEvent(me, 1)

 



Send MotionEvent event

原文:http://www.cnblogs.com/season-xie/p/6345320.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!