|
1 | 1 | package moe.feng.common.stepperview;
|
2 | 2 |
|
3 | 3 | import android.animation.LayoutTransition;
|
4 |
| -import android.animation.ObjectAnimator; |
5 | 4 | import android.animation.ValueAnimator;
|
6 |
| -import android.annotation.SuppressLint; |
7 | 5 | import android.content.Context;
|
8 | 6 | import android.content.res.TypedArray;
|
9 | 7 | import android.graphics.PorterDuff;
|
10 | 8 | import android.graphics.drawable.Drawable;
|
11 | 9 | import android.os.Build;
|
12 |
| -import android.os.Bundle; |
| 10 | +import android.os.Parcel; |
13 | 11 | import android.os.Parcelable;
|
14 | 12 | import android.support.annotation.*;
|
15 | 13 | import android.text.TextUtils;
|
@@ -757,71 +755,82 @@ public void setErrorColorResource(@ColorRes int colorRes) {
|
757 | 755 | // Save/Restore View Instance State
|
758 | 756 | @Override
|
759 | 757 | public Parcelable onSaveInstanceState() {
|
760 |
| - Bundle bundle = new Bundle(); |
761 | 758 | ItemViewState state = new ItemViewState(super.onSaveInstanceState());
|
762 | 759 | state.title = mTitle;
|
763 | 760 | state.summary = mSummary;
|
764 | 761 | state.summaryFinished = mSummaryFinished;
|
765 | 762 | state.index = mIndex;
|
766 | 763 | state.isLastStep = isLastStep;
|
767 | 764 | state.state = mState;
|
768 |
| - state.animationDuration = mAnimationDuration; |
769 |
| - state.normalColor = mNormalColor; |
770 |
| - state.activatedColor = mActivatedColor; |
771 |
| - state.doneIcon = mDoneIcon; |
772 | 765 | state.errorText = mErrorText;
|
773 |
| - state.lineColor = mLineColor; |
774 |
| - state.errorColor = mErrorColor; |
775 |
| - state.alwaysShowSummary = mAlwaysShowSummary; |
776 |
| - bundle.putParcelable(ItemViewState.STATE, state); |
777 |
| - return bundle; |
| 766 | + return state; |
778 | 767 | }
|
779 | 768 |
|
780 | 769 | @Override
|
781 | 770 | public void onRestoreInstanceState(Parcelable state) {
|
782 |
| - if (state instanceof Bundle) { |
783 |
| - Bundle bundle = (Bundle) state; |
784 |
| - ItemViewState viewState = bundle.getParcelable(ItemViewState.STATE); |
| 771 | + if (state instanceof ItemViewState) { |
| 772 | + ItemViewState viewState = (ItemViewState) state; |
785 | 773 | super.onRestoreInstanceState(viewState.getSuperState());
|
786 | 774 | setTitle(viewState.title);
|
787 | 775 | setSummary(viewState.summary);
|
788 | 776 | setSummaryFinished(viewState.summaryFinished);
|
789 | 777 | setIndex(viewState.index);
|
790 | 778 | setIsLastStep(viewState.isLastStep);
|
791 | 779 | setState(viewState.state);
|
792 |
| - setAnimationDuration(viewState.animationDuration); |
793 |
| - setNormalColor(viewState.normalColor); |
794 |
| - setActivatedColor(viewState.activatedColor); |
795 |
| - setDoneIcon(viewState.doneIcon); |
796 | 780 | setErrorText(viewState.errorText);
|
797 |
| - setLineColor(viewState.lineColor); |
798 |
| - setErrorColor(viewState.errorColor); |
799 |
| - setAlwaysShowSummary(viewState.alwaysShowSummary); |
800 | 781 | return;
|
801 | 782 | }
|
802 | 783 | super.onRestoreInstanceState(BaseSavedState.EMPTY_STATE);
|
803 | 784 | }
|
804 | 785 |
|
805 | 786 | protected static class ItemViewState extends BaseSavedState {
|
806 | 787 |
|
807 |
| - private static final String STATE = VerticalStepperItemView.class.getSimpleName() + ".STATE"; |
808 |
| - |
809 | 788 | CharSequence title, summary, summaryFinished;
|
810 | 789 | int index = 1;
|
811 | 790 | boolean isLastStep = false;
|
812 | 791 | int state = STATE_NORMAL;
|
813 | 792 | CharSequence errorText;
|
814 | 793 |
|
815 |
| - int animationDuration; |
816 |
| - int normalColor, activatedColor, lineColor, errorColor; |
817 |
| - Drawable doneIcon; |
818 |
| - |
819 |
| - boolean alwaysShowSummary; |
820 |
| - |
821 | 794 | ItemViewState(Parcelable superState) {
|
822 | 795 | super(superState);
|
823 | 796 | }
|
824 | 797 |
|
| 798 | + private ItemViewState(Parcel in) { |
| 799 | + super(in); |
| 800 | + title = in.readString(); |
| 801 | + summary = in.readString(); |
| 802 | + summaryFinished = in.readString(); |
| 803 | + index = in.readInt(); |
| 804 | + isLastStep = in.readByte() != 0; |
| 805 | + state = in.readInt(); |
| 806 | + errorText = in.readString(); |
| 807 | + } |
| 808 | + |
| 809 | + @Override |
| 810 | + public void writeToParcel(Parcel out, int flags) { |
| 811 | + super.writeToParcel(out, flags); |
| 812 | + out.writeString(title != null ? title.toString() : null); |
| 813 | + out.writeString(summary != null ? summary.toString() : null); |
| 814 | + out.writeString(summaryFinished != null ? summaryFinished.toString() : null); |
| 815 | + out.writeInt(index); |
| 816 | + out.writeByte(isLastStep ? (byte) 1 : (byte) 0); |
| 817 | + out.writeInt(state); |
| 818 | + out.writeString(errorText != null ? errorText.toString() : null); |
| 819 | + } |
| 820 | + |
| 821 | + public static final Parcelable.Creator<ItemViewState> CREATOR = |
| 822 | + new Parcelable.Creator<ItemViewState>() { |
| 823 | + @Override |
| 824 | + public ItemViewState createFromParcel(Parcel source) { |
| 825 | + return new ItemViewState(source); |
| 826 | + } |
| 827 | + |
| 828 | + @Override |
| 829 | + public ItemViewState[] newArray(int size) { |
| 830 | + return new ItemViewState[size]; |
| 831 | + } |
| 832 | + }; |
| 833 | + |
825 | 834 | }
|
826 | 835 |
|
827 | 836 | private static boolean isPreLollipop() {
|
|
0 commit comments