Merge "Convert Blink light to TogglePreferenceController"
This commit is contained in:
committed by
Android (Google) Code Review
commit
07b361c40f
@@ -26,14 +26,12 @@ import android.os.UserHandle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.RingtonePreference;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settings.gestures.SwipeToNotificationPreferenceController;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
@@ -97,21 +95,17 @@ public class ConfigureNotificationSettings extends DashboardFragment {
|
||||
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
final BadgingNotificationPreferenceController badgeController =
|
||||
new BadgingNotificationPreferenceController(context);
|
||||
final PulseNotificationPreferenceController pulseController =
|
||||
new PulseNotificationPreferenceController(context);
|
||||
final LockScreenNotificationPreferenceController lockScreenNotificationController =
|
||||
new LockScreenNotificationPreferenceController(context,
|
||||
KEY_LOCKSCREEN,
|
||||
KEY_LOCKSCREEN_WORK_PROFILE_HEADER,
|
||||
KEY_LOCKSCREEN_WORK_PROFILE);
|
||||
if (lifecycle != null) {
|
||||
lifecycle.addObserver(pulseController);
|
||||
lifecycle.addObserver(lockScreenNotificationController);
|
||||
}
|
||||
controllers.add(new RecentNotifyingAppsPreferenceController(
|
||||
context, new NotificationBackend(), app, host));
|
||||
controllers.add(badgeController);
|
||||
controllers.add(pulseController);
|
||||
controllers.add(lockScreenNotificationController);
|
||||
controllers.add(new NotificationRingtonePreferenceController(context) {
|
||||
@Override
|
||||
|
@@ -24,33 +24,28 @@ import android.os.Handler;
|
||||
import android.provider.Settings;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.TwoStatePreference;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
|
||||
import static android.provider.Settings.System.NOTIFICATION_LIGHT_PULSE;
|
||||
|
||||
public class PulseNotificationPreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener,
|
||||
LifecycleObserver, OnResume, OnPause {
|
||||
public class PulseNotificationPreferenceController extends TogglePreferenceController
|
||||
implements OnResume, OnPause {
|
||||
|
||||
private static final String TAG = "PulseNotifPrefContr";
|
||||
private static final String KEY_NOTIFICATION_PULSE = "notification_pulse";
|
||||
private static final int ON = 1;
|
||||
private static final int OFF = 0;
|
||||
private SettingObserver mSettingObserver;
|
||||
|
||||
public PulseNotificationPreferenceController(Context context) {
|
||||
super(context);
|
||||
public PulseNotificationPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
Preference preference = screen.findPreference(KEY_NOTIFICATION_PULSE);
|
||||
Preference preference = screen.findPreference(getPreferenceKey());
|
||||
if (preference != null) {
|
||||
mSettingObserver = new SettingObserver(preference);
|
||||
}
|
||||
@@ -71,32 +66,22 @@ public class PulseNotificationPreferenceController extends AbstractPreferenceCon
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_NOTIFICATION_PULSE;
|
||||
public int getAvailabilityStatus() {
|
||||
return mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_intrusiveNotificationLed) ? AVAILABLE
|
||||
: DISABLED_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return mContext.getResources()
|
||||
.getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed);
|
||||
public boolean isChecked() {
|
||||
return Settings.System.getInt(mContext.getContentResolver(), NOTIFICATION_LIGHT_PULSE, OFF)
|
||||
== ON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
try {
|
||||
final boolean checked = Settings.System.getInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_LIGHT_PULSE) == 1;
|
||||
((TwoStatePreference) preference).setChecked(checked);
|
||||
} catch (Settings.SettingNotFoundException snfe) {
|
||||
Log.e(TAG, NOTIFICATION_LIGHT_PULSE + " not found");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final boolean val = (Boolean) newValue;
|
||||
return Settings.System.putInt(mContext.getContentResolver(),
|
||||
NOTIFICATION_LIGHT_PULSE, val ? 1 : 0);
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
return Settings.System.putInt(mContext.getContentResolver(), NOTIFICATION_LIGHT_PULSE,
|
||||
isChecked ? ON : OFF);
|
||||
}
|
||||
|
||||
class SettingObserver extends ContentObserver {
|
||||
|
Reference in New Issue
Block a user