Merge "Use checkboxes on notification settings pages"
diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java
index 8b0ed46..18b77bc 100644
--- a/src/com/android/settings/notification/NotificationSettingsBase.java
+++ b/src/com/android/settings/notification/NotificationSettingsBase.java
@@ -30,6 +30,7 @@
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
+import com.android.settings.widget.MasterCheckBoxPreference;
import com.android.settings.widget.MasterSwitchPreference;
import com.android.settings.widget.SwitchBar;
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
@@ -277,9 +278,9 @@
protected Preference populateSingleChannelPrefs(PreferenceGroup parent,
final NotificationChannel channel, final boolean groupBlocked) {
- MasterSwitchPreference channelPref = new MasterSwitchPreference(
+ MasterCheckBoxPreference channelPref = new MasterCheckBoxPreference(
getPrefContext());
- channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null
+ channelPref.setCheckBoxEnabled(mSuspendedAppsAdmin == null
&& isChannelBlockable(channel)
&& isChannelConfigurable(channel)
&& !groupBlocked);
diff --git a/src/com/android/settings/widget/MasterCheckBoxPreference.java b/src/com/android/settings/widget/MasterCheckBoxPreference.java
index 333c9aa..552f51c 100644
--- a/src/com/android/settings/widget/MasterCheckBoxPreference.java
+++ b/src/com/android/settings/widget/MasterCheckBoxPreference.java
@@ -34,6 +34,7 @@
private CheckBox mCheckBox;
private boolean mChecked;
+ private boolean mEnableCheckBox = true;
public MasterCheckBoxPreference(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
@@ -88,9 +89,7 @@
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
- if (mCheckBox != null) {
- mCheckBox.setEnabled(enabled);
- }
+ setCheckBoxEnabled(enabled);
}
public boolean isChecked() {
@@ -104,6 +103,13 @@
}
}
+ public void setCheckBoxEnabled(boolean enabled) {
+ mEnableCheckBox = enabled;
+ if (mCheckBox != null) {
+ mCheckBox.setEnabled(enabled);
+ }
+ }
+
public CheckBox getCheckBox() {
return mCheckBox;
}
diff --git a/tests/robotests/src/com/android/settings/widget/MasterCheckBoxPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/MasterCheckBoxPreferenceTest.java
index e6530d5..ac3e0b6 100644
--- a/tests/robotests/src/com/android/settings/widget/MasterCheckBoxPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/MasterCheckBoxPreferenceTest.java
@@ -89,6 +89,23 @@
}
@Test
+ public void setCheckboxEnabled_shouldOnlyUpdateCheckBoxEnabledState() {
+ final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
+ LayoutInflater.from(mContext).inflate(
+ R.layout.preference_widget_master_checkbox, null));
+ final CheckBox checkBox = (CheckBox) holder.findViewById(R.id.checkboxWidget);
+ mPreference.onBindViewHolder(holder);
+
+ mPreference.setCheckBoxEnabled(false);
+ assertThat(mPreference.isEnabled()).isTrue();
+ assertThat(checkBox.isEnabled()).isFalse();
+
+ mPreference.setCheckBoxEnabled(true);
+ assertThat(mPreference.isEnabled()).isTrue();
+ assertThat(checkBox.isEnabled()).isTrue();
+ }
+
+ @Test
public void clickWidgetView_shouldToggleCheckBox() {
final LayoutInflater inflater = LayoutInflater.from(mContext);
final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(