Add bottom padding of profile group on Bluetooth detail page
- This CL add a bottom padding preference to make UI consistency. - Update test case Bug: 146522686 Test: make -j42 RunSettingsRoboTests Change-Id: I525d8a3b71535972755de92924a3c04768f68e63
This commit is contained in:
26
res/layout/preference_bluetooth_profile_category.xml
Normal file
26
res/layout/preference_bluetooth_profile_category.xml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
Copyright (C) 2020 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||||
|
android:paddingTop="16dp"
|
||||||
|
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
|
||||||
|
</LinearLayout>
|
@@ -28,6 +28,7 @@ import androidx.preference.PreferenceFragmentCompat;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.bluetooth.A2dpProfile;
|
import com.android.settingslib.bluetooth.A2dpProfile;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
@@ -48,6 +49,8 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
|
|||||||
implements Preference.OnPreferenceClickListener,
|
implements Preference.OnPreferenceClickListener,
|
||||||
LocalBluetoothProfileManager.ServiceListener {
|
LocalBluetoothProfileManager.ServiceListener {
|
||||||
private static final String KEY_PROFILES_GROUP = "bluetooth_profiles";
|
private static final String KEY_PROFILES_GROUP = "bluetooth_profiles";
|
||||||
|
private static final String KEY_BOTTOM_PREFERENCE = "bottom_preference";
|
||||||
|
private static final int ORDINAL = 99;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final String HIGH_QUALITY_AUDIO_PREF_TAG = "A2dpProfileHighQualityAudio";
|
static final String HIGH_QUALITY_AUDIO_PREF_TAG = "A2dpProfileHighQualityAudio";
|
||||||
@@ -55,7 +58,9 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
|
|||||||
private LocalBluetoothManager mManager;
|
private LocalBluetoothManager mManager;
|
||||||
private LocalBluetoothProfileManager mProfileManager;
|
private LocalBluetoothProfileManager mProfileManager;
|
||||||
private CachedBluetoothDevice mCachedDevice;
|
private CachedBluetoothDevice mCachedDevice;
|
||||||
private PreferenceCategory mProfilesContainer;
|
|
||||||
|
@VisibleForTesting
|
||||||
|
PreferenceCategory mProfilesContainer;
|
||||||
|
|
||||||
public BluetoothDetailsProfilesController(Context context, PreferenceFragmentCompat fragment,
|
public BluetoothDetailsProfilesController(Context context, PreferenceFragmentCompat fragment,
|
||||||
LocalBluetoothManager manager, CachedBluetoothDevice device, Lifecycle lifecycle) {
|
LocalBluetoothManager manager, CachedBluetoothDevice device, Lifecycle lifecycle) {
|
||||||
@@ -69,6 +74,7 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
|
|||||||
@Override
|
@Override
|
||||||
protected void init(PreferenceScreen screen) {
|
protected void init(PreferenceScreen screen) {
|
||||||
mProfilesContainer = (PreferenceCategory)screen.findPreference(getPreferenceKey());
|
mProfilesContainer = (PreferenceCategory)screen.findPreference(getPreferenceKey());
|
||||||
|
mProfilesContainer.setLayoutResource(R.layout.preference_bluetooth_profile_category);
|
||||||
// Call refresh here even though it will get called later in onResume, to avoid the
|
// Call refresh here even though it will get called later in onResume, to avoid the
|
||||||
// list of switches appearing to "pop" into the page.
|
// list of switches appearing to "pop" into the page.
|
||||||
refresh();
|
refresh();
|
||||||
@@ -283,6 +289,16 @@ public class BluetoothDetailsProfilesController extends BluetoothDetailsControll
|
|||||||
mProfilesContainer.removePreference(pref);
|
mProfilesContainer.removePreference(pref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Preference preference = mProfilesContainer.findPreference(KEY_BOTTOM_PREFERENCE);
|
||||||
|
if (preference == null) {
|
||||||
|
preference = new Preference(mContext);
|
||||||
|
preference.setLayoutResource(R.layout.preference_bluetooth_profile_category);
|
||||||
|
preference.setEnabled(false);
|
||||||
|
preference.setKey(KEY_BOTTOM_PREFERENCE);
|
||||||
|
preference.setOrder(ORDINAL);
|
||||||
|
mProfilesContainer.addPreference(preference);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -29,6 +29,7 @@ import android.bluetooth.BluetoothDevice;
|
|||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceCategory;
|
import androidx.preference.PreferenceCategory;
|
||||||
import androidx.preference.SwitchPreference;
|
import androidx.preference.SwitchPreference;
|
||||||
|
|
||||||
@@ -84,6 +85,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
|||||||
mController = new BluetoothDetailsProfilesController(mContext, mFragment, mLocalManager,
|
mController = new BluetoothDetailsProfilesController(mContext, mFragment, mLocalManager,
|
||||||
mCachedDevice, mLifecycle);
|
mCachedDevice, mLifecycle);
|
||||||
mProfiles.setKey(mController.getPreferenceKey());
|
mProfiles.setKey(mController.getPreferenceKey());
|
||||||
|
mController.mProfilesContainer = mProfiles;
|
||||||
mScreen.addPreference(mProfiles);
|
mScreen.addPreference(mProfiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,11 +195,14 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
|||||||
private List<SwitchPreference> getProfileSwitches(boolean expectOnlyMConnectable) {
|
private List<SwitchPreference> getProfileSwitches(boolean expectOnlyMConnectable) {
|
||||||
if (expectOnlyMConnectable) {
|
if (expectOnlyMConnectable) {
|
||||||
assertThat(mConnectableProfiles).isNotEmpty();
|
assertThat(mConnectableProfiles).isNotEmpty();
|
||||||
assertThat(mProfiles.getPreferenceCount()).isEqualTo(mConnectableProfiles.size());
|
assertThat(mProfiles.getPreferenceCount() - 1).isEqualTo(mConnectableProfiles.size());
|
||||||
}
|
}
|
||||||
List<SwitchPreference> result = new ArrayList<>();
|
List<SwitchPreference> result = new ArrayList<>();
|
||||||
for (int i = 0; i < mProfiles.getPreferenceCount(); i++) {
|
for (int i = 0; i < mProfiles.getPreferenceCount(); i++) {
|
||||||
result.add((SwitchPreference)mProfiles.getPreference(i));
|
final Preference preference = mProfiles.getPreference(i);
|
||||||
|
if (preference instanceof SwitchPreference) {
|
||||||
|
result.add((SwitchPreference) preference);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -236,7 +241,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
|||||||
mController.onDeviceAttributesChanged();
|
mController.onDeviceAttributesChanged();
|
||||||
|
|
||||||
// There should have been no new switches added.
|
// There should have been no new switches added.
|
||||||
assertThat(mProfiles.getPreferenceCount()).isEqualTo(2);
|
assertThat(mProfiles.getPreferenceCount()).isEqualTo(3);
|
||||||
|
|
||||||
// Make sure both switches got disabled.
|
// Make sure both switches got disabled.
|
||||||
assertThat(switches.get(0).isEnabled()).isFalse();
|
assertThat(switches.get(0).isEnabled()).isFalse();
|
||||||
@@ -258,7 +263,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
|||||||
assertThat(mConnectableProfiles.get(0).isEnabled(mDevice)).isFalse();
|
assertThat(mConnectableProfiles.get(0).isEnabled(mDevice)).isFalse();
|
||||||
|
|
||||||
// Make sure no new preferences were added.
|
// Make sure no new preferences were added.
|
||||||
assertThat(mProfiles.getPreferenceCount()).isEqualTo(2);
|
assertThat(mProfiles.getPreferenceCount()).isEqualTo(3);
|
||||||
|
|
||||||
// Clicking the pref again should make the profile once again preferred.
|
// Clicking the pref again should make the profile once again preferred.
|
||||||
pref.performClick();
|
pref.performClick();
|
||||||
@@ -266,7 +271,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
|||||||
assertThat(mConnectableProfiles.get(0).isEnabled(mDevice)).isTrue();
|
assertThat(mConnectableProfiles.get(0).isEnabled(mDevice)).isTrue();
|
||||||
|
|
||||||
// Make sure we still haven't gotten any new preferences added.
|
// Make sure we still haven't gotten any new preferences added.
|
||||||
assertThat(mProfiles.getPreferenceCount()).isEqualTo(2);
|
assertThat(mProfiles.getPreferenceCount()).isEqualTo(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -295,7 +300,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
|||||||
assertThat(pref.isChecked()).isTrue();
|
assertThat(pref.isChecked()).isTrue();
|
||||||
|
|
||||||
pref.performClick();
|
pref.performClick();
|
||||||
assertThat(mProfiles.getPreferenceCount()).isEqualTo(1);
|
assertThat(mProfiles.getPreferenceCount()).isEqualTo(2);
|
||||||
assertThat(mDevice.getPhonebookAccessPermission())
|
assertThat(mDevice.getPhonebookAccessPermission())
|
||||||
.isEqualTo(BluetoothDevice.ACCESS_REJECTED);
|
.isEqualTo(BluetoothDevice.ACCESS_REJECTED);
|
||||||
}
|
}
|
||||||
@@ -318,7 +323,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
|||||||
assertThat(pref.isChecked()).isFalse();
|
assertThat(pref.isChecked()).isFalse();
|
||||||
|
|
||||||
pref.performClick();
|
pref.performClick();
|
||||||
assertThat(mProfiles.getPreferenceCount()).isEqualTo(1);
|
assertThat(mProfiles.getPreferenceCount()).isEqualTo(2);
|
||||||
assertThat(mDevice.getPhonebookAccessPermission())
|
assertThat(mDevice.getPhonebookAccessPermission())
|
||||||
.isEqualTo(BluetoothDevice.ACCESS_ALLOWED);
|
.isEqualTo(BluetoothDevice.ACCESS_ALLOWED);
|
||||||
}
|
}
|
||||||
@@ -340,7 +345,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
|||||||
assertThat(pref.isChecked()).isFalse();
|
assertThat(pref.isChecked()).isFalse();
|
||||||
|
|
||||||
pref.performClick();
|
pref.performClick();
|
||||||
assertThat(mProfiles.getPreferenceCount()).isEqualTo(1);
|
assertThat(mProfiles.getPreferenceCount()).isEqualTo(2);
|
||||||
assertThat(mDevice.getMessageAccessPermission()).isEqualTo(BluetoothDevice.ACCESS_ALLOWED);
|
assertThat(mDevice.getMessageAccessPermission()).isEqualTo(BluetoothDevice.ACCESS_ALLOWED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,7 +391,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
|||||||
setupDevice(makeDefaultDeviceConfig());
|
setupDevice(makeDefaultDeviceConfig());
|
||||||
addMockA2dpProfile(true, false, false);
|
addMockA2dpProfile(true, false, false);
|
||||||
showScreen(mController);
|
showScreen(mController);
|
||||||
assertThat(mProfiles.getPreferenceCount()).isEqualTo(1);
|
assertThat(mProfiles.getPreferenceCount()).isEqualTo(2);
|
||||||
SwitchPreference pref = (SwitchPreference) mProfiles.getPreference(0);
|
SwitchPreference pref = (SwitchPreference) mProfiles.getPreference(0);
|
||||||
assertThat(pref.getKey())
|
assertThat(pref.getKey())
|
||||||
.isNotEqualTo(BluetoothDetailsProfilesController.HIGH_QUALITY_AUDIO_PREF_TAG);
|
.isNotEqualTo(BluetoothDetailsProfilesController.HIGH_QUALITY_AUDIO_PREF_TAG);
|
||||||
@@ -408,7 +413,7 @@ public class BluetoothDetailsProfilesControllerTest extends BluetoothDetailsCont
|
|||||||
setupDevice(makeDefaultDeviceConfig());
|
setupDevice(makeDefaultDeviceConfig());
|
||||||
A2dpProfile audioProfile = addMockA2dpProfile(true, true, true);
|
A2dpProfile audioProfile = addMockA2dpProfile(true, true, true);
|
||||||
showScreen(mController);
|
showScreen(mController);
|
||||||
assertThat(mProfiles.getPreferenceCount()).isEqualTo(2);
|
assertThat(mProfiles.getPreferenceCount()).isEqualTo(3);
|
||||||
|
|
||||||
// Disabling media audio should cause the high quality audio switch to disappear, but not
|
// Disabling media audio should cause the high quality audio switch to disappear, but not
|
||||||
// the regular audio one.
|
// the regular audio one.
|
||||||
|
Reference in New Issue
Block a user