Loading res/xml/zen_mode_block_settings.xml +7 −7 Original line number Diff line number Diff line Loading @@ -24,15 +24,15 @@ android:title="@string/zen_mode_block_effects_screen_off" android:key="zen_mode_block_screen_off"> <CheckBoxPreference <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_intent" android:title="@string/zen_mode_block_effect_intent" /> <CheckBoxPreference <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_light" android:title="@string/zen_mode_block_effect_light" /> <CheckBoxPreference <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_ambient" android:title="@string/zen_mode_block_effect_ambient" /> Loading @@ -40,19 +40,19 @@ <PreferenceCategory android:title="@string/zen_mode_block_effects_screen_on" android:key="zen_mode_block_screen_on"> <CheckBoxPreference <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_badge" android:title="@string/zen_mode_block_effect_badge" /> <CheckBoxPreference <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_status" android:title="@string/zen_mode_block_effect_status" /> <CheckBoxPreference <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_peek" android:title="@string/zen_mode_block_effect_peek" /> <CheckBoxPreference <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_list" android:title="@string/zen_mode_block_effect_list" /> </PreferenceCategory> Loading res/xml/zen_mode_settings.xml +2 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,8 @@ <!-- sound vibration --> <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_sound" android:title="@string/zen_mode_block_effect_sound" /> android:title="@string/zen_mode_block_effect_sound" android:enabled="false"/> <!-- What to block (effects) --> <Preference Loading src/com/android/settings/notification/ZenModeVisEffectPreferenceController.java +3 −2 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.support.v7.preference.PreferenceScreen; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settings.widget.DisabledCheckBoxPreference; public class ZenModeVisEffectPreferenceController extends AbstractZenModePreferenceController Loading Loading @@ -78,9 +79,9 @@ public class ZenModeVisEffectPreferenceController if (parentSuppressed) { ((CheckBoxPreference) preference).setChecked(parentSuppressed); onPreferenceChange(preference, parentSuppressed); preference.setEnabled(false); ((DisabledCheckBoxPreference) preference).enableCheckbox(false); } else { preference.setEnabled(true); ((DisabledCheckBoxPreference) preference).enableCheckbox(true); ((CheckBoxPreference) preference).setChecked(suppressed); } } Loading src/com/android/settings/widget/DisabledCheckBoxPreference.java +50 −11 Original line number Diff line number Diff line Loading @@ -17,46 +17,85 @@ package com.android.settings.widget; import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.content.res.TypedArray; import android.support.v7.preference.CheckBoxPreference; import android.support.v7.preference.PreferenceViewHolder; import android.util.AttributeSet; import android.view.View; /** * A CheckboxPreference with a disabled checkbox. Differs from CheckboxPreference.setDisabled() * in that the text is not dimmed. * A CheckboxPreference that can disable its checkbox separate from its text. * Differs from CheckboxPreference.setDisabled() in that the text is not dimmed. */ public class DisabledCheckBoxPreference extends CheckBoxPreference { private PreferenceViewHolder mViewHolder; private View mCheckBox; private boolean mEnabledCheckBox; public DisabledCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { public DisabledCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); setupDisabledCheckBoxPreference(context, attrs, defStyleAttr, defStyleRes); } public DisabledCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setupDisabledCheckBoxPreference(context, attrs, defStyleAttr, 0); } public DisabledCheckBoxPreference(Context context, AttributeSet attrs) { super(context, attrs); setupDisabledCheckBoxPreference(context, attrs, 0, 0); } public DisabledCheckBoxPreference(Context context) { super(context); setupDisabledCheckBoxPreference(context, null, 0, 0); } private void setupDisabledCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { final TypedArray a = context.obtainStyledAttributes( attrs, com.android.internal.R.styleable.Preference, defStyleAttr, defStyleRes); for (int i = a.getIndexCount() - 1; i >= 0; i--) { int attr = a.getIndex(i); switch (attr) { case com.android.internal.R.styleable.Preference_enabled: mEnabledCheckBox = a.getBoolean(attr, true); break; } } a.recycle(); // Always tell super class this preference is enabled. // We manually enable/disable checkbox using enableCheckBox. super.setEnabled(true); enableCheckbox(mEnabledCheckBox); } public void enableCheckbox(boolean enabled) { mEnabledCheckBox = enabled; if (mViewHolder != null && mCheckBox != null) { mCheckBox.setEnabled(mEnabledCheckBox); mViewHolder.itemView.setEnabled(mEnabledCheckBox); } } @Override public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); mViewHolder = holder; mCheckBox = holder.findViewById(android.R.id.checkbox); View view = holder.findViewById(android.R.id.checkbox); view.setEnabled(false); holder.itemView.setEnabled(false); enableCheckbox(mEnabledCheckBox); } @Override protected void performClick(View view) { // Do nothing // only perform clicks if the checkbox is enabled if (mEnabledCheckBox) { super.performClick(view); } } } tests/robotests/src/com/android/settings/notification/ZenModeVisEffectPreferenceControllerTest.java +6 −5 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import android.support.v7.preference.PreferenceScreen; import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settings.widget.DisabledCheckBoxPreference; import org.junit.Before; import org.junit.Test; Loading @@ -58,7 +59,7 @@ public class ZenModeVisEffectPreferenceControllerTest { @Mock private ZenModeBackend mBackend; @Mock private CheckBoxPreference mockPref; private DisabledCheckBoxPreference mockPref; private Context mContext; private FakeFeatureFactory mFeatureFactory; @Mock Loading Loading @@ -114,7 +115,7 @@ public class ZenModeVisEffectPreferenceControllerTest { mController.updateState(mockPref); verify(mockPref).setChecked(false); verify(mockPref).setEnabled(true); verify(mockPref).enableCheckbox(true); } @Test Loading @@ -123,7 +124,7 @@ public class ZenModeVisEffectPreferenceControllerTest { mController.updateState(mockPref); verify(mockPref).setChecked(true); verify(mockPref).setEnabled(true); verify(mockPref).enableCheckbox(true); } @Test Loading @@ -138,7 +139,7 @@ public class ZenModeVisEffectPreferenceControllerTest { mController.updateState(mockPref); verify(mockPref).setChecked(true); verify(mockPref).setEnabled(false); verify(mockPref).enableCheckbox(false); verify(mBackend, times(1)).saveVisualEffectsPolicy(SUPPRESSED_EFFECT_PEEK, true); } Loading @@ -154,7 +155,7 @@ public class ZenModeVisEffectPreferenceControllerTest { mController.updateState(mockPref); verify(mockPref).setChecked(false); verify(mockPref).setEnabled(true); verify(mockPref).enableCheckbox(true); verify(mBackend, never()).saveVisualEffectsPolicy(SUPPRESSED_EFFECT_PEEK, true); } Loading Loading
res/xml/zen_mode_block_settings.xml +7 −7 Original line number Diff line number Diff line Loading @@ -24,15 +24,15 @@ android:title="@string/zen_mode_block_effects_screen_off" android:key="zen_mode_block_screen_off"> <CheckBoxPreference <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_intent" android:title="@string/zen_mode_block_effect_intent" /> <CheckBoxPreference <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_light" android:title="@string/zen_mode_block_effect_light" /> <CheckBoxPreference <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_ambient" android:title="@string/zen_mode_block_effect_ambient" /> Loading @@ -40,19 +40,19 @@ <PreferenceCategory android:title="@string/zen_mode_block_effects_screen_on" android:key="zen_mode_block_screen_on"> <CheckBoxPreference <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_badge" android:title="@string/zen_mode_block_effect_badge" /> <CheckBoxPreference <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_status" android:title="@string/zen_mode_block_effect_status" /> <CheckBoxPreference <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_peek" android:title="@string/zen_mode_block_effect_peek" /> <CheckBoxPreference <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_list" android:title="@string/zen_mode_block_effect_list" /> </PreferenceCategory> Loading
res/xml/zen_mode_settings.xml +2 −1 Original line number Diff line number Diff line Loading @@ -25,7 +25,8 @@ <!-- sound vibration --> <com.android.settings.widget.DisabledCheckBoxPreference android:key="zen_effect_sound" android:title="@string/zen_mode_block_effect_sound" /> android:title="@string/zen_mode_block_effect_sound" android:enabled="false"/> <!-- What to block (effects) --> <Preference Loading
src/com/android/settings/notification/ZenModeVisEffectPreferenceController.java +3 −2 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.support.v7.preference.PreferenceScreen; import com.android.settings.core.PreferenceControllerMixin; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settings.widget.DisabledCheckBoxPreference; public class ZenModeVisEffectPreferenceController extends AbstractZenModePreferenceController Loading Loading @@ -78,9 +79,9 @@ public class ZenModeVisEffectPreferenceController if (parentSuppressed) { ((CheckBoxPreference) preference).setChecked(parentSuppressed); onPreferenceChange(preference, parentSuppressed); preference.setEnabled(false); ((DisabledCheckBoxPreference) preference).enableCheckbox(false); } else { preference.setEnabled(true); ((DisabledCheckBoxPreference) preference).enableCheckbox(true); ((CheckBoxPreference) preference).setChecked(suppressed); } } Loading
src/com/android/settings/widget/DisabledCheckBoxPreference.java +50 −11 Original line number Diff line number Diff line Loading @@ -17,46 +17,85 @@ package com.android.settings.widget; import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.content.res.TypedArray; import android.support.v7.preference.CheckBoxPreference; import android.support.v7.preference.PreferenceViewHolder; import android.util.AttributeSet; import android.view.View; /** * A CheckboxPreference with a disabled checkbox. Differs from CheckboxPreference.setDisabled() * in that the text is not dimmed. * A CheckboxPreference that can disable its checkbox separate from its text. * Differs from CheckboxPreference.setDisabled() in that the text is not dimmed. */ public class DisabledCheckBoxPreference extends CheckBoxPreference { private PreferenceViewHolder mViewHolder; private View mCheckBox; private boolean mEnabledCheckBox; public DisabledCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { public DisabledCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); setupDisabledCheckBoxPreference(context, attrs, defStyleAttr, defStyleRes); } public DisabledCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); setupDisabledCheckBoxPreference(context, attrs, defStyleAttr, 0); } public DisabledCheckBoxPreference(Context context, AttributeSet attrs) { super(context, attrs); setupDisabledCheckBoxPreference(context, attrs, 0, 0); } public DisabledCheckBoxPreference(Context context) { super(context); setupDisabledCheckBoxPreference(context, null, 0, 0); } private void setupDisabledCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { final TypedArray a = context.obtainStyledAttributes( attrs, com.android.internal.R.styleable.Preference, defStyleAttr, defStyleRes); for (int i = a.getIndexCount() - 1; i >= 0; i--) { int attr = a.getIndex(i); switch (attr) { case com.android.internal.R.styleable.Preference_enabled: mEnabledCheckBox = a.getBoolean(attr, true); break; } } a.recycle(); // Always tell super class this preference is enabled. // We manually enable/disable checkbox using enableCheckBox. super.setEnabled(true); enableCheckbox(mEnabledCheckBox); } public void enableCheckbox(boolean enabled) { mEnabledCheckBox = enabled; if (mViewHolder != null && mCheckBox != null) { mCheckBox.setEnabled(mEnabledCheckBox); mViewHolder.itemView.setEnabled(mEnabledCheckBox); } } @Override public void onBindViewHolder(PreferenceViewHolder holder) { super.onBindViewHolder(holder); mViewHolder = holder; mCheckBox = holder.findViewById(android.R.id.checkbox); View view = holder.findViewById(android.R.id.checkbox); view.setEnabled(false); holder.itemView.setEnabled(false); enableCheckbox(mEnabledCheckBox); } @Override protected void performClick(View view) { // Do nothing // only perform clicks if the checkbox is enabled if (mEnabledCheckBox) { super.performClick(view); } } }
tests/robotests/src/com/android/settings/notification/ZenModeVisEffectPreferenceControllerTest.java +6 −5 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ import android.support.v7.preference.PreferenceScreen; import com.android.settings.testutils.FakeFeatureFactory; import com.android.settings.testutils.SettingsRobolectricTestRunner; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settings.widget.DisabledCheckBoxPreference; import org.junit.Before; import org.junit.Test; Loading @@ -58,7 +59,7 @@ public class ZenModeVisEffectPreferenceControllerTest { @Mock private ZenModeBackend mBackend; @Mock private CheckBoxPreference mockPref; private DisabledCheckBoxPreference mockPref; private Context mContext; private FakeFeatureFactory mFeatureFactory; @Mock Loading Loading @@ -114,7 +115,7 @@ public class ZenModeVisEffectPreferenceControllerTest { mController.updateState(mockPref); verify(mockPref).setChecked(false); verify(mockPref).setEnabled(true); verify(mockPref).enableCheckbox(true); } @Test Loading @@ -123,7 +124,7 @@ public class ZenModeVisEffectPreferenceControllerTest { mController.updateState(mockPref); verify(mockPref).setChecked(true); verify(mockPref).setEnabled(true); verify(mockPref).enableCheckbox(true); } @Test Loading @@ -138,7 +139,7 @@ public class ZenModeVisEffectPreferenceControllerTest { mController.updateState(mockPref); verify(mockPref).setChecked(true); verify(mockPref).setEnabled(false); verify(mockPref).enableCheckbox(false); verify(mBackend, times(1)).saveVisualEffectsPolicy(SUPPRESSED_EFFECT_PEEK, true); } Loading @@ -154,7 +155,7 @@ public class ZenModeVisEffectPreferenceControllerTest { mController.updateState(mockPref); verify(mockPref).setChecked(false); verify(mockPref).setEnabled(true); verify(mockPref).enableCheckbox(true); verify(mBackend, never()).saveVisualEffectsPolicy(SUPPRESSED_EFFECT_PEEK, true); } Loading