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

Commit 8f12a1e3 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "m3: guard wear material3 UI change for AlertDialog" into main

parents e0ee4f07 fec8df10
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>