diff options
author | 2024-09-27 15:11:00 +0000 | |
---|---|---|
committer | 2024-10-02 21:27:52 +0000 | |
commit | 10d832e73ded578f9b390076884748ce75ec4dbb (patch) | |
tree | dbac7aba57ce47d7069864e7bb33f83ae14e5501 | |
parent | a9c83e9d9c2679bea3f76e754f21d697a8f6193d (diff) |
Adding Material 3 theme
This custom theme supports color, typography and shape overlay.
BUG: b/367378964
Relnote: "N/A"
Test: Manual. Existing Test passes.
Flag: NONE "RESOURCE-ONLY"
LOW_COVERAGE_REASON=FLAG_NOT_ENABLED
Change-Id: I9f65b111da896fbda0a0d7a54fadbafe7cde9f06
11 files changed, 1008 insertions, 3 deletions
diff --git a/PermissionController/Android.bp b/PermissionController/Android.bp index 21d6f4774..596b2dbb5 100644 --- a/PermissionController/Android.bp +++ b/PermissionController/Android.bp @@ -158,6 +158,7 @@ android_library { "androidx.compose.runtime_runtime-livedata", "androidx.compose.ui_ui", "androidx.wear.compose_compose-material", + "androidx.wear.compose_compose-material3", "android.content.pm.flags-aconfig-java-export", "android.os.flags-aconfig-java-export", ], diff --git a/PermissionController/res/values-watch/donottranslate.xml b/PermissionController/res/values-watch/donottranslate.xml index c3ab3cbb1..309c51388 100644 --- a/PermissionController/res/values-watch/donottranslate.xml +++ b/PermissionController/res/values-watch/donottranslate.xml @@ -28,4 +28,55 @@ <string name="wear_material_compose_caption_1_font_family">font-family-text-medium-device-default</string> <string name="wear_material_compose_caption_2_font_family">font-family-text-medium-device-default</string> <string name="wear_material_compose_caption_3_font_family">font-family-text-medium-device-default</string> + + <string name="wear_compose_material3_arc_small_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_arc_medium_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_arc_large_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_body_extra_small_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_body_small_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_body_medium_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_body_large_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_display_small_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_display_medium_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_display_large_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_label_small_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_label_medium_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_label_large_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_numeral_extra_small_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_numeral_small_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_numeral_medium_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_numeral_large_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_numeral_extra_large_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_title_small_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_title_medium_font_family">font-family-flex-device-default</string> + <string name="wear_compose_material3_title_large_font_family">font-family-flex-device-default</string> + + <dimen name="wear_compose_material3_arc_small_font_size">14</dimen> + <dimen name="wear_compose_material3_arc_medium_font_size">15</dimen> + <dimen name="wear_compose_material3_arc_large_font_size">20</dimen> + <dimen name="wear_compose_material3_body_extra_small_font_size">10</dimen> + <dimen name="wear_compose_material3_body_small_font_size">12</dimen> + <dimen name="wear_compose_material3_body_medium_font_size">14</dimen> + <dimen name="wear_compose_material3_body_large_font_size">16</dimen> + <dimen name="wear_compose_material3_display_small_font_size">24</dimen> + <dimen name="wear_compose_material3_display_medium_font_size">30</dimen> + <dimen name="wear_compose_material3_display_large_font_size">40</dimen> + <dimen name="wear_compose_material3_label_small_font_size">13</dimen> + <dimen name="wear_compose_material3_label_medium_font_size">15</dimen> + <dimen name="wear_compose_material3_label_large_font_size">20</dimen> + <dimen name="wear_compose_material3_numeral_extra_small_font_size">24</dimen> + <dimen name="wear_compose_material3_numeral_small_font_size">30</dimen> + <dimen name="wear_compose_material3_numeral_medium_font_size">40</dimen> + <dimen name="wear_compose_material3_numeral_large_font_size">50</dimen> + <dimen name="wear_compose_material3_numeral_extra_large_font_size">60</dimen> + <dimen name="wear_compose_material3_title_small_font_size">14</dimen> + <dimen name="wear_compose_material3_title_medium_font_size">16</dimen> + <dimen name="wear_compose_material3_title_large_font_size">20</dimen> + + <dimen name="wear_compose_material3_shape_corner_extra_small_size">4</dimen> + <dimen name="wear_compose_material3_shape_corner_small_size">8</dimen> + <dimen name="wear_compose_material3_shape_corner_medium_size">18</dimen> + <dimen name="wear_compose_material3_shape_corner_large_size">26</dimen> + <dimen name="wear_compose_material3_shape_corner_extra_large_size">36</dimen> + </resources> diff --git a/PermissionController/res/values/overlayable.xml b/PermissionController/res/values/overlayable.xml index 31f3355e4..510bb900f 100644 --- a/PermissionController/res/values/overlayable.xml +++ b/PermissionController/res/values/overlayable.xml @@ -460,7 +460,7 @@ <item type="style" name="AppDataSharingUpdateSettingsIcon" /> <!-- END SAFETY LABELS STYLE --> - <!--START WEAR SPECIFIC FONT STRINGS --> + <!--START WEAR SPECIFIC MATERIAL2 FONT STRINGS --> <item type="string" name="wear_material_compose_display_1_font_family" /> <item type="string" name="wear_material_compose_display_2_font_family" /> <item type="string" name="wear_material_compose_display_3_font_family" /> @@ -473,7 +473,75 @@ <item type="string" name="wear_material_compose_caption_1_font_family" /> <item type="string" name="wear_material_compose_caption_2_font_family" /> <item type="string" name="wear_material_compose_caption_3_font_family" /> - <!--END WEAR SPECIFIC FONT STRINGS --> + <!--END WEAR SPECIFIC MATERIAL2 FONT STRINGS --> + + <!--START WEAR SPECIFIC MATERIAL3 FONT FACE TOKENS--> + <item type="string" name="wear_compose_material3_arc_small_font_family" /> + <item type="string" name="wear_compose_material3_arc_medium_font_family" /> + <item type="string" name="wear_compose_material3_arc_large_font_family" /> + + <item type="string" name="wear_compose_material3_body_extra_small_font_family" /> + <item type="string" name="wear_compose_material3_body_small_font_family" /> + <item type="string" name="wear_compose_material3_body_medium_font_family" /> + <item type="string" name="wear_compose_material3_body_large_font_family" /> + + <item type="string" name="wear_compose_material3_display_small_font_family" /> + <item type="string" name="wear_compose_material3_display_medium_font_family" /> + <item type="string" name="wear_compose_material3_display_large_font_family" /> + + <item type="string" name="wear_compose_material3_label_small_font_family" /> + <item type="string" name="wear_compose_material3_label_medium_font_family" /> + <item type="string" name="wear_compose_material3_label_large_font_family" /> + + <item type="string" name="wear_compose_material3_numeral_extra_small_font_family" /> + <item type="string" name="wear_compose_material3_numeral_small_font_family" /> + <item type="string" name="wear_compose_material3_numeral_medium_font_family" /> + <item type="string" name="wear_compose_material3_numeral_large_font_family" /> + <item type="string" name="wear_compose_material3_numeral_extra_large_font_family" /> + + <item type="string" name="wear_compose_material3_title_small_font_family" /> + <item type="string" name="wear_compose_material3_title_medium_font_family" /> + <item type="string" name="wear_compose_material3_title_large_font_family" /> + <!--END WEAR SPECIFIC MATERIAL3 FONT FACE TOKENS--> + + + <!--START WEAR SPECIFIC MATERIAL3 FONT SIZE TOKENS--> + <item type="dimen" name="wear_compose_material3_arc_small_font_size" /> + <item type="dimen" name="wear_compose_material3_arc_medium_font_size" /> + <item type="dimen" name="wear_compose_material3_arc_large_font_size" /> + + <item type="dimen" name="wear_compose_material3_body_extra_small_font_size" /> + <item type="dimen" name="wear_compose_material3_body_small_font_size" /> + <item type="dimen" name="wear_compose_material3_body_medium_font_size" /> + <item type="dimen" name="wear_compose_material3_body_large_font_size" /> + + <item type="dimen" name="wear_compose_material3_display_small_font_size" /> + <item type="dimen" name="wear_compose_material3_display_medium_font_size" /> + <item type="dimen" name="wear_compose_material3_display_large_font_size" /> + + <item type="dimen" name="wear_compose_material3_label_small_font_size" /> + <item type="dimen" name="wear_compose_material3_label_medium_font_size" /> + <item type="dimen" name="wear_compose_material3_label_large_font_size" /> + + <item type="dimen" name="wear_compose_material3_numeral_extra_small_font_size" /> + <item type="dimen" name="wear_compose_material3_numeral_small_font_size" /> + <item type="dimen" name="wear_compose_material3_numeral_medium_font_size" /> + <item type="dimen" name="wear_compose_material3_numeral_large_font_size" /> + <item type="dimen" name="wear_compose_material3_numeral_extra_large_font_size" /> + + <item type="dimen" name="wear_compose_material3_title_small_font_size" /> + <item type="dimen" name="wear_compose_material3_title_medium_font_size" /> + <item type="dimen" name="wear_compose_material3_title_large_font_size" /> + <!--END WEAR SPECIFIC MATERIAL3 FONT SIZE TOKENS--> + + <!--START WEAR SPECIFIC MATERIAL3 SHAPE TOKENS--> + <item type="dimen" name="wear_compose_material3_shape_corner_extra_small_size" /> + <item type="dimen" name="wear_compose_material3_shape_corner_small_size" /> + <item type="dimen" name="wear_compose_material3_shape_corner_medium_size" /> + <item type="dimen" name="wear_compose_material3_shape_corner_large_size" /> + <item type="dimen" name="wear_compose_material3_shape_corner_extra_large_size" /> + <!--END WEAR SPECIFIC MATERIAL3 SHAPE TOKENS--> + <!-- START ENHANCED CONFIRMATION DIALOG --> <item type="style" name="Theme.EnhancedConfirmationDialog" /> diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/ResourceHelper.kt b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/ResourceHelper.kt new file mode 100644 index 000000000..3c2c38578 --- /dev/null +++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/ResourceHelper.kt @@ -0,0 +1,53 @@ +/* + * 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. + */ +package com.android.permissioncontroller.permission.ui.wear.theme + +import android.content.Context +import androidx.annotation.ColorRes +import androidx.annotation.DimenRes +import androidx.annotation.DoNotInline +import androidx.annotation.StringRes +import androidx.compose.ui.graphics.Color + +internal object ResourceHelper { + @DoNotInline + fun getColor(context: Context, @ColorRes id: Int): Color? { + return try { + val colorInt = context.resources.getColor(id, context.theme) + Color(colorInt) + } catch (e: Exception) { + null + } + } + + @DoNotInline + fun getString(context: Context, @StringRes id: Int): String? { + return try { + context.resources.getString(id) + } catch (e: Exception) { + null + } + } + + @DoNotInline + fun getDimen(context: Context, @DimenRes id: Int): Float? { + return try { + context.resources.getDimension(id) + } catch (e: Exception) { + null + } + } +} diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearComposeMaterial3ColorScheme.kt b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearComposeMaterial3ColorScheme.kt new file mode 100644 index 000000000..6af9a28ec --- /dev/null +++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearComposeMaterial3ColorScheme.kt @@ -0,0 +1,179 @@ +/* + * 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. + */ +package com.android.permissioncontroller.permission.ui.wear.theme + +import android.content.Context +import android.os.Build +import androidx.annotation.ColorRes +import androidx.annotation.RequiresApi +import androidx.compose.ui.graphics.Color +import androidx.wear.compose.material3.ColorScheme + +/** + * Creates a dynamic color maps that can be overlaid. In wear we only support dark theme for the + * time being. If the device supports dynamic color generation these resources are updated with the + * generated colors + */ +internal object WearComposeMaterial3ColorScheme { + + private fun Color.updatedColor(context: Context, @ColorRes colorRes: Int): Color { + return ResourceHelper.getColor(context, colorRes) ?: this + } + + @RequiresApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE) + fun dynamicColorScheme(context: Context): ColorScheme { + val defaultColorScheme = ColorScheme() + return ColorScheme( + primary = + defaultColorScheme.primary.updatedColor( + context, + android.R.color.system_primary_fixed, + ), + primaryDim = + defaultColorScheme.primaryDim.updatedColor( + context, + android.R.color.system_primary_fixed_dim, + ), + primaryContainer = + defaultColorScheme.primaryContainer.updatedColor( + context, + android.R.color.system_primary_container_dark, + ), + onPrimary = + defaultColorScheme.onPrimary.updatedColor( + context, + android.R.color.system_on_primary_fixed, + ), + onPrimaryContainer = + defaultColorScheme.onPrimaryContainer.updatedColor( + context, + android.R.color.system_on_primary_container_dark, + ), + secondary = + defaultColorScheme.secondary.updatedColor( + context, + android.R.color.system_secondary_fixed, + ), + secondaryDim = + defaultColorScheme.secondaryDim.updatedColor( + context, + android.R.color.system_secondary_fixed_dim, + ), + secondaryContainer = + defaultColorScheme.secondaryContainer.updatedColor( + context, + android.R.color.system_secondary_container_dark, + ), + onSecondary = + defaultColorScheme.onSecondary.updatedColor( + context, + android.R.color.system_on_secondary_fixed, + ), + onSecondaryContainer = + defaultColorScheme.onSecondaryContainer.updatedColor( + context, + android.R.color.system_on_secondary_container_dark, + ), + tertiary = + defaultColorScheme.tertiary.updatedColor( + context, + android.R.color.system_tertiary_fixed, + ), + tertiaryDim = + defaultColorScheme.tertiaryDim.updatedColor( + context, + android.R.color.system_tertiary_fixed_dim, + ), + tertiaryContainer = + defaultColorScheme.tertiaryContainer.updatedColor( + context, + android.R.color.system_tertiary_container_dark, + ), + onTertiary = + defaultColorScheme.onTertiary.updatedColor( + context, + android.R.color.system_on_tertiary_fixed, + ), + onTertiaryContainer = + defaultColorScheme.onTertiaryContainer.updatedColor( + context, + android.R.color.system_on_tertiary_container_dark, + ), + surfaceContainerLow = + defaultColorScheme.surfaceContainerLow.updatedColor( + context, + android.R.color.system_surface_container_low_dark, + ), + surfaceContainer = + defaultColorScheme.surfaceContainer.updatedColor( + context, + android.R.color.system_surface_container_dark, + ), + surfaceContainerHigh = + defaultColorScheme.surfaceContainerHigh.updatedColor( + context, + android.R.color.system_surface_container_high_dark, + ), + onSurface = + defaultColorScheme.onSurface.updatedColor( + context, + android.R.color.system_on_surface_dark, + ), + onSurfaceVariant = + defaultColorScheme.onSurfaceVariant.updatedColor( + context, + android.R.color.system_on_surface_variant_dark, + ), + outline = + defaultColorScheme.outline.updatedColor( + context, + android.R.color.system_outline_dark, + ), + outlineVariant = + defaultColorScheme.outlineVariant.updatedColor( + context, + android.R.color.system_outline_variant_dark, + ), + background = + defaultColorScheme.background.updatedColor( + context, + android.R.color.system_background_dark, + ), + onBackground = + defaultColorScheme.onBackground.updatedColor( + context, + android.R.color.system_on_background_dark, + ), + error = + defaultColorScheme.error.updatedColor(context, android.R.color.system_error_dark), + onError = + defaultColorScheme.onError.updatedColor( + context, + android.R.color.system_on_error_dark, + ), + errorContainer = + defaultColorScheme.errorContainer.updatedColor( + context, + android.R.color.system_error_container_dark, + ), + onErrorContainer = + defaultColorScheme.onErrorContainer.updatedColor( + context, + android.R.color.system_on_error_container_dark, + ), + ) + } +} diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearComposeMaterial3Shapes.kt b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearComposeMaterial3Shapes.kt new file mode 100644 index 000000000..f81022842 --- /dev/null +++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearComposeMaterial3Shapes.kt @@ -0,0 +1,66 @@ +/* + * 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. + */ +package com.android.permissioncontroller.permission.ui.wear.theme + +import android.content.Context +import androidx.annotation.DimenRes +import androidx.compose.foundation.shape.CornerBasedShape +import androidx.compose.foundation.shape.CornerSize +import androidx.compose.ui.unit.dp +import androidx.wear.compose.material3.Shapes +import com.android.permissioncontroller.R + +// TODO(b/324928718): Use system defined symbols. +internal object WearComposeMaterial3Shapes { + private fun CornerBasedShape.updatedShape( + context: Context, + @DimenRes cornerSizeRes: Int, + ): CornerBasedShape { + val size = ResourceHelper.getDimen(context, cornerSizeRes)?.dp ?: return this + return copy(CornerSize(size)) + } + + fun dynamicShapes(context: Context): Shapes { + val defaultShapes = Shapes() + return Shapes( + extraLarge = + defaultShapes.extraLarge.updatedShape( + context, + R.dimen.wear_compose_material3_shape_corner_extra_large_size, + ), + large = + defaultShapes.large.updatedShape( + context, + R.dimen.wear_compose_material3_shape_corner_large_size, + ), + medium = + defaultShapes.medium.updatedShape( + context, + R.dimen.wear_compose_material3_shape_corner_medium_size, + ), + small = + defaultShapes.small.updatedShape( + context, + R.dimen.wear_compose_material3_shape_corner_small_size, + ), + extraSmall = + defaultShapes.extraSmall.updatedShape( + context, + R.dimen.wear_compose_material3_shape_corner_extra_small_size, + ), + ) + } +} diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearComposeMaterial3TypeScaleTokens.kt b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearComposeMaterial3TypeScaleTokens.kt new file mode 100644 index 000000000..a4ec9ee1d --- /dev/null +++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearComposeMaterial3TypeScaleTokens.kt @@ -0,0 +1,109 @@ +/* + * 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. + */ +package com.android.permissioncontroller.permission.ui.wear.theme + +/* + * These values are retrieved from https://carbon.googleplex.com/wear-m3/pages and + * modified by UX. + * These values are internal to material3 library. We copied them to support flex font families + * Do not edit directly. Copy paste from compose material library. + */ + +internal object WearComposeMaterial3TypeScaleTokens { + val ArcLargeRoundness = 100.0f + val ArcLargeWeight = 600.0f + val ArcLargeWidth = 100.0f + + val ArcMediumRoundness = 100.0f + val ArcMediumWeight = 600.0f + val ArcMediumWidth = 90.0f + + val ArcSmallRoundness = 100.0f + val ArcSmallWeight = 550.0f + val ArcSmallWidth = 90.0f + + val BodyExtraSmallRoundness = 100.0f + val BodyExtraSmallWeight = 500.0f + val BodyExtraSmallWidth = 84.0f + + val BodyLargeRoundness = 100.0f + val BodyLargeWeight = 450.0f + val BodyLargeWidth = 90.0f + + val BodyMediumRoundness = 100.0f + val BodyMediumWeight = 450.0f + val BodyMediumWidth = 90.0f + + val BodySmallRoundness = 100.0f + val BodySmallWeight = 500.0f + val BodySmallWidth = 86.0f + + val DisplayLargeRoundness = 100.0f + val DisplayLargeWeight = 450.0f + val DisplayLargeWidth = 100.0f + + val DisplayMediumRoundness = 100.0f + val DisplayMediumWeight = 500.0f + val DisplayMediumWidth = 100.0f + + val DisplaySmallRoundness = 100.0f + val DisplaySmallWeight = 500.0f + val DisplaySmallWidth = 100.0f + + val LabelLargeRoundness = 100.0f + val LabelLargeWeight = 500.0f + val LabelLargeWidth = 100.0f + + val LabelMediumRoundness = 100.0f + val LabelMediumWeight = 500.0f + val LabelMediumWidth = 90.0f + + val LabelSmallRoundness = 100.0f + val LabelSmallWeight = 500.0f + val LabelSmallWidth = 84.0f + + val NumeralExtraLargeRoundness = 100.0f + val NumeralExtraLargeWeight = 550.0f + val NumeralExtraLargeWidth = 100.0f + + val NumeralExtraSmallRoundness = 100.0f + val NumeralExtraSmallWeight = 550.0f + val NumeralExtraSmallWidth = 100.0f + + val NumeralLargeRoundness = 100.0f + val NumeralLargeWeight = 600.0f + val NumeralLargeWidth = 100.0f + + val NumeralMediumRoundness = 100.0f + val NumeralMediumWidth = 100.0f + val NumeralMediumWeight = 600.0f + + val NumeralSmallRoundness = 100.0f + val NumeralSmallWeight = 600.0f + val NumeralSmallWidth = 100.0f + + val TitleLargeRoundness = 100.0f + val TitleLargeWeight = 500.0f + val TitleLargeWidth = 100.0f + + val TitleMediumRoundness = 100.0f + val TitleMediumWeight = 550.0f + val TitleMediumWidth = 100.0f + + val TitleSmallRoundness = 100.0f + val TitleSmallWeight = 550.0f + val TitleSmallWidth = 100.0f +} diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearComposeMaterial3Typography.kt b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearComposeMaterial3Typography.kt new file mode 100644 index 000000000..ceae526a7 --- /dev/null +++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearComposeMaterial3Typography.kt @@ -0,0 +1,240 @@ +/* + * 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. + */ +package com.android.permissioncontroller.permission.ui.wear.theme + +import android.content.Context +import androidx.annotation.DimenRes +import androidx.annotation.StringRes +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.DeviceFontFamilyName +import androidx.compose.ui.text.font.Font +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontVariation +import androidx.compose.ui.unit.sp +import androidx.wear.compose.material3.Typography +import com.android.permissioncontroller.R + +internal object WearComposeMaterial3Typography { + + private const val DEVICE_DEFAULT_FLEX_FONT_TYPE = "font-family-flex-device-default" + + fun fontFamily( + context: Context, + @StringRes id: Int, + variationSettings: FontVariation.Settings? = null, + ): FontFamily { + val typefaceName = ResourceHelper.getString(context, id) ?: DEVICE_DEFAULT_FLEX_FONT_TYPE + + val font = + if (variationSettings != null) { + Font( + familyName = DeviceFontFamilyName(typefaceName), + variationSettings = variationSettings, + ) + } else { + Font(familyName = DeviceFontFamilyName(typefaceName)) + } + return FontFamily(font) + } + + private fun TextStyle.updatedTextStyle( + context: Context, + @StringRes fontRes: Int, + variationSettings: FontVariation.Settings? = null, + @DimenRes fontSizeRes: Int, + ): TextStyle { + + val fontFamily = + fontFamily(context = context, id = fontRes, variationSettings = variationSettings) + val fontSize = ResourceHelper.getDimen(context = context, id = fontSizeRes)?.sp ?: fontSize + + return copy(fontFamily = fontFamily, fontSize = fontSize) + } + + fun dynamicTypography(context: Context): Typography { + val defaultTypography = Typography() + return Typography( + arcLarge = + defaultTypography.arcLarge.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_arc_large_font_family, + fontSizeRes = R.dimen.wear_compose_material3_arc_large_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.ArcLargeVariationSettings, + ), + arcMedium = + defaultTypography.arcMedium.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_arc_medium_font_family, + fontSizeRes = R.dimen.wear_compose_material3_arc_medium_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.ArcMediumVariationSettings, + ), + arcSmall = + defaultTypography.arcSmall.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_arc_small_font_family, + fontSizeRes = R.dimen.wear_compose_material3_arc_small_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.ArcSmallVariationSettings, + ), + bodyLarge = + defaultTypography.bodyLarge.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_body_large_font_family, + fontSizeRes = R.dimen.wear_compose_material3_body_large_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.BodyLargeVariationSettings, + ), + bodyMedium = + defaultTypography.bodyMedium.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_body_medium_font_family, + fontSizeRes = R.dimen.wear_compose_material3_body_medium_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.BodyMediumVariationSettings, + ), + bodySmall = + defaultTypography.bodySmall.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_body_small_font_family, + fontSizeRes = R.dimen.wear_compose_material3_body_small_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.BodySmallVariationSettings, + ), + bodyExtraSmall = + defaultTypography.bodyExtraSmall.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_body_extra_small_font_family, + fontSizeRes = R.dimen.wear_compose_material3_body_extra_small_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.BodyExtraSmallVariationSettings, + ), + displayLarge = + defaultTypography.displayLarge.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_display_large_font_family, + fontSizeRes = R.dimen.wear_compose_material3_display_large_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.DisplayLargeVariationSettings, + ), + displayMedium = + defaultTypography.displayMedium.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_display_medium_font_family, + fontSizeRes = R.dimen.wear_compose_material3_display_medium_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.DisplayMediumVariationSettings, + ), + displaySmall = + defaultTypography.displaySmall.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_display_small_font_family, + fontSizeRes = R.dimen.wear_compose_material3_display_small_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.DisplaySmallVariationSettings, + ), + labelLarge = + defaultTypography.labelLarge.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_label_large_font_family, + fontSizeRes = R.dimen.wear_compose_material3_label_large_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.LabelLargeVariationSettings, + ), + labelMedium = + defaultTypography.labelMedium.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_label_medium_font_family, + fontSizeRes = R.dimen.wear_compose_material3_label_medium_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.LabelMediumVariationSettings, + ), + labelSmall = + defaultTypography.labelSmall.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_label_small_font_family, + fontSizeRes = R.dimen.wear_compose_material3_label_small_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.LabelSmallVariationSettings, + ), + numeralExtraLarge = + defaultTypography.numeralExtraLarge.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_numeral_extra_large_font_family, + fontSizeRes = R.dimen.wear_compose_material3_numeral_extra_large_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.NumeralExtraLargeVariationSettings, + ), + numeralLarge = + defaultTypography.numeralLarge.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_numeral_large_font_family, + fontSizeRes = R.dimen.wear_compose_material3_numeral_large_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.NumeralLargeVariationSettings, + ), + numeralMedium = + defaultTypography.numeralMedium.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_numeral_medium_font_family, + fontSizeRes = R.dimen.wear_compose_material3_numeral_medium_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.NumeralMediumVariationSettings, + ), + numeralSmall = + defaultTypography.numeralSmall.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_numeral_small_font_family, + fontSizeRes = R.dimen.wear_compose_material3_numeral_small_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.NumeralSmallVariationSettings, + ), + numeralExtraSmall = + defaultTypography.numeralExtraSmall.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_numeral_extra_small_font_family, + fontSizeRes = R.dimen.wear_compose_material3_numeral_extra_small_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.NumeralExtraSmallVariationSettings, + ), + titleLarge = + defaultTypography.titleLarge.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_title_large_font_family, + fontSizeRes = R.dimen.wear_compose_material3_title_large_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.TitleLargeVariationSettings, + ), + titleMedium = + defaultTypography.titleMedium.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_title_medium_font_family, + fontSizeRes = R.dimen.wear_compose_material3_title_medium_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.TitleMediumVariationSettings, + ), + titleSmall = + defaultTypography.titleSmall.updatedTextStyle( + context = context, + fontRes = R.string.wear_compose_material3_title_small_font_family, + fontSizeRes = R.dimen.wear_compose_material3_title_small_font_size, + variationSettings = + WearComposeMaterial3VariableFontTokens.TitleSmallVariationSettings, + ), + ) + } +} diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearComposeMaterial3VariableFontTokens.kt b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearComposeMaterial3VariableFontTokens.kt new file mode 100644 index 000000000..1b42a3b05 --- /dev/null +++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearComposeMaterial3VariableFontTokens.kt @@ -0,0 +1,186 @@ +/* + * 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. + */ +package com.android.permissioncontroller.permission.ui.wear.theme + +import androidx.compose.ui.text.font.FontVariation + +internal object WearComposeMaterial3VariableFontTokens { + val ArcLargeVariationSettings = + FontVariation.Settings( + FontVariation.Setting("ROND", WearComposeMaterial3TypeScaleTokens.ArcLargeRoundness), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.ArcLargeWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.ArcLargeWeight), + ) + val ArcMediumVariationSettings = + FontVariation.Settings( + FontVariation.Setting("ROND", WearComposeMaterial3TypeScaleTokens.ArcMediumRoundness), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.ArcMediumWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.ArcMediumWeight), + ) + val ArcSmallVariationSettings = + FontVariation.Settings( + FontVariation.Setting("ROND", WearComposeMaterial3TypeScaleTokens.ArcSmallRoundness), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.ArcSmallWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.ArcSmallWeight), + ) + val BodyExtraSmallVariationSettings = + FontVariation.Settings( + FontVariation.Setting( + "ROND", + WearComposeMaterial3TypeScaleTokens.BodyExtraSmallRoundness, + ), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.BodyExtraSmallWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.BodyExtraSmallWeight), + ) + val BodyLargeVariationSettings = + FontVariation.Settings( + FontVariation.Setting("ROND", WearComposeMaterial3TypeScaleTokens.BodyLargeRoundness), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.BodyLargeWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.BodyLargeWeight), + ) + val BodyMediumVariationSettings = + FontVariation.Settings( + FontVariation.Setting("ROND", WearComposeMaterial3TypeScaleTokens.BodyMediumRoundness), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.BodyMediumWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.BodyMediumWeight), + ) + val BodySmallVariationSettings = + FontVariation.Settings( + FontVariation.Setting("ROND", WearComposeMaterial3TypeScaleTokens.BodySmallRoundness), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.BodySmallWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.BodySmallWeight), + ) + val DisplayLargeVariationSettings = + FontVariation.Settings( + FontVariation.Setting( + "ROND", + WearComposeMaterial3TypeScaleTokens.DisplayLargeRoundness, + ), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.DisplayLargeWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.DisplayLargeWeight), + ) + val DisplayMediumVariationSettings = + FontVariation.Settings( + FontVariation.Setting( + "ROND", + WearComposeMaterial3TypeScaleTokens.DisplayMediumRoundness, + ), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.DisplayMediumWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.DisplayMediumWeight), + ) + val DisplaySmallVariationSettings = + FontVariation.Settings( + FontVariation.Setting( + "ROND", + WearComposeMaterial3TypeScaleTokens.DisplaySmallRoundness, + ), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.DisplaySmallWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.DisplaySmallWeight), + ) + val LabelLargeVariationSettings = + FontVariation.Settings( + FontVariation.Setting("ROND", WearComposeMaterial3TypeScaleTokens.LabelLargeRoundness), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.LabelLargeWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.LabelLargeWeight), + ) + val LabelMediumVariationSettings = + FontVariation.Settings( + FontVariation.Setting("ROND", WearComposeMaterial3TypeScaleTokens.LabelMediumRoundness), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.LabelMediumWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.LabelMediumWeight), + ) + val LabelSmallVariationSettings = + FontVariation.Settings( + FontVariation.Setting("ROND", WearComposeMaterial3TypeScaleTokens.LabelSmallRoundness), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.LabelSmallWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.LabelSmallWeight), + ) + val NumeralExtraLargeVariationSettings = + FontVariation.Settings( + FontVariation.Setting( + "ROND", + WearComposeMaterial3TypeScaleTokens.NumeralExtraLargeRoundness, + ), + FontVariation.Setting( + "wdth", + WearComposeMaterial3TypeScaleTokens.NumeralExtraLargeWidth, + ), + FontVariation.Setting( + "wght", + WearComposeMaterial3TypeScaleTokens.NumeralExtraLargeWeight, + ), + ) + val NumeralExtraSmallVariationSettings = + FontVariation.Settings( + FontVariation.Setting( + "ROND", + WearComposeMaterial3TypeScaleTokens.NumeralExtraSmallRoundness, + ), + FontVariation.Setting( + "wdth", + WearComposeMaterial3TypeScaleTokens.NumeralExtraSmallWidth, + ), + FontVariation.Setting( + "wght", + WearComposeMaterial3TypeScaleTokens.NumeralExtraSmallWeight, + ), + ) + val NumeralLargeVariationSettings = + FontVariation.Settings( + FontVariation.Setting( + "ROND", + WearComposeMaterial3TypeScaleTokens.NumeralLargeRoundness, + ), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.NumeralLargeWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.NumeralLargeWeight), + ) + val NumeralMediumVariationSettings = + FontVariation.Settings( + FontVariation.Setting( + "ROND", + WearComposeMaterial3TypeScaleTokens.NumeralMediumRoundness, + ), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.NumeralMediumWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.NumeralMediumWeight), + ) + val NumeralSmallVariationSettings = + FontVariation.Settings( + FontVariation.Setting( + "ROND", + WearComposeMaterial3TypeScaleTokens.NumeralSmallRoundness, + ), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.NumeralSmallWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.NumeralSmallWeight), + ) + val TitleLargeVariationSettings = + FontVariation.Settings( + FontVariation.Setting("ROND", WearComposeMaterial3TypeScaleTokens.TitleLargeRoundness), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.TitleLargeWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.TitleLargeWeight), + ) + val TitleMediumVariationSettings = + FontVariation.Settings( + FontVariation.Setting("ROND", WearComposeMaterial3TypeScaleTokens.TitleMediumRoundness), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.TitleMediumWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.TitleMediumWeight), + ) + val TitleSmallVariationSettings = + FontVariation.Settings( + FontVariation.Setting("ROND", WearComposeMaterial3TypeScaleTokens.TitleSmallRoundness), + FontVariation.Setting("wdth", WearComposeMaterial3TypeScaleTokens.TitleSmallWidth), + FontVariation.Setting("wght", WearComposeMaterial3TypeScaleTokens.TitleSmallWeight), + ) +} diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearOverlayableMaterial3Theme.kt b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearOverlayableMaterial3Theme.kt new file mode 100644 index 000000000..d2b2324ea --- /dev/null +++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearOverlayableMaterial3Theme.kt @@ -0,0 +1,37 @@ +/* + * 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. + */ +package com.android.permissioncontroller.permission.ui.wear.theme + +import android.os.Build +import androidx.compose.runtime.Composable +import androidx.compose.ui.platform.LocalContext +import androidx.wear.compose.material3.MaterialTheme + +/** The Material 3 Theme Wrapper for Supporting RRO. */ +@Composable +fun WearOverlayableMaterial3Theme(content: @Composable () -> Unit) { + val context = LocalContext.current + if (Build.VERSION.SDK_INT >= 36) { + MaterialTheme( + colorScheme = WearComposeMaterial3ColorScheme.dynamicColorScheme(context), + typography = WearComposeMaterial3Typography.dynamicTypography(context), + shapes = WearComposeMaterial3Shapes.dynamicShapes(context), + content = content, + ) + } else { + MaterialTheme(content = content) + } +} diff --git a/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearPermissionTheme.kt b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearPermissionTheme.kt index 933cf19f9..1d6d25ab1 100644 --- a/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearPermissionTheme.kt +++ b/PermissionController/src/com/android/permissioncontroller/permission/ui/wear/theme/WearPermissionTheme.kt @@ -1,3 +1,18 @@ +/* + * 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. + */ package com.android.permissioncontroller.permission.ui.wear.theme import android.content.Context @@ -16,7 +31,7 @@ import androidx.wear.compose.material.MaterialTheme import androidx.wear.compose.material.Typography import com.android.permissioncontroller.R -/** The Material 3 Theme Wrapper for Supporting RRO. */ +/** The Material 2.5 Theme Wrapper for Supporting RRO. */ @Composable fun WearPermissionTheme(content: @Composable () -> Unit) { val context = LocalContext.current |