diff options
author | Kevin <kevhan@google.com> | 2019-04-19 11:49:00 -0700 |
---|---|---|
committer | Kevin Han <kevhan@google.com> | 2019-04-23 19:27:53 +0000 |
commit | 728deff7c04eede92253aa6a45bd2fb8e0b5b7cf (patch) | |
tree | cd3f3c1774bf4c8427852ffbab835e7fc00e866d /go/quickstep | |
parent | 52645638e905b7fcdf27a2a77575a6c65973f532 (diff) | |
download | android_packages_apps_Trebuchet-728deff7c04eede92253aa6a45bd2fb8e0b5b7cf.tar.gz android_packages_apps_Trebuchet-728deff7c04eede92253aa6a45bd2fb8e0b5b7cf.tar.bz2 android_packages_apps_Trebuchet-728deff7c04eede92253aa6a45bd2fb8e0b5b7cf.zip |
Add clear all view that scales off device height
Add a custom clear all view that scales its height based off the height
of the device in portrait. This view holds and lays out the actual
button.
Bug: 114136250
Test: Task items + clear all scale to fit flush with screen size
Change-Id: I72b175681c104588970d57cde34cebc0f06b55a0
(cherry picked from commit a2b8ca883040a33a60968c83d6ef9c48468ffe32)
Diffstat (limited to 'go/quickstep')
4 files changed, 76 insertions, 19 deletions
diff --git a/go/quickstep/res/layout/clear_all_button.xml b/go/quickstep/res/layout/clear_all_button.xml index eceffec42..003ee860e 100644 --- a/go/quickstep/res/layout/clear_all_button.xml +++ b/go/quickstep/res/layout/clear_all_button.xml @@ -14,15 +14,20 @@ See the License for the specific language governing permissions and limitations under the License. --> -<Button xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/clear_all_button" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:layout_gravity="center_horizontal" - android:background="@drawable/clear_all_button" - android:gravity="center" - android:text="@string/recents_clear_all" - android:textAllCaps="false" - android:textColor="@color/clear_all_button_text" - android:textSize="14sp"> -</Button> +<com.android.quickstep.views.ClearAllItemView + xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/clear_all_item_view" + android:layout_width="match_parent" + android:layout_height="match_parent"> + <Button + android:id="@+id/clear_all_button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center_horizontal" + android:background="@drawable/clear_all_button" + android:gravity="center" + android:text="@string/recents_clear_all" + android:textAllCaps="false" + android:textColor="@color/clear_all_button_text" + android:textSize="14sp"/> +</com.android.quickstep.views.ClearAllItemView> diff --git a/go/quickstep/src/com/android/quickstep/TaskAdapter.java b/go/quickstep/src/com/android/quickstep/TaskAdapter.java index be6faca88..8651698f6 100644 --- a/go/quickstep/src/com/android/quickstep/TaskAdapter.java +++ b/go/quickstep/src/com/android/quickstep/TaskAdapter.java @@ -16,6 +16,7 @@ package com.android.quickstep; import android.view.LayoutInflater; +import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; @@ -84,10 +85,11 @@ public final class TaskAdapter extends Adapter<ViewHolder> { itemView.setOnClickListener(view -> mTaskActionController.launchTask(taskHolder)); return taskHolder; case ITEM_TYPE_CLEAR_ALL: - Button clearView = (Button) LayoutInflater.from(parent.getContext()) + View clearView = LayoutInflater.from(parent.getContext()) .inflate(R.layout.clear_all_button, parent, false); ClearAllHolder clearAllHolder = new ClearAllHolder(clearView); - clearView.setOnClickListener(mClearAllListener); + Button clearViewButton = clearView.findViewById(R.id.clear_all_button); + clearViewButton.setOnClickListener(mClearAllListener); return clearAllHolder; default: throw new IllegalArgumentException("No known holder for item type: " + viewType); diff --git a/go/quickstep/src/com/android/quickstep/views/ClearAllItemView.java b/go/quickstep/src/com/android/quickstep/views/ClearAllItemView.java new file mode 100644 index 000000000..378dbf4e4 --- /dev/null +++ b/go/quickstep/src/com/android/quickstep/views/ClearAllItemView.java @@ -0,0 +1,41 @@ +/* + * 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.views; + +import static com.android.quickstep.views.TaskLayoutUtils.getClearAllItemHeight; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.FrameLayout; + +/** + * Recycler view item that lays out the clear all button and measures the space it takes based on + * the device height. + */ +public final class ClearAllItemView extends FrameLayout { + + public ClearAllItemView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int buttonHeight = getClearAllItemHeight(getContext()); + int newHeightSpec = MeasureSpec.makeMeasureSpec(buttonHeight, MeasureSpec.EXACTLY); + super.onMeasure(widthMeasureSpec, newHeightSpec); + } +} diff --git a/go/quickstep/src/com/android/quickstep/views/TaskLayoutUtils.java b/go/quickstep/src/com/android/quickstep/views/TaskLayoutUtils.java index f7d6495d2..e28a9e04f 100644 --- a/go/quickstep/src/com/android/quickstep/views/TaskLayoutUtils.java +++ b/go/quickstep/src/com/android/quickstep/views/TaskLayoutUtils.java @@ -26,6 +26,8 @@ import com.android.launcher3.InvariantDeviceProfile; */ public final class TaskLayoutUtils { + private static final float CLEAR_ALL_ITEM_TO_HEIGHT_RATIO = 7.0f / 64; + private TaskLayoutUtils() {} /** @@ -39,12 +41,19 @@ public final class TaskLayoutUtils { 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); + final int availableTaskSpace = availableHeight - getClearAllItemHeight(context); + return (int) (availableTaskSpace * 1.0f / MAX_TASKS_TO_DISPLAY); } - public static int getClearAllButtonHeight(Context context) { - // TODO: Implement this - return 0; + /** + * Calculate clear all item height scaled to available height in portrait mode. + * + * @param context current context + * @return clear all item height + */ + public static int getClearAllItemHeight(Context context) { + final int availableHeight = + InvariantDeviceProfile.INSTANCE.get(context).portraitProfile.availableHeightPx; + return (int) (CLEAR_ALL_ITEM_TO_HEIGHT_RATIO * availableHeight); } } |