Skip to content

Commit

Permalink
[M3][Dialog] Add date and time picker themes to M3 dialog themes
Browse files Browse the repository at this point in the history
Also moves all theme overlays to separate files for internal building purpose.

PiperOrigin-RevId: 421385265
  • Loading branch information
drchen authored and dsn5ft committed Jan 13, 2022
1 parent 698cf9b commit 8342f90
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 112 deletions.
Expand Up @@ -17,7 +17,4 @@
<resources>
<!-- Styles for MaterialComponents Dialogs. -->
<style name="Base.Widget.MaterialComponents.CheckedTextView" parent="android:Widget.Material.CheckedTextView"/>
<style name="Base.ThemeOverlay.MaterialComponents.Dialog" parent="Base.V14.ThemeOverlay.MaterialComponents.Dialog">
<item name="android:windowBackground">@drawable/mtrl_dialog_background</item>
</style>
</resources>
Expand Up @@ -15,16 +15,6 @@
limitations under the License.
-->
<resources>
<!-- MaterialComponents ThemeOverlays for Framework Alert Dialogs. -->

<style name="Base.ThemeOverlay.MaterialComponents.Dialog.Alert.Framework" parent="@android:style/Theme.Material.Dialog.Alert">
<item name="android:buttonBarButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog.Flush</item>
</style>

<style name="Base.ThemeOverlay.MaterialComponents.Light.Dialog.Alert.Framework" parent="@android:style/Theme.Material.Light.Dialog.Alert">
<item name="android:buttonBarButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog.Flush</item>
</style>

<!-- Themes V21 and above specify an android:alertDialogTheme so that text
buttons are used instead of filled buttons. The android:alertDialogTheme
used by default by the framework pre-21 is not public and therefore we
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2020 The Android Open Source Project
Copyright 2022 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.
Expand All @@ -15,6 +15,9 @@
limitations under the License.
-->
<resources>
<style name="Base.ThemeOverlay.MaterialComponents.Dialog" parent="Base.V14.ThemeOverlay.MaterialComponents.Dialog">
<item name="android:windowBackground">@drawable/mtrl_dialog_background</item>
</style>

<!--
The default theme overlay used by Material3 for framework
Expand All @@ -31,6 +34,17 @@
<item name="android:buttonBarButtonStyle">@style/Widget.Material3.Button.TextButton.Dialog.Flush</item>
</style>

<!--
MaterialComponents ThemeOverlays for Framework Alert Dialogs.
-->
<style name="Base.ThemeOverlay.MaterialComponents.Dialog.Alert.Framework" parent="@android:style/Theme.Material.Dialog.Alert">
<item name="android:buttonBarButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog.Flush</item>
</style>

<style name="Base.ThemeOverlay.MaterialComponents.Light.Dialog.Alert.Framework" parent="@android:style/Theme.Material.Light.Dialog.Alert">
<item name="android:buttonBarButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog.Flush</item>
</style>

<!--
The default theme overlay used by MaterialComponents for framework
(non-AppCompat) alert dialogs, via the android:alertDialogTheme attribute.
Expand Down
Expand Up @@ -14,7 +14,7 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<resources xmlns:tools="http://schemas.android.com/tools">
<resources>
<!-- Themes for MaterialComponents Dialogs. -->

<!--
Expand Down Expand Up @@ -53,34 +53,6 @@

<style name="Theme.MaterialComponents.Light.Dialog.FixedSize" parent="Base.Theme.MaterialComponents.Light.Dialog.FixedSize"/>

<!--
The default theme overlay used by MaterialComponents for regular dialogs.
-->
<style name="ThemeOverlay.MaterialComponents.Dialog" parent="Base.ThemeOverlay.MaterialComponents.Dialog"/>

<!--
The default MaterialComponents theme overlay used for AlertDialogs built via the
alertDialogTheme attribute.
-->
<style name="ThemeOverlay.MaterialComponents.Dialog.Alert" parent="Base.ThemeOverlay.MaterialComponents.Dialog.Alert"/>

<!--
The default MaterialComponents theme overlay for AlertDialogs built with the MaterialAlertDialogBuilder, via the
materialAlertDialogTheme attribute.
-->
<style name="ThemeOverlay.MaterialComponents.MaterialAlertDialog" parent="Base.ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="materialAlertDialogTitlePanelStyle">@style/MaterialAlertDialog.MaterialComponents.Title.Panel</item>
<item name="materialAlertDialogTitleIconStyle">@style/MaterialAlertDialog.MaterialComponents.Title.Icon</item>
<item name="materialAlertDialogTitleTextStyle">@style/MaterialAlertDialog.MaterialComponents.Title.Text</item>
</style>

<!-- A theme overlay for MaterialComponents Alert Dialog panels with a center aligned title text and icon. -->
<style name="ThemeOverlay.MaterialComponents.MaterialAlertDialog.Centered" parent="Base.ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="materialAlertDialogTitlePanelStyle">@style/MaterialAlertDialog.MaterialComponents.Title.Panel.CenterStacked</item>
<item name="materialAlertDialogTitleIconStyle">@style/MaterialAlertDialog.MaterialComponents.Title.Icon.CenterStacked</item>
<item name="materialAlertDialogTitleTextStyle">@style/MaterialAlertDialog.MaterialComponents.Title.Text.CenterStacked</item>
</style>

<!-- Themes for M3 Dialogs. -->

<!--
Expand Down Expand Up @@ -125,40 +97,4 @@
<item name="windowMinWidthMinor">@dimen/abc_dialog_min_width_minor</item>
</style>

<style name="ThemeOverlay.Material3.Dialog" parent="Base.ThemeOverlay.Material3.Dialog"/>

<!--
The default Material3 theme overlay used for AlertDialogs built via the
alertDialogTheme attribute.
-->
<style name="ThemeOverlay.Material3.Dialog.Alert" parent="ThemeOverlay.MaterialComponents.Dialog.Alert">
<item name="buttonBarButtonStyle">@style/Widget.Material3.Button.TextButton.Dialog.Flush</item>
<item name="android:windowElevation" tools:ignore="NewApi">@dimen/m3_alert_dialog_elevation</item>
</style>

<!--
The default Material3 theme overlay for AlertDialogs built with the MaterialAlertDialogBuilder, via the
materialAlertDialogTheme attribute.
-->
<style name="ThemeOverlay.Material3.MaterialAlertDialog" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="alertDialogStyle">@style/MaterialAlertDialog.Material3</item>
<item name="android:windowElevation" tools:ignore="NewApi">@dimen/m3_alert_dialog_elevation</item>
<item name="android:checkedTextViewStyle" tools:ignore="NewApi">@style/Widget.Material3.CheckedTextView</item>
<item name="buttonBarButtonStyle">@style/Widget.Material3.Button.TextButton.Dialog</item>
<item name="buttonBarPositiveButtonStyle">@style/Widget.Material3.Button.TextButton.Dialog</item>
<item name="buttonBarNegativeButtonStyle">@style/Widget.Material3.Button.TextButton.Dialog</item>
<item name="buttonBarNeutralButtonStyle">@style/Widget.Material3.Button.TextButton.Dialog.Flush</item>
<item name="materialAlertDialogTitlePanelStyle">@style/MaterialAlertDialog.Material3.Title.Panel</item>
<item name="materialAlertDialogTitleIconStyle">@style/MaterialAlertDialog.Material3.Title.Icon</item>
<item name="materialAlertDialogTitleTextStyle">@style/MaterialAlertDialog.Material3.Title.Text</item>
<item name="materialAlertDialogBodyTextStyle">@style/MaterialAlertDialog.Material3.Body.Text</item>
</style>

<!-- A theme overlay for Material3 Alert Dialog panels with a center aligned title text and icon. -->
<style name="ThemeOverlay.Material3.MaterialAlertDialog.Centered">
<item name="materialAlertDialogTitlePanelStyle">@style/MaterialAlertDialog.Material3.Title.Panel.CenterStacked</item>
<item name="materialAlertDialogTitleIconStyle">@style/MaterialAlertDialog.Material3.Title.Icon.CenterStacked</item>
<item name="materialAlertDialogTitleTextStyle">@style/MaterialAlertDialog.Material3.Title.Text.CenterStacked</item>
</style>

</resources>
Expand Up @@ -208,6 +208,12 @@
<item name="alertDialogTheme">@style/ThemeOverlay.Material3.Dialog.Alert</item>
<item name="materialAlertDialogTheme">@style/ThemeOverlay.Material3.MaterialAlertDialog</item>

<!-- Picker styles and themes. -->
<item name="materialCalendarStyle">@style/Widget.Material3.MaterialCalendar</item>
<item name="materialCalendarFullscreenTheme">@style/ThemeOverlay.Material3.MaterialCalendar.Fullscreen</item>
<item name="materialCalendarTheme">@style/ThemeOverlay.Material3.MaterialCalendar</item>
<item name="materialTimePickerTheme">@style/ThemeOverlay.Material3.MaterialTimePicker</item>

<!-- Theme overlays. -->
<item name="dynamicColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Light</item>
</style>
Expand Down Expand Up @@ -401,17 +407,19 @@
<item name="alertDialogTheme">@style/ThemeOverlay.Material3.Dialog.Alert</item>
<item name="materialAlertDialogTheme">@style/ThemeOverlay.Material3.MaterialAlertDialog</item>

<!-- Picker styles and themes. -->
<item name="materialCalendarStyle">@style/Widget.Material3.MaterialCalendar</item>
<item name="materialCalendarFullscreenTheme">@style/ThemeOverlay.Material3.MaterialCalendar.Fullscreen</item>
<item name="materialCalendarTheme">@style/ThemeOverlay.Material3.MaterialCalendar</item>
<item name="materialTimePickerTheme">@style/ThemeOverlay.Material3.MaterialTimePicker</item>

<!-- Theme overlays. -->
<item name="dynamicColorThemeOverlay">@style/ThemeOverlay.Material3.DynamicColors.Dark</item>
</style>

<style name="Base.Theme.Material3.Light.Dialog" parent="Base.V14.Theme.Material3.Light.Dialog"/>
<style name="Base.Theme.Material3.Dark.Dialog" parent="Base.V14.Theme.Material3.Dark.Dialog"/>

<style name="Base.ThemeOverlay.Material3.Dialog" parent="Base.ThemeOverlay.MaterialComponents.Dialog">
<item name="materialButtonStyle">@style/Widget.Material3.Button.TextButton.Dialog.Flush</item>
</style>

<style name="Base.V14.Theme.MaterialComponents.Dialog" parent="Base.V14.Theme.MaterialComponents.Dialog.Bridge">
<item name="viewInflaterClass">com.google.android.material.theme.MaterialComponentsViewInflater</item>

Expand Down Expand Up @@ -516,30 +524,6 @@
<item name="textAppearanceSmallPopupMenu">?attr/textAppearanceSubtitle1</item>
</style>

<style name="Base.V14.ThemeOverlay.MaterialComponents.Dialog" parent="ThemeOverlay.AppCompat.Dialog">
<!-- Widget styles -->
<item name="materialButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog.Flush</item>
</style>

<style name="Base.V14.ThemeOverlay.MaterialComponents.Dialog.Alert" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<!-- Widget styles -->
<item name="buttonBarButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog.Flush</item>
</style>

<style name="Base.V14.ThemeOverlay.MaterialComponents.MaterialAlertDialog" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<!-- Widget styles -->
<item name="materialAlertDialogButtonSpacerVisibility">@integer/mtrl_view_invisible</item>
<item name="alertDialogStyle">@style/MaterialAlertDialog.MaterialComponents</item>
<item name="android:checkedTextViewStyle" tools:ignore="NewApi">@style/Widget.MaterialComponents.CheckedTextView</item>
<item name="android:dialogCornerRadius" tools:ignore="newApi">@null</item>
<item name="buttonBarButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog</item>
<item name="buttonBarPositiveButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog</item>
<item name="buttonBarNegativeButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog</item>
<item name="buttonBarNeutralButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog.Flush</item>
<item name="android:backgroundDimAmount">0.32</item>
<item name="materialAlertDialogBodyTextStyle">@style/MaterialAlertDialog.MaterialComponents.Body.Text</item>
</style>

<!-- Themes in the "Base.Theme" family vary based on the current platform
version to provide the correct basis on each device. You probably don't
want to use them directly in your apps.
Expand Down Expand Up @@ -585,9 +569,4 @@
<item name="windowFixedHeightMajor">@dimen/abc_dialog_fixed_height_major</item>
<item name="windowFixedHeightMinor">@dimen/abc_dialog_fixed_height_minor</item>
</style>

<style name="Base.ThemeOverlay.MaterialComponents.Dialog" parent="Base.V14.ThemeOverlay.MaterialComponents.Dialog"/>
<style name="Base.ThemeOverlay.MaterialComponents.Dialog.Alert" parent="Base.V14.ThemeOverlay.MaterialComponents.Dialog.Alert"/>
<style name="Base.ThemeOverlay.MaterialComponents.MaterialAlertDialog" parent="Base.V14.ThemeOverlay.MaterialComponents.MaterialAlertDialog"/>

</resources>
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2022 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.
-->
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Base.V14.ThemeOverlay.MaterialComponents.Dialog" parent="ThemeOverlay.AppCompat.Dialog">
<!-- Widget styles -->
<item name="materialButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog.Flush</item>
</style>

<style name="Base.V14.ThemeOverlay.MaterialComponents.Dialog.Alert" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<!-- Widget styles -->
<item name="buttonBarButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog.Flush</item>
</style>

<style name="Base.V14.ThemeOverlay.MaterialComponents.MaterialAlertDialog" parent="ThemeOverlay.AppCompat.Dialog.Alert">
<!-- Widget styles -->
<item name="materialAlertDialogButtonSpacerVisibility">@integer/mtrl_view_invisible</item>
<item name="alertDialogStyle">@style/MaterialAlertDialog.MaterialComponents</item>
<item name="android:checkedTextViewStyle" tools:ignore="NewApi">@style/Widget.MaterialComponents.CheckedTextView</item>
<item name="android:dialogCornerRadius" tools:ignore="newApi">@null</item>
<item name="buttonBarButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog</item>
<item name="buttonBarPositiveButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog</item>
<item name="buttonBarNegativeButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog</item>
<item name="buttonBarNeutralButtonStyle">@style/Widget.MaterialComponents.Button.TextButton.Dialog.Flush</item>
<item name="android:backgroundDimAmount">0.32</item>
<item name="materialAlertDialogBodyTextStyle">@style/MaterialAlertDialog.MaterialComponents.Body.Text</item>
</style>

<style name="Base.ThemeOverlay.MaterialComponents.Dialog" parent="Base.V14.ThemeOverlay.MaterialComponents.Dialog"/>
<style name="Base.ThemeOverlay.MaterialComponents.Dialog.Alert" parent="Base.V14.ThemeOverlay.MaterialComponents.Dialog.Alert"/>
<style name="Base.ThemeOverlay.MaterialComponents.MaterialAlertDialog" parent="Base.V14.ThemeOverlay.MaterialComponents.MaterialAlertDialog"/>

<!--
The default theme overlay used by MaterialComponents for regular dialogs.
-->
<style name="ThemeOverlay.MaterialComponents.Dialog" parent="Base.ThemeOverlay.MaterialComponents.Dialog"/>

<!--
The default MaterialComponents theme overlay used for AlertDialogs built via the
alertDialogTheme attribute.
-->
<style name="ThemeOverlay.MaterialComponents.Dialog.Alert" parent="Base.ThemeOverlay.MaterialComponents.Dialog.Alert"/>

<!--
The default MaterialComponents theme overlay for AlertDialogs built with the MaterialAlertDialogBuilder, via the
materialAlertDialogTheme attribute.
-->
<style name="ThemeOverlay.MaterialComponents.MaterialAlertDialog" parent="Base.ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="materialAlertDialogTitlePanelStyle">@style/MaterialAlertDialog.MaterialComponents.Title.Panel</item>
<item name="materialAlertDialogTitleIconStyle">@style/MaterialAlertDialog.MaterialComponents.Title.Icon</item>
<item name="materialAlertDialogTitleTextStyle">@style/MaterialAlertDialog.MaterialComponents.Title.Text</item>
</style>

<!-- A theme overlay for MaterialComponents Alert Dialog panels with a center aligned title text and icon. -->
<style name="ThemeOverlay.MaterialComponents.MaterialAlertDialog.Centered" parent="Base.ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="materialAlertDialogTitlePanelStyle">@style/MaterialAlertDialog.MaterialComponents.Title.Panel.CenterStacked</item>
<item name="materialAlertDialogTitleIconStyle">@style/MaterialAlertDialog.MaterialComponents.Title.Icon.CenterStacked</item>
<item name="materialAlertDialogTitleTextStyle">@style/MaterialAlertDialog.MaterialComponents.Title.Text.CenterStacked</item>
</style>

<style name="Base.ThemeOverlay.Material3.Dialog" parent="Base.ThemeOverlay.MaterialComponents.Dialog">
<item name="materialButtonStyle">@style/Widget.Material3.Button.TextButton.Dialog.Flush</item>
</style>

<style name="ThemeOverlay.Material3.Dialog" parent="Base.ThemeOverlay.Material3.Dialog"/>

<!--
The default Material3 theme overlay used for AlertDialogs built via the
alertDialogTheme attribute.
-->
<style name="ThemeOverlay.Material3.Dialog.Alert" parent="ThemeOverlay.MaterialComponents.Dialog.Alert">
<item name="buttonBarButtonStyle">@style/Widget.Material3.Button.TextButton.Dialog.Flush</item>
<item name="android:windowElevation" tools:ignore="NewApi">@dimen/m3_alert_dialog_elevation</item>
</style>

<!--
The default Material3 theme overlay for AlertDialogs built with the MaterialAlertDialogBuilder, via the
materialAlertDialogTheme attribute.
-->
<style name="ThemeOverlay.Material3.MaterialAlertDialog" parent="ThemeOverlay.MaterialComponents.MaterialAlertDialog">
<item name="alertDialogStyle">@style/MaterialAlertDialog.Material3</item>
<item name="android:windowElevation" tools:ignore="NewApi">@dimen/m3_alert_dialog_elevation</item>
<item name="android:checkedTextViewStyle" tools:ignore="NewApi">@style/Widget.Material3.CheckedTextView</item>
<item name="buttonBarButtonStyle">@style/Widget.Material3.Button.TextButton.Dialog</item>
<item name="buttonBarPositiveButtonStyle">@style/Widget.Material3.Button.TextButton.Dialog</item>
<item name="buttonBarNegativeButtonStyle">@style/Widget.Material3.Button.TextButton.Dialog</item>
<item name="buttonBarNeutralButtonStyle">@style/Widget.Material3.Button.TextButton.Dialog.Flush</item>
<item name="materialAlertDialogTitlePanelStyle">@style/MaterialAlertDialog.Material3.Title.Panel</item>
<item name="materialAlertDialogTitleIconStyle">@style/MaterialAlertDialog.Material3.Title.Icon</item>
<item name="materialAlertDialogTitleTextStyle">@style/MaterialAlertDialog.Material3.Title.Text</item>
<item name="materialAlertDialogBodyTextStyle">@style/MaterialAlertDialog.Material3.Body.Text</item>
</style>

<!-- A theme overlay for Material3 Alert Dialog panels with a center aligned title text and icon. -->
<style name="ThemeOverlay.Material3.MaterialAlertDialog.Centered">
<item name="materialAlertDialogTitlePanelStyle">@style/MaterialAlertDialog.Material3.Title.Panel.CenterStacked</item>
<item name="materialAlertDialogTitleIconStyle">@style/MaterialAlertDialog.Material3.Title.Icon.CenterStacked</item>
<item name="materialAlertDialogTitleTextStyle">@style/MaterialAlertDialog.Material3.Title.Text.CenterStacked</item>
</style>
</resources>

0 comments on commit 8342f90

Please sign in to comment.