to top
BasicGestureDetect / src / com.example.android.basicgesturedetect /

GestureListener.java

1
/*
2
 * Copyright 2013 The Android Open Source Project
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
 
17
package com.example.android.basicgesturedetect;
18
 
19
import android.view.GestureDetector;
20
import android.view.MotionEvent;
21
 
22
import com.example.android.common.logger.Log;
23
 
24
public class GestureListener extends GestureDetector.SimpleOnGestureListener {
25
 
26
    public static final String TAG = "GestureListener";
27
 
29
    @Override
30
    public boolean onSingleTapUp(MotionEvent e) {
31
        // Up motion completing a single tap occurred.
32
        Log.i(TAG, "Single Tap Up");
33
        return false;
34
    }
35
 
36
    @Override
37
    public void onLongPress(MotionEvent e) {
38
        // Touch has been long enough to indicate a long press.
39
        // Does not indicate motion is complete yet (no up event necessarily)
40
        Log.i(TAG, "Long Press");
41
    }
42
 
43
    @Override
44
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
45
    float distanceY) {
46
        // User attempted to scroll
47
        Log.i(TAG, "Scroll");
48
        return false;
49
    }
50
 
51
    @Override
52
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
53
    float velocityY) {
54
        // Fling event occurred.  Notification of this one happens after an "up" event.
55
        Log.i(TAG, "Fling");
56
        return false;
57
    }
58
 
59
    @Override
60
    public void onShowPress(MotionEvent e) {
61
        // User performed a down event, and hasn't moved yet.
62
        Log.i(TAG, "Show Press");
63
    }
64
 
65
    @Override
66
    public boolean onDown(MotionEvent e) {
67
        // "Down" event - User touched the screen.
68
        Log.i(TAG, "Down");
69
        return false;
70
    }
71
 
72
    @Override
73
    public boolean onDoubleTap(MotionEvent e) {
74
        // User tapped the screen twice.
75
        Log.i(TAG, "Double tap");
76
        return false;
77
    }
78
 
79
    @Override
80
    public boolean onDoubleTapEvent(MotionEvent e) {
81
        // Since double-tap is actually several events which are considered one aggregate
82
        // gesture, there's a separate callback for an individual event within the doubletap
83
        // occurring.  This occurs for down, up, and move.
84
        Log.i(TAG, "Event within double tap");
85
        return false;
86
    }
87
 
88
    @Override
89
    public boolean onSingleTapConfirmed(MotionEvent e) {
90
        // A confirmed single-tap event has occurred.  Only called when the detector has
91
        // determined that the first tap stands alone, and is not part of a double tap.
92
        Log.i(TAG, "Single tap confirmed");
93
        return false;
94
    }
96
}