Merge "Update the style for collapsing toolbar" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
ea2a359561
@@ -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>
|
|
@@ -446,12 +446,4 @@
|
|||||||
<dimen name="chartview_trapezoid_radius">2dp</dimen>
|
<dimen name="chartview_trapezoid_radius">2dp</dimen>
|
||||||
<dimen name="chartview_trapezoid_margin_start">1dp</dimen>
|
<dimen name="chartview_trapezoid_margin_start">1dp</dimen>
|
||||||
<dimen name="chartview_trapezoid_margin_bottom">2dp</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>
|
</resources>
|
||||||
|
@@ -787,7 +787,7 @@
|
|||||||
<item name="android:fontFamily">@*android:string/config_headlineFontFamily</item>
|
<item name="android:fontFamily">@*android:string/config_headlineFontFamily</item>
|
||||||
</style>
|
</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_width">wrap_content</item>
|
||||||
<item name="android:layout_height">wrap_content</item>
|
<item name="android:layout_height">wrap_content</item>
|
||||||
<item name="android:layout_marginBottom">@dimen/homepage_title_margin_bottom</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:textSize">16sp</item>
|
||||||
<item name="android:textColor">?android:attr/textColorSecondary</item>
|
<item name="android:textColor">?android:attr/textColorSecondary</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="ToolbarText.Collapsed" parent="CollapsingToolbarTitle.Collapsed"/>
|
|
||||||
<style name="ToolbarText.Expanded" parent="CollapsingToolbarTitle"/>
|
|
||||||
<style name="ToolbarText.MoreThanTwoLines" parent="CollapsingToolbarTitle.MoreThanTwoLines"/>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -272,5 +272,7 @@
|
|||||||
<style name="Theme.NotificationHistory" parent="@android:style/Theme.DeviceDefault.DayNight">
|
<style name="Theme.NotificationHistory" parent="@android:style/Theme.DeviceDefault.DayNight">
|
||||||
<item name="android:windowActionBar">false</item>
|
<item name="android:windowActionBar">false</item>
|
||||||
<item name="android:windowNoTitle">true</item>
|
<item name="android:windowNoTitle">true</item>
|
||||||
|
<item name="android:navigationBarColor">@android:color/transparent</item>
|
||||||
|
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||||
</style>
|
</style>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -49,8 +49,6 @@ import com.android.settingslib.drawer.Tile;
|
|||||||
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
import com.google.android.material.appbar.CollapsingToolbarLayout;
|
||||||
import com.google.android.setupcompat.util.WizardManagerHelper;
|
import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -61,7 +59,6 @@ public class SettingsBaseActivity extends FragmentActivity {
|
|||||||
protected static final boolean DEBUG_TIMING = false;
|
protected static final boolean DEBUG_TIMING = false;
|
||||||
private static final String TAG = "SettingsBaseActivity";
|
private static final String TAG = "SettingsBaseActivity";
|
||||||
private static final String DATA_SCHEME_PKG = "package";
|
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
|
// Serves as a temporary list of tiles to ignore until we heard back from the PM that they
|
||||||
// are disabled.
|
// are disabled.
|
||||||
@@ -95,7 +92,7 @@ public class SettingsBaseActivity extends FragmentActivity {
|
|||||||
|
|
||||||
if (FeatureFlagUtils.isEnabled(this, FeatureFlags.SILKY_HOME)
|
if (FeatureFlagUtils.isEnabled(this, FeatureFlags.SILKY_HOME)
|
||||||
&& isToolbarEnabled() && !isAnySetupWizard) {
|
&& isToolbarEnabled() && !isAnySetupWizard) {
|
||||||
super.setContentView(R.layout.settings_collapsing_base_layout);
|
super.setContentView(R.layout.collapsing_toolbar_base_layout);
|
||||||
mCollapsingToolbarLayout = findViewById(R.id.collapsing_toolbar);
|
mCollapsingToolbarLayout = findViewById(R.id.collapsing_toolbar);
|
||||||
} else {
|
} else {
|
||||||
super.setContentView(R.layout.settings_base_layout);
|
super.setContentView(R.layout.settings_base_layout);
|
||||||
@@ -108,7 +105,6 @@ public class SettingsBaseActivity extends FragmentActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setActionBar(toolbar);
|
setActionBar(toolbar);
|
||||||
initCollapsingToolbar();
|
|
||||||
|
|
||||||
if (DEBUG_TIMING) {
|
if (DEBUG_TIMING) {
|
||||||
Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
|
Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
|
||||||
@@ -207,50 +203,6 @@ public class SettingsBaseActivity extends FragmentActivity {
|
|||||||
return true;
|
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) {
|
private void onCategoriesChanged(Set<String> categories) {
|
||||||
final int N = mCategoryListeners.size();
|
final int N = mCategoryListeners.size();
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
|
Reference in New Issue
Block a user