diff options
| author | 2024-10-14 23:03:59 +0000 | |
|---|---|---|
| committer | 2024-10-15 06:59:20 +0000 | |
| commit | ea0ecb329ecf96d0f2dcc51a9c59e81cc38e1912 (patch) | |
| tree | 882fe47ff1b7eb3c50fd7b099b445891509be1a7 | |
| parent | 391f3cff518cb349c69c02debd7d136f8f55aaed (diff) | |
[EXPD] Make non-collapsible toolbar style customizable
Setting Theme.CollapsingToolbar.Settings (which inherits from
Theme.MaterialComponents) as android:theme on AppBarLayout overrides
almost all the theme attributes from the original OEM customizable
Theme.DeviceDefault.Settings theme, because Theme.MaterialComponents
eventually inherits from android:Theme.Material which resets everything.
This change creates a PlatformBridge theme overlay that allows adding
the required theme attributes for MaterialComponents to work, without
resetting everything and make child views deviate from the intended
platform theme.
An OEM will be able to set android:toolbarStyle to customize the action
bar after this change, which is the intended way for customization.
The new theme overlay is only used for the OEM-only
non_collapsing_toolbar_content_layout.xml for now, so that there's no
risk of regression on AOSP or Pixel builds.
Bug: 349675008
Test: atest CtsPermissionUiTestCases
Flag: com.android.permission.flags.app_permission_fragment_uses_preferences
Relnote: N/A
Change-Id: I106c07680ccd4514f888506117c165a5764f1ce5
4 files changed, 202 insertions, 4 deletions
diff --git a/packages/SettingsLib/CollapsingToolbarBaseActivity/res/layout-v31/non_collapsing_toolbar_content_layout.xml b/packages/SettingsLib/CollapsingToolbarBaseActivity/res/layout-v31/non_collapsing_toolbar_content_layout.xml index 33519cba2940..dd7eac776583 100644 --- a/packages/SettingsLib/CollapsingToolbarBaseActivity/res/layout-v31/non_collapsing_toolbar_content_layout.xml +++ b/packages/SettingsLib/CollapsingToolbarBaseActivity/res/layout-v31/non_collapsing_toolbar_content_layout.xml @@ -26,12 +26,12 @@ android:outlineAmbientShadowColor="@android:color/transparent" android:outlineSpotShadowColor="@android:color/transparent" android:background="@android:color/transparent" - android:theme="@style/Theme.CollapsingToolbar.Settings"> + android:theme="@style/ThemeOverlay.MaterialComponents.PlatformBridge.CollapsingToolbar"> <Toolbar android:id="@+id/action_bar" android:layout_width="match_parent" - android:layout_height="?attr/actionBarSize" + android:layout_height="?android:attr/actionBarSize" android:theme="?android:attr/actionBarTheme" android:transitionName="shared_element_view" app:layout_collapseMode="pin"/> diff --git a/packages/SettingsLib/CollapsingToolbarBaseActivity/res/values-night-v31/themes.xml b/packages/SettingsLib/CollapsingToolbarBaseActivity/res/values-night-v31/themes.xml index c20beaf9bf93..02f171cf0d9e 100644 --- a/packages/SettingsLib/CollapsingToolbarBaseActivity/res/values-night-v31/themes.xml +++ b/packages/SettingsLib/CollapsingToolbarBaseActivity/res/values-night-v31/themes.xml @@ -21,4 +21,15 @@ <item name="colorPrimary">@color/settingslib_primary_dark_device_default_settings</item> <item name="colorAccent">@color/settingslib_accent_device_default_dark</item> </style> -</resources>
\ No newline at end of file + + <!-- + ~ TODO(b/349675008): Remove this theme overlay once the platform bridge theme properly sets + ~ the MaterialComponents colors based on the platform theme. + --> + <style name="ThemeOverlay.MaterialComponents.PlatformBridge.CollapsingToolbar"> + <item name="elevationOverlayEnabled">true</item> + <item name="elevationOverlayColor">?attr/colorPrimary</item> + <item name="colorPrimary">@color/settingslib_primary_dark_device_default_settings</item> + <item name="colorAccent">@color/settingslib_accent_device_default_dark</item> + </style> +</resources> diff --git a/packages/SettingsLib/CollapsingToolbarBaseActivity/res/values-v31/themes.xml b/packages/SettingsLib/CollapsingToolbarBaseActivity/res/values-v31/themes.xml index 9ecc297c6d36..403931764d7e 100644 --- a/packages/SettingsLib/CollapsingToolbarBaseActivity/res/values-v31/themes.xml +++ b/packages/SettingsLib/CollapsingToolbarBaseActivity/res/values-v31/themes.xml @@ -21,4 +21,15 @@ <item name="colorPrimary">@color/settingslib_primary_device_default_settings_light</item> <item name="colorAccent">@color/settingslib_accent_device_default_light</item> </style> -</resources>
\ No newline at end of file + + <!-- + ~ TODO(b/349675008): Remove this theme overlay once the platform bridge theme properly sets + ~ the MaterialComponents colors based on the platform theme. + --> + <style name="ThemeOverlay.MaterialComponents.PlatformBridge.CollapsingToolbar"> + <item name="elevationOverlayEnabled">true</item> + <item name="elevationOverlayColor">?attr/colorPrimary</item> + <item name="colorPrimary">@color/settingslib_primary_device_default_settings_light</item> + <item name="colorAccent">@color/settingslib_accent_device_default_light</item> + </style> +</resources> diff --git a/packages/SettingsLib/CollapsingToolbarBaseActivity/res/values-v31/themes_bridge.xml b/packages/SettingsLib/CollapsingToolbarBaseActivity/res/values-v31/themes_bridge.xml new file mode 100644 index 000000000000..bcb9baf94706 --- /dev/null +++ b/packages/SettingsLib/CollapsingToolbarBaseActivity/res/values-v31/themes_bridge.xml @@ -0,0 +1,176 @@ +<?xml version="1.0" encoding="utf-8"?> + +<!-- + Copyright (C) 2024 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. +--> + +<!-- See appcompat/appcompat/THEMES for the theme structure. --> +<resources> + <!-- + ~ Bridge theme overlay to simulate AppCompat themes based on a platform theme. + ~ Only non-widget attributes are included here since we should still use the platform widgets. + ~ Only public theme attributes (as in platform public-final.xml) can be referenced here since + ~ this is used in modules. + --> + <style name="Base.V31.ThemeOverlay.AppCompat.PlatformBridge" parent=""> + <!-- START Base.V7.Theme.AppCompat --> + + <item name="colorBackgroundFloating">?android:colorBackgroundFloating</item> + + <item name="isLightTheme">?android:isLightTheme</item> + + <item name="selectableItemBackground">?android:selectableItemBackground</item> + <item name="selectableItemBackgroundBorderless">?android:selectableItemBackgroundBorderless</item> + <item name="homeAsUpIndicator">?android:homeAsUpIndicator</item> + + <item name="dividerVertical">?android:dividerVertical</item> + <item name="dividerHorizontal">?android:dividerHorizontal</item> + + <!-- List attributes --> + <item name="textAppearanceListItem">?android:textAppearanceListItem</item> + <item name="textAppearanceListItemSmall">?android:textAppearanceListItemSmall</item> + <item name="textAppearanceListItemSecondary">?android:textAppearanceListItemSecondary</item> + <item name="listPreferredItemHeight">?android:listPreferredItemHeight</item> + <item name="listPreferredItemHeightSmall">?android:listPreferredItemHeightSmall</item> + <item name="listPreferredItemHeightLarge">?android:listPreferredItemHeightLarge</item> + <item name="listPreferredItemPaddingLeft">?android:listPreferredItemPaddingLeft</item> + <item name="listPreferredItemPaddingRight">?android:listPreferredItemPaddingRight</item> + <item name="listPreferredItemPaddingStart">?android:listPreferredItemPaddingStart</item> + <item name="listPreferredItemPaddingEnd">?android:listPreferredItemPaddingEnd</item> + + <!-- Color palette --> + <item name="colorPrimaryDark">?android:colorPrimaryDark</item> + <item name="colorPrimary">?android:colorPrimary</item> + <item name="colorAccent">?android:colorAccent</item> + + <item name="colorControlNormal">?android:colorControlNormal</item> + <item name="colorControlActivated">?android:colorControlActivated</item> + <item name="colorControlHighlight">?android:colorControlHighlight</item> + <item name="colorButtonNormal">?android:colorButtonNormal</item> + + <item name="colorError">?android:colorError</item> + + <!-- END Base.V7.Theme.AppCompat --> + </style> + <style name="Base.ThemeOverlay.AppCompat.PlatformBridge" parent="Base.V31.ThemeOverlay.AppCompat.PlatformBridge" /> + <style name="ThemeOverlay.AppCompat.PlatformBridge" parent="Base.ThemeOverlay.AppCompat.PlatformBridge" /> + + <!-- + ~ Bridge theme overlay to simulate MaterialComponents themes based on a platform theme. + --> + <style name="Base.V31.ThemeOverlay.MaterialComponents.PlatformBridge" parent="ThemeOverlay.AppCompat.PlatformBridge"> + <!-- START Base.V14.Theme.MaterialComponents.Bridge --> + <!-- + ~ This is copied as-is from the original bridge theme since it is guaranteed to not affect + ~ existing widgets. + --> + + <item name="isMaterialTheme">true</item> + + <item name="colorPrimaryVariant">@color/design_dark_default_color_primary_variant</item> + <item name="colorSecondary">@color/design_dark_default_color_secondary</item> + <item name="colorSecondaryVariant">@color/design_dark_default_color_secondary_variant</item> + <item name="colorSurface">@color/design_dark_default_color_surface</item> + <item name="colorPrimarySurface">?attr/colorSurface</item> + <item name="colorOnPrimary">@color/design_dark_default_color_on_primary</item> + <item name="colorOnSecondary">@color/design_dark_default_color_on_secondary</item> + <item name="colorOnBackground">@color/design_dark_default_color_on_background</item> + <item name="colorOnError">@color/design_dark_default_color_on_error</item> + <item name="colorOnSurface">@color/design_dark_default_color_on_surface</item> + <item name="colorOnPrimarySurface">?attr/colorOnSurface</item> + + <item name="scrimBackground">@color/mtrl_scrim_color</item> + <item name="popupMenuBackground">@drawable/mtrl_popupmenu_background_overlay</item> + + <item name="minTouchTargetSize">@dimen/mtrl_min_touch_target_size</item> + + <!-- MaterialComponents Widget styles --> + <item name="badgeStyle">@style/Widget.MaterialComponents.Badge</item> + <item name="bottomAppBarStyle">@style/Widget.MaterialComponents.BottomAppBar</item> + <item name="chipStyle">@style/Widget.MaterialComponents.Chip.Action</item> + <item name="chipGroupStyle">@style/Widget.MaterialComponents.ChipGroup</item> + <item name="chipStandaloneStyle">@style/Widget.MaterialComponents.Chip.Entry</item> + <item name="circularProgressIndicatorStyle">@style/Widget.MaterialComponents.CircularProgressIndicator</item> + <item name="extendedFloatingActionButtonStyle">@style/Widget.MaterialComponents.ExtendedFloatingActionButton.Icon</item> + <item name="linearProgressIndicatorStyle">@style/Widget.MaterialComponents.LinearProgressIndicator</item> + <item name="materialButtonStyle">@style/Widget.MaterialComponents.Button</item> + <item name="materialButtonOutlinedStyle">@style/Widget.MaterialComponents.Button.OutlinedButton</item> + <item name="materialButtonToggleGroupStyle">@style/Widget.MaterialComponents.MaterialButtonToggleGroup</item> + <item name="materialCardViewStyle">@style/Widget.MaterialComponents.CardView</item> + <item name="navigationRailStyle">@style/Widget.MaterialComponents.NavigationRailView</item> + <item name="sliderStyle">@style/Widget.MaterialComponents.Slider</item> + + <!-- Type styles --> + <item name="textAppearanceHeadline1">@style/TextAppearance.MaterialComponents.Headline1</item> + <item name="textAppearanceHeadline2">@style/TextAppearance.MaterialComponents.Headline2</item> + <item name="textAppearanceHeadline3">@style/TextAppearance.MaterialComponents.Headline3</item> + <item name="textAppearanceHeadline4">@style/TextAppearance.MaterialComponents.Headline4</item> + <item name="textAppearanceHeadline5">@style/TextAppearance.MaterialComponents.Headline5</item> + <item name="textAppearanceHeadline6">@style/TextAppearance.MaterialComponents.Headline6</item> + <item name="textAppearanceSubtitle1">@style/TextAppearance.MaterialComponents.Subtitle1</item> + <item name="textAppearanceSubtitle2">@style/TextAppearance.MaterialComponents.Subtitle2</item> + <item name="textAppearanceBody1">@style/TextAppearance.MaterialComponents.Body1</item> + <item name="textAppearanceBody2">@style/TextAppearance.MaterialComponents.Body2</item> + <item name="textAppearanceCaption">@style/TextAppearance.MaterialComponents.Caption</item> + <item name="textAppearanceButton">@style/TextAppearance.MaterialComponents.Button</item> + <item name="textAppearanceOverline">@style/TextAppearance.MaterialComponents.Overline</item> + + <!-- Shape styles --> + <item name="shapeAppearanceSmallComponent"> + @style/ShapeAppearance.MaterialComponents.SmallComponent + </item> + <item name="shapeAppearanceMediumComponent"> + @style/ShapeAppearance.MaterialComponents.MediumComponent + </item> + <item name="shapeAppearanceLargeComponent"> + @style/ShapeAppearance.MaterialComponents.LargeComponent + </item> + + <!-- Motion --> + <item name="motionEasingStandard">@string/material_motion_easing_standard</item> + <item name="motionEasingEmphasized">@string/material_motion_easing_emphasized</item> + <item name="motionEasingDecelerated">@string/material_motion_easing_decelerated</item> + <item name="motionEasingAccelerated">@string/material_motion_easing_accelerated</item> + <item name="motionEasingLinear">@string/material_motion_easing_linear</item> + + <item name="motionDurationShort1">@integer/material_motion_duration_short_1</item> + <item name="motionDurationShort2">@integer/material_motion_duration_short_2</item> + <item name="motionDurationMedium1">@integer/material_motion_duration_medium_1</item> + <item name="motionDurationMedium2">@integer/material_motion_duration_medium_2</item> + <item name="motionDurationLong1">@integer/material_motion_duration_long_1</item> + <item name="motionDurationLong2">@integer/material_motion_duration_long_2</item> + + <item name="motionPath">@integer/material_motion_path</item> + + <!-- Elevation Overlays --> + <item name="elevationOverlayEnabled">true</item> + <item name="elevationOverlayColor">?attr/colorOnSurface</item> + + <!-- END Base.V14.Theme.MaterialComponents.Bridge --> + + <!-- START Base.V14.Theme.MaterialComponents --> + <!-- + ~ Only a subset of widget attributes being actually used are included here since there are + ~ too many of them and they need to be investigated on a case-by-case basis. + --> + + <!-- Framework, AppCompat, or Design Widget styles --> + <item name="appBarLayoutStyle">@style/Widget.MaterialComponents.AppBarLayout.Surface</item> + + <!-- END Base.V14.Theme.MaterialComponents --> + </style> + <style name="Base.ThemeOverlay.MaterialComponents.PlatformBridge" parent="Base.V31.ThemeOverlay.AppCompat.PlatformBridge" /> + <style name="ThemeOverlay.MaterialComponents.PlatformBridge" parent="Base.ThemeOverlay.AppCompat.PlatformBridge" /> +</resources> |