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 static com.android.launcher3.config.FeatureFlags.ENABLE_OVERVIEW_ACTIONS; 19 import static com.android.quickstep.SysUINavigationMode.removeShelfFromOverview; 20 21 import android.content.Context; 22 import android.graphics.Rect; 23 import android.view.View; 24 import android.view.ViewGroup; 25 26 import com.android.launcher3.DeviceProfile; 27 import com.android.launcher3.R; 28 import com.android.launcher3.touch.PagedOrientationHandler; 29 import com.android.quickstep.LauncherActivityInterface; 30 import com.android.quickstep.SysUINavigationMode; 31 32 public class LayoutUtils { 33 34 /** 35 * The height for the swipe up motion 36 */ getDefaultSwipeHeight(Context context, DeviceProfile dp)37 public static float getDefaultSwipeHeight(Context context, DeviceProfile dp) { 38 float swipeHeight = dp.allAppsCellHeightPx - dp.allAppsIconTextSizePx; 39 if (SysUINavigationMode.getMode(context) == SysUINavigationMode.Mode.NO_BUTTON) { 40 swipeHeight -= dp.getInsets().bottom; 41 } 42 return swipeHeight; 43 } 44 getShelfTrackingDistance(Context context, DeviceProfile dp, PagedOrientationHandler orientationHandler)45 public static int getShelfTrackingDistance(Context context, DeviceProfile dp, 46 PagedOrientationHandler orientationHandler) { 47 // Track the bottom of the window. 48 if (ENABLE_OVERVIEW_ACTIONS.get() && removeShelfFromOverview(context)) { 49 Rect taskSize = new Rect(); 50 LauncherActivityInterface.INSTANCE.calculateTaskSize(context, dp, taskSize, 51 orientationHandler); 52 return (dp.heightPx - taskSize.height()) / 2; 53 } 54 int shelfHeight = dp.hotseatBarSizePx + dp.getInsets().bottom; 55 int spaceBetweenShelfAndRecents = (int) context.getResources().getDimension( 56 R.dimen.task_card_vert_space); 57 return shelfHeight + spaceBetweenShelfAndRecents; 58 } 59 60 /** 61 * Recursively sets view and all children enabled/disabled. 62 * @param view Top most parent view to change. 63 * @param enabled True = enable, False = disable. 64 */ setViewEnabled(View view, boolean enabled)65 public static void setViewEnabled(View view, boolean enabled) { 66 view.setEnabled(enabled); 67 if (view instanceof ViewGroup) { 68 for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) { 69 setViewEnabled(((ViewGroup) view).getChildAt(i), enabled); 70 } 71 } 72 } 73 } 74