diff options
author | Danny Baumann <dannybaumann@web.de> | 2013-04-18 14:37:09 +0200 |
---|---|---|
committer | Danny Baumann <dannybaumann@web.de> | 2013-04-18 18:17:05 +0200 |
commit | 54ffa7ac8ff99bf31ff2dbd1ce5c52140b4c7cbe (patch) | |
tree | bbd97aa9eb7f33bbbc733ba7b2db21d0fcae3cd9 /src/com/android/settings/BrightnessPreference.java | |
parent | b703712df50be38f7b96a6496af90fd3a8897e5f (diff) | |
download | packages_apps_settings-54ffa7ac8ff99bf31ff2dbd1ce5c52140b4c7cbe.zip packages_apps_settings-54ffa7ac8ff99bf31ff2dbd1ce5c52140b4c7cbe.tar.gz packages_apps_settings-54ffa7ac8ff99bf31ff2dbd1ce5c52140b4c7cbe.tar.bz2 |
Correctly restore brightness customize dialog hierarchy.
This is especially important when rotating the device.
Change-Id: Iaf1ceb46943e9d0a171d6a75d3d446dbec205095
Diffstat (limited to 'src/com/android/settings/BrightnessPreference.java')
-rw-r--r-- | src/com/android/settings/BrightnessPreference.java | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/src/com/android/settings/BrightnessPreference.java b/src/com/android/settings/BrightnessPreference.java index 6c2768d..42e307f 100644 --- a/src/com/android/settings/BrightnessPreference.java +++ b/src/com/android/settings/BrightnessPreference.java @@ -64,6 +64,8 @@ public class BrightnessPreference extends SeekBarDialogPreference implements private boolean mRestoredOldState; + private AutoBrightnessCustomizeDialog mCustomizeDialog; + private static final int SEEK_BAR_RANGE = 10000; private ContentObserver mBrightnessObserver = new ContentObserver(new Handler()) { @@ -119,8 +121,7 @@ public class BrightnessPreference extends SeekBarDialogPreference implements adjustButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Dialog d = new AutoBrightnessCustomizeDialog(getContext()); - d.show(); + showCustomizeDialog(null); } }); } @@ -306,6 +307,26 @@ public class BrightnessPreference extends SeekBarDialogPreference implements Settings.System.SCREEN_BRIGHTNESS_MODE, mode); } + private void showCustomizeDialog(Bundle state) { + if (mCustomizeDialog != null && mCustomizeDialog.isShowing()) { + return; + } + + mCustomizeDialog = new AutoBrightnessCustomizeDialog(getContext()); + if (state != null) { + mCustomizeDialog.onRestoreInstanceState(state); + } + mCustomizeDialog.show(); + } + + @Override + public void onActivityDestroy() { + super.onActivityDestroy(); + if (mCustomizeDialog != null) { + mCustomizeDialog.dismiss(); + } + } + @Override protected Parcelable onSaveInstanceState() { final Parcelable superState = super.onSaveInstanceState(); @@ -318,6 +339,10 @@ public class BrightnessPreference extends SeekBarDialogPreference implements myState.oldAutomatic = mOldAutomatic == 1; myState.oldProgress = mOldBrightness; myState.curBrightness = mCurBrightness; + myState.customizeDialogShown = mCustomizeDialog != null && mCustomizeDialog.isShowing(); + if (myState.customizeDialogShown) { + myState.customizeDialogState = mCustomizeDialog.onSaveInstanceState(); + } // Restore the old state when the activity or dialog is being paused restoreOldState(); @@ -339,6 +364,10 @@ public class BrightnessPreference extends SeekBarDialogPreference implements setMode(myState.automatic ? 1 : 0); setBrightness(myState.progress, false); mCurBrightness = myState.curBrightness; + + if (myState.customizeDialogShown) { + showCustomizeDialog(myState.customizeDialogState); + } } private static class SavedState extends BaseSavedState { @@ -348,6 +377,8 @@ public class BrightnessPreference extends SeekBarDialogPreference implements int progress; int oldProgress; int curBrightness; + boolean customizeDialogShown; + Bundle customizeDialogState; public SavedState(Parcel source) { super(source); @@ -356,6 +387,8 @@ public class BrightnessPreference extends SeekBarDialogPreference implements oldAutomatic = source.readInt() == 1; oldProgress = source.readInt(); curBrightness = source.readInt(); + customizeDialogShown = source.readInt() == 1; + customizeDialogState = source.readBundle(); } @Override @@ -366,6 +399,8 @@ public class BrightnessPreference extends SeekBarDialogPreference implements dest.writeInt(oldAutomatic ? 1 : 0); dest.writeInt(oldProgress); dest.writeInt(curBrightness); + dest.writeInt(customizeDialogShown ? 1 : 0); + dest.writeBundle(customizeDialogState); } public SavedState(Parcelable superState) { |