最終更新:2013-03-25 (月) 14:00:51 (4043d)  

android.view.GestureDetector
Top / android.view.GestureDetector

public class GestureDetector

ViewonTouchEventを委譲することにより、より抽象度の高い、ジェスチャを捕捉することができるようになる

http://developer.android.com/reference/android/view/GestureDetector.html

継承

概要

  • Detects various gestures and events using the supplied MotionEvents. The GestureDetector.OnGestureListener callback will notify users when a particular motion event has occurred. This class should only be used with MotionEvents reported via touch (don't use for trackball events).

使い方

  • アクティビティ
    public class TestGesture extends Activity implements
    	GestureDetector.OnGestureListener,		// 長押し(onLongPress)のイベントが取得できます。
    	GestureDetector.OnDoubleTapListener		// ダブルタップのイベントが取得できます。
    	{
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    	    this.gestureDetector = new GestureDetector(this, this);
    	}
    
    	/**
    	 * タッチイベント
    	 */
    	@Override
    	public boolean onTouchEvent(MotionEvent event) {
    	    // Activityのタッチイベント中でGestureDetectorのイベントを呼び出す
    	    // 長押しやダブルタップ等はGestureDetector内で判定されて、
    	    // GestureDetectorに登録したリスナー(このクラス)に処理が振り分けられる
    	    // if文で戻り値を判定することで、GestureDetectorで処理した後、
    	    // 通常のonTouchEventをそのまま継続するかどうかを選択できる
    	    if(this.gestureDetector.onTouchEvent(event)) return true;
    
    	    return super.onTouchEvent(event);
    	}
    	...
    }

メソッド

  • GestureDetector.isLongpressEnabled?()
  • GestureDetector.onTouchEvent(MotionEvent ev) Analyzes the given motion event and if applicable triggers the appropriate callbacks on the GestureDetector.OnGestureListener supplied.
  • GestureDetector.setIsLongpressEnabled?(boolean isLongpressEnabled?) Set whether longpress is enabled, if this is enabled when a user presses and holds down you get a longpress event and nothing further.
  • GestureDetector.setOnDoubleTapListener?(GestureDetector.OnDoubleTapListener? onDoubleTapListener?) Sets the listener which will be called for double-tap and related gestures.

ネストされたクラス

インターフェイス

GestureDetector.OnDoubleTapListener?

  • OnDoubleTapListener.onDoubleTap?(MotionEvent e) - Notified when a double-tap occurs.
  • OnDoubleTapListener.onDoubleTapEvent?(MotionEvent e) - Notified when an event within a double-tap gesture occurs, including the down, move, and up events.
  • OnDoubleTapListener.onSingleTapConfirmed?(MotionEvent e) - Notified when a single-tap occurs.

GestureDetector.OnGestureListener

クラス

GestureDetector.SimpleOnGestureListener

  • SimpleOnGestureListener.onDoubleTap?(MotionEvent e) - Notified when a double-tap occurs.
  • SimpleOnGestureListener.onDoubleTapEvent?(MotionEvent e) - Notified when an event within a double-tap gesture occurs, including the down, move, and up events.
  • SimpleOnGestureListener.onDown?(MotionEvent e) - Notified when a tap occurs with the down MotionEvent that triggered it.
  • SimpleOnGestureListener.onFling?(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) - Notified of a fling event when it occurs with the initial on down MotionEvent and the matching up MotionEvent.
  • SimpleOnGestureListener.onLongPress?(MotionEvent e) - Notified when a long press occurs with the initial on down MotionEvent that trigged it.
  • SimpleOnGestureListener.onScroll?(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) - Notified when a scroll occurs with the initial on down MotionEvent and the current move MotionEvent.
  • SimpleOnGestureListener.onShowPress?(MotionEvent e) - The user has performed a down MotionEvent and not performed a move or up yet.
  • SimpleOnGestureListener.onSingleTapConfirmed?(MotionEvent e) - Notified when a single-tap occurs.
  • SimpleOnGestureListener.onSingleTapUp?(MotionEvent e) - Notified when a tap occurs with the up MotionEvent that triggered it.

関連

参考