Improve Bluetooth pairing dialog & contact sharing toggle
Before change: https://screenshot.googleplex.com/Agr29KTvgptbsag
After change: https://screenshot.googleplex.com/ArjiavkFAFiuCTR
Bug: 274521434
Test: RunSettingsRoboTests
Change-Id: Ib896b70bc219de128b733b75249bf80e3389f221
diff --git a/res/layout/bluetooth_pin_confirm.xml b/res/layout/bluetooth_pin_confirm.xml
index 7b5b046..bcc47ad 100644
--- a/res/layout/bluetooth_pin_confirm.xml
+++ b/res/layout/bluetooth_pin_confirm.xml
@@ -76,15 +76,37 @@
android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Body1"
android:visibility="gone" />
- <CheckBox
- android:id="@+id/phonebook_sharing_message_confirm_pin"
- android:layout_width="wrap_content"
+ <LinearLayout
+ android:id="@+id/phonebook_sharing"
android:layout_height="wrap_content"
- android:minHeight="@dimen/min_tap_target_size"
+ android:layout_width="match_parent"
android:layout_marginStart="@dimen/bluetooth_dialog_padding"
android:layout_marginEnd="@dimen/bluetooth_dialog_padding"
- android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Body1" />
-
+ android:orientation="horizontal">
+ <LinearLayout
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:layout_weight="1"
+ android:layout_marginEnd="10dp"
+ android:orientation="vertical">
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/bluetooth_pairing_phonebook_toggle_text"
+ android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Body1" />
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/bluetooth_pairing_phonebook_toggle_details"
+ android:textAppearance="@*android:style/TextAppearance.DeviceDefault.Caption" />
+ </LinearLayout>
+ <Switch
+ android:id="@+id/phonebook_sharing_message_confirm_pin"
+ android:layout_width="wrap_content"
+ android:layout_height="match_parent"
+ android:layout_weight="0"
+ android:gravity="center_vertical" />
+ </LinearLayout>
</LinearLayout>
</ScrollView>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 948709b..6074739 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1504,6 +1504,12 @@
<!-- Checkbox message in pairing dialogs. [CHAR LIMIT=NONE] -->
<string name="bluetooth_pairing_shares_phonebook">Allow access to your contacts and call history</string>
+ <!-- Phonebook sharing toggle message in pairing dialogs. [CHAR LIMIT=NONE] -->
+ <string name="bluetooth_pairing_phonebook_toggle_text">Also allow access to contacts and call history</string>
+
+ <!-- Phonebook sharing toggle detailed message in pairing dialogs. [CHAR LIMIT=NONE] -->
+ <string name="bluetooth_pairing_phonebook_toggle_details">Info will be used for call announcements and more</string>
+
<!-- Title for BT error dialogs. -->
<string name="bluetooth_error_title"></string>
diff --git a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
index 1fd09a3..555868b 100644
--- a/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDetailsProfilesController.java
@@ -156,6 +156,7 @@
} else if (profile instanceof PbapServerProfile) {
profilePref.setChecked(device.getPhonebookAccessPermission()
== BluetoothDevice.ACCESS_ALLOWED);
+ profilePref.setSummary(profile.getSummaryResourceForDevice(mCachedDevice.getDevice()));
} else if (profile instanceof PanProfile) {
profilePref.setChecked(profile.getConnectionStatus(device) ==
BluetoothProfile.STATE_CONNECTED);
diff --git a/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java b/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java
index e11c275..1bac598 100644
--- a/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java
+++ b/src/com/android/settings/bluetooth/BluetoothPairingDialogFragment.java
@@ -33,6 +33,7 @@
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
+import android.widget.Switch;
import android.widget.TextView;
import androidx.annotation.VisibleForTesting;
@@ -339,11 +340,9 @@
TextView pairingViewCaption = (TextView) view.findViewById(R.id.pairing_caption);
TextView pairingViewContent = (TextView) view.findViewById(R.id.pairing_subhead);
TextView messagePairing = (TextView) view.findViewById(R.id.pairing_code_message);
- CheckBox contactSharing = (CheckBox) view.findViewById(
+ Switch contactSharing = (Switch) view.findViewById(
R.id.phonebook_sharing_message_confirm_pin);
- contactSharing.setText(getString(R.string.bluetooth_pairing_shares_phonebook));
-
- contactSharing.setVisibility(
+ view.findViewById(R.id.phonebook_sharing).setVisibility(
mPairingController.isContactSharingVisible() ? View.VISIBLE : View.GONE);
mPairingController.setContactSharingState();
contactSharing.setChecked(mPairingController.getContactSharingState());
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDialogTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDialogTest.java
index 517b435..2044881 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDialogTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothPairingDialogTest.java
@@ -33,7 +33,6 @@
import android.text.TextUtils;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
-import android.widget.CheckBox;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
@@ -276,7 +275,7 @@
}
@Test
- public void contactSharingCheckbox_conditionIsReady_showsUi() {
+ public void contactSharingToggle_conditionIsReady_showsUi() {
// set the dialog variant to confirmation/consent
when(controller.getDialogType()).thenReturn(BluetoothPairingController.CONFIRMATION_DIALOG);
// set a fake device name and pretend the profile has not been set up for it
@@ -286,14 +285,14 @@
// build the fragment
BluetoothPairingDialogFragment frag = makeFragment();
- // verify that the checkbox is visible and that the device name is correct
- CheckBox sharingCheckbox =
- frag.getmDialog().findViewById(R.id.phonebook_sharing_message_confirm_pin);
- assertThat(sharingCheckbox.getVisibility()).isEqualTo(View.VISIBLE);
+ // verify that the toggle is visible
+ View sharingToggle =
+ frag.getmDialog().findViewById(R.id.phonebook_sharing);
+ assertThat(sharingToggle.getVisibility()).isEqualTo(View.VISIBLE);
}
@Test
- public void contactSharingCheckbox_conditionIsNotReady_doesNotShowUi() {
+ public void contactSharingToggle_conditionIsNotReady_doesNotShowUi() {
// set the dialog variant to confirmation/consent
when(controller.getDialogType()).thenReturn(BluetoothPairingController.CONFIRMATION_DIALOG);
// set a fake device name and pretend the profile has been set up for it
@@ -303,10 +302,10 @@
// build the fragment
BluetoothPairingDialogFragment frag = makeFragment();
- // verify that the checkbox is gone
- CheckBox sharingCheckbox =
- frag.getmDialog().findViewById(R.id.phonebook_sharing_message_confirm_pin);
- assertThat(sharingCheckbox.getVisibility()).isEqualTo(View.GONE);
+ // verify that the toggle is gone
+ View sharingToggle =
+ frag.getmDialog().findViewById(R.id.phonebook_sharing);
+ assertThat(sharingToggle.getVisibility()).isEqualTo(View.GONE);
}
@Test