blob: 8bce1b09517bc56c513c6ee3c1139bdd8e64753d [file] [log] [blame]
Keisuke Kuroyanagi5f318b62016-04-01 19:16:31 +09001/*
2 * Copyright (C) 2016 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
17package android.widget.espresso;
18
19import org.hamcrest.Matcher;
20
21import android.support.test.espresso.UiController;
22import android.support.test.espresso.ViewAction;
23import android.support.test.espresso.action.CoordinatesProvider;
24import android.support.test.espresso.action.GeneralClickAction;
25import android.support.test.espresso.action.PrecisionDescriber;
26import android.support.test.espresso.action.Tapper;
27import android.view.View;
28import android.view.ViewConfiguration;
29
30public final class ViewClickAction implements ViewAction {
31 private final GeneralClickAction mGeneralClickAction;
32
33 public ViewClickAction(Tapper tapper, CoordinatesProvider coordinatesProvider,
34 PrecisionDescriber precisionDescriber) {
35 mGeneralClickAction = new GeneralClickAction(tapper, coordinatesProvider,
36 precisionDescriber);
37 }
38
39 @Override
40 public Matcher<View> getConstraints() {
41 return mGeneralClickAction.getConstraints();
42 }
43
44 @Override
45 public String getDescription() {
46 return mGeneralClickAction.getDescription();
47 }
48
49 @Override
50 public void perform(UiController uiController, View view) {
51 mGeneralClickAction.perform(uiController, view);
52 long doubleTapTimeout = ViewConfiguration.getDoubleTapTimeout();
53 if (0 < doubleTapTimeout) {
54 // Wait to avoid false gesture detection. Without this wait, consecutive clicks can be
55 // detected as a double click or triple click. e.g. 2 double clicks on TextView are
56 // detected as a triple click and a single click because espresso isn't aware of
57 // TextView specific gestures.
58 uiController.loopMainThreadForAtLeast(doubleTapTimeout);
59 }
60 }
61}