blob: 98444b3d654260ed9e281d5849e7fbc507c3e6ae [file] [log] [blame]
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.view.cts;
import android.graphics.Rect;
import android.test.InstrumentationTestCase;
import android.test.TouchUtils;
import android.view.View;
import android.view.Window;
class GestureDetectorTestUtil {
/**
* Test GestureDetector.SimpleOnGestureListener
* @param testcase InstrumentationTestCase
* @param activity GestureDetectorStubActivity
*/
public static void testGestureDetector(InstrumentationTestCase testcase,
GestureDetectorStubActivity activity) {
// wait for launching view complete
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
View view = activity.getView();
TouchUtils.clickView(testcase, view);
TouchUtils.longClickView(testcase, view);
TouchUtils.scrollToBottom(testcase, activity, activity.getViewGroup());
TouchUtils.touchAndCancelView(testcase, view);
Rect windowRect = new Rect();
Window window = activity.getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(windowRect);
int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int statusBarHeight = contentViewTop - windowRect.top;
int fromX = 1;
int toX = 10;
// Y has to be outside the status bar bounding box
int fromY = statusBarHeight + 1;
int toY = statusBarHeight + 51;
int stepCount = 20;
TouchUtils.drag(testcase, fromX, toX, fromY, toY, stepCount);
InstrumentationTestCase.assertTrue(activity.isDown);
InstrumentationTestCase.assertTrue(activity.isScroll);
InstrumentationTestCase.assertTrue(activity.isFling);
InstrumentationTestCase.assertTrue(activity.isSingleTapUp);
InstrumentationTestCase.assertTrue(activity.onLongPress);
InstrumentationTestCase.assertTrue(activity.onShowPress);
InstrumentationTestCase.assertTrue(activity.onSingleTapConfirmed);
// Test onDoubleTap
InstrumentationTestCase.assertFalse(activity.onDoubleTap);
InstrumentationTestCase.assertFalse(activity.onDoubleTapEvent);
TouchUtils.tapView(testcase, view);
TouchUtils.tapView(testcase, view);
InstrumentationTestCase.assertTrue(activity.onDoubleTap);
InstrumentationTestCase.assertTrue(activity.onDoubleTapEvent);
}
}