1/*
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.support.design.testutils;
18
19import android.support.test.espresso.action.CoordinatesProvider;
20import android.support.test.espresso.action.GeneralSwipeAction;
21import android.support.test.espresso.action.Press;
22import android.support.test.espresso.action.Swipe;
23import android.view.View;
24
25public class SwipeUtils {
26
27    public static GeneralSwipeAction swipeUp(final int swipeX,
28            final int swipeStartY, final int swipeAmountY) {
29        return new GeneralSwipeAction(
30                Swipe.SLOW,
31                new CoordinatesProvider() {
32                    @Override
33                    public float[] calculateCoordinates(View view) {
34                        return new float[] { swipeX, swipeStartY };
35                    }
36                },
37                new CoordinatesProvider() {
38                    @Override
39                    public float[] calculateCoordinates(View view) {
40                        return new float[] { swipeX, swipeStartY - swipeAmountY };
41                    }
42                },
43                Press.FINGER
44        );
45    }
46
47    public static GeneralSwipeAction swipeDown(final int swipeX,
48            final int swipeStartY, final int swipeAmountY) {
49        return new GeneralSwipeAction(
50                Swipe.SLOW,
51                new CoordinatesProvider() {
52                    @Override
53                    public float[] calculateCoordinates(View view) {
54                        return new float[] { swipeX, swipeStartY };
55                    }
56                },
57                new CoordinatesProvider() {
58                    @Override
59                    public float[] calculateCoordinates(View view) {
60                        return new float[] { swipeX, swipeStartY + swipeAmountY };
61                    }
62                },
63                Press.FINGER
64        );
65    }
66
67
68}
69