Merge "Set click listeners on displayPreference"
This commit is contained in:
committed by
Android (Google) Code Review
commit
f703d1cb3b
@@ -28,6 +28,8 @@ public class ZenModeVisEffectsAllPreferenceController
|
|||||||
extends AbstractZenModePreferenceController
|
extends AbstractZenModePreferenceController
|
||||||
implements ZenCustomRadioButtonPreference.OnRadioButtonClickListener {
|
implements ZenCustomRadioButtonPreference.OnRadioButtonClickListener {
|
||||||
|
|
||||||
|
private ZenCustomRadioButtonPreference mPreference;
|
||||||
|
|
||||||
protected static final int EFFECTS = Policy.SUPPRESSED_EFFECT_SCREEN_OFF
|
protected static final int EFFECTS = Policy.SUPPRESSED_EFFECT_SCREEN_OFF
|
||||||
| Policy.SUPPRESSED_EFFECT_SCREEN_ON
|
| Policy.SUPPRESSED_EFFECT_SCREEN_ON
|
||||||
| Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
|
| Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
|
||||||
@@ -43,6 +45,13 @@ public class ZenModeVisEffectsAllPreferenceController
|
|||||||
super(context, key, lifecycle);
|
super(context, key, lifecycle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreference = (ZenCustomRadioButtonPreference) screen.findPreference(getPreferenceKey());
|
||||||
|
mPreference.setOnRadioButtonClickListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return true;
|
return true;
|
||||||
@@ -54,17 +63,7 @@ public class ZenModeVisEffectsAllPreferenceController
|
|||||||
|
|
||||||
boolean everythingBlocked = Policy.areAllVisualEffectsSuppressed(
|
boolean everythingBlocked = Policy.areAllVisualEffectsSuppressed(
|
||||||
mBackend.mPolicy.suppressedVisualEffects);
|
mBackend.mPolicy.suppressedVisualEffects);
|
||||||
ZenCustomRadioButtonPreference pref = (ZenCustomRadioButtonPreference) preference;
|
mPreference.setChecked(everythingBlocked);
|
||||||
pref.setOnRadioButtonClickListener(this);
|
|
||||||
pref.setChecked(everythingBlocked);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void deselect(PreferenceScreen screen) {
|
|
||||||
ZenCustomRadioButtonPreference preference =
|
|
||||||
(ZenCustomRadioButtonPreference) screen.findPreference(getPreferenceKey());
|
|
||||||
if (preference != null) {
|
|
||||||
preference.setChecked(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -16,9 +16,8 @@
|
|||||||
|
|
||||||
package com.android.settings.notification;
|
package com.android.settings.notification;
|
||||||
|
|
||||||
import android.app.NotificationManager.Policy;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
@@ -30,10 +29,13 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
|
|||||||
public class ZenModeVisEffectsCustomPreferenceController
|
public class ZenModeVisEffectsCustomPreferenceController
|
||||||
extends AbstractZenModePreferenceController {
|
extends AbstractZenModePreferenceController {
|
||||||
|
|
||||||
protected static final int INTERRUPTIVE_EFFECTS = Policy.SUPPRESSED_EFFECT_AMBIENT
|
private ZenCustomRadioButtonPreference mPreference;
|
||||||
| Policy.SUPPRESSED_EFFECT_PEEK
|
|
||||||
| Policy.SUPPRESSED_EFFECT_LIGHTS
|
protected static final int INTERRUPTIVE_EFFECTS =
|
||||||
| Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
|
NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT
|
||||||
|
| NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK
|
||||||
|
| NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS
|
||||||
|
| NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
|
||||||
|
|
||||||
public ZenModeVisEffectsCustomPreferenceController(Context context, Lifecycle lifecycle,
|
public ZenModeVisEffectsCustomPreferenceController(Context context, Lifecycle lifecycle,
|
||||||
String key) {
|
String key) {
|
||||||
@@ -46,25 +48,31 @@ public class ZenModeVisEffectsCustomPreferenceController
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateState(Preference preference) {
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
super.updateState(preference);
|
super.displayPreference(screen);
|
||||||
|
mPreference = (ZenCustomRadioButtonPreference) screen.findPreference(getPreferenceKey());
|
||||||
|
|
||||||
ZenCustomRadioButtonPreference pref = (ZenCustomRadioButtonPreference) preference;
|
mPreference.setOnGearClickListener(p -> {
|
||||||
pref.setChecked(areCustomOptionsSelected());
|
|
||||||
|
|
||||||
pref.setOnGearClickListener(p -> {
|
|
||||||
launchCustomSettings();
|
launchCustomSettings();
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
pref.setOnRadioButtonClickListener(p -> {
|
mPreference.setOnRadioButtonClickListener(p -> {
|
||||||
launchCustomSettings();
|
launchCustomSettings();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
|
||||||
|
mPreference.setChecked(areCustomOptionsSelected());
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean areCustomOptionsSelected() {
|
protected boolean areCustomOptionsSelected() {
|
||||||
boolean allEffectsSuppressed =
|
boolean allEffectsSuppressed =
|
||||||
Policy.areAllVisualEffectsSuppressed(mBackend.mPolicy.suppressedVisualEffects);
|
NotificationManager.Policy.areAllVisualEffectsSuppressed(
|
||||||
|
mBackend.mPolicy.suppressedVisualEffects);
|
||||||
boolean noEffectsSuppressed = mBackend.mPolicy.suppressedVisualEffects == 0;
|
boolean noEffectsSuppressed = mBackend.mPolicy.suppressedVisualEffects == 0;
|
||||||
|
|
||||||
return !(allEffectsSuppressed || noEffectsSuppressed);
|
return !(allEffectsSuppressed || noEffectsSuppressed);
|
||||||
|
@@ -28,6 +28,8 @@ public class ZenModeVisEffectsNonePreferenceController
|
|||||||
extends AbstractZenModePreferenceController
|
extends AbstractZenModePreferenceController
|
||||||
implements ZenCustomRadioButtonPreference.OnRadioButtonClickListener {
|
implements ZenCustomRadioButtonPreference.OnRadioButtonClickListener {
|
||||||
|
|
||||||
|
private ZenCustomRadioButtonPreference mPreference;
|
||||||
|
|
||||||
protected static final int EFFECTS = Policy.SUPPRESSED_EFFECT_SCREEN_OFF
|
protected static final int EFFECTS = Policy.SUPPRESSED_EFFECT_SCREEN_OFF
|
||||||
| Policy.SUPPRESSED_EFFECT_SCREEN_ON
|
| Policy.SUPPRESSED_EFFECT_SCREEN_ON
|
||||||
| Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
|
| Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT
|
||||||
@@ -43,6 +45,13 @@ public class ZenModeVisEffectsNonePreferenceController
|
|||||||
super(context, key, lifecycle);
|
super(context, key, lifecycle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void displayPreference(PreferenceScreen screen) {
|
||||||
|
super.displayPreference(screen);
|
||||||
|
mPreference = (ZenCustomRadioButtonPreference) screen.findPreference(getPreferenceKey());
|
||||||
|
mPreference.setOnRadioButtonClickListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return true;
|
return true;
|
||||||
@@ -53,9 +62,7 @@ public class ZenModeVisEffectsNonePreferenceController
|
|||||||
super.updateState(preference);
|
super.updateState(preference);
|
||||||
|
|
||||||
boolean nothingBlocked = mBackend.mPolicy.suppressedVisualEffects == 0;
|
boolean nothingBlocked = mBackend.mPolicy.suppressedVisualEffects == 0;
|
||||||
ZenCustomRadioButtonPreference pref = (ZenCustomRadioButtonPreference) preference;
|
mPreference.setChecked(nothingBlocked);
|
||||||
pref.setOnRadioButtonClickListener(this);
|
|
||||||
pref.setChecked(nothingBlocked);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -64,12 +71,4 @@ public class ZenModeVisEffectsNonePreferenceController
|
|||||||
MetricsProto.MetricsEvent.ACTION_ZEN_SOUND_ONLY, true);
|
MetricsProto.MetricsEvent.ACTION_ZEN_SOUND_ONLY, true);
|
||||||
mBackend.saveVisualEffectsPolicy(EFFECTS, false);
|
mBackend.saveVisualEffectsPolicy(EFFECTS, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void deselect(PreferenceScreen screen) {
|
|
||||||
ZenCustomRadioButtonPreference preference =
|
|
||||||
(ZenCustomRadioButtonPreference) screen.findPreference(getPreferenceKey());
|
|
||||||
if (preference != null) {
|
|
||||||
preference.setChecked(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -85,6 +85,7 @@ public class ZenModeVisEffectsCustomPreferenceControllerTest {
|
|||||||
ReflectionHelpers.setField(mController, "mBackend", mBackend);
|
ReflectionHelpers.setField(mController, "mBackend", mBackend);
|
||||||
|
|
||||||
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mockPref);
|
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mockPref);
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user