Split BluetoothSettings into two pages
This cl splits the BluetoothSettings into paired device page and pairing page, including small changes about: 1. Refactor the pages so they could get as much as static preference from xml file rather than dynamically add/remove them everytime. 2. Remove creating method in BluetoothDeviceNamePreferenceController and add it in xml file 3. Create BluetoothPairingDetail page, basically move the logic from BluetoothSettings. 4. Make pairing preference clickable and jump to BluetoothPairingDetail 5. Add and update bunch of tests Bug: 35877041 Test: RunSettingsRoboTests Change-Id: Ief9e9690c612f7b46c58e866e5cecc511af642c8
This commit is contained in:
@@ -19,12 +19,15 @@ package com.android.settings.bluetooth;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.preference.PreferenceGroup;
|
||||
import android.text.BidiFormatter;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.dashboard.RestrictedDashboardFragment;
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||
import com.android.settingslib.bluetooth.BluetoothDeviceFilter;
|
||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||
@@ -47,7 +50,6 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
|
||||
private static final String TAG = "DeviceListPreferenceFragment";
|
||||
|
||||
private static final String KEY_BT_DEVICE_LIST = "bt_device_list";
|
||||
private static final String KEY_BT_SCAN = "bt_scan";
|
||||
|
||||
private BluetoothDeviceFilter.Filter mFilter;
|
||||
@@ -57,7 +59,8 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
LocalBluetoothAdapter mLocalAdapter;
|
||||
LocalBluetoothManager mLocalManager;
|
||||
|
||||
private PreferenceGroup mDeviceListGroup;
|
||||
@VisibleForTesting
|
||||
PreferenceGroup mDeviceListGroup;
|
||||
|
||||
final WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference> mDevicePreferenceMap =
|
||||
new WeakHashMap<CachedBluetoothDevice, BluetoothDevicePreference>();
|
||||
@@ -86,17 +89,13 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
}
|
||||
mLocalAdapter = mLocalManager.getBluetoothAdapter();
|
||||
|
||||
addPreferencesForActivity();
|
||||
initPreferencesFromPreferenceScreen();
|
||||
|
||||
mDeviceListGroup = (PreferenceCategory) findPreference(KEY_BT_DEVICE_LIST);
|
||||
mDeviceListGroup = (PreferenceCategory) findPreference(getDeviceListKey());
|
||||
}
|
||||
|
||||
void setDeviceListGroup(PreferenceGroup preferenceGroup) {
|
||||
mDeviceListGroup = preferenceGroup;
|
||||
}
|
||||
|
||||
/** Add preferences from the subclass. */
|
||||
abstract void addPreferencesForActivity();
|
||||
/** find and update preference that already existed in preference screen */
|
||||
abstract void initPreferencesFromPreferenceScreen();
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
@@ -105,8 +104,6 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
|
||||
mLocalManager.setForegroundActivity(getActivity());
|
||||
mLocalManager.getEventManager().registerCallback(this);
|
||||
|
||||
updateProgressUi(mLocalAdapter.isDiscovering());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -122,7 +119,6 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
}
|
||||
|
||||
void removeAllDevices() {
|
||||
mLocalAdapter.stopScanning();
|
||||
mDevicePreferenceMap.clear();
|
||||
mDeviceListGroup.removeAll();
|
||||
}
|
||||
@@ -157,6 +153,7 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
btPreference.onClicked();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeviceAdded(CachedBluetoothDevice cachedDevice) {
|
||||
if (mDevicePreferenceMap.get(cachedDevice) != null) {
|
||||
return;
|
||||
@@ -202,6 +199,16 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
// Does nothing by default
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void updateFooterPreference(Preference myDevicePreference) {
|
||||
final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
|
||||
|
||||
myDevicePreference.setTitle(getString(
|
||||
R.string.bluetooth_footer_mac_message,
|
||||
bidiFormatter.unicodeWrap(mLocalAdapter.getAddress())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeviceDeleted(CachedBluetoothDevice cachedDevice) {
|
||||
BluetoothDevicePreference preference = mDevicePreferenceMap.remove(cachedDevice);
|
||||
if (preference != null) {
|
||||
@@ -209,21 +216,39 @@ public abstract class DeviceListPreferenceFragment extends
|
||||
}
|
||||
}
|
||||
|
||||
public void onScanningStateChanged(boolean started) {
|
||||
updateProgressUi(started);
|
||||
}
|
||||
@Override
|
||||
public void onScanningStateChanged(boolean started) {}
|
||||
|
||||
private void updateProgressUi(boolean start) {
|
||||
if (mDeviceListGroup instanceof BluetoothProgressCategory) {
|
||||
((BluetoothProgressCategory) mDeviceListGroup).setProgress(start);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onBluetoothStateChanged(int bluetoothState) {}
|
||||
|
||||
public void onBluetoothStateChanged(int bluetoothState) {
|
||||
if (bluetoothState == BluetoothAdapter.STATE_OFF) {
|
||||
updateProgressUi(false);
|
||||
/**
|
||||
* Add bluetooth device preferences to {@code preferenceGroup} which satisfy the {@code filter}
|
||||
*
|
||||
* This method will also (1) set the title for {@code preferenceGroup} and (2) change the
|
||||
* default preferenceGroup and filter
|
||||
* @param preferenceGroup
|
||||
* @param titleId
|
||||
* @param filter
|
||||
* @param addCachedDevices
|
||||
*/
|
||||
public void addDeviceCategory(PreferenceGroup preferenceGroup, int titleId,
|
||||
BluetoothDeviceFilter.Filter filter, boolean addCachedDevices) {
|
||||
cacheRemoveAllPrefs(preferenceGroup);
|
||||
preferenceGroup.setTitle(titleId);
|
||||
mDeviceListGroup = preferenceGroup;
|
||||
setFilter(filter);
|
||||
if (addCachedDevices) {
|
||||
addCachedDevices();
|
||||
}
|
||||
preferenceGroup.setEnabled(true);
|
||||
removeCachedPrefs(preferenceGroup);
|
||||
}
|
||||
|
||||
public void onConnectionStateChanged(CachedBluetoothDevice cachedDevice, int state) { }
|
||||
|
||||
/**
|
||||
* Return the key of the {@link PreferenceGroup} that contains the bluetooth devices
|
||||
*/
|
||||
public abstract String getDeviceListKey();
|
||||
}
|
||||
|
Reference in New Issue
Block a user