Use SettingsLib's MainSwitchBar to replace SwitchBar in Settings.

To log Settings metrics, the MainSwitch extends MainSwitchBar and
replace the SwitchBar in SettingsActivity.

Bug: 175181773
Test: Run robotest and apply the widget in Settings and see the ui

Change-Id: I3add3702e9058ad9192b5172c7cf0e2ccfb55a70
This commit is contained in:
Stanley Wang
2020-12-25 16:27:32 +08:00
parent c61c2fb1d7
commit b87ddba6cd
51 changed files with 783 additions and 271 deletions

View File

@@ -60,13 +60,14 @@ import com.android.settings.development.bluetooth.BluetoothSampleRateDialogPrefe
import com.android.settings.development.qstile.DevelopmentTiles;
import com.android.settings.development.storage.SharedDataPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.SettingsMainSwitchBar;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
import com.android.settingslib.development.SystemPropPoker;
import com.android.settingslib.search.SearchIndexable;
import com.android.settingslib.widget.OnMainSwitchChangeListener;
import com.google.android.setupcompat.util.WizardManagerHelper;
@@ -75,7 +76,7 @@ import java.util.List;
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFragment
implements SwitchBar.OnSwitchChangeListener, OemUnlockDialogHost, AdbDialogHost,
implements OnMainSwitchChangeListener, OemUnlockDialogHost, AdbDialogHost,
AdbClearKeysDialogHost, LogPersistDialogHost,
BluetoothA2dpHwOffloadRebootDialog.OnA2dpHwDialogConfirmedListener,
AbstractBluetoothPreferenceController.Callback {
@@ -86,7 +87,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
new BluetoothA2dpConfigStore();
private boolean mIsAvailable = true;
private SwitchBar mSwitchBar;
private SettingsMainSwitchBar mSwitchBar;
private DevelopmentSwitchBarController mSwitchBarController;
private List<AbstractPreferenceController> mPreferenceControllers = new ArrayList<>();
private BluetoothA2dp mBluetoothA2dp;
@@ -197,10 +198,13 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
}
// Set up primary switch
mSwitchBar = ((SettingsActivity) getActivity()).getSwitchBar();
mSwitchBar.setTitle(getContext().getString(R.string.developer_options_main_switch_title));
mSwitchBar.show();
mSwitchBar.setTranslationZ(
getActivity().findViewById(R.id.main_content).getTranslationZ() + 1);
mSwitchBarController = new DevelopmentSwitchBarController(
this /* DevelopmentSettings */, mSwitchBar, mIsAvailable,
getSettingsLifecycle());
mSwitchBar.show();
// Restore UI state based on whether developer options is enabled
if (DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(getContext())) {
@@ -231,7 +235,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
if (DevelopmentTiles.WirelessDebugging.class.getName().equals(
componentName.getClassName()) && getDevelopmentOptionsController(
WirelessDebuggingPreferenceController.class).isAvailable()) {
WirelessDebuggingPreferenceController.class).isAvailable()) {
Log.d(TAG, "Long press from wireless debugging qstile");
new SubSettingLauncher(getContext())
.setDestination(WirelessDebuggingFragment.class.getName())
@@ -383,7 +387,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
@Override
protected int getPreferenceScreenResId() {
return Utils.isMonkeyRunning()? R.xml.placeholder_prefs : R.xml.development_settings;
return Utils.isMonkeyRunning() ? R.xml.placeholder_prefs : R.xml.development_settings;
}
@Override
@@ -557,7 +561,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
controllers.add(new DefaultLaunchPreferenceController(context, "quick_settings_tiles"));
controllers.add(new DefaultLaunchPreferenceController(context, "feature_flags_dashboard"));
controllers.add(
new DefaultLaunchPreferenceController(context, "default_usb_configuration"));
new DefaultLaunchPreferenceController(context, "default_usb_configuration"));
controllers.add(new DefaultLaunchPreferenceController(context, "density"));
controllers.add(new DefaultLaunchPreferenceController(context, "background_check"));
controllers.add(new DefaultLaunchPreferenceController(context, "inactive_apps"));