Merge "Update the style for collapsing toolbar" into sc-dev
diff --git a/res/layout/settings_collapsing_base_layout.xml b/res/layout/settings_collapsing_base_layout.xml
deleted file mode 100644
index 97d249c..0000000
--- a/res/layout/settings_collapsing_base_layout.xml
+++ /dev/null
@@ -1,68 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-     Copyright (C) 2021 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.
--->
-<androidx.coordinatorlayout.widget.CoordinatorLayout
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    android:id="@+id/content_parent"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:fitsSystemWindows="true">
-
-    <com.google.android.material.appbar.AppBarLayout
-        android:id="@+id/app_bar"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:fitsSystemWindows="true"
-        android:outlineAmbientShadowColor="@android:color/transparent"
-        android:outlineSpotShadowColor="@android:color/transparent"
-        android:background="@android:color/transparent"
-        android:theme="@style/Theme.CollapsingToolbar.Settings">
-
-        <com.google.android.material.appbar.CollapsingToolbarLayout
-            android:id="@+id/collapsing_toolbar"
-            android:layout_width="match_parent"
-            android:layout_height="@dimen/toolbar_one_line_height"
-            android:clipToPadding="false"
-            app:contentScrim="@color/color_surface_header"
-            app:maxLines="3"
-            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
-            app:scrimAnimationDuration="50"
-            app:scrimVisibleHeightTrigger="@dimen/scrim_visible_height_trigger"
-            app:statusBarScrim="@empty"
-            app:titleCollapseMode="fade"
-            app:collapsedTitleTextAppearance="@style/ToolbarText.Collapsed"
-            app:expandedTitleTextAppearance="@style/ToolbarText.Expanded"
-            app:expandedTitleMarginStart="@dimen/expanded_title_margin_start"
-            app:expandedTitleMarginEnd="@dimen/expanded_title_margin_end"
-            app:toolbarId="@id/action_bar">
-
-            <Toolbar
-                android:id="@+id/action_bar"
-                android:layout_width="match_parent"
-                android:layout_height="?attr/actionBarSize"
-                android:theme="?android:attr/actionBarTheme"
-                app:layout_collapseMode="pin"/>
-
-        </com.google.android.material.appbar.CollapsingToolbarLayout>
-    </com.google.android.material.appbar.AppBarLayout>
-
-    <FrameLayout
-        android:id="@+id/content_frame"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
-</androidx.coordinatorlayout.widget.CoordinatorLayout>
\ No newline at end of file
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 6047092..304feb8 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -446,12 +446,4 @@
     <dimen name="chartview_trapezoid_radius">2dp</dimen>
     <dimen name="chartview_trapezoid_margin_start">1dp</dimen>
     <dimen name="chartview_trapezoid_margin_bottom">2dp</dimen>
-
-    <!-- Collapsing toolbar layout dimensions -->
-    <dimen name="toolbar_one_line_height">226dp</dimen>
-    <dimen name="toolbar_two_lines_height">270dp</dimen>
-    <dimen name="toolbar_three_lines_height">314dp</dimen>
-    <dimen name="scrim_visible_height_trigger">174dp</dimen>
-    <dimen name="expanded_title_margin_start">24dp</dimen>
-    <dimen name="expanded_title_margin_end">24dp</dimen>
 </resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index e91ddcb..b27cc5d 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -787,7 +787,7 @@
         <item name="android:fontFamily">@*android:string/config_headlineFontFamily</item>
     </style>
 
-    <style name="HomepageTitleText" parent="ToolbarText.Expanded">
+    <style name="HomepageTitleText" parent="CollapsingToolbarTitle.Expanded">
         <item name="android:layout_width">wrap_content</item>
         <item name="android:layout_height">wrap_content</item>
         <item name="android:layout_marginBottom">@dimen/homepage_title_margin_bottom</item>
@@ -879,8 +879,4 @@
         <item name="android:textSize">16sp</item>
         <item name="android:textColor">?android:attr/textColorSecondary</item>
     </style>
-
-    <style name="ToolbarText.Collapsed" parent="CollapsingToolbarTitle.Collapsed"/>
-    <style name="ToolbarText.Expanded" parent="CollapsingToolbarTitle"/>
-    <style name="ToolbarText.MoreThanTwoLines" parent="CollapsingToolbarTitle.MoreThanTwoLines"/>
 </resources>
diff --git a/res/values/themes.xml b/res/values/themes.xml
index 02f94d2..0bd7c5b 100644
--- a/res/values/themes.xml
+++ b/res/values/themes.xml
@@ -272,5 +272,7 @@
     <style name="Theme.NotificationHistory" parent="@android:style/Theme.DeviceDefault.DayNight">
         <item name="android:windowActionBar">false</item>
         <item name="android:windowNoTitle">true</item>
+        <item name="android:navigationBarColor">@android:color/transparent</item>
+        <item name="android:statusBarColor">@android:color/transparent</item>
     </style>
 </resources>
diff --git a/src/com/android/settings/core/SettingsBaseActivity.java b/src/com/android/settings/core/SettingsBaseActivity.java
index 569e480..e0e41de 100644
--- a/src/com/android/settings/core/SettingsBaseActivity.java
+++ b/src/com/android/settings/core/SettingsBaseActivity.java
@@ -49,8 +49,6 @@
 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 @@
     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 @@
 
         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 @@
             return;
         }
         setActionBar(toolbar);
-        initCollapsingToolbar();
 
         if (DEBUG_TIMING) {
             Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
@@ -207,50 +203,6 @@
         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<String> categories) {
         final int N = mCategoryListeners.size();
         for (int i = 0; i < N; i++) {