From 524f4c4fbab4107856db4860f0f8f157fed53f72 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Mon, 11 Jul 2022 11:03:54 -0700 Subject: [PATCH 1/2] Fixing tab width and panner not aligned with the all-apps icons Bug: 234008165 Test: Verified on device Change-Id: Ibec3eed4aef730439d79b086d6ae23b63b66361e Merged-in: Ibec3eed4aef730439d79b086d6ae23b63b66361e --- .../launcher3/allapps/WorkEduCard.java | 18 +++++---- .../launcher3/allapps/WorkModeSwitch.java | 39 ++++++++++++++++--- .../PersonalWorkSlidingTabStrip.java | 22 +++++++++++ 3 files changed, 67 insertions(+), 12 deletions(-) diff --git a/src/com/android/launcher3/allapps/WorkEduCard.java b/src/com/android/launcher3/allapps/WorkEduCard.java index 836cd5af93..c357764811 100644 --- a/src/com/android/launcher3/allapps/WorkEduCard.java +++ b/src/com/android/launcher3/allapps/WorkEduCard.java @@ -15,6 +15,8 @@ */ package com.android.launcher3.allapps; +import static com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip.getTabWidth; + import android.content.Context; import android.util.AttributeSet; import android.view.View; @@ -87,14 +89,10 @@ public class WorkEduCard extends FrameLayout implements } @Override - public void onAnimationRepeat(Animation animation) { - - } + public void onAnimationRepeat(Animation animation) { } @Override - public void onAnimationStart(Animation animation) { - - } + public void onAnimationStart(Animation animation) { } private void removeCard() { if (mPosition == -1) { @@ -107,8 +105,14 @@ public class WorkEduCard extends FrameLayout implements } } + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + int size = MeasureSpec.getSize(widthMeasureSpec); + findViewById(R.id.wrapper).getLayoutParams().width = getTabWidth(getContext(), size); + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + public void setPosition(int position) { mPosition = position; } - } diff --git a/src/com/android/launcher3/allapps/WorkModeSwitch.java b/src/com/android/launcher3/allapps/WorkModeSwitch.java index 733577eabf..f26ed87298 100644 --- a/src/com/android/launcher3/allapps/WorkModeSwitch.java +++ b/src/com/android/launcher3/allapps/WorkModeSwitch.java @@ -16,20 +16,24 @@ package com.android.launcher3.allapps; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TURN_OFF_WORK_APPS_TAP; +import static com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip.getTabWidth; import android.content.Context; import android.graphics.Insets; import android.graphics.Rect; import android.util.AttributeSet; import android.view.View; +import android.view.ViewGroup.MarginLayoutParams; import android.view.ViewGroup; import android.view.WindowInsets; import android.widget.Button; import com.android.launcher3.DeviceProfile; import com.android.launcher3.Insettable; +import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.anim.KeyboardInsetAnimationCallback; +import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.model.StringCache; import com.android.launcher3.views.ActivityContext; import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip; @@ -85,16 +89,41 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi @Override public void setInsets(Rect insets) { - int bottomInset = insets.bottom - mInsets.bottom; mInsets.set(insets); - ViewGroup.MarginLayoutParams marginLayoutParams = - (ViewGroup.MarginLayoutParams) getLayoutParams(); - if (marginLayoutParams != null) { - marginLayoutParams.bottomMargin = bottomInset + marginLayoutParams.bottomMargin; + ViewGroup.MarginLayoutParams lp = (MarginLayoutParams) getLayoutParams(); + if (lp != null) { + int bottomMargin = getResources().getDimensionPixelSize(R.dimen.work_fab_margin_bottom); + if (FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get()) { + bottomMargin <<= 1; // Double margin to add space above search bar. + bottomMargin += getResources().getDimensionPixelSize(R.dimen.qsb_widget_height); + } + + DeviceProfile dp = ActivityContext.lookupContext(getContext()).getDeviceProfile(); + if (!dp.isGestureMode) { + if (dp.isTaskbarPresent) { + bottomMargin += dp.taskbarSize; + } else { + bottomMargin += insets.bottom; + } + } + + lp.bottomMargin = bottomMargin; } } + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + super.onLayout(changed, left, top, right, bottom); + DeviceProfile dp = ActivityContext.lookupContext(getContext()).getDeviceProfile(); + View parent = (View) getParent(); + int size = parent.getWidth() - parent.getPaddingLeft() - parent.getPaddingRight() + - 2 * dp.allAppsLeftRightPadding; + int tabWidth = getTabWidth(getContext(), size); + int shift = (size - tabWidth) / 2 + dp.allAppsLeftRightPadding; + setTranslationX(Utilities.isRtl(getResources()) ? shift : -shift); + } + @Override public void onActivePageChanged(int page) { mOnWorkTab = page == ActivityAllAppsContainerView.AdapterHolder.WORK; diff --git a/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java b/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java index 11185fb511..49db2a0b5f 100644 --- a/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java +++ b/src/com/android/launcher3/workprofile/PersonalWorkSlidingTabStrip.java @@ -23,7 +23,9 @@ import android.widget.LinearLayout; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.android.launcher3.DeviceProfile; import com.android.launcher3.pageindicators.PageIndicator; +import com.android.launcher3.views.ActivityContext; /** * Supports two indicator colors, dedicated for personal and work tabs. @@ -72,6 +74,26 @@ public class PersonalWorkSlidingTabStrip extends LinearLayout implements PageInd return false; } + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + if (getPaddingLeft() == 0 && getPaddingRight() == 0) { + // If any padding is not specified, restrict the width to emulate padding + int size = MeasureSpec.getSize(widthMeasureSpec); + size = getTabWidth(getContext(), size); + widthMeasureSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY); + } + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + } + + /** + * Returns distance between left and right app icons + */ + public static int getTabWidth(Context context, int totalWidth) { + DeviceProfile grid = ActivityContext.lookupContext(context).getDeviceProfile(); + int iconPadding = totalWidth / grid.numShownAllAppsColumns - grid.allAppsIconSizePx; + return totalWidth - iconPadding; + } + /** * Interface definition for a callback to be invoked when an active page has been changed. */ From 42b640404aa3e5b3990f9220797809c9ab3a066f Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Wed, 22 Jun 2022 13:34:23 -0700 Subject: [PATCH 2/2] Removing tabWidth calculation and using DeviceProfile directly This removes some dependency on FloatingHeaderView, making it easier to replace Bug: 234008165 Test: Verified that the UI does not change Change-Id: I363c98c23f84fe570ea9cb1a40128359f5b67c9f Merged-In: I363c98c23f84fe570ea9cb1a40128359f5b67c9f --- .../appprediction/AppsDividerView.java | 8 ----- .../appprediction/PredictionRowView.java | 7 ---- .../launcher3/allapps/FloatingHeaderRow.java | 5 --- .../launcher3/allapps/FloatingHeaderView.java | 33 ++----------------- .../launcher3/allapps/PluginHeaderRow.java | 5 --- .../launcher3/allapps/WorkEduCard.java | 2 -- .../launcher3/allapps/WorkModeSwitch.java | 6 ++-- .../launcher3/allapps/WorkProfileManager.java | 20 ----------- 8 files changed, 5 insertions(+), 81 deletions(-) diff --git a/quickstep/src/com/android/launcher3/appprediction/AppsDividerView.java b/quickstep/src/com/android/launcher3/appprediction/AppsDividerView.java index 0284ae4803..f42b39fb2d 100644 --- a/quickstep/src/com/android/launcher3/appprediction/AppsDividerView.java +++ b/quickstep/src/com/android/launcher3/appprediction/AppsDividerView.java @@ -21,7 +21,6 @@ import static com.android.launcher3.util.OnboardingPrefs.ALL_APPS_VISITED_COUNT; import android.annotation.TargetApi; import android.content.Context; import android.graphics.Canvas; -import android.graphics.Rect; import android.graphics.Typeface; import android.os.Build; import android.text.Layout; @@ -33,7 +32,6 @@ import android.view.View; import androidx.annotation.ColorInt; import androidx.core.content.ContextCompat; -import com.android.launcher3.DeviceProfile; import com.android.launcher3.R; import com.android.launcher3.allapps.FloatingHeaderRow; import com.android.launcher3.allapps.FloatingHeaderView; @@ -238,12 +236,6 @@ public class AppsDividerView extends View implements FloatingHeaderRow { getPaddingBottom() + getPaddingTop()); } - @Override - public void setInsets(Rect insets, DeviceProfile grid) { - int leftRightPadding = grid.allAppsLeftRightPadding; - setPadding(leftRightPadding, getPaddingTop(), leftRightPadding, getPaddingBottom()); - } - @Override public void setVerticalScroll(int scroll, boolean isScrolledOut) { setTranslationY(scroll); diff --git a/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java b/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java index 1dec73721c..351a3bc164 100644 --- a/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java +++ b/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java @@ -19,7 +19,6 @@ package com.android.launcher3.appprediction; import android.annotation.TargetApi; import android.content.Context; import android.graphics.Canvas; -import android.graphics.Rect; import android.os.Build; import android.util.AttributeSet; import android.view.LayoutInflater; @@ -251,12 +250,6 @@ public class PredictionRowView getTypeClass() { return PredictionRowView.class; diff --git a/src/com/android/launcher3/allapps/FloatingHeaderRow.java b/src/com/android/launcher3/allapps/FloatingHeaderRow.java index 6ff2132286..75e527aaa8 100644 --- a/src/com/android/launcher3/allapps/FloatingHeaderRow.java +++ b/src/com/android/launcher3/allapps/FloatingHeaderRow.java @@ -15,11 +15,8 @@ */ package com.android.launcher3.allapps; -import android.graphics.Rect; import android.view.View; -import com.android.launcher3.DeviceProfile; - /** * A abstract representation of a row in all-apps view */ @@ -29,8 +26,6 @@ public interface FloatingHeaderRow { void setup(FloatingHeaderView parent, FloatingHeaderRow[] allRows, boolean tabsHidden); - void setInsets(Rect insets, DeviceProfile grid); - int getExpectedHeight(); /** diff --git a/src/com/android/launcher3/allapps/FloatingHeaderView.java b/src/com/android/launcher3/allapps/FloatingHeaderView.java index 6ecbad24e8..d0331c9266 100644 --- a/src/com/android/launcher3/allapps/FloatingHeaderView.java +++ b/src/com/android/launcher3/allapps/FloatingHeaderView.java @@ -30,7 +30,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; -import com.android.launcher3.DeviceProfile; import com.android.launcher3.Insettable; import com.android.launcher3.R; import com.android.launcher3.allapps.BaseAllAppsContainerView.AdapterHolder; @@ -158,22 +157,6 @@ public class FloatingHeaderView extends LinearLayout implements PluginManagerWrapper.INSTANCE.get(getContext()).removePluginListener(this); } - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - mTabLayout.getLayoutParams().width = getTabWidth(); - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - } - - /** - * Returns distance between left and right app icons - */ - public int getTabWidth() { - DeviceProfile grid = ActivityContext.lookupContext(getContext()).getDeviceProfile(); - int totalWidth = getMeasuredWidth() - getPaddingLeft() - getPaddingRight(); - int iconPadding = totalWidth / grid.numShownAllAppsColumns - grid.allAppsIconSizePx; - return totalWidth - iconPadding - grid.allAppsIconDrawablePaddingPx; - } - private void recreateAllRowsArray() { int pluginCount = mPluginRows.size(); if (pluginCount == 0) { @@ -423,15 +406,6 @@ public class FloatingHeaderView extends LinearLayout implements p.y = getTop() - mCurrentRV.getTop() - ((ViewGroup) mCurrentRV.getParent()).getTop(); } - public boolean hasVisibleContent() { - for (FloatingHeaderRow row : mAllRows) { - if (row.hasVisibleContent()) { - return true; - } - } - return false; - } - public boolean isHeaderProtectionSupported() { return mHeaderProtectionSupported; } @@ -443,10 +417,9 @@ public class FloatingHeaderView extends LinearLayout implements @Override public void setInsets(Rect insets) { - DeviceProfile grid = ActivityContext.lookupContext(getContext()).getDeviceProfile(); - for (FloatingHeaderRow row : mAllRows) { - row.setInsets(insets, grid); - } + int leftRightPadding = ActivityContext.lookupContext(getContext()) + .getDeviceProfile().allAppsLeftRightPadding; + setPadding(leftRightPadding, getPaddingTop(), leftRightPadding, getPaddingBottom()); } public T findFixedRowByType(Class type) { diff --git a/src/com/android/launcher3/allapps/PluginHeaderRow.java b/src/com/android/launcher3/allapps/PluginHeaderRow.java index 5b5fbb7ff9..a9d36d1909 100644 --- a/src/com/android/launcher3/allapps/PluginHeaderRow.java +++ b/src/com/android/launcher3/allapps/PluginHeaderRow.java @@ -18,10 +18,8 @@ package com.android.launcher3.allapps; import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; -import android.graphics.Rect; import android.view.View; -import com.android.launcher3.DeviceProfile; import com.android.systemui.plugins.AllAppsRow; /** @@ -42,9 +40,6 @@ public class PluginHeaderRow implements FloatingHeaderRow { public void setup(FloatingHeaderView parent, FloatingHeaderRow[] allRows, boolean tabsHidden) { } - @Override - public void setInsets(Rect insets, DeviceProfile grid) { } - @Override public int getExpectedHeight() { return mPlugin.getExpectedHeight(); diff --git a/src/com/android/launcher3/allapps/WorkEduCard.java b/src/com/android/launcher3/allapps/WorkEduCard.java index c357764811..539cff1a37 100644 --- a/src/com/android/launcher3/allapps/WorkEduCard.java +++ b/src/com/android/launcher3/allapps/WorkEduCard.java @@ -72,8 +72,6 @@ public class WorkEduCard extends FrameLayout implements protected void onFinishInflate() { super.onFinishInflate(); findViewById(R.id.action_btn).setOnClickListener(this); - MarginLayoutParams lp = ((MarginLayoutParams) findViewById(R.id.wrapper).getLayoutParams()); - lp.width = mActivityContext.getAppsView().getFloatingHeaderView().getTabWidth(); } @Override diff --git a/src/com/android/launcher3/allapps/WorkModeSwitch.java b/src/com/android/launcher3/allapps/WorkModeSwitch.java index f26ed87298..edb012854a 100644 --- a/src/com/android/launcher3/allapps/WorkModeSwitch.java +++ b/src/com/android/launcher3/allapps/WorkModeSwitch.java @@ -24,7 +24,6 @@ import android.graphics.Rect; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup.MarginLayoutParams; -import android.view.ViewGroup; import android.view.WindowInsets; import android.widget.Button; @@ -54,7 +53,6 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi private boolean mWorkEnabled; private boolean mOnWorkTab; - public WorkModeSwitch(Context context) { this(context, null, 0); } @@ -90,7 +88,7 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi @Override public void setInsets(Rect insets) { mInsets.set(insets); - ViewGroup.MarginLayoutParams lp = (MarginLayoutParams) getLayoutParams(); + MarginLayoutParams lp = (MarginLayoutParams) getLayoutParams(); if (lp != null) { int bottomMargin = getResources().getDimensionPixelSize(R.dimen.work_fab_margin_bottom); if (FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get()) { @@ -99,6 +97,7 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi } DeviceProfile dp = ActivityContext.lookupContext(getContext()).getDeviceProfile(); + lp.rightMargin = lp.leftMargin = dp.allAppsLeftRightPadding; if (!dp.isGestureMode) { if (dp.isTaskbarPresent) { bottomMargin += dp.taskbarSize; @@ -111,7 +110,6 @@ public class WorkModeSwitch extends Button implements Insettable, View.OnClickLi } } - @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); diff --git a/src/com/android/launcher3/allapps/WorkProfileManager.java b/src/com/android/launcher3/allapps/WorkProfileManager.java index b70cb13b07..2f5b7a2dd3 100644 --- a/src/com/android/launcher3/allapps/WorkProfileManager.java +++ b/src/com/android/launcher3/allapps/WorkProfileManager.java @@ -26,7 +26,6 @@ import android.os.Process; import android.os.UserHandle; import android.os.UserManager; import android.util.Log; -import android.view.ViewGroup; import androidx.annotation.IntDef; import androidx.annotation.Nullable; @@ -34,7 +33,6 @@ import androidx.annotation.RequiresApi; import com.android.launcher3.DeviceProfile; import com.android.launcher3.R; -import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.workprofile.PersonalWorkSlidingTabStrip; @@ -144,24 +142,6 @@ public class WorkProfileManager implements PersonalWorkSlidingTabStrip.OnActiveP mWorkModeSwitch = (WorkModeSwitch) mAllApps.getLayoutInflater().inflate( R.layout.work_mode_fab, mAllApps, false); } - ViewGroup.MarginLayoutParams lp = - (ViewGroup.MarginLayoutParams) mWorkModeSwitch.getLayoutParams(); - int workFabMarginBottom = - mWorkModeSwitch.getResources().getDimensionPixelSize( - R.dimen.work_fab_margin_bottom); - if (FeatureFlags.ENABLE_FLOATING_SEARCH_BAR.get()) { - workFabMarginBottom <<= 1; // Double margin to add space above search bar. - workFabMarginBottom += - mWorkModeSwitch.getResources().getDimensionPixelSize(R.dimen.qsb_widget_height); - } - if (!mAllApps.mActivityContext.getDeviceProfile().isGestureMode){ - workFabMarginBottom += mAllApps.mActivityContext.getDeviceProfile().getInsets().bottom; - } - lp.bottomMargin = workFabMarginBottom; - int totalScreenWidth = mDeviceProfile.widthPx; - int personalWorkTabWidth = - mAllApps.mActivityContext.getAppsView().getFloatingHeaderView().getTabWidth(); - lp.rightMargin = lp.leftMargin = (totalScreenWidth - personalWorkTabWidth) / 2; if (mWorkModeSwitch.getParent() != mAllApps) { mAllApps.addView(mWorkModeSwitch); }