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

Commit ceaa1657 authored by Zoey Chen's avatar Zoey Chen Committed by Android (Google) Code Review
Browse files

Merge "[Settings] Apply new style to dialog" into main

parents 22e56834 09841d6b
Loading
Loading
Loading
Loading
+0 −21
Original line number Diff line number Diff line
<!--
    Copyright (C) 2016 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp"
        android:height="24dp" android:viewportWidth="960" android:viewportHeight="960"
        android:tint="?android:attr/colorControlNormal">
    <path android:fillColor="@android:color/white"
          android:pathData="M480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM480,800Q614,800 707,707Q800,614 800,480Q800,473 799.5,465.5Q799,458 799,453Q794,482 772,501Q750,520 720,520L640,520Q607,520 583.5,496.5Q560,473 560,440L560,400L400,400L400,320Q400,287 423.5,263.5Q447,240 480,240L520,240L520,240Q520,217 532.5,199.5Q545,182 563,171Q543,166 522.5,163Q502,160 480,160Q346,160 253,253Q160,346 160,480Q160,480 160,480Q160,480 160,480L360,480Q426,480 473,527Q520,574 520,640L520,680L400,680L400,790Q420,795 439.5,797.5Q459,800 480,800Z"/>
</vector>
 No newline at end of file
+25 −0
Original line number Diff line number Diff line
<!--
    Copyright (C) 2025 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.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="32dp"
        android:height="32dp"
        android:viewportWidth="960"
        android:viewportHeight="960"
        android:tint="?android:attr/colorControlNormal">
    <path
        android:fillColor="@android:color/white"
        android:pathData="M480,880Q396.67,880 323.67,848.5Q250.67,817 196.5,762.83Q142.33,708.67 111.17,635.33Q80,562 80,478.67Q80,395 111.17,322.5Q142.33,250 196.5,195.83Q250.67,141.67 323.67,110.83Q396.67,80 480,80Q563.67,80 636.5,110.83Q709.33,141.67 763.5,195.83Q817.67,250 848.83,322.5Q880,395 880,478.67Q880,562 848.83,635.33Q817.67,708.67 763.5,762.83Q709.33,817 636.5,848.5Q563.67,880 480,880ZM480,814Q512,778 534,734Q556,690 570,632.67L390.67,632.67Q404,687.33 426,732.33Q448,777.33 480,814ZM388.67,800.67Q366,764.33 349.5,723.17Q333,682 322,632.67L182.67,632.67Q217.67,696.67 265.5,736Q313.33,775.33 388.67,800.67ZM572,800Q638.67,778.67 691.5,735.67Q744.33,692.67 777.33,632.67L638.67,632.67Q627,681.33 610.83,722.5Q594.67,763.67 572,800ZM158,566L309.33,566Q306.33,541.33 305.5,520.5Q304.67,499.67 304.67,478.67Q304.67,455 305.83,435.5Q307,416 310,393.33L158,393.33Q151.67,416 149.17,435.17Q146.67,454.33 146.67,478.67Q146.67,503 149.17,523.17Q151.67,543.33 158,566ZM377.33,566L583.33,566Q587,538.67 588.17,519.17Q589.33,499.67 589.33,478.67Q589.33,458.33 588.17,439.5Q587,420.67 583.33,393.33L377.33,393.33Q373.67,420.67 372.5,439.5Q371.33,458.33 371.33,478.67Q371.33,499.67 372.5,519.17Q373.67,538.67 377.33,566ZM650,566L802,566Q808.33,543.33 810.83,523.17Q813.33,503 813.33,478.67Q813.33,454.33 810.83,435.17Q808.33,416 802,393.33L650.67,393.33Q653.67,423.33 654.83,442.17Q656,461 656,478.67Q656,500.33 654.5,519.83Q653,539.33 650,566ZM638,326.67L777.33,326.67Q745.67,264 692.83,221Q640,178 571.33,159.33Q594,195 610.17,235.5Q626.33,276 638,326.67ZM390.67,326.67L570.67,326.67Q559.33,276.67 535.67,230.67Q512,184.67 480,147.33Q450,177.33 429,219.67Q408,262 390.67,326.67ZM182.67,326.67L322.67,326.67Q333,278 348.83,237.83Q364.67,197.67 388,160Q319.33,178.67 267.5,221Q215.67,263.33 182.67,326.67Z"/>
</vector>
+6 −0
Original line number Diff line number Diff line
@@ -555,4 +555,10 @@
    <dimen name="display_block_padding">5dp</dimen>
    <dimen name="display_block_highlight_width">2dp</dimen>
    <dimen name="display_block_corner_radius">10dp</dimen>

    <!-- Locale Picker -->
    <dimen name="locale_picker_dialog_icon_padding">10dp</dimen>
    <dimen name="locale_picker_dialog_title_padding">16dp</dimen>
    <dimen name="locale_picker_dialog_message_padding_left_right">24dp</dimen>
    <dimen name="locale_picker_dialog_message_padding_bottom">32dp</dimen>
</resources>
+5 −4
Original line number Diff line number Diff line
@@ -502,7 +502,7 @@
    <!-- The text of the confirmation dialog showing the system locale will be changed. [CHAR LIMIT=NONE]-->
    <string name="desc_notice_device_locale_settings_change">Your device settings and regional preferences will change.</string>
    <!-- A dialog button for confirmmation of system locale change. [CHAR LIMIT=25]-->
    <!-- A dialog button for confirmation of system locale change. [CHAR LIMIT=25]-->
    <string name="button_label_confirmation_of_system_locale_change">Change</string>
    <!-- Title for saying this selected locale is unavailable to use. [CHAR LIMIT=50]-->
@@ -530,10 +530,11 @@
    <!-- Category for more language settings. [CHAR LIMIT=NONE]-->
    <string name="more_language_settings_category">More language settings</string>
    <!-- Title for asking to change system locale region or not. [CHAR LIMIT=50]-->
    <string name="title_change_system_locale_region">Change region to %s ?</string>
    <string name="title_change_system_locale_region">Change region to <xliff:g id="system_language_region" example="Canada">%1$s</xliff:g> ?</string>
    <!-- Message for asking to change system locale region or not. [CHAR LIMIT=50]-->
    <string name="body_change_system_locale_region">Your device will keep %s as a system language</string>
    <string name="top_intro_numbering_system_title">The digits used will be dependent on the numbering system</string>
    <string name="body_change_system_locale_region">Your device will keep <xliff:g id="system_language" example="English">%1$s</xliff:g> as a system language</string>
    <!-- Description for the numbering system language. [CHAR LIMIT=NONE]-->
    <string name="top_intro_numbering_system_title">Most apps will use your regional preferences</string>
    <!-- Regional Preferences begin -->
    <!-- The title of the menu entry of regional preferences. [CHAR LIMIT=50] -->
+54 −46
Original line number Diff line number Diff line
@@ -29,19 +29,20 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.window.OnBackInvokedCallback;
import android.window.OnBackInvokedDispatcher;

import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;

import com.android.internal.app.LocaleStore;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.utils.CustomDialogHelper;

/**
 * Create a dialog for system locale events.
@@ -58,7 +59,6 @@ public class LocaleDialogFragment extends InstrumentedDialogFragment {
    static final String ARG_SHOW_DIALOG = "arg_show_dialog";

    private boolean mShouldKeepDialog;
    private AlertDialog mAlertDialog;
    private OnBackInvokedDispatcher mBackDispatcher;

    private OnBackInvokedCallback mBackCallback = () -> {
@@ -106,45 +106,53 @@ public class LocaleDialogFragment extends InstrumentedDialogFragment {
        LocaleListEditor parentFragment = (LocaleListEditor) getParentFragment();
        LocaleDialogController controller = getLocaleDialogController(getContext(), this,
                parentFragment);
        LocaleDialogController.DialogContent dialogContent = controller.getDialogContent();
        ViewGroup viewGroup = (ViewGroup) LayoutInflater.from(getContext()).inflate(
                R.layout.locale_dialog, null);
        setDialogTitle(viewGroup, dialogContent.mTitle);
        setDialogMessage(viewGroup, dialogContent.mMessage);

        AlertDialog.Builder builder = new AlertDialog.Builder(getContext())
                .setView(viewGroup);
        if (!dialogContent.mPositiveButton.isEmpty()) {
            builder.setPositiveButton(dialogContent.mPositiveButton, controller);
        }
        if (!dialogContent.mNegativeButton.isEmpty()) {
            builder.setNegativeButton(dialogContent.mNegativeButton, controller);
        }
        mAlertDialog = builder.create();
        getOnBackInvokedDispatcher().registerOnBackInvokedCallback(PRIORITY_DEFAULT, mBackCallback);
        mAlertDialog.setCanceledOnTouchOutside(false);
        mAlertDialog.setOnDismissListener(dialogInterface -> {
            mAlertDialog.getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(
        Dialog dialog = createDialog(getContext(), controller);
        dialog.setCanceledOnTouchOutside(false);
        getOnBackInvokedDispatcher(dialog).registerOnBackInvokedCallback(PRIORITY_DEFAULT,
                mBackCallback);
        dialog.setOnDismissListener(dialogInterface -> {
            getOnBackInvokedDispatcher(dialog).unregisterOnBackInvokedCallback(
                    mBackCallback);
        });

        return mAlertDialog;
        return dialog;
    }

    private static void setDialogTitle(View root, String content) {
        TextView titleView = root.findViewById(R.id.dialog_title);
        if (titleView == null) {
            return;
        }
        titleView.setText(content);
    }

    private static void setDialogMessage(View root, String content) {
        TextView textView = root.findViewById(R.id.dialog_msg);
        if (textView == null) {
            return;
    private Dialog createDialog(Context context, LocaleDialogController controller) {
        CustomDialogHelper dialogHelper = new CustomDialogHelper(context);
        LocaleDialogController.DialogContent dialogContent = controller.getDialogContent();
        dialogHelper.setIcon(context.getDrawable(R.drawable.ic_settings_language_32dp))
                .setTitle(dialogContent.mTitle)
                .setMessage(dialogContent.mMessage)
                .setIconPadding(0,
                        context.getResources().getDimensionPixelSize(
                                R.dimen.locale_picker_dialog_icon_padding),
                        0, 0)
                .setTitlePadding(0,
                        context.getResources().getDimensionPixelSize(
                                R.dimen.locale_picker_dialog_title_padding),
                        0,
                        context.getResources().getDimensionPixelSize(
                                R.dimen.locale_picker_dialog_title_padding))
                .setMessagePadding(context.getResources().getDimensionPixelSize(
                                R.dimen.locale_picker_dialog_message_padding_left_right), 0,
                        context.getResources().getDimensionPixelSize(
                                R.dimen.locale_picker_dialog_message_padding_left_right),
                        context.getResources().getDimensionPixelSize(
                                R.dimen.locale_picker_dialog_message_padding_bottom))
                .setPositiveButton(dialogContent.mPositiveButton,
                        view -> {
                            controller.onClick(dialogHelper.getDialog(),
                                    DialogInterface.BUTTON_POSITIVE);
                            dialogHelper.getDialog().dismiss();
                        });
        if (dialogContent.mNegativeButton != 0) {
            dialogHelper.setBackButton(dialogContent.mNegativeButton, view -> {
                controller.onClick(dialogHelper.getDialog(), DialogInterface.BUTTON_NEGATIVE);
                dialogHelper.getDialog().dismiss();
            });
        }
        textView.setText(content);
        return dialogHelper.getDialog();
    }

    @VisibleForTesting
@@ -158,11 +166,11 @@ public class LocaleDialogFragment extends InstrumentedDialogFragment {
    }

    @VisibleForTesting
    public OnBackInvokedDispatcher getOnBackInvokedDispatcher() {
    public @NonNull OnBackInvokedDispatcher getOnBackInvokedDispatcher(@NonNull Dialog dialog) {
        if (mBackDispatcher != null) {
            return mBackDispatcher;
        } else {
            return mAlertDialog.getOnBackInvokedDispatcher();
            return dialog.getOnBackInvokedDispatcher();
        }
    }

@@ -223,15 +231,15 @@ public class LocaleDialogFragment extends InstrumentedDialogFragment {
                            R.string.title_change_system_locale), mLocaleInfo.getFullNameNative());
                    dialogContent.mMessage = mContext.getString(
                            R.string.desc_notice_device_locale_settings_change);
                    dialogContent.mPositiveButton = mContext.getString(
                            R.string.button_label_confirmation_of_system_locale_change);
                    dialogContent.mNegativeButton = mContext.getString(R.string.cancel);
                    dialogContent.mPositiveButton =
                            R.string.button_label_confirmation_of_system_locale_change;
                    dialogContent.mNegativeButton = R.string.cancel;
                    break;
                case DIALOG_NOT_AVAILABLE_LOCALE:
                    dialogContent.mTitle = String.format(mContext.getString(
                            R.string.title_unavailable_locale), mLocaleInfo.getFullNameNative());
                    dialogContent.mMessage = mContext.getString(R.string.desc_unavailable_locale);
                    dialogContent.mPositiveButton = mContext.getString(R.string.okay);
                    dialogContent.mPositiveButton = R.string.okay;
                    break;
                case DIALOG_ADD_SYSTEM_LOCALE:
                    dialogContent.mTitle = String.format(mContext.getString(
@@ -239,8 +247,8 @@ public class LocaleDialogFragment extends InstrumentedDialogFragment {
                            mLocaleInfo.getFullNameNative());
                    dialogContent.mMessage = mContext.getString(
                            R.string.desc_system_locale_addition);
                    dialogContent.mPositiveButton = mContext.getString(R.string.add);
                    dialogContent.mNegativeButton = mContext.getString(R.string.cancel);
                    dialogContent.mPositiveButton = R.string.add;
                    dialogContent.mNegativeButton = R.string.cancel;
                    break;
                default:
                    break;
@@ -252,8 +260,8 @@ public class LocaleDialogFragment extends InstrumentedDialogFragment {
        static class DialogContent {
            String mTitle = "";
            String mMessage = "";
            String mPositiveButton = "";
            String mNegativeButton = "";
            int mPositiveButton = 0;
            int mNegativeButton = 0;
        }
    }
}
Loading