1

プログラムでジェスチャをシミュレートするにはどうすればよいですか。

私はすべてのポイントを取得し、アプリにこれらの描画を繰り返してもらいたいと考えています。

public void onGestureStarted(GestureOverlayView gestureOverlayView, MotionEvent motionEvent) {
            Log.d("TAG", "Started gesture: \n" + motionEvent.getRawX() + "\n" +
                    motionEvent.getRawY() + "\n" + motionEvent.getEventTime());

            gestures.add(new GesturePoint(motionEvent.getRawX(), motionEvent.getRawY(), 100));
        }

        @Override
        public void onGesture(GestureOverlayView gestureOverlayView, MotionEvent motionEvent) {
            //To change body of implemented methods use File | Settings | File Templates.
            gestures.add(new GesturePoint(motionEvent.getRawX(), motionEvent.getRawY(), 100));
            Log.e("TAG", "gesture: \n" + motionEvent.getRawX() + "\n" +
                    motionEvent.getRawY() + "\n" + motionEvent.getEventTime());
        }

        @Override
        public void onGestureEnded(GestureOverlayView gestureOverlayView, MotionEvent motionEvent) {
            gestures.add(new GesturePoint(motionEvent.getRawX(), motionEvent.getRawY(), 100));

            Log.d("TAG", "Ended gesture: \n" + motionEvent.getRawX() + "\n" +
                    motionEvent.getRawY() + "\n" + motionEvent.getEventTime());

            g.addStroke(new GestureStroke(gestures));
            gestureOverlayView.setGesture(g);

startDraw(Arraylist) のような方法はありますか?

ユーザーの操作をシミュレートするために必要です。

4

1 に答える 1

2

MotionEventクラスを使用できます。簡単な使用:

MotionEvent emulateActionDown = MotionEvent.obtain
(
    // The time (in ms) when the user originally pressed down to start a stream of position events. 
    // This must be obtained from uptimeMillis().
    SystemClock.uptimeMillis(),
    // The the time (in ms) when this specific event was generated. 
    // This must be obtained from uptimeMillis().
    SystemClock.uptimeMillis()+20,
    // The kind of action being performed, such as ACTION_DOWN.
    MotionEvent.ACTION_DOWN, 
    // The X coordinate of this event.
    1, 
    // The Y coordinate of this event.
    1, 
    // The state of any meta / modifier keys that were in effect when the event was generated. 
    0
)

例は、単純な ACTION_DOWN エミュレーションを示しています。次に、このイベントを View のonTouchEventメソッドに渡すことができます。

myView.onTouchEvent(emulateActionDown);

ここを見てください: MotionEvent -> 取得

于 2013-05-10T16:20:04.603 に答える