Skip to content

Commit

Permalink
#32 added support to restore currentMonthIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatansalas committed Jan 22, 2017
1 parent 77b9007 commit 8c82588
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
Expand Down Expand Up @@ -59,6 +60,9 @@ public final class CalendarView extends LinearLayout {
private static final Interpolator DEFAULT_ANIM_INTERPOLATOR = new DecelerateInterpolator(3.0f);
private static final long DEFAULT_ANIM_DURATION = 1500;

private static final String KEY_STATE = "superState";
private static final String KEY_MONTH_INDEX = "currentMonthIndex";

private static final int SUNDAY = 1;
private static final int MONDAY = 2;
private static final int TUESDAY = 4;
Expand Down Expand Up @@ -233,11 +237,26 @@ public CalendarView(Context context, AttributeSet attrs) {

@Override
protected Parcelable onSaveInstanceState() {
return super.onSaveInstanceState();
final Parcelable superState = super.onSaveInstanceState();
final Bundle stateToSave = new Bundle();

stateToSave.putParcelable(KEY_STATE, superState);
stateToSave.putInt(KEY_MONTH_INDEX, currentMonthIndex);

return stateToSave;
}

@Override
protected void onRestoreInstanceState(Parcelable state) {
if (state instanceof Bundle) {
final Bundle savedInstanceState = (Bundle) state;

state = savedInstanceState.getParcelable(KEY_STATE);
currentMonthIndex = savedInstanceState.getInt(KEY_MONTH_INDEX);

update(Calendar.getInstance(Locale.getDefault()));
}

super.onRestoreInstanceState(state);
}

Expand Down

0 comments on commit 8c82588

Please sign in to comment.