1 /* 2 * Copyright (C) 2009 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 android.view.cts; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 import android.os.Handler; 22 import android.view.GestureDetector; 23 import android.view.MotionEvent; 24 import android.view.View; 25 import android.view.ViewGroup; 26 import android.view.GestureDetector.SimpleOnGestureListener; 27 import android.view.View.OnTouchListener; 28 import android.widget.Button; 29 30 public class GestureDetectorStubActivity extends Activity { 31 32 public boolean isDown; 33 public boolean isScroll; 34 public boolean isFling; 35 public boolean isSingleTapUp; 36 public boolean onShowPress; 37 public boolean onLongPress; 38 public boolean onDoubleTap; 39 public boolean onDoubleTapEvent; 40 public boolean onSingleTapConfirmed; 41 42 private GestureDetector mGestureDetector; 43 private MockOnGestureListener mOnGestureListener; 44 private Handler mHandler; 45 private View mView; 46 private Button mTop; 47 private Button mButton; 48 private ViewGroup mViewGroup; 49 50 @Override 51 protected void onCreate(Bundle savedInstanceState) { 52 super.onCreate(savedInstanceState); 53 54 mOnGestureListener = new MockOnGestureListener(); 55 mHandler = new Handler(); 56 57 mGestureDetector = new GestureDetector(this, mOnGestureListener, mHandler); 58 mGestureDetector.setOnDoubleTapListener(mOnGestureListener); 59 mView = new View(this); 60 mButton = new Button(this); 61 mTop = new Button(this); 62 mView.setOnTouchListener(new MockOnTouchListener()); 63 64 mViewGroup = new ViewGroup(this) { 65 @Override 66 protected void onLayout(boolean changed, int l, int t, int r, int b) { 67 } 68 }; 69 mViewGroup.addView(mView); 70 mViewGroup.addView(mTop); 71 mViewGroup.addView(mButton); 72 mViewGroup.setOnTouchListener(new MockOnTouchListener()); 73 setContentView(mViewGroup); 74 75 } 76 77 public View getView() { 78 return mView; 79 } 80 81 public ViewGroup getViewGroup() { 82 return mViewGroup; 83 } 84 85 public GestureDetector getGestureDetector() { 86 return mGestureDetector; 87 } 88 89 public class MockOnGestureListener extends SimpleOnGestureListener { 90 public boolean onDown(MotionEvent e) { 91 isDown = true; 92 return true; 93 } 94 95 public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { 96 isFling = true; 97 return true; 98 } 99 100 public void onLongPress(MotionEvent e) { 101 onLongPress = true; 102 } 103 104 public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { 105 isScroll = true; 106 return true; 107 } 108 109 public void onShowPress(MotionEvent e) { 110 onShowPress = true; 111 } 112 113 public boolean onSingleTapUp(MotionEvent e) { 114 isSingleTapUp = true; 115 return true; 116 } 117 118 public boolean onDoubleTap(MotionEvent e) { 119 onDoubleTap = true; 120 return false; 121 } 122 123 public boolean onDoubleTapEvent(MotionEvent e) { 124 onDoubleTapEvent = true; 125 return false; 126 } 127 128 public boolean onSingleTapConfirmed(MotionEvent e) { 129 onSingleTapConfirmed = true; 130 return false; 131 } 132 } 133 134 class MockOnTouchListener implements OnTouchListener { 135 136 public boolean onTouch(View v, MotionEvent event) { 137 mGestureDetector.onTouchEvent(event); 138 return true; 139 } 140 } 141 142 } 143