summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Chen Bai <chenbai@google.com> 2024-11-20 05:20:15 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-11-20 05:20:15 +0000
commit827b83863a015ed4fb2f6e6036b68a3840912d30 (patch)
tree42cdedb3c483e4eaa0f44d6170a33a0f11851bbe
parent922f8254f36be00c528ebbab5d157b0698e74623 (diff)
parent7673e94f43d756413a271fe27802dc7052e37190 (diff)
Merge "m3: guard wear material3 UI change for Button" into main
-rw-r--r--core/java/android/widget/Button.java46
-rw-r--r--core/java/android/widget/flags/flags.aconfig10
-rw-r--r--core/res/res/drawable-watch-v36/btn_background_material_filled.xml2
-rw-r--r--core/res/res/drawable-watch-v36/btn_background_material_filled_tonal.xml2
-rw-r--r--core/res/res/values-watch-v36/config.xml3
-rw-r--r--core/res/res/values-watch-v36/styles_material.xml4
-rw-r--r--core/res/res/values/styles_device_defaults.xml1
-rw-r--r--core/res/res/values/symbols.xml3
8 files changed, 62 insertions, 9 deletions
diff --git a/core/java/android/widget/Button.java b/core/java/android/widget/Button.java
index 98c00ac7f6f7..0bf6380eb904 100644
--- a/core/java/android/widget/Button.java
+++ b/core/java/android/widget/Button.java
@@ -16,17 +16,22 @@
package android.widget;
-import static android.view.flags.Flags.enableArrowIconOnHoverWhenClickable;
import static android.view.flags.Flags.FLAG_ENABLE_ARROW_ICON_ON_HOVER_WHEN_CLICKABLE;
+import static android.view.flags.Flags.enableArrowIconOnHoverWhenClickable;
import android.annotation.FlaggedApi;
+import android.app.compat.CompatChanges;
+import android.compat.annotation.ChangeId;
+import android.compat.annotation.EnabledSince;
import android.content.Context;
+import android.content.pm.PackageManager;
import android.util.AttributeSet;
import android.view.InputDevice;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.PointerIcon;
import android.widget.RemoteViews.RemoteView;
+import android.widget.flags.Flags;
/**
* A user interface element the user can tap or click to perform an action.
@@ -88,6 +93,12 @@ import android.widget.RemoteViews.RemoteView;
@RemoteView
public class Button extends TextView {
+ @ChangeId
+ @EnabledSince(targetSdkVersion = 36)
+ private static final long WEAR_MATERIAL3_BUTTON = 376561342L;
+
+ private static Boolean sUseWearMaterial3Style;
+
/**
* Simple constructor to use when creating a button from code.
*
@@ -118,7 +129,18 @@ public class Button extends TextView {
* @see android.view.View#View(Context, AttributeSet)
*/
public Button(Context context, AttributeSet attrs) {
- this(context, attrs, com.android.internal.R.attr.buttonStyle);
+ // Starting sdk 36+, wear devices will use a specific material3
+ // design. The new design will be applied when all of following conditions are met:
+ // 1. app target sdk is 36 or above.
+ // 2. feature flag rolled-out.
+ // 3. device is a watch.
+ // getButtonDefaultStyleAttr and getButtonDefaultStyleRes works together to alter the UI
+ // while considering the conditions above.
+ // Their results are mutual exclusive. i.e. when conditions above are all true,
+ // getButtonDefaultStyleRes returns non-zero value(new wear material3), abd
+ // getButtonDefaultStyleAttr returns 0. Otherwise, getButtonDefaultStyleAttr returns system
+ // attr com.android.internal.R.attr.buttonStyle and getButtonDefaultStyleRes returns 0.
+ this(context, attrs, getButtonDefaultStyleAttr(context), getButtonDefaultStyleRes());
}
/**
@@ -189,4 +211,24 @@ public class Button extends TextView {
}
return super.onResolvePointerIcon(event, pointerIndex);
}
+
+ private static int getButtonDefaultStyleAttr(Context context) {
+ sUseWearMaterial3Style = useWearMaterial3Style(context);
+ if (sUseWearMaterial3Style) {
+ return 0;
+ }
+ return com.android.internal.R.attr.buttonStyle;
+ }
+
+ private static int getButtonDefaultStyleRes() {
+ if (sUseWearMaterial3Style != null && sUseWearMaterial3Style) {
+ return com.android.internal.R.style.Widget_DeviceDefault_Button_WearMaterial3;
+ }
+ return 0;
+ }
+
+ private static boolean useWearMaterial3Style(Context context) {
+ return Flags.useWearMaterial3Ui() && CompatChanges.isChangeEnabled(WEAR_MATERIAL3_BUTTON)
+ && context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH);
+ }
}
diff --git a/core/java/android/widget/flags/flags.aconfig b/core/java/android/widget/flags/flags.aconfig
index f0ed83be8f1e..d9dc36ccc8c3 100644
--- a/core/java/android/widget/flags/flags.aconfig
+++ b/core/java/android/widget/flags/flags.aconfig
@@ -8,4 +8,12 @@ flag {
metadata {
purpose: PURPOSE_BUGFIX
}
-} \ No newline at end of file
+}
+
+flag {
+ name: "use_wear_material3_ui"
+ namespace: "wear_frameworks"
+ description: "Whether enable material3 style for wear frameworks' widgets."
+ is_exported: true
+ bug: "369480667"
+}
diff --git a/core/res/res/drawable-watch-v36/btn_background_material_filled.xml b/core/res/res/drawable-watch-v36/btn_background_material_filled.xml
index 0029de14e34a..6e74f64fea60 100644
--- a/core/res/res/drawable-watch-v36/btn_background_material_filled.xml
+++ b/core/res/res/drawable-watch-v36/btn_background_material_filled.xml
@@ -19,7 +19,7 @@
<item>
<shape android:shape="rectangle">
<solid android:color="@color/btn_material_filled_background_color"/>
- <corners android:radius="?android:attr/buttonCornerRadius"/>
+ <corners android:radius="@dimen/config_wearMaterial3_buttonCornerRadius"/>
<size
android:width="@dimen/btn_material_width"
android:height="@dimen/btn_material_height" />
diff --git a/core/res/res/drawable-watch-v36/btn_background_material_filled_tonal.xml b/core/res/res/drawable-watch-v36/btn_background_material_filled_tonal.xml
index 105f077cd841..fbd697371329 100644
--- a/core/res/res/drawable-watch-v36/btn_background_material_filled_tonal.xml
+++ b/core/res/res/drawable-watch-v36/btn_background_material_filled_tonal.xml
@@ -19,7 +19,7 @@
<item>
<shape android:shape="rectangle">
<solid android:color="@color/btn_material_filled_tonal_background_color"/>
- <corners android:radius="?android:attr/buttonCornerRadius"/>
+ <corners android:radius="@dimen/config_wearMaterial3_buttonCornerRadius"/>
<size
android:width="@dimen/btn_material_width"
android:height="@dimen/btn_material_height" />
diff --git a/core/res/res/values-watch-v36/config.xml b/core/res/res/values-watch-v36/config.xml
index bb9da177e4fd..1143ae30fe9d 100644
--- a/core/res/res/values-watch-v36/config.xml
+++ b/core/res/res/values-watch-v36/config.xml
@@ -15,7 +15,6 @@
-->
<resources>
- <!-- Overrides system value -->
- <dimen name="config_buttonCornerRadius">26dp</dimen>
+ <dimen name="config_wearMaterial3_buttonCornerRadius">26dp</dimen>
<dimen name="config_bottomDialogCornerRadius">18dp</dimen>
</resources>
diff --git a/core/res/res/values-watch-v36/styles_material.xml b/core/res/res/values-watch-v36/styles_material.xml
index b2760e7c10a7..00f3f092b768 100644
--- a/core/res/res/values-watch-v36/styles_material.xml
+++ b/core/res/res/values-watch-v36/styles_material.xml
@@ -18,13 +18,13 @@
<resources>
<!-- Button Styles -->
<!-- Material Button - Filled -->
- <style name="Widget.DeviceDefault.Button.Filled" parent="Widget.DeviceDefault.Button">
+ <style name="Widget.DeviceDefault.Button.Filled" parent="Widget.DeviceDefault.Button.WearMaterial3">
<item name="android:background">@drawable/btn_background_material_filled</item>
<item name="textAppearance">@style/TextAppearance.Widget.Button.Material.Filled</item>
</style>
<!-- Material Button - Filled Tonal(Override system default button styles) -->
- <style name="Widget.DeviceDefault.Button">
+ <style name="Widget.DeviceDefault.Button.WearMaterial3">
<item name="background">@drawable/btn_background_material_filled_tonal</item>
<item name="textAppearance">@style/TextAppearance.Widget.Button.Material</item>
<item name="minHeight">@dimen/btn_material_height</item>
diff --git a/core/res/res/values/styles_device_defaults.xml b/core/res/res/values/styles_device_defaults.xml
index 3b2f24409a88..acc1ff8fb9db 100644
--- a/core/res/res/values/styles_device_defaults.xml
+++ b/core/res/res/values/styles_device_defaults.xml
@@ -43,6 +43,7 @@ easier.
<item name="textAppearance">?attr/textAppearanceButton</item>
<item name="textColor">@color/btn_colored_text_material</item>
</style>
+ <style name="Widget.DeviceDefault.Button.WearMaterial3"/>
<style name="Widget.DeviceDefault.TextView" parent="Widget.Material.TextView" />
<style name="Widget.DeviceDefault.CheckedTextView" parent="Widget.Material.CheckedTextView"/>
<style name="Widget.DeviceDefault.AutoCompleteTextView" parent="Widget.Material.AutoCompleteTextView"/>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 3ecbf4983f26..850939f1fd64 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -5796,4 +5796,7 @@
<!-- Fingerprint screen off unlock config -->
<java-symbol type="bool" name="config_screen_off_udfps_enabled" />
+
+ <!-- Style for Wear Material3 Button. Will only be used for sdk 36 or above. -->
+ <java-symbol type="style" name="Widget.DeviceDefault.Button.WearMaterial3" />
</resources>