diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java index 2a4bb607673e7..7148351cef03d 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java @@ -127,12 +127,12 @@ public class QSAnimator implements Callback, PageListener, Listener, OnLayoutCha @Override public void onTuningChanged(String key, String newValue) { if (ALLOW_FANCY_ANIMATION.equals(key)) { - mAllowFancy = newValue == null || Integer.parseInt(newValue) != 0; + mAllowFancy = TunerService.parseIntegerSwitch(newValue, true); if (!mAllowFancy) { clearAnimationState(); } } else if (MOVE_FULL_ROWS.equals(key)) { - mFullRows = newValue == null || Integer.parseInt(newValue) != 0; + mFullRows = TunerService.parseIntegerSwitch(newValue, true); } else if (QuickQSPanel.NUM_QUICK_TILES.equals(key)) { mNumQuickTiles = mQuickQsPanel.getNumQuickTiles(mQs.getContext()); clearAnimationState(); diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java index 3fc258b1e8e9c..bdc73d9bf4c43 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java +++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java @@ -191,7 +191,7 @@ public class QSPanel extends LinearLayout implements Tunable, Callback, Brightne } private void updateViewVisibilityForTuningValue(View view, @Nullable String newValue) { - view.setVisibility(newValue == null || Integer.parseInt(newValue) != 0 ? VISIBLE : GONE); + view.setVisibility(TunerService.parseIntegerSwitch(newValue, true) ? VISIBLE : GONE); } public void openDetails(String subPanel) { diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java index 8517d9086fc7b..9c2060dfc2c27 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java @@ -274,7 +274,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C @Override public void onTuningChanged(String key, String newValue) { if (CLOCK_SECONDS.equals(key)) { - mShowSeconds = newValue != null && Integer.parseInt(newValue) != 0; + mShowSeconds = TunerService.parseIntegerSwitch(newValue, false); updateShowSeconds(); } else { setClockVisibleByUser(!StatusBarIconController.getIconBlacklist(newValue) diff --git a/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java b/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java index 3a9d1c7caeb89..35ade2cb58303 100644 --- a/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java +++ b/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java @@ -109,4 +109,12 @@ public abstract class TunerService { }); dialog.show(); } + + public static boolean parseIntegerSwitch(String value, boolean defaultValue) { + try { + return value != null ? Integer.parseInt(value) != 0 : defaultValue; + } catch (NumberFormatException e) { + return defaultValue; + } + } } diff --git a/packages/SystemUI/src/com/android/systemui/tuner/TunerSwitch.java b/packages/SystemUI/src/com/android/systemui/tuner/TunerSwitch.java index f53d516907123..89049f8188b89 100644 --- a/packages/SystemUI/src/com/android/systemui/tuner/TunerSwitch.java +++ b/packages/SystemUI/src/com/android/systemui/tuner/TunerSwitch.java @@ -38,7 +38,7 @@ public class TunerSwitch extends SwitchPreference implements Tunable { @Override public void onTuningChanged(String key, String newValue) { - setChecked(newValue != null ? Integer.parseInt(newValue) != 0 : mDefault); + setChecked(TunerService.parseIntegerSwitch(newValue, mDefault)); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java index dd552646955a8..d089b2ff5c528 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java +++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java @@ -108,28 +108,23 @@ public class VolumeDialogComponent implements VolumeComponent, TunerService.Tuna @Override public void onTuningChanged(String key, String newValue) { + boolean volumeDownToEnterSilent = mVolumePolicy.volumeDownToEnterSilent; + boolean volumeUpToExitSilent = mVolumePolicy.volumeUpToExitSilent; + boolean doNotDisturbWhenSilent = mVolumePolicy.doNotDisturbWhenSilent; + if (VOLUME_DOWN_SILENT.equals(key)) { - final boolean volumeDownToEnterSilent = newValue != null - ? Integer.parseInt(newValue) != 0 - : DEFAULT_VOLUME_DOWN_TO_ENTER_SILENT; - setVolumePolicy(volumeDownToEnterSilent, - mVolumePolicy.volumeUpToExitSilent, mVolumePolicy.doNotDisturbWhenSilent, - mVolumePolicy.vibrateToSilentDebounce); + volumeDownToEnterSilent = + TunerService.parseIntegerSwitch(newValue, DEFAULT_VOLUME_DOWN_TO_ENTER_SILENT); } else if (VOLUME_UP_SILENT.equals(key)) { - final boolean volumeUpToExitSilent = newValue != null - ? Integer.parseInt(newValue) != 0 - : DEFAULT_VOLUME_UP_TO_EXIT_SILENT; - setVolumePolicy(mVolumePolicy.volumeDownToEnterSilent, - volumeUpToExitSilent, mVolumePolicy.doNotDisturbWhenSilent, - mVolumePolicy.vibrateToSilentDebounce); + volumeUpToExitSilent = + TunerService.parseIntegerSwitch(newValue, DEFAULT_VOLUME_UP_TO_EXIT_SILENT); } else if (VOLUME_SILENT_DO_NOT_DISTURB.equals(key)) { - final boolean doNotDisturbWhenSilent = newValue != null - ? Integer.parseInt(newValue) != 0 - : DEFAULT_DO_NOT_DISTURB_WHEN_SILENT; - setVolumePolicy(mVolumePolicy.volumeDownToEnterSilent, - mVolumePolicy.volumeUpToExitSilent, doNotDisturbWhenSilent, - mVolumePolicy.vibrateToSilentDebounce); + doNotDisturbWhenSilent = + TunerService.parseIntegerSwitch(newValue, DEFAULT_DO_NOT_DISTURB_WHEN_SILENT); } + + setVolumePolicy(volumeDownToEnterSilent, volumeUpToExitSilent, doNotDisturbWhenSilent, + mVolumePolicy.vibrateToSilentDebounce); } private void setVolumePolicy(boolean volumeDownToEnterSilent, boolean volumeUpToExitSilent,