• 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 package com.android.launcher3.taskbar;
17 
18 import static com.android.launcher3.Utilities.dpToPx;
19 import static com.android.launcher3.Utilities.dpiFromPx;
20 
21 import android.content.res.Resources;
22 import android.util.DisplayMetrics;
23 
24 import androidx.core.content.res.ResourcesCompat;
25 
26 import com.android.launcher3.DeviceProfile;
27 import com.android.launcher3.R;
28 
29 /**
30  * Utility class that contains the different taskbar thresholds logic.
31  */
32 public class TaskbarThresholdUtils {
33 
34     // We divide the screen into this many parts, and use the result to scale the thresholds to
35     // any size device. Note that this value was calculated arbitrarily by using two tablet devices
36     // as data points.
37     private static final float SCREEN_UNITS = 1 / 80f;
38 
getThreshold(Resources r, DeviceProfile dp, int thresholdDimen, int multiplierDimen)39     private static int getThreshold(Resources r, DeviceProfile dp, int thresholdDimen,
40             int multiplierDimen) {
41         float landscapeScreenHeight = dp.isLandscape ? dp.heightPx : dp.widthPx;
42         float screenPart = (landscapeScreenHeight * SCREEN_UNITS);
43         float defaultDp = dpiFromPx(screenPart, DisplayMetrics.DENSITY_DEVICE_STABLE);
44         float thisDp = dpToPx(defaultDp);
45         float multiplier = ResourcesCompat.getFloat(r, multiplierDimen);
46         float value = (thisDp) * multiplier;
47 
48         return Math.round(value);
49     }
50 
51     /**
52      * Returns the threshold that determines if we should show taskbar.
53      */
getFromNavThreshold(Resources r, DeviceProfile dp)54     public static int getFromNavThreshold(Resources r, DeviceProfile dp) {
55         return getThreshold(r, dp, R.dimen.taskbar_from_nav_threshold,
56                 R.dimen.taskbar_nav_threshold_mult);
57     }
58 
59     /**
60      * Returns the threshold that we start moving the app window.
61      */
getAppWindowThreshold(Resources r, DeviceProfile dp)62     public static int getAppWindowThreshold(Resources r, DeviceProfile dp) {
63         return getThreshold(r, dp, R.dimen.taskbar_app_window_threshold,
64                 R.dimen.taskbar_app_window_threshold_mult);
65     }
66 
67     /**
68      * Returns the threshold for whether we land in home or overview.
69      */
getHomeOverviewThreshold(Resources r, DeviceProfile dp)70     public static int getHomeOverviewThreshold(Resources r, DeviceProfile dp) {
71         return getThreshold(r, dp, R.dimen.taskbar_home_overview_threshold,
72                 R.dimen.taskbar_home_overview_threshold_mult);
73     }
74 
75     /**
76      * Returns the threshold that we use to allow swipe to catch up to finger.
77      */
getCatchUpThreshold(Resources r, DeviceProfile dp)78     public static int getCatchUpThreshold(Resources r, DeviceProfile dp) {
79         return getThreshold(r, dp, R.dimen.taskbar_catch_up_threshold,
80                 R.dimen.taskbar_catch_up_threshold_mult);
81     }
82 }
83