From 86fd923d6f5f84daf1fbe9035264f02675089627 Mon Sep 17 00:00:00 2001 From: Mill Chen Date: Fri, 16 Apr 2021 03:02:34 +0800 Subject: [PATCH] Update the style for collapsing toolbar The new version of collapsing toolbar has been updated and it needs the edge-to-edge configruation to work smoothly. Added the configuration for Notification history and removed useless styles. This change is also trying to reuse the layout that is from SettingsLib and remove the one from Settings. Bug: 183496853 Test: visual verified Change-Id: Iecfb96fe5ead91b0421050c3dfc1c1ab456aafff --- .../settings_collapsing_base_layout.xml | 68 ------------------- res/values/dimens.xml | 8 --- res/values/styles.xml | 6 +- res/values/themes.xml | 2 + .../settings/core/SettingsBaseActivity.java | 50 +------------- 5 files changed, 4 insertions(+), 130 deletions(-) delete mode 100644 res/layout/settings_collapsing_base_layout.xml diff --git a/res/layout/settings_collapsing_base_layout.xml b/res/layout/settings_collapsing_base_layout.xml deleted file mode 100644 index 97d249c00ac..00000000000 --- a/res/layout/settings_collapsing_base_layout.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 6047092f8d3..304feb82021 100755 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -446,12 +446,4 @@ 2dp 1dp 2dp - - - 226dp - 270dp - 314dp - 174dp - 24dp - 24dp diff --git a/res/values/styles.xml b/res/values/styles.xml index 31f44dd609a..cb0027e2495 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -781,7 +781,7 @@ @*android:string/config_headlineFontFamily - - - diff --git a/src/com/android/settings/core/SettingsBaseActivity.java b/src/com/android/settings/core/SettingsBaseActivity.java index 569e4805b8d..e0e41dee2d2 100644 --- a/src/com/android/settings/core/SettingsBaseActivity.java +++ b/src/com/android/settings/core/SettingsBaseActivity.java @@ -49,8 +49,6 @@ import com.android.settingslib.drawer.Tile; import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.setupcompat.util.WizardManagerHelper; -import java.lang.reflect.Field; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -61,7 +59,6 @@ public class SettingsBaseActivity extends FragmentActivity { protected static final boolean DEBUG_TIMING = false; private static final String TAG = "SettingsBaseActivity"; private static final String DATA_SCHEME_PKG = "package"; - private static final int TOOLBAR_MAX_LINE_NUMBER = 2; // Serves as a temporary list of tiles to ignore until we heard back from the PM that they // are disabled. @@ -95,7 +92,7 @@ public class SettingsBaseActivity extends FragmentActivity { if (FeatureFlagUtils.isEnabled(this, FeatureFlags.SILKY_HOME) && isToolbarEnabled() && !isAnySetupWizard) { - super.setContentView(R.layout.settings_collapsing_base_layout); + super.setContentView(R.layout.collapsing_toolbar_base_layout); mCollapsingToolbarLayout = findViewById(R.id.collapsing_toolbar); } else { super.setContentView(R.layout.settings_base_layout); @@ -108,7 +105,6 @@ public class SettingsBaseActivity extends FragmentActivity { return; } setActionBar(toolbar); - initCollapsingToolbar(); if (DEBUG_TIMING) { Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms"); @@ -207,50 +203,6 @@ public class SettingsBaseActivity extends FragmentActivity { return true; } - private void initCollapsingToolbar() { - if (mCollapsingToolbarLayout == null) { - return; - } - mCollapsingToolbarLayout.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, - int oldLeft, int oldTop, int oldRight, int oldBottom) { - v.removeOnLayoutChangeListener(this); - final int count = getLineCount(); - if (count > TOOLBAR_MAX_LINE_NUMBER) { - ViewGroup.LayoutParams lp = mCollapsingToolbarLayout.getLayoutParams(); - lp.height = getResources() - .getDimensionPixelSize(R.dimen.toolbar_three_lines_height); - mCollapsingToolbarLayout.setLayoutParams(lp); - } else if (count == TOOLBAR_MAX_LINE_NUMBER) { - ViewGroup.LayoutParams lp = mCollapsingToolbarLayout.getLayoutParams(); - lp.height = - getResources().getDimensionPixelSize(R.dimen.toolbar_two_lines_height); - mCollapsingToolbarLayout.setLayoutParams(lp); - } - } - }); - } - - private int getLineCount() { - try { - final Class toolbarClazz = mCollapsingToolbarLayout.getClass(); - final Field textHelperField = toolbarClazz.getDeclaredField("collapsingTextHelper"); - textHelperField.setAccessible(true); - final Object textHelperObj = textHelperField.get(mCollapsingToolbarLayout); - - final Field layoutField = textHelperObj.getClass().getDeclaredField("textLayout"); - layoutField.setAccessible(true); - final Object layoutObj = layoutField.get(textHelperObj); - - final Method method = layoutObj.getClass().getDeclaredMethod("getLineCount"); - return (int) method.invoke(layoutObj); - } catch (Exception e) { - return 0; - } - } - - private void onCategoriesChanged(Set categories) { final int N = mCategoryListeners.size(); for (int i = 0; i < N; i++) {