Use FooterPreference in xml explicitly
We don't rely on FooterPreferenceMixinCompat to create footer preference in dashboard fragment. Instead, declare a FooterPreference explicitly in xml of screen. Test: visual, robotest Bug: 124129485 Change-Id: I4c5b60c3926583eb0d9f0d4cd6996bf169d6408c
This commit is contained in:
@@ -28,11 +28,8 @@ import com.android.settings.core.SettingsUIDeviceConfig;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.slices.SlicePreferenceController;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
import com.android.settingslib.search.SearchIndexable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -66,25 +63,6 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
|
||||
return R.xml.connected_devices;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
return buildPreferenceControllers(context, getSettingsLifecycle());
|
||||
}
|
||||
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
Lifecycle lifecycle) {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
final DiscoverableFooterPreferenceController discoverableFooterPreferenceController =
|
||||
new DiscoverableFooterPreferenceController(context);
|
||||
controllers.add(discoverableFooterPreferenceController);
|
||||
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(discoverableFooterPreferenceController);
|
||||
}
|
||||
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
@@ -93,7 +71,6 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
|
||||
use(AvailableMediaDeviceGroupController.class).init(this);
|
||||
use(ConnectedDeviceGroupController.class).init(this);
|
||||
use(PreviouslyConnectedDevicePreferenceController.class).init(this);
|
||||
use(DiscoverableFooterPreferenceController.class).init(this);
|
||||
use(SlicePreferenceController.class).setSliceUri(nearbyEnabled
|
||||
? Uri.parse(getString(R.string.config_nearby_devices_slice_uri))
|
||||
: null);
|
||||
@@ -111,11 +88,5 @@ public class ConnectedDeviceDashboardFragment extends DashboardFragment {
|
||||
sir.xmlResId = R.xml.connected_devices;
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractPreferenceController> createPreferenceControllers(Context
|
||||
context) {
|
||||
return buildPreferenceControllers(context, null /* lifecycle */);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@@ -32,32 +32,29 @@ import com.android.settings.R;
|
||||
import com.android.settings.bluetooth.AlwaysDiscoverable;
|
||||
import com.android.settings.bluetooth.Utils;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
import com.android.settingslib.widget.FooterPreference;
|
||||
import com.android.settingslib.widget.FooterPreferenceMixinCompat;
|
||||
|
||||
/**
|
||||
* Controller that shows and updates the bluetooth device name
|
||||
*/
|
||||
public class DiscoverableFooterPreferenceController extends BasePreferenceController
|
||||
implements LifecycleObserver, OnResume, OnPause {
|
||||
implements LifecycleObserver, OnStart, OnStop {
|
||||
private static final String KEY = "discoverable_footer_preference";
|
||||
|
||||
@VisibleForTesting
|
||||
BroadcastReceiver mBluetoothChangedReceiver;
|
||||
@VisibleForTesting
|
||||
LocalBluetoothManager mLocalManager;
|
||||
private FooterPreferenceMixinCompat mFooterPreferenceMixin;
|
||||
private FooterPreference mPreference;
|
||||
private BluetoothAdapter mBluetoothAdapter;
|
||||
private AlwaysDiscoverable mAlwaysDiscoverable;
|
||||
private FooterPreference mPreference;
|
||||
|
||||
public DiscoverableFooterPreferenceController(Context context) {
|
||||
super(context, KEY);
|
||||
public DiscoverableFooterPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mLocalManager = Utils.getLocalBtManager(context);
|
||||
if (mLocalManager == null) {
|
||||
return;
|
||||
@@ -67,53 +64,21 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro
|
||||
initReceiver();
|
||||
}
|
||||
|
||||
private void initReceiver() {
|
||||
mBluetoothChangedReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
|
||||
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
|
||||
BluetoothAdapter.ERROR);
|
||||
updateFooterPreferenceTitle(state);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void init(DashboardFragment fragment) {
|
||||
mFooterPreferenceMixin = new FooterPreferenceMixinCompat(fragment,
|
||||
fragment.getSettingsLifecycle());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void init(FooterPreferenceMixinCompat footerPreferenceMixin, FooterPreference preference,
|
||||
AlwaysDiscoverable alwaysDiscoverable) {
|
||||
mFooterPreferenceMixin = footerPreferenceMixin;
|
||||
mPreference = preference;
|
||||
mAlwaysDiscoverable = alwaysDiscoverable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
addFooterPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH)
|
||||
? AVAILABLE
|
||||
? AVAILABLE_UNSEARCHABLE
|
||||
: UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
private void addFooterPreference(PreferenceScreen screen) {
|
||||
mPreference = mFooterPreferenceMixin.createFooterPreference();
|
||||
mPreference.setKey(KEY);
|
||||
screen.addPreference(mPreference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
public void onStart() {
|
||||
if (mLocalManager == null) {
|
||||
return;
|
||||
}
|
||||
@@ -124,7 +89,7 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
public void onStop() {
|
||||
if (mLocalManager == null) {
|
||||
return;
|
||||
}
|
||||
@@ -132,7 +97,7 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro
|
||||
mAlwaysDiscoverable.stop();
|
||||
}
|
||||
|
||||
private void updateFooterPreferenceTitle (int bluetoothState) {
|
||||
private void updateFooterPreferenceTitle(int bluetoothState) {
|
||||
if (bluetoothState == BluetoothAdapter.STATE_ON) {
|
||||
mPreference.setTitle(getPreferenceTitle());
|
||||
} else {
|
||||
@@ -150,4 +115,17 @@ public class DiscoverableFooterPreferenceController extends BasePreferenceContro
|
||||
mContext.getText(R.string.bluetooth_device_name_summary),
|
||||
BidiFormatter.getInstance().unicodeWrap(deviceName));
|
||||
}
|
||||
|
||||
private void initReceiver() {
|
||||
mBluetoothChangedReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
|
||||
final int state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE,
|
||||
BluetoothAdapter.ERROR);
|
||||
updateFooterPreferenceTitle(state);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user