• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.quickstep.util;
17 
18 import android.content.Context;
19 import android.graphics.Rect;
20 import android.view.View;
21 import android.view.ViewGroup;
22 
23 import com.android.launcher3.DeviceProfile;
24 import com.android.launcher3.util.DisplayController;
25 import com.android.launcher3.util.NavigationMode;
26 import com.android.quickstep.BaseContainerInterface;
27 import com.android.quickstep.orientation.RecentsPagedOrientationHandler;
28 
29 public class LayoutUtils {
30 
31     private static final float SQUARE_ASPECT_RATIO_TOLERANCE = 0.05f;
32 
33     /**
34      * The height for the swipe up motion
35      */
getDefaultSwipeHeight(Context context, DeviceProfile dp)36     public static float getDefaultSwipeHeight(Context context, DeviceProfile dp) {
37         float swipeHeight = dp.allAppsCellHeightPx - dp.allAppsIconTextSizePx;
38         if (DisplayController.getNavigationMode(context) == NavigationMode.NO_BUTTON) {
39             swipeHeight -= dp.getInsets().bottom;
40         }
41         return swipeHeight;
42     }
43 
getShelfTrackingDistance( Context context, DeviceProfile dp, RecentsPagedOrientationHandler orientationHandler, BaseContainerInterface<?, ?> baseContainerInterface)44     public static int getShelfTrackingDistance(
45             Context context,
46             DeviceProfile dp,
47             RecentsPagedOrientationHandler orientationHandler,
48             BaseContainerInterface<?, ?> baseContainerInterface) {
49         // Track the bottom of the window.
50         Rect taskSize = new Rect();
51         baseContainerInterface.calculateTaskSize(context, dp, taskSize,
52                 orientationHandler);
53         return orientationHandler.getDistanceToBottomOfRect(dp, taskSize);
54     }
55 
56     /**
57      * Recursively sets view and all children enabled/disabled.
58      * @param view Top most parent view to change.
59      * @param enabled True = enable, False = disable.
60      */
setViewEnabled(View view, boolean enabled)61     public static void setViewEnabled(View view, boolean enabled) {
62         view.setEnabled(enabled);
63         if (view instanceof ViewGroup) {
64             for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
65                 setViewEnabled(((ViewGroup) view).getChildAt(i), enabled);
66             }
67         }
68     }
69 
70     /**
71      * Returns true iff the device's aspect ratio is within
72      * {@link LayoutUtils#SQUARE_ASPECT_RATIO_TOLERANCE} of 1:1
73      */
isAspectRatioSquare(float aspectRatio)74     public static boolean isAspectRatioSquare(float aspectRatio) {
75         return Float.compare(aspectRatio, 1f - SQUARE_ASPECT_RATIO_TOLERANCE) >= 0
76                 && Float.compare(aspectRatio, 1f + SQUARE_ASPECT_RATIO_TOLERANCE) <= 0;
77     }
78 }
79