Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fec8df10 authored by Chen Bai's avatar Chen Bai
Browse files

m3: guard wear material3 UI change for AlertDialog

Share the same UX change guarding condition as Platform Button
(ag/30167572):
1. app target sdk is 36 or above.
2. feature flag rolled-out.
3. device is a watch.
4. button uses Theme.DeviceDefault.

Group Wear Material3 styles to a new layout and only refer it
in the new style. This decouple the new from old style hierarchy to
avoid messing up layout if existing AlertDialog has its own style
tweeks.

Bug: 377422490
Bug: 379365266
Test: manual
Flag: android.widget.flags.use_wear_material3_ui
Change-Id: I230b74d5e2b0d2b599f24a01d7548076f45151d1
parent cd0151ce
Loading
Loading
Loading
Loading
+35 −1
Original line number Diff line number Diff line
@@ -20,9 +20,13 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;

import android.annotation.Nullable;
import android.app.AlertDialog;
import android.app.compat.CompatChanges;
import android.compat.annotation.ChangeId;
import android.compat.annotation.EnabledSince;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
@@ -58,6 +62,7 @@ import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.flags.Flags;

import com.android.internal.R;

@@ -66,6 +71,12 @@ import java.lang.ref.WeakReference;
public class AlertController {
    public static final int MICRO = 1;

    private static boolean sUseWearMaterial3Style;

    @ChangeId
    @EnabledSince(targetSdkVersion = 36)
    private static final long WEAR_MATERIAL3_ALERTDIALOG = 379365266L;

    private final Context mContext;
    private final DialogInterface mDialogInterface;
    protected final Window mWindow;
@@ -210,7 +221,8 @@ public class AlertController {
        mHandler = new ButtonHandler(di);

        final TypedArray a = context.obtainStyledAttributes(null,
                R.styleable.AlertDialog, R.attr.alertDialogStyle, 0);
                R.styleable.AlertDialog, getAlertDialogDefStyleAttr(context),
                getAlertDialogDefStyleRes());

        mAlertDialogLayout = a.getResourceId(
                R.styleable.AlertDialog_layout, R.layout.alert_dialog);
@@ -236,6 +248,28 @@ public class AlertController {
        window.requestFeature(Window.FEATURE_NO_TITLE);
    }

    private int getAlertDialogDefStyleAttr(Context context) {
        sUseWearMaterial3Style = useWearMaterial3Style(context);
        if (sUseWearMaterial3Style) {
            return 0;
        }
        return R.attr.alertDialogStyle;
    }

    private int getAlertDialogDefStyleRes() {
        if (sUseWearMaterial3Style) {
            return com.android.internal.R.style.AlertDialog_DeviceDefault_WearMaterial3;
        }
        return 0;
    }

    private static boolean useWearMaterial3Style(Context context) {
        return Flags.useWearMaterial3Ui()
                && CompatChanges.isChangeEnabled(WEAR_MATERIAL3_ALERTDIALOG)
                && context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WATCH)
                && context.getThemeResId() == com.android.internal.R.style.Theme_DeviceDefault;
    }

    static boolean canTextInput(View v) {
        if (v.onCheckIsTextEditor()) {
            return true;
+4 −0
Original line number Diff line number Diff line
@@ -57,6 +57,10 @@
    </style>

    <!--  AlertDialog Styles  -->
    <style name="AlertDialog.DeviceDefault.WearMaterial3">
        <item name="layout">@layout/alert_dialog_wear_material3</item>
    </style>

    <style name="Widget.DeviceDefault.Button.ButtonBar.AlertDialog.WearMaterial3" parent="Widget.DeviceDefault.Button">
        <item name="android:textSize">0sp</item>
        <item name="android:gravity">center</item>
+3 −0
Original line number Diff line number Diff line
@@ -5824,5 +5824,8 @@
  <!-- Style for Wear Material3 Button. Will only be used for sdk 36 or above. -->
  <java-symbol type="style" name="Widget.DeviceDefault.Button.WearMaterial3" />

  <!-- Style for Wear Material3 AlertDialog. Will only be used for sdk 36 or above. -->
  <java-symbol type="style" name="AlertDialog.DeviceDefault.WearMaterial3" />

  <java-symbol type="bool" name="config_allowNormalBrightnessForDozePolicy" />
</resources>