Merge changes from topic "fabFixMoveToTM" into tm-dev

* changes:
  Removing tabWidth calculation and using DeviceProfile directly
  Fixing tab width and panner not aligned with the all-apps icons
This commit is contained in:
TreeHugger Robot
2022-08-09 19:16:58 +00:00
committed by Android (Google) Code Review
9 changed files with 70 additions and 91 deletions

View File

@@ -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);

View File

@@ -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<T extends Context & ActivityContext & DeviceProfi
}
}
@Override
public void setInsets(Rect insets, DeviceProfile grid) {
int leftRightPadding = grid.allAppsLeftRightPadding;
setPadding(leftRightPadding, getPaddingTop(), leftRightPadding, getPaddingBottom());
}
@Override
public Class<PredictionRowView> getTypeClass() {
return PredictionRowView.class;

View File

@@ -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();
/**

View File

@@ -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 extends FloatingHeaderRow> T findFixedRowByType(Class<T> type) {

View File

@@ -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();

View File

@@ -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;
@@ -70,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
@@ -87,14 +87,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 +103,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;
}
}

View File

@@ -16,20 +16,23 @@
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;
import android.view.ViewGroup.MarginLayoutParams;
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;
@@ -50,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);
}
@@ -85,15 +87,40 @@ 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;
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();
lp.rightMargin = lp.leftMargin = dp.allAppsLeftRightPadding;
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) {

View File

@@ -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);
}

View File

@@ -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.
*/