• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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.launcher3;
18 
19 import static android.view.MotionEvent.CLASSIFICATION_TWO_FINGER_SWIPE;
20 
21 import android.annotation.TargetApi;
22 import android.os.Build;
23 import android.view.MotionEvent;
24 
25 /** Handles motion events from trackpad. */
26 public class MotionEventsUtils {
27 
28     /** {@link MotionEvent#CLASSIFICATION_MULTI_FINGER_SWIPE} is hidden. */
29     public static final int CLASSIFICATION_MULTI_FINGER_SWIPE = 4;
30 
31     /** {@link MotionEvent#AXIS_GESTURE_SWIPE_FINGER_COUNT} is hidden. */
32     private static final int AXIS_GESTURE_SWIPE_FINGER_COUNT = 53;
33 
34     @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
isTrackpadScroll(MotionEvent event)35     public static boolean isTrackpadScroll(MotionEvent event) {
36         return event.getClassification() == CLASSIFICATION_TWO_FINGER_SWIPE;
37     }
38 
39     @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
isTrackpadMultiFingerSwipe(MotionEvent event)40     public static boolean isTrackpadMultiFingerSwipe(MotionEvent event) {
41         return event.getClassification() == CLASSIFICATION_MULTI_FINGER_SWIPE;
42     }
43 
isTrackpadThreeFingerSwipe(MotionEvent event)44     public static boolean isTrackpadThreeFingerSwipe(MotionEvent event) {
45         return isTrackpadMultiFingerSwipe(event) && event.getAxisValue(
46                 AXIS_GESTURE_SWIPE_FINGER_COUNT) == 3;
47     }
48 
isTrackpadFourFingerSwipe(MotionEvent event)49     public static boolean isTrackpadFourFingerSwipe(MotionEvent event) {
50         return isTrackpadMultiFingerSwipe(event) && event.getAxisValue(
51                 AXIS_GESTURE_SWIPE_FINGER_COUNT) == 4;
52     }
53 
isTrackpadMotionEvent(MotionEvent event)54     public static boolean isTrackpadMotionEvent(MotionEvent event) {
55         return isTrackpadScroll(event) || isTrackpadMultiFingerSwipe(event);
56     }
57 }
58