diff options
| author | Jeff Davidson <jpd@google.com> | 2014-11-12 18:36:41 -0800 |
|---|---|---|
| committer | Jeff Davidson <jpd@google.com> | 2014-11-14 15:27:21 -0800 |
| commit | ce32b21727422ac3ce4aca49d46746545cc4243d (patch) | |
| tree | b3e075f5b78451c96b8d45eb96ae0f0b1f212ef1 /src/com/android/settings/AppListSwitchPreference.java | |
| parent | 26104298eb53d2dfa693eec32934f9ac0aa3d525 (diff) | |
| download | packages_apps_Settings-ce32b21727422ac3ce4aca49d46746545cc4243d.tar.gz packages_apps_Settings-ce32b21727422ac3ce4aca49d46746545cc4243d.tar.bz2 packages_apps_Settings-ce32b21727422ac3ce4aca49d46746545cc4243d.zip | |
Final UX for Wi-Fi assistant platform settings.
When one app is available, the toggle works as before. When multiple
apps are available, we allow the user to choose the app in a dialog
before turning on the setting.
Bug: 13780935
Change-Id: I1c4391bf97a53febe580fb2b896b4850372062e7
Diffstat (limited to 'src/com/android/settings/AppListSwitchPreference.java')
| -rw-r--r-- | src/com/android/settings/AppListSwitchPreference.java | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/com/android/settings/AppListSwitchPreference.java b/src/com/android/settings/AppListSwitchPreference.java new file mode 100644 index 000000000..f9f1ba017 --- /dev/null +++ b/src/com/android/settings/AppListSwitchPreference.java @@ -0,0 +1,59 @@ +package com.android.settings; + +import android.content.Context; +import android.os.Bundle; +import android.util.AttributeSet; +import android.util.Log; +import android.view.View; +import android.widget.Checkable; + +/** + * A hybrid of AppListPreference and SwitchPreference, representing a preference which can be on or + * off but must have a selected value when turned on. + * + * It is invalid to show this preference when zero valid apps are present. + */ +public class AppListSwitchPreference extends AppListPreference { + private static final String TAG = "AppListSwitchPref"; + + private Checkable mSwitch; + + public AppListSwitchPreference(Context context, AttributeSet attrs) { + super(context, attrs, 0, R.style.AppListSwitchPreference); + } + + @Override + protected void onBindView(View view) { + super.onBindView(view); + mSwitch = (Checkable) view.findViewById(com.android.internal.R.id.switchWidget); + mSwitch.setChecked(getValue() != null); + } + + @Override + protected void showDialog(Bundle state) { + if (getValue() != null) { + // Turning off the current value. + if (callChangeListener(null)) { + setValue(null); + } + } else if (getEntryValues() == null || getEntryValues().length == 0) { + Log.e(TAG, "Attempting to show dialog with zero entries: " + getKey()); + } else if (getEntryValues().length == 1) { + // Suppress the dialog and just toggle the preference with the only choice. + String value = getEntryValues()[0].toString(); + if (callChangeListener(value)) { + setValue(value); + } + } else { + super.showDialog(state); + } + } + + @Override + public void setValue(String value) { + super.setValue(value); + if (mSwitch != null) { + mSwitch.setChecked(value != null); + } + } +} |
