From 1834728db68354ff905024ad9ea98a4ebe8b8612 Mon Sep 17 00:00:00 2001 From: Kevin Date: Fri, 19 Apr 2019 10:52:18 -0700 Subject: [PATCH] Calculate task height directly off portrait height Change task height calculation implementation to be directly based off device height in portrait mode. This allows the recycler view layout manager's job to be simpler while still ensuring that task height changes dynamically based off device configuration changes. Bug: 114136250 Test: Go to recents Go, task height is based off portrait mode height Change-Id: I9c7cada3b89d2b2cea5ece8c357a40ce5974a2e6 (cherry picked from commit 3172c6811ba4b59763c3fb196b3b26b8411e8210) --- .../android/quickstep/TaskLayoutManager.java | 42 ------------------- .../quickstep/views/IconRecentsView.java | 4 +- .../android/quickstep/views/TaskItemView.java | 9 ++++ .../quickstep/views/TaskLayoutUtils.java | 22 +++++++++- 4 files changed, 32 insertions(+), 45 deletions(-) delete mode 100644 go/quickstep/src/com/android/quickstep/TaskLayoutManager.java diff --git a/go/quickstep/src/com/android/quickstep/TaskLayoutManager.java b/go/quickstep/src/com/android/quickstep/TaskLayoutManager.java deleted file mode 100644 index ecb2499264..0000000000 --- a/go/quickstep/src/com/android/quickstep/TaskLayoutManager.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.quickstep; - -import android.content.Context; -import android.view.View; - -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.LinearLayoutManager; - -/** - * Layout manager for task list that restricts child height based off the max number of tasks the - * recycler view should hold and the height of the recycler view. - */ -public final class TaskLayoutManager extends LinearLayoutManager { - - public TaskLayoutManager(Context context, int vertical, boolean b) { - super(context, vertical, b); - } - - @Override - public void measureChildWithMargins(@NonNull View child, int widthUsed, int heightUsed) { - // Request child view takes up 1 / MAX_TASKS of the total view height. - int heightUsedByView = (int) (getHeight() * - (TaskAdapter.MAX_TASKS_TO_DISPLAY - 1.0f) / TaskAdapter.MAX_TASKS_TO_DISPLAY); - super.measureChildWithMargins(child, widthUsed, heightUsedByView); - } -} diff --git a/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java b/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java index 6b4d03cc28..09d5ae6f01 100644 --- a/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java +++ b/go/quickstep/src/com/android/quickstep/views/IconRecentsView.java @@ -41,6 +41,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.ItemTouchHelper; +import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver; import androidx.recyclerview.widget.RecyclerView.OnChildAttachStateChangeListener; @@ -54,7 +55,6 @@ import com.android.quickstep.RecentsToActivityHelper; import com.android.quickstep.TaskActionController; import com.android.quickstep.TaskAdapter; import com.android.quickstep.TaskHolder; -import com.android.quickstep.TaskLayoutManager; import com.android.quickstep.TaskListLoader; import com.android.quickstep.TaskSwipeCallback; import com.android.systemui.shared.recents.model.Task; @@ -155,7 +155,7 @@ public final class IconRecentsView extends FrameLayout { recyclerViewParams.height = getTaskListHeight(mDeviceProfile); mTaskRecyclerView.setAdapter(mTaskAdapter); mTaskRecyclerView.setLayoutManager( - new TaskLayoutManager(mContext, VERTICAL, true /* reverseLayout */)); + new LinearLayoutManager(mContext, VERTICAL, true /* reverseLayout */)); ItemTouchHelper helper = new ItemTouchHelper( new TaskSwipeCallback(mTaskActionController)); helper.attachToRecyclerView(mTaskRecyclerView); diff --git a/go/quickstep/src/com/android/quickstep/views/TaskItemView.java b/go/quickstep/src/com/android/quickstep/views/TaskItemView.java index 572747bfdd..7d9916e5bb 100644 --- a/go/quickstep/src/com/android/quickstep/views/TaskItemView.java +++ b/go/quickstep/src/com/android/quickstep/views/TaskItemView.java @@ -15,6 +15,8 @@ */ package com.android.quickstep.views; +import static com.android.quickstep.views.TaskLayoutUtils.getTaskHeight; + import android.content.Context; import android.content.res.Resources; import android.graphics.Bitmap; @@ -88,6 +90,13 @@ public final class TaskItemView extends LinearLayout { CONTENT_TRANSITION_PROGRESS.setValue(this, 1.0f); } + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int taskHeight = getTaskHeight(getContext()); + int newHeightSpec = MeasureSpec.makeMeasureSpec(taskHeight,MeasureSpec.EXACTLY); + super.onMeasure(widthMeasureSpec, newHeightSpec); + } + /** * Resets task item view to empty, loading UI. */ diff --git a/go/quickstep/src/com/android/quickstep/views/TaskLayoutUtils.java b/go/quickstep/src/com/android/quickstep/views/TaskLayoutUtils.java index 5bb30ad9c8..bda3e4dd3e 100644 --- a/go/quickstep/src/com/android/quickstep/views/TaskLayoutUtils.java +++ b/go/quickstep/src/com/android/quickstep/views/TaskLayoutUtils.java @@ -15,8 +15,12 @@ */ package com.android.quickstep.views; +import static com.android.quickstep.TaskAdapter.MAX_TASKS_TO_DISPLAY; + +import android.content.Context; + import com.android.launcher3.DeviceProfile; -import com.android.quickstep.TaskAdapter; +import com.android.launcher3.InvariantDeviceProfile; /** * Utils to determine dynamically task and view sizes based off the device height and width. @@ -30,10 +34,26 @@ public final class TaskLayoutUtils { private TaskLayoutUtils() {} public static int getTaskListHeight(DeviceProfile dp) { + // TODO: Remove this as task height is determined directly from device height. int clearAllSpace = getClearAllButtonHeight(dp) + 2 * getClearAllButtonTopBottomMargin(dp); return getDeviceLongWidth(dp) - clearAllSpace; } + /** + * Calculate task height based off the available height in portrait mode such that when the + * recents list is full, the total height fills in the available device height perfectly. In + * landscape mode, we keep the same task height so that tasks scroll off the top. + * + * @param context current context + * @return task height + */ + public static int getTaskHeight(Context context) { + final int availableHeight = + InvariantDeviceProfile.INSTANCE.get(context).portraitProfile.availableHeightPx; + // TODO: Take into account clear all button height for task height + return (int) (availableHeight * 1.0f / MAX_TASKS_TO_DISPLAY); + } + public static int getClearAllButtonHeight(DeviceProfile dp) { return (int) (BUTTON_TO_DEVICE_HEIGHT_RATIO * getDeviceLongWidth(dp)); }