|
9 | 9 | import android.graphics.Rect;
|
10 | 10 | import android.graphics.drawable.Drawable;
|
11 | 11 | import android.os.Build;
|
| 12 | +import android.os.Bundle; |
12 | 13 | import android.os.Parcel;
|
13 | 14 | import android.os.Parcelable;
|
14 | 15 | import android.support.annotation.NonNull;
|
| 16 | +import android.support.v4.app.BundleCompat; |
15 | 17 | import android.support.v4.view.MotionEventCompat;
|
16 | 18 | import android.support.v4.view.ViewCompat;
|
17 | 19 | import android.util.AttributeSet;
|
@@ -76,6 +78,10 @@ public class SlidingUpPanelLayout extends ViewGroup {
|
76 | 78 | private static final int[] DEFAULT_ATTRS = new int[]{
|
77 | 79 | android.R.attr.gravity
|
78 | 80 | };
|
| 81 | + /** |
| 82 | + * Tag for the sliding state stored inside the bundle |
| 83 | + */ |
| 84 | + public static final String SLIDING_STATE = "sliding_state"; |
79 | 85 |
|
80 | 86 | /**
|
81 | 87 | * Minimum velocity that will be detected as a fling
|
@@ -1298,22 +1304,21 @@ public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
|
1298 | 1304 |
|
1299 | 1305 | @Override
|
1300 | 1306 | public Parcelable onSaveInstanceState() {
|
1301 |
| - Parcelable superState = super.onSaveInstanceState(); |
1302 |
| - |
1303 |
| - SavedState ss = new SavedState(superState); |
1304 |
| - if (mSlideState != PanelState.DRAGGING) { |
1305 |
| - ss.mSlideState = mSlideState; |
1306 |
| - } else { |
1307 |
| - ss.mSlideState = mLastNotDraggingSlideState; |
1308 |
| - } |
1309 |
| - return ss; |
| 1307 | + Bundle bundle = new Bundle(); |
| 1308 | + bundle.putParcelable("superState", super.onSaveInstanceState()); |
| 1309 | + bundle.putSerializable(SLIDING_STATE, mSlideState != PanelState.DRAGGING ? mSlideState : mLastNotDraggingSlideState); |
| 1310 | + return bundle; |
1310 | 1311 | }
|
1311 | 1312 |
|
1312 | 1313 | @Override
|
1313 | 1314 | public void onRestoreInstanceState(Parcelable state) {
|
1314 |
| - SavedState ss = (SavedState) state; |
1315 |
| - super.onRestoreInstanceState(ss.getSuperState()); |
1316 |
| - mSlideState = ss.mSlideState != null ? ss.mSlideState : DEFAULT_SLIDE_STATE; |
| 1315 | + if(state instanceof Bundle) { |
| 1316 | + Bundle bundle = (Bundle) state; |
| 1317 | + mSlideState = (PanelState) bundle.getSerializable(SLIDING_STATE); |
| 1318 | + mSlideState = mSlideState == null ? DEFAULT_SLIDE_STATE : mSlideState; |
| 1319 | + state = bundle.getParcelable("superState"); |
| 1320 | + } |
| 1321 | + super.onRestoreInstanceState(state); |
1317 | 1322 | }
|
1318 | 1323 |
|
1319 | 1324 | private class DragHelperCallback extends ViewDragHelper.Callback {
|
@@ -1453,42 +1458,4 @@ public LayoutParams(Context c, AttributeSet attrs) {
|
1453 | 1458 | ta.recycle();
|
1454 | 1459 | }
|
1455 | 1460 | }
|
1456 |
| - |
1457 |
| - static class SavedState extends BaseSavedState { |
1458 |
| - PanelState mSlideState; |
1459 |
| - |
1460 |
| - SavedState(Parcelable superState) { |
1461 |
| - super(superState); |
1462 |
| - } |
1463 |
| - |
1464 |
| - private SavedState(Parcel in) { |
1465 |
| - super(in); |
1466 |
| - String panelStateString = in.readString(); |
1467 |
| - try { |
1468 |
| - mSlideState = panelStateString != null ? Enum.valueOf(PanelState.class, panelStateString) |
1469 |
| - : PanelState.COLLAPSED; |
1470 |
| - } catch (IllegalArgumentException e) { |
1471 |
| - mSlideState = PanelState.COLLAPSED; |
1472 |
| - } |
1473 |
| - } |
1474 |
| - |
1475 |
| - @Override |
1476 |
| - public void writeToParcel(Parcel out, int flags) { |
1477 |
| - super.writeToParcel(out, flags); |
1478 |
| - out.writeString(mSlideState == null ? null : mSlideState.toString()); |
1479 |
| - } |
1480 |
| - |
1481 |
| - public static final Parcelable.Creator<SavedState> CREATOR = |
1482 |
| - new Parcelable.Creator<SavedState>() { |
1483 |
| - @Override |
1484 |
| - public SavedState createFromParcel(Parcel in) { |
1485 |
| - return new SavedState(in); |
1486 |
| - } |
1487 |
| - |
1488 |
| - @Override |
1489 |
| - public SavedState[] newArray(int size) { |
1490 |
| - return new SavedState[size]; |
1491 |
| - } |
1492 |
| - }; |
1493 |
| - } |
1494 | 1461 | }
|
0 commit comments