1 /*
2  * Copyright (C) 2020 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.android.server.accessibility.magnification;
18 
19 import android.annotation.IntDef;
20 import android.content.Context;
21 import android.view.ViewConfiguration;
22 
23 import com.android.internal.R;
24 import com.android.server.accessibility.gestures.GestureMatcher;
25 
26 import java.lang.annotation.Retention;
27 import java.lang.annotation.RetentionPolicy;
28 
29 /**
30  * A class to define gesture id of {@link GestureMatcher} for magnification.
31  *
32  */
33 class MagnificationGestureMatcher {
34 
35     private static final int GESTURE_BASE = 100;
36     public static final int GESTURE_TWO_FINGERS_DOWN_OR_SWIPE = GESTURE_BASE + 1;
37     public static final int GESTURE_SWIPE = GESTURE_BASE + 2;
38     public static final int GESTURE_SINGLE_TAP = GESTURE_BASE + 3;
39     public static final int GESTURE_SINGLE_TAP_AND_HOLD = GESTURE_BASE + 4;
40     public static final int GESTURE_TRIPLE_TAP = GESTURE_BASE + 5;
41     public static final int GESTURE_TRIPLE_TAP_AND_HOLD = GESTURE_BASE + 6;
42 
43     @IntDef(prefix = {"GESTURE_MAGNIFICATION_"}, value = {
44             GESTURE_TWO_FINGERS_DOWN_OR_SWIPE,
45             GESTURE_SWIPE
46     })
47     @Retention(RetentionPolicy.SOURCE)
48     @interface GestureId {
49     }
50 
51     /**
52      * Returns the string representation of a gesture id.
53      * @param gestureId the gesture Id.
54      * @return "none" if the id is not listed in {@link GestureId}.
55      */
gestureIdToString(@estureId int gestureId)56     static String gestureIdToString(@GestureId int gestureId) {
57         switch (gestureId) {
58             case GESTURE_SWIPE:
59                 return "GESTURE_SWIPE";
60             case GESTURE_TWO_FINGERS_DOWN_OR_SWIPE:
61                 return "GESTURE_TWO_FINGERS_DOWN_OR_SWIPE";
62             case GESTURE_SINGLE_TAP:
63                 return "GESTURE_SINGLE_TAP";
64             case GESTURE_SINGLE_TAP_AND_HOLD:
65                 return "GESTURE_SINGLE_TAP_AND_HOLD";
66             case GESTURE_TRIPLE_TAP:
67                 return "GESTURE_TRIPLE_TAP";
68             case GESTURE_TRIPLE_TAP_AND_HOLD:
69                 return "GESTURE_TRIPLE_TAP_AND_HOLD";
70         }
71         return "none";
72     }
73 
74     /**
75      * @param context
76      * @return the duration in milliseconds between the first tap's down event and
77      * the second tap's down event to be considered that the user is going to performing
78      *  panning/scaling gesture.
79      */
getMagnificationMultiTapTimeout(Context context)80     static int getMagnificationMultiTapTimeout(Context context) {
81         return ViewConfiguration.getDoubleTapTimeout() + context.getResources().getInteger(
82                 R.integer.config_screen_magnification_multi_tap_adjustment);
83     }
84 }
85