From fd388805d69bd284817d74c86db71bac85d345e0 Mon Sep 17 00:00:00 2001 From: Fabian Kozynski Date: Thu, 24 Mar 2022 14:40:57 -0400 Subject: [PATCH] Calculate min height for header in code Having a resource that depended on 6 other resources was becoming unmaintainable. Replace with in code calculation, guaranteeing that it'll always be up to date for handheld devices. Test: manual Fixes: 225405922 Change-Id: Ieb13b1d71d4b205ea37ff096e447f93bbaec2630 --- .../res/layout/qs_customize_header.xml | 1 - packages/SystemUI/res/values-land/dimens.xml | 5 ---- packages/SystemUI/res/values/dimens.xml | 6 +---- .../systemui/qs/customize/QSCustomizer.java | 1 + .../systemui/qs/customize/TileAdapter.java | 27 ++++++++++++++++++- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/packages/SystemUI/res/layout/qs_customize_header.xml b/packages/SystemUI/res/layout/qs_customize_header.xml index 626d53aba6115..ec2f77049b2b5 100644 --- a/packages/SystemUI/res/layout/qs_customize_header.xml +++ b/packages/SystemUI/res/layout/qs_customize_header.xml @@ -21,6 +21,5 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center" - android:minHeight="@dimen/qs_customize_header_min_height" android:textAppearance="@style/TextAppearance.QSEdit" android:text="@string/drag_to_rearrange_tiles" /> \ No newline at end of file diff --git a/packages/SystemUI/res/values-land/dimens.xml b/packages/SystemUI/res/values-land/dimens.xml index c386a3e684a92..609713bb23578 100644 --- a/packages/SystemUI/res/values-land/dimens.xml +++ b/packages/SystemUI/res/values-land/dimens.xml @@ -25,11 +25,6 @@ 0dp 12dp 8dp - - 48dp diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index a309cc4ff1f5b..1ece5dc69f1ab 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -476,11 +476,7 @@ 8dp 24dp 16dp - - 68dp + 8dp 20dp 28dp diff --git a/packages/SystemUI/src/com/android/systemui/qs/customize/QSCustomizer.java b/packages/SystemUI/src/com/android/systemui/qs/customize/QSCustomizer.java index 71f0a33fd3747..8ad011904d3dc 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/customize/QSCustomizer.java +++ b/packages/SystemUI/src/com/android/systemui/qs/customize/QSCustomizer.java @@ -88,6 +88,7 @@ public class QSCustomizer extends LinearLayout { LayoutParams lp = (LayoutParams) mTransparentView.getLayoutParams(); lp.height = QSUtils.getQsHeaderSystemIconsAreaHeight(mContext); mTransparentView.setLayoutParams(lp); + mRecyclerView.getAdapter().notifyItemChanged(0); } void updateNavBackDrop(Configuration newConfig, LightBarController lightBarController) { diff --git a/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java b/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java index c1970b962d2e4..e52bfbd67275f 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/qs/customize/TileAdapter.java @@ -17,6 +17,7 @@ package com.android.systemui.qs.customize; import android.content.ComponentName; import android.content.Context; import android.content.res.Resources; +import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.Drawable; @@ -277,7 +278,9 @@ public class TileAdapter extends RecyclerView.Adapter implements TileSta final Context context = parent.getContext(); LayoutInflater inflater = LayoutInflater.from(context); if (viewType == TYPE_HEADER) { - return new Holder(inflater.inflate(R.layout.qs_customize_header, parent, false)); + View v = inflater.inflate(R.layout.qs_customize_header, parent, false); + v.setMinimumHeight(calculateHeaderMinHeight(context)); + return new Holder(v); } if (viewType == TYPE_DIVIDER) { return new Holder(inflater.inflate(R.layout.qs_customize_tile_divider, parent, false)); @@ -835,4 +838,26 @@ public class TileAdapter extends RecyclerView.Adapter implements TileSta super.clearView(recyclerView, viewHolder); } }; + + private static int calculateHeaderMinHeight(Context context) { + Resources res = context.getResources(); + // style used in qs_customize_header.xml for the Toolbar + TypedArray toolbarStyle = context.obtainStyledAttributes( + R.style.QSCustomizeToolbar, com.android.internal.R.styleable.Toolbar); + int buttonStyle = toolbarStyle.getResourceId( + com.android.internal.R.styleable.Toolbar_navigationButtonStyle, 0); + toolbarStyle.recycle(); + int buttonMinWidth = 0; + if (buttonStyle != 0) { + TypedArray t = context.obtainStyledAttributes(buttonStyle, android.R.styleable.View); + buttonMinWidth = t.getDimensionPixelSize(android.R.styleable.View_minWidth, 0); + t.recycle(); + } + return res.getDimensionPixelSize(R.dimen.qs_panel_padding_top) + + res.getDimensionPixelSize(R.dimen.brightness_mirror_height) + + res.getDimensionPixelSize(R.dimen.qs_brightness_margin_top) + + res.getDimensionPixelSize(R.dimen.qs_brightness_margin_bottom) + - buttonMinWidth + - res.getDimensionPixelSize(R.dimen.qs_tile_margin_top_bottom); + } }