Change TaskIconMenu to lay out vertically
Still lays out horizontally when in phone
landscape.
TODO(b/186583656), need to center view.
Also have all layout be dynamic instead of having
some cases be in XML and some in code.
Bug: 181704764
Test: Task menu visible with all options in
portrait/landscape tablet
portrait phone
fake/real landscape phone
Change-Id: I3632eeb174f3e4baf2c9d69d51c1815c3c512e59
diff --git a/quickstep/res/layout/task_menu.xml b/quickstep/res/layout/task_menu.xml
index 3916ff9..a219bca 100644
--- a/quickstep/res/layout/task_menu.xml
+++ b/quickstep/res/layout/task_menu.xml
@@ -16,7 +16,7 @@
-->
<com.android.quickstep.views.TaskMenuView
xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="@drawable/task_menu_bg"
@@ -35,12 +35,10 @@
<LinearLayout
android:id="@+id/menu_option_layout"
- style="@style/TaskMenu"
- android:divider="@drawable/all_apps_divider"
- android:showDividers="beginning"
- android:paddingStart="@dimen/task_card_menu_horizontal_padding"
- android:paddingEnd="@dimen/task_card_menu_horizontal_padding"
android:layout_width="match_parent"
- android:layout_height="wrap_content"/>
+ android:layout_height="wrap_content"
+ android:orientation="horizontal"
+ android:divider="@drawable/all_apps_divider"
+ android:showDividers="beginning" />
</com.android.quickstep.views.TaskMenuView>
\ No newline at end of file
diff --git a/quickstep/res/layout/task_view_menu_option.xml b/quickstep/res/layout/task_view_menu_option.xml
index 102ae9b..a7d6e89 100644
--- a/quickstep/res/layout/task_view_menu_option.xml
+++ b/quickstep/res/layout/task_view_menu_option.xml
@@ -16,9 +16,8 @@
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- style="@style/TaskMenu.Option"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_gravity="center"
android:orientation="vertical"
android:paddingTop="@dimen/task_card_menu_option_vertical_padding"
android:paddingBottom="@dimen/task_card_menu_option_vertical_padding"
@@ -29,22 +28,19 @@
android:id="@+id/icon"
android:layout_width="@dimen/system_shortcut_icon_size"
android:layout_height="@dimen/system_shortcut_icon_size"
- android:layout_marginTop="@dimen/system_shortcut_header_icon_padding"
- android:layout_marginBottom="@dimen/deep_shortcut_drawable_padding"
+ android:layout_marginStart="@dimen/task_menu_option_start_margin"
android:layout_gravity="center_horizontal"
android:backgroundTint="?android:attr/textColorTertiary"/>
<TextView
style="@style/BaseIcon"
android:id="@+id/text"
- android:layout_width="match_parent"
+ android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:paddingBottom="@dimen/popup_padding_end"
+ android:layout_marginStart="@dimen/task_menu_option_start_margin"
android:textSize="12sp"
android:textColor="?android:attr/textColorPrimary"
android:fontFamily="sans-serif"
- android:gravity="center_horizontal"
- android:layout_gravity="center_horizontal"
android:focusable="false" />
</LinearLayout>
diff --git a/quickstep/res/values-land/dimens.xml b/quickstep/res/values-land/dimens.xml
index 7cb01f6..668aea2 100644
--- a/quickstep/res/values-land/dimens.xml
+++ b/quickstep/res/values-land/dimens.xml
@@ -15,7 +15,5 @@
limitations under the License.
-->
<resources>
- <dimen name="task_card_menu_horizontal_padding">24dp</dimen>
-
<dimen name="overview_task_margin">8dp</dimen>
</resources>
\ No newline at end of file
diff --git a/quickstep/res/values-land/styles.xml b/quickstep/res/values-land/styles.xml
deleted file mode 100644
index 0824b4f..0000000
--- a/quickstep/res/values-land/styles.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2018 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.
--->
-<resources>
- <!-- Task Menu layout styles. -->
- <style name="TaskMenu">
- <item name="android:orientation">horizontal</item>
- </style>
-
- <!-- Task Menu Option layout styles. -->
- <style name="TaskMenu.Option">
- <item name="android:layout_width">0dp</item>
- <item name="android:layout_weight">1</item>
- </style>
-</resources>
\ No newline at end of file
diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml
index 99be502..9c0a083 100644
--- a/quickstep/res/values/dimens.xml
+++ b/quickstep/res/values/dimens.xml
@@ -67,7 +67,7 @@
in various configurations -->
<dimen name="task_card_menu_option_vertical_padding">8dp</dimen>
<dimen name="task_card_menu_shadow_height">3dp</dimen>
- <dimen name="task_card_menu_horizontal_padding">0dp</dimen>
+ <dimen name="task_menu_option_start_margin">12dp</dimen>
<!-- Copied from framework resource:
docked_stack_divider_thickness - 2 * docked_stack_divider_insets -->
<dimen name="multi_window_task_divider_size">10dp</dimen>
diff --git a/quickstep/res/values/styles.xml b/quickstep/res/values/styles.xml
index 82a91a7..7c7d20a 100644
--- a/quickstep/res/values/styles.xml
+++ b/quickstep/res/values/styles.xml
@@ -15,16 +15,6 @@
limitations under the License.
-->
<resources>
- <!-- Task Menu layout styles. -->
- <style name="TaskMenu">
- <item name="android:orientation">vertical</item>
- </style>
-
- <!-- Task Menu Option layout styles. -->
- <style name="TaskMenu.Option">
- <item name="android:layout_width">match_parent</item>
- <item name="android:layout_height">wrap_content</item>
- </style>
<style name="TextAppearance.GestureTutorial"
parent="android:TextAppearance.Material.Body1" />
diff --git a/quickstep/src/com/android/quickstep/views/TaskMenuView.java b/quickstep/src/com/android/quickstep/views/TaskMenuView.java
index f55cdac..32cd367 100644
--- a/quickstep/src/com/android/quickstep/views/TaskMenuView.java
+++ b/quickstep/src/com/android/quickstep/views/TaskMenuView.java
@@ -201,12 +201,13 @@
}
private void addMenuOption(SystemShortcut menuOption) {
- ViewGroup menuOptionView = (ViewGroup) mActivity.getLayoutInflater().inflate(
+ LinearLayout menuOptionView = (LinearLayout) mActivity.getLayoutInflater().inflate(
R.layout.task_view_menu_option, this, false);
menuOption.setIconAndLabelFor(
menuOptionView.findViewById(R.id.icon), menuOptionView.findViewById(R.id.text));
LayoutParams lp = (LayoutParams) menuOptionView.getLayoutParams();
- mTaskView.getPagedOrientationHandler().setLayoutParamsForTaskMenuOptionItem(lp);
+ mTaskView.getPagedOrientationHandler().setLayoutParamsForTaskMenuOptionItem(lp,
+ menuOptionView, mActivity.getDeviceProfile());
menuOptionView.setEnabled(menuOption.isEnabled());
menuOptionView.setAlpha(menuOption.isEnabled() ? 1 : 0.5f);
menuOptionView.setOnClickListener(view -> {
@@ -228,16 +229,15 @@
mActivity.getDragLayer().getDescendantRectRelativeToSelf(taskView, sTempRect);
Rect insets = mActivity.getDragLayer().getInsets();
BaseDragLayer.LayoutParams params = (BaseDragLayer.LayoutParams) getLayoutParams();
+ // TODO(b/186583656) Move the entire menu to the center/make smaller than thumbnail width
params.width = orientationHandler.getTaskMenuWidth(taskView.getThumbnail());
// Gravity set to Left instead of Start as sTempRect.left measures Left distance not Start
params.gravity = Gravity.LEFT;
setLayoutParams(params);
setScaleX(taskView.getScaleX());
setScaleY(taskView.getScaleY());
- boolean canActivityRotate = taskView.getRecentsView()
- .mOrientationState.isRecentsActivityRotationAllowed();
- mOptionLayout.setOrientation(orientationHandler
- .getTaskMenuLayoutOrientation(canActivityRotate, mOptionLayout));
+ orientationHandler.setTaskMenuLayoutOrientation(
+ mActivity.getDeviceProfile(), mOptionLayout);
setPosition(sTempRect.left - insets.left, sTempRect.top - insets.top, 0);
}
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 3312915..a799b4a 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -65,6 +65,7 @@
import android.view.View;
import android.view.ViewConfiguration;
import android.view.animation.Interpolator;
+import android.widget.LinearLayout;
import androidx.core.graphics.ColorUtils;
import androidx.core.os.BuildCompat;
@@ -752,6 +753,16 @@
ColorUtils.blendARGB(0, color, tintAmount));
}
+ /**
+ * Sets start margin on the provided {@param view} to be {@param margin}.
+ * Assumes {@param view} is a child of {@link LinearLayout}
+ */
+ public static void setStartMarginForView(View view, int margin) {
+ LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) view.getLayoutParams();
+ lp.setMarginStart(margin);
+ view.setLayoutParams(lp);
+ }
+
private static class FixedSizeEmptyDrawable extends ColorDrawable {
private final int mSize;
diff --git a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java
index 2254ab3..2fd5efc 100644
--- a/src/com/android/launcher3/touch/LandscapePagedViewHandler.java
+++ b/src/com/android/launcher3/touch/LandscapePagedViewHandler.java
@@ -254,16 +254,21 @@
}
@Override
- public int getTaskMenuLayoutOrientation(boolean canRecentsActivityRotate,
+ public void setTaskMenuLayoutOrientation(DeviceProfile deviceProfile,
LinearLayout taskMenuLayout) {
- return LinearLayout.HORIZONTAL;
+ taskMenuLayout.setOrientation(LinearLayout.HORIZONTAL);
}
@Override
- public void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp) {
+ public void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp,
+ LinearLayout viewGroup, DeviceProfile deviceProfile) {
+ // Phone fake landscape
+ viewGroup.setOrientation(LinearLayout.VERTICAL);
lp.width = 0;
lp.height = WRAP_CONTENT;
lp.weight = 1;
+ Utilities.setStartMarginForView(viewGroup.findViewById(R.id.text), 0);
+ Utilities.setStartMarginForView(viewGroup.findViewById(R.id.icon), 0);
}
/* ---------- The following are only used by TaskViewTouchHandler. ---------- */
diff --git a/src/com/android/launcher3/touch/PagedOrientationHandler.java b/src/com/android/launcher3/touch/PagedOrientationHandler.java
index c9149ff..6c2f17e 100644
--- a/src/com/android/launcher3/touch/PagedOrientationHandler.java
+++ b/src/com/android/launcher3/touch/PagedOrientationHandler.java
@@ -101,8 +101,9 @@
float getTaskMenuX(float x, View thumbnailView, int overScroll);
float getTaskMenuY(float y, View thumbnailView, int overScroll);
int getTaskMenuWidth(View view);
- int getTaskMenuLayoutOrientation(boolean canRecentsActivityRotate, LinearLayout taskMenuLayout);
- void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp);
+ void setTaskMenuLayoutOrientation(DeviceProfile deviceProfile, LinearLayout taskMenuLayout);
+ void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp,
+ LinearLayout viewGroup, DeviceProfile deviceProfile);
int getDistanceToBottomOfRect(DeviceProfile dp, Rect rect);
List<SplitPositionOption> getSplitPositionOptions(DeviceProfile dp);
FloatProperty getSplitSelectTaskOffset(FloatProperty primary, FloatProperty secondary,
diff --git a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java
index 31586e7..f6a6448 100644
--- a/src/com/android/launcher3/touch/PortraitPagedViewHandler.java
+++ b/src/com/android/launcher3/touch/PortraitPagedViewHandler.java
@@ -253,14 +253,34 @@
}
@Override
- public int getTaskMenuLayoutOrientation(boolean canRecentsActivityRotate,
+ public void setTaskMenuLayoutOrientation(DeviceProfile deviceProfile,
LinearLayout taskMenuLayout) {
- return canRecentsActivityRotate ? taskMenuLayout.getOrientation() : LinearLayout.VERTICAL;
+ if (deviceProfile.isLandscape && !deviceProfile.isTablet) {
+ // Phone landscape
+ taskMenuLayout.setOrientation(LinearLayout.HORIZONTAL);
+ } else {
+ // Phone Portrait, LargeScreen Landscape/Portrait
+ taskMenuLayout.setOrientation(LinearLayout.VERTICAL);
+ }
}
@Override
- public void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp) {
- // no-op, defaults are fine
+ public void setLayoutParamsForTaskMenuOptionItem(LinearLayout.LayoutParams lp,
+ LinearLayout viewGroup, DeviceProfile deviceProfile) {
+ if (deviceProfile.isLandscape && !deviceProfile.isTablet) {
+ // Phone landscape
+ viewGroup.setOrientation(LinearLayout.VERTICAL);
+ lp.width = 0;
+ lp.weight = 1;
+ Utilities.setStartMarginForView(viewGroup.findViewById(R.id.text), 0);
+ Utilities.setStartMarginForView(viewGroup.findViewById(R.id.icon), 0);
+ } else {
+ // Phone Portrait, LargeScreen Landscape/Portrait
+ viewGroup.setOrientation(LinearLayout.HORIZONTAL);
+ lp.width = LinearLayout.LayoutParams.WRAP_CONTENT;
+ }
+
+ lp.height = LinearLayout.LayoutParams.WRAP_CONTENT;
}
/* ---------- The following are only used by TaskViewTouchHandler. ---------- */