Детектор жестов работает не так, как ожидалось

Я пытаюсь использовать детектор жестов, найденный здесь: /questions/87999/obnaruzhenie-zhestov-na-makete-setki/88017#88017 Это мой код:

public class FullScreenGallery extends Activity {
int plane;
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private GestureDetector gestureDetector;
View.OnTouchListener gestureListener;
ImageView image;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);    //To change body of overridden methods use File | Settings | File Templates.
    setContentView(R.layout.full_screengallery);
    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);

    final ImageView image = (ImageView) findViewById(R.id.imagePlane);
    plane = sp.getInt("PLANE",0);
    // Gesture detection
    gestureDetector = new GestureDetector(this, new MyGestureDetector());
    gestureListener = new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            return gestureDetector.onTouchEvent(event);
        }
    };

    image.setOnTouchListener(gestureListener);
    Context context = this;



    }


}

class MyGestureDetector extends GestureDetector.SimpleOnGestureListener {
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        try {
            if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
                return false;
            // right to left swipe
            if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {

                Toast.makeText(FullScreenGallery.this, "Left Swipe", Toast.LENGTH_SHORT).show();
                Log.d("NICK", "Left Swipe");
        switch(X){
        case 0:
            Log.d("NICK", "Left Swipe,1");
        break;

                }
            }  else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
                Toast.makeText(FullScreenGallery.this, "Right Swipe", Toast.LENGTH_SHORT).show();
                Log.d("NICK", "Right Swipe");
                switch(X){
        case 0:
            Log.d("NICK", "Right Swipe,1");
        break;
                }
            }
        } catch (Exception e) {
            // nothing
            Log.d("NICK", "Exception");
        }
        return false;
    }

    @Override
    public boolean onDown(MotionEvent e) {
        return true;    //To change body of overridden methods use File | Settings | File Templates.
    }
}

и мой вывод журнала при запуске:

01-02 16:02:28.059: DEBUG/NICK(454): Left Swipe
01-02 16:02:28.059: DEBUG/NICK(454): Left Swipe, 1
01-02 16:02:28.069: DEBUG/NICK(454): Exception
01-02 16:02:50.500: DEBUG/NICK(454): Left Swipe
01-02 16:02:50.500: DEBUG/NICK(454): Exception
01-02 16:02:52.362: DEBUG/NICK(454): Left Swipe
01-02 16:02:52.362: DEBUG/NICK(454): Exception
01-02 16:02:53.593: DEBUG/NICK(454): Right Swipe
01-02 16:02:53.593: DEBUG/NICK(454): Exception
01-02 16:02:54.715: DEBUG/NICK(454): Right Swipe
01-02 16:02:54.715: DEBUG/NICK(454): Exception
01-02 16:02:55.625: DEBUG/NICK(454): Right Swipe
01-02 16:02:55.625: DEBUG/NICK(454): Exception
01-02 16:02:56.336: DEBUG/NICK(454): Right Swipe
01-02 16:02:56.336: DEBUG/NICK(454): Right Swipe,1
01-02 16:02:56.336: DEBUG/NICK(454): Exception
01-02 16:02:57.177: DEBUG/NICK(454): Right Swipe
01-02 16:02:58.088: DEBUG/NICK(454): Right Swipe
01-02 16:02:58.959: DEBUG/NICK(454): Right Swipe

Итак, я понимаю, что получаю исключение, но я не знаю, почему или как это исправить, чтобы я мог что-то сделать по смахиванию, кроме простого тоста. Любые предложения о том, что может вызвать это?

0 ответов

Другие вопросы по тегам