Use checkboxes on notification settings pages
Test: make RunSettingsRoboTests Bug: 63927402 Change-Id: Id751b807eae8a7a9165b0d020f10dd42f51382d1
This commit is contained in:
@@ -30,6 +30,7 @@ import com.android.settings.applications.LayoutPreference;
|
|||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.search.BaseSearchIndexProvider;
|
import com.android.settings.search.BaseSearchIndexProvider;
|
||||||
import com.android.settings.search.Indexable;
|
import com.android.settings.search.Indexable;
|
||||||
|
import com.android.settings.widget.MasterCheckBoxPreference;
|
||||||
import com.android.settings.widget.MasterSwitchPreference;
|
import com.android.settings.widget.MasterSwitchPreference;
|
||||||
import com.android.settings.widget.SwitchBar;
|
import com.android.settings.widget.SwitchBar;
|
||||||
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
|
import com.android.settings.wrapper.NotificationChannelGroupWrapper;
|
||||||
@@ -277,9 +278,9 @@ abstract public class NotificationSettingsBase extends DashboardFragment {
|
|||||||
|
|
||||||
protected Preference populateSingleChannelPrefs(PreferenceGroup parent,
|
protected Preference populateSingleChannelPrefs(PreferenceGroup parent,
|
||||||
final NotificationChannel channel, final boolean groupBlocked) {
|
final NotificationChannel channel, final boolean groupBlocked) {
|
||||||
MasterSwitchPreference channelPref = new MasterSwitchPreference(
|
MasterCheckBoxPreference channelPref = new MasterCheckBoxPreference(
|
||||||
getPrefContext());
|
getPrefContext());
|
||||||
channelPref.setSwitchEnabled(mSuspendedAppsAdmin == null
|
channelPref.setCheckBoxEnabled(mSuspendedAppsAdmin == null
|
||||||
&& isChannelBlockable(channel)
|
&& isChannelBlockable(channel)
|
||||||
&& isChannelConfigurable(channel)
|
&& isChannelConfigurable(channel)
|
||||||
&& !groupBlocked);
|
&& !groupBlocked);
|
||||||
|
@@ -34,6 +34,7 @@ public class MasterCheckBoxPreference extends TwoTargetPreference {
|
|||||||
|
|
||||||
private CheckBox mCheckBox;
|
private CheckBox mCheckBox;
|
||||||
private boolean mChecked;
|
private boolean mChecked;
|
||||||
|
private boolean mEnableCheckBox = true;
|
||||||
|
|
||||||
public MasterCheckBoxPreference(Context context, AttributeSet attrs,
|
public MasterCheckBoxPreference(Context context, AttributeSet attrs,
|
||||||
int defStyleAttr, int defStyleRes) {
|
int defStyleAttr, int defStyleRes) {
|
||||||
@@ -88,9 +89,7 @@ public class MasterCheckBoxPreference extends TwoTargetPreference {
|
|||||||
@Override
|
@Override
|
||||||
public void setEnabled(boolean enabled) {
|
public void setEnabled(boolean enabled) {
|
||||||
super.setEnabled(enabled);
|
super.setEnabled(enabled);
|
||||||
if (mCheckBox != null) {
|
setCheckBoxEnabled(enabled);
|
||||||
mCheckBox.setEnabled(enabled);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isChecked() {
|
public boolean isChecked() {
|
||||||
@@ -104,6 +103,13 @@ public class MasterCheckBoxPreference extends TwoTargetPreference {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCheckBoxEnabled(boolean enabled) {
|
||||||
|
mEnableCheckBox = enabled;
|
||||||
|
if (mCheckBox != null) {
|
||||||
|
mCheckBox.setEnabled(enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public CheckBox getCheckBox() {
|
public CheckBox getCheckBox() {
|
||||||
return mCheckBox;
|
return mCheckBox;
|
||||||
}
|
}
|
||||||
|
@@ -88,6 +88,23 @@ public class MasterCheckBoxPreferenceTest {
|
|||||||
assertThat(checkBox.isEnabled()).isFalse();
|
assertThat(checkBox.isEnabled()).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Test
|
||||||
public void clickWidgetView_shouldToggleCheckBox() {
|
public void clickWidgetView_shouldToggleCheckBox() {
|
||||||
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
final LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||||
|
Reference in New Issue
Block a user