blob: fb244b07f331a98178bb670686dac553bf46d9ae [file] [log] [blame]
Tracy Zhoud248ee72023-01-23 22:06:19 -08001/*
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
Tracy Zhoua33fb692023-03-20 10:57:02 -070017package com.android.launcher3;
Tracy Zhoud248ee72023-01-23 22:06:19 -080018
19import static android.view.MotionEvent.CLASSIFICATION_TWO_FINGER_SWIPE;
20
Tracy Zhoud248ee72023-01-23 22:06:19 -080021import android.annotation.TargetApi;
22import android.os.Build;
23import android.view.MotionEvent;
24
25/** Handles motion events from trackpad. */
26public class MotionEventsUtils {
27
28 /** {@link MotionEvent#CLASSIFICATION_MULTI_FINGER_SWIPE} is hidden. */
29 public static final int CLASSIFICATION_MULTI_FINGER_SWIPE = 4;
30
Tracy Zhou48ac5a02023-05-27 11:23:31 -070031 /** {@link MotionEvent#AXIS_GESTURE_SWIPE_FINGER_COUNT} is hidden. */
32 private static final int AXIS_GESTURE_SWIPE_FINGER_COUNT = 53;
33
Tracy Zhoud248ee72023-01-23 22:06:19 -080034 @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
35 public static boolean isTrackpadScroll(MotionEvent event) {
Sunny Goyal5ee3d982024-09-12 15:05:07 -070036 return event.getClassification() == CLASSIFICATION_TWO_FINGER_SWIPE;
Tracy Zhoud248ee72023-01-23 22:06:19 -080037 }
38
39 @TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
40 public static boolean isTrackpadMultiFingerSwipe(MotionEvent event) {
Sunny Goyal5ee3d982024-09-12 15:05:07 -070041 return event.getClassification() == CLASSIFICATION_MULTI_FINGER_SWIPE;
Tracy Zhoud248ee72023-01-23 22:06:19 -080042 }
43
Tracy Zhou7dc9e3a2023-03-15 01:12:30 -070044 public static boolean isTrackpadThreeFingerSwipe(MotionEvent event) {
Tracy Zhou48ac5a02023-05-27 11:23:31 -070045 return isTrackpadMultiFingerSwipe(event) && event.getAxisValue(
46 AXIS_GESTURE_SWIPE_FINGER_COUNT) == 3;
Tracy Zhou7dc9e3a2023-03-15 01:12:30 -070047 }
48
49 public static boolean isTrackpadFourFingerSwipe(MotionEvent event) {
Tracy Zhou48ac5a02023-05-27 11:23:31 -070050 return isTrackpadMultiFingerSwipe(event) && event.getAxisValue(
51 AXIS_GESTURE_SWIPE_FINGER_COUNT) == 4;
Tracy Zhou7dc9e3a2023-03-15 01:12:30 -070052 }
53
Tracy Zhoud248ee72023-01-23 22:06:19 -080054 public static boolean isTrackpadMotionEvent(MotionEvent event) {
55 return isTrackpadScroll(event) || isTrackpadMultiFingerSwipe(event);
56 }
57}