• 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.touch.PagedOrientationHandler;
25 import com.android.quickstep.LauncherActivityInterface;
26 import com.android.quickstep.SysUINavigationMode;
27 
28 public class LayoutUtils {
29 
30     /**
31      * The height for the swipe up motion
32      */
getDefaultSwipeHeight(Context context, DeviceProfile dp)33     public static float getDefaultSwipeHeight(Context context, DeviceProfile dp) {
34         float swipeHeight = dp.allAppsCellHeightPx - dp.allAppsIconTextSizePx;
35         if (SysUINavigationMode.getMode(context) == SysUINavigationMode.Mode.NO_BUTTON) {
36             swipeHeight -= dp.getInsets().bottom;
37         }
38         return swipeHeight;
39     }
40 
getShelfTrackingDistance(Context context, DeviceProfile dp, PagedOrientationHandler orientationHandler)41     public static int getShelfTrackingDistance(Context context, DeviceProfile dp,
42             PagedOrientationHandler orientationHandler) {
43         // Track the bottom of the window.
44         Rect taskSize = new Rect();
45         LauncherActivityInterface.INSTANCE.calculateTaskSize(
46                 context, dp, taskSize, orientationHandler);
47         return orientationHandler.getDistanceToBottomOfRect(dp, taskSize);
48     }
49 
50     /**
51      * Recursively sets view and all children enabled/disabled.
52      * @param view Top most parent view to change.
53      * @param enabled True = enable, False = disable.
54      */
setViewEnabled(View view, boolean enabled)55     public static void setViewEnabled(View view, boolean enabled) {
56         view.setEnabled(enabled);
57         if (view instanceof ViewGroup) {
58             for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
59                 setViewEnabled(((ViewGroup) view).getChildAt(i), enabled);
60             }
61         }
62     }
63 }
64