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

Commit 2da2cf8f authored by Haijie Hong's avatar Haijie Hong Committed by Android (Google) Code Review
Browse files

Merge "Update button style of bluetooth pairing dialog" into main

parents a628aa81 1b2a77ae
Loading
Loading
Loading
Loading
+28 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:paddingTop="@dimen/bluetooth_dialog_padding_top">
@@ -134,6 +135,32 @@
                android:clickable="true"
                style="@style/SettingslibSwitchStyle.Expressive" />
        </LinearLayout>
        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:layout_marginStart="@dimen/bluetooth_dialog_padding"
            android:layout_marginEnd="@dimen/bluetooth_dialog_padding">
            <Button
                android:id="@+id/negative_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:visibility="gone"
                android:text="@string/bluetooth_pairing_decline"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                style="@style/Widget.SettingsLib.DialogButton.Outline"/>
            <Button
                android:id="@+id/positive_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:visibility="gone"
                android:text="@string/bluetooth_pairing_accept"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                style="@style/Widget.SettingsLib.DialogButton.Outline"/>
        </androidx.constraintlayout.widget.ConstraintLayout>
    </LinearLayout>

</ScrollView>
+26 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

@@ -86,6 +87,30 @@
            android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Body1"
            android:textColor="?android:attr/textColorSecondary"/>

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:layout_marginStart="@dimen/bluetooth_pairing_padding"
            android:layout_marginEnd="@dimen/bluetooth_pairing_padding">
            <Button
                android:id="@+id/negative_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@android:string/cancel"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                style="@style/Widget.SettingsLib.DialogButton.Outline"/>
            <Button
                android:id="@+id/positive_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@android:string/ok"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                style="@style/Widget.SettingsLib.DialogButton.Outline"/>
        </androidx.constraintlayout.widget.ConstraintLayout>
    </LinearLayout>

</ScrollView>
+32 −24
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package com.android.settings.bluetooth;
import android.app.Dialog;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputFilter;
@@ -48,7 +46,7 @@ import com.android.settings.flags.Flags;
 * for the bluetooth device.
 */
public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment implements
        TextWatcher, OnClickListener {
        TextWatcher {

    private static final String TAG = "BTPairingDialogFragment";

@@ -109,22 +107,19 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i
    @Override
    public void afterTextChanged(Editable s) {
        // enable the positive button when we detect potentially valid input
        Button positiveButton = mDialog.getButton(DialogInterface.BUTTON_POSITIVE);
        if (positiveButton != null) {
            positiveButton.setEnabled(mPairingController.isPasskeyValid(s));
        }
        mDialog.findViewById(R.id.positive_button).setEnabled(mPairingController.isPasskeyValid(s));
        // notify the controller about user input
        mPairingController.updateUserInput(s.toString());
    }

    @Override
    public void onClick(DialogInterface dialog, int which) {
        if (which == DialogInterface.BUTTON_POSITIVE) {
    protected void onAcceptButtonClicked() {
        mPositiveClicked = true;
        mPairingController.onDialogPositiveClick(this);
        } else if (which == DialogInterface.BUTTON_NEGATIVE) {
            mPairingController.onDialogNegativeClick(this);
        mPairingDialogActivity.dismiss();
    }

    protected void onDeclineButtonClicked() {
        mPairingController.onDialogNegativeClick(this);
        mPairingDialogActivity.dismiss();
    }

@@ -225,12 +220,10 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i
        mBuilder.setTitle(getString(R.string.bluetooth_pairing_request,
                mPairingController.getDeviceName()));
        mBuilder.setView(createPinEntryView());
        mBuilder.setPositiveButton(getString(android.R.string.ok), this);
        mBuilder.setNegativeButton(getString(android.R.string.cancel), this);
        AlertDialog dialog = mBuilder.create();
        dialog.setOnShowListener(d -> {
            if (TextUtils.isEmpty(getPairingViewText())) {
                mDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(false);
                mDialog.findViewById(R.id.positive_button).setEnabled(false);
            }
            if (mPairingView != null && mPairingView.requestFocus()) {
                InputMethodManager imm = (InputMethodManager)
@@ -295,6 +288,11 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i
        pairingView.setFilters(new InputFilter[]{
                new LengthFilter(maxLength)});

        Button negativeButton = view.findViewById(R.id.negative_button);
        negativeButton.setOnClickListener(v -> onDeclineButtonClicked());
        Button positiveButton = view.findViewById(R.id.positive_button);
        positiveButton.setOnClickListener(v -> onAcceptButtonClicked());

        return view;
    }

@@ -302,12 +300,13 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i
     * Creates a dialog with UI elements that allow the user to confirm a pairing request.
     */
    private AlertDialog createConfirmationDialog() {
        if (mPairingController.hasPairingContent()) {
            mBuilder.setTitle(getString(R.string.bluetooth_pairing_confirmation_title));
        } else {
            mBuilder.setTitle(getString(R.string.bluetooth_pairing_request,
                    mPairingController.getDeviceName()));
        }
        mBuilder.setView(createView());
        mBuilder.setPositiveButton(
                getString(com.android.settingslib.R.string.bluetooth_pairing_accept), this);
        mBuilder.setNegativeButton(
                getString(com.android.settingslib.R.string.bluetooth_pairing_decline), this);
        AlertDialog dialog = mBuilder.create();
        return dialog;
    }
@@ -327,7 +326,6 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i
        mBuilder.setTitle(getString(R.string.bluetooth_pairing_request,
                mPairingController.getDeviceName()));
        mBuilder.setView(createView());
        mBuilder.setNegativeButton(getString(android.R.string.cancel), this);
        AlertDialog dialog = mBuilder.create();

        // Tell the controller the dialog has been created.
@@ -378,6 +376,16 @@ public class BluetoothPairingDialogFragment extends InstrumentedDialogFragment i
            mPairingController.isCoordinatedSetMemberDevice() || mPairingController.isLateBonding();

        messagePairingSet.setVisibility(setPairingMessage ? View.VISIBLE : View.GONE);

        Button negativeButton = view.findViewById(R.id.negative_button);
        negativeButton.setVisibility(View.VISIBLE);
        negativeButton.setOnClickListener(v -> onDeclineButtonClicked());
        if (mPairingController.getDialogType() == BluetoothPairingController.CONFIRMATION_DIALOG) {
            Button positiveButton = view.findViewById(R.id.positive_button);
            positiveButton.setVisibility(View.VISIBLE);
            positiveButton.setOnClickListener(v -> onAcceptButtonClicked());
        }

        return view;
    }

+8 −8
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.app.Dialog;
import android.content.Context;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
@@ -108,7 +107,7 @@ public class BluetoothPairingDialogTest {

        // test that the positive button is enabled when passkey is valid
        frag.afterTextChanged(new SpannableStringBuilder(FILLER));
        View button = frag.getmDialog().getButton(AlertDialog.BUTTON_POSITIVE);
        View button = frag.getmDialog().findViewById(R.id.positive_button);
        assertThat(button).isNotNull();
        assertThat(button.getVisibility()).isEqualTo(View.VISIBLE);
    }
@@ -208,7 +207,7 @@ public class BluetoothPairingDialogTest {
        BluetoothPairingDialogFragment frag = makeFragment();

        // click the button and verify that the controller hook was called
        frag.onClick(frag.getmDialog(), AlertDialog.BUTTON_POSITIVE);
        frag.onAcceptButtonClicked();
        verify(controller, times(1)).onDialogPositiveClick(any());
    }

@@ -224,7 +223,7 @@ public class BluetoothPairingDialogTest {
        BluetoothPairingDialogFragment frag = makeFragment();

        // click the button and verify that the controller hook was called
        frag.onClick(frag.getmDialog(), AlertDialog.BUTTON_NEGATIVE);
        frag.onDeclineButtonClicked();
        verify(controller, times(1)).onDialogNegativeClick(any());
    }

@@ -269,7 +268,8 @@ public class BluetoothPairingDialogTest {

        // test that the positive button is enabled when passkey is valid
        frag.afterTextChanged(new SpannableStringBuilder(FILLER));
        View button = frag.getmDialog().getButton(AlertDialog.BUTTON_POSITIVE);
        View button = frag.getmDialog().findViewById(R.id.positive_button);

        assertThat(button).isNotNull();
        assertThat(button.isEnabled()).isFalse();
    }
@@ -379,7 +379,7 @@ public class BluetoothPairingDialogTest {
        BluetoothPairingDialogFragment frag = makeFragment();

        // click the button and verify that the controller hook was called
        frag.onClick(frag.getmDialog(), AlertDialog.BUTTON_POSITIVE);
        frag.onAcceptButtonClicked();

        verify(controller, times(1)).onDialogPositiveClick(any());
        verify(dialogActivity, times(1)).dismiss();
@@ -397,7 +397,7 @@ public class BluetoothPairingDialogTest {
        BluetoothPairingDialogFragment frag = makeFragment();

        // click the button and verify that the controller hook was called
        frag.onClick(frag.getmDialog(), AlertDialog.BUTTON_NEGATIVE);
        frag.onDeclineButtonClicked();

        verify(controller, times(1)).onDialogNegativeClick(any());
        verify(dialogActivity, times(1)).dismiss();
@@ -482,7 +482,7 @@ public class BluetoothPairingDialogTest {
        AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
        assertThat(dialog).isNotNull();
        boolean expected = !TextUtils.isEmpty(existingText);
        assertThat(dialog.getButton(Dialog.BUTTON_POSITIVE).isEnabled()).isEqualTo(expected);
        assertThat(dialog.findViewById(R.id.positive_button).isEnabled()).isEqualTo(expected);
    }

    private void setupFragment(BluetoothPairingDialogFragment frag) {