1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 11:42:16 -05:00

Save/restore slider state

This commit is contained in:
cketti 2014-02-01 00:49:39 +01:00
parent 67abde055a
commit 6e7fa0df03

View File

@ -26,6 +26,8 @@ package com.fsck.k9.activity.setup;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.os.Parcelable;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;
@ -37,6 +39,8 @@ import com.fsck.k9.*;
* @author Jay Weisskopf
*/
public class SliderPreference extends DialogPreference {
private static final String STATE_KEY_SUPER = "super";
private static final String STATE_KEY_SEEK_BAR_VALUE = "seek_bar_value";
protected final static int SEEKBAR_RESOLUTION = 10000;
@ -168,5 +172,22 @@ public class SliderPreference extends DialogPreference {
super.onDialogClosed(positiveResult);
}
// TODO: Save and restore preference state.
@Override
protected Parcelable onSaveInstanceState() {
Parcelable superState = super.onSaveInstanceState();
Bundle state = new Bundle();
state.putParcelable(STATE_KEY_SUPER, superState);
state.putInt(STATE_KEY_SEEK_BAR_VALUE, mSeekBarValue);
return state;
}
@Override
protected void onRestoreInstanceState(Parcelable state) {
Bundle bundle = (Bundle) state;
super.onRestoreInstanceState(bundle.getParcelable(STATE_KEY_SUPER));
mSeekBarValue = bundle.getInt(STATE_KEY_SEEK_BAR_VALUE);
callChangeListener((float) mSeekBarValue / SEEKBAR_RESOLUTION);
}
}