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 a2b8ca8830
)
This commit is contained in:
parent
52645638e9
commit
728deff7c0
|
@ -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>
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue