|
7 | 7 | import android.content.res.TypedArray;
|
8 | 8 | import android.database.DataSetObserver;
|
9 | 9 | import android.graphics.Canvas;
|
| 10 | +import android.graphics.Color; |
| 11 | +import android.graphics.Paint; |
10 | 12 | import android.graphics.Rect;
|
11 | 13 | import android.graphics.drawable.Drawable;
|
12 | 14 | import android.os.Build;
|
13 |
| -import android.os.Parcel; |
14 |
| -import android.os.Parcelable; |
15 |
| -import android.support.v4.os.ParcelableCompat; |
16 |
| -import android.support.v4.os.ParcelableCompatCreatorCallbacks; |
17 | 15 | import android.support.v4.view.KeyEventCompat;
|
18 | 16 | import android.support.v4.view.MotionEventCompat;
|
19 | 17 | import android.support.v4.view.VelocityTrackerCompat;
|
|
24 | 22 | import android.view.FocusFinder;
|
25 | 23 | import android.view.Gravity;
|
26 | 24 | import android.view.KeyEvent;
|
27 |
| -import android.view.LayoutInflater; |
28 | 25 | import android.view.MotionEvent;
|
29 | 26 | import android.view.SoundEffectConstants;
|
30 | 27 | import android.view.VelocityTracker;
|
|
34 | 31 | import android.view.ViewParent;
|
35 | 32 | import android.view.accessibility.AccessibilityEvent;
|
36 | 33 | import android.view.animation.Interpolator;
|
37 |
| -import android.widget.ImageView; |
38 | 34 | import android.widget.LinearLayout;
|
39 | 35 | import android.widget.Scroller;
|
40 | 36 |
|
@@ -647,82 +643,6 @@ void populate() {
|
647 | 643 | }
|
648 | 644 | }
|
649 | 645 |
|
650 |
| - /** |
651 |
| - * This is the persistent state that is saved by CustomViewPager. Only needed |
652 |
| - * if you are creating a sublass of CustomViewPager that must save its own |
653 |
| - * state, in which case it should implement a subclass of this which |
654 |
| - * contains that state. |
655 |
| - */ |
656 |
| - // public static class SavedState extends BaseSavedState { |
657 |
| - // int position; |
658 |
| - // Parcelable adapterState; |
659 |
| - // ClassLoader loader; |
660 |
| - // |
661 |
| - // public SavedState(Parcelable superState) { |
662 |
| - // super(superState); |
663 |
| - // } |
664 |
| - // |
665 |
| - // |
666 |
| - // public void writeToParcel(Parcel out, int flags) { |
667 |
| - // super.writeToParcel(out, flags); |
668 |
| - // out.writeInt(position); |
669 |
| - // out.writeParcelable(adapterState, flags); |
670 |
| - // } |
671 |
| - // |
672 |
| - // |
673 |
| - // public String toString() { |
674 |
| - // return "FragmentPager.SavedState{" |
675 |
| - // + Integer.toHexString(System.identityHashCode(this)) |
676 |
| - // + " position=" + position + "}"; |
677 |
| - // } |
678 |
| - // |
679 |
| - // public static final Parcelable.Creator<SavedState> CREATOR |
680 |
| - // = ParcelableCompat.newCreator(new ParcelableCompatCreatorCallbacks<SavedState>() { |
681 |
| - // |
682 |
| - // public SavedState createFromParcel(Parcel in, ClassLoader loader) { |
683 |
| - // return new SavedState(in, loader); |
684 |
| - // } |
685 |
| - // |
686 |
| - // public SavedState[] newArray(int size) { |
687 |
| - // return new SavedState[size]; |
688 |
| - // } |
689 |
| - // }); |
690 |
| - // |
691 |
| - // SavedState(Parcel in, ClassLoader loader) { |
692 |
| - // super(in); |
693 |
| - // if (loader == null) { |
694 |
| - // loader = getClass().getClassLoader(); |
695 |
| - // } |
696 |
| - // position = in.readInt(); |
697 |
| - // adapterState = in.readParcelable(loader); |
698 |
| - // this.loader = loader; |
699 |
| - // } |
700 |
| - // } |
701 |
| - // |
702 |
| - // |
703 |
| - // public Parcelable onSaveInstanceState() { |
704 |
| - // Parcelable superState = super.onSaveInstanceState(); |
705 |
| - // SavedState ss = new SavedState(superState); |
706 |
| - // ss.position = mCurItem; |
707 |
| - // return ss; |
708 |
| - // } |
709 |
| - // |
710 |
| - // |
711 |
| - // public void onRestoreInstanceState(Parcelable state) { |
712 |
| - // if (!(state instanceof SavedState)) { |
713 |
| - // super.onRestoreInstanceState(state); |
714 |
| - // return; |
715 |
| - // } |
716 |
| - // |
717 |
| - // SavedState ss = (SavedState)state; |
718 |
| - // super.onRestoreInstanceState(ss.getSuperState()); |
719 |
| - // |
720 |
| - // setCurrentItemInternal(ss.position, false, true); |
721 |
| - // mRestoredCurItem = ss.position; |
722 |
| - // mRestoredAdapterState = ss.adapterState; |
723 |
| - // mRestoredClassLoader = ss.loader; |
724 |
| - // } |
725 |
| - |
726 | 646 | protected void setMenu(View v) {
|
727 | 647 | ItemInfo ii = new ItemInfo();
|
728 | 648 | ii.position = 0;
|
@@ -878,10 +798,8 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
878 | 798 | }
|
879 | 799 | }
|
880 | 800 |
|
881 |
| - |
882 | 801 | protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
883 | 802 | super.onSizeChanged(w, h, oldw, oldh);
|
884 |
| - |
885 | 803 | // Make sure scroll position is set correctly.
|
886 | 804 | if (w != oldw) {
|
887 | 805 | recomputeScrollPosition(w, oldw, mShadowWidth, mShadowWidth);
|
@@ -911,7 +829,6 @@ private void recomputeScrollPosition(int width, int oldWidth, int margin, int ol
|
911 | 829 | }
|
912 | 830 | }
|
913 | 831 |
|
914 |
| - |
915 | 832 | protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
916 | 833 | mInLayout = true;
|
917 | 834 | populate();
|
@@ -1386,14 +1303,41 @@ private int determineTargetPage(int currentPage, float pageOffset, int velocity,
|
1386 | 1303 |
|
1387 | 1304 | protected void onDraw(Canvas canvas) {
|
1388 | 1305 | super.onDraw(canvas);
|
| 1306 | + final int behindWidth = getBehindWidth(); |
1389 | 1307 | // Draw the margin drawable if needed.
|
1390 | 1308 | if (mShadowWidth > 0 && mShadowDrawable != null) {
|
1391 |
| - final int left = this.getBehindWidth() - mShadowWidth; |
| 1309 | + final int left = behindWidth - mShadowWidth; |
1392 | 1310 | mShadowDrawable.setBounds(left, mTopPageBounds, left + mShadowWidth,
|
1393 | 1311 | mBottomPageBounds);
|
1394 | 1312 | mShadowDrawable.draw(canvas);
|
1395 | 1313 | }
|
1396 |
| - } |
| 1314 | + |
| 1315 | + if (mFadeEnabled) { |
| 1316 | + final float openPercent = (mScroller.getCurrX()) / (float) behindWidth; |
| 1317 | + onDrawBehindFade(canvas, openPercent, behindWidth); |
| 1318 | + } |
| 1319 | + } |
| 1320 | + |
| 1321 | + private float mFadeDegree; |
| 1322 | + private Paint mBehindFadePaint = new Paint(); |
| 1323 | + private boolean mFadeEnabled; |
| 1324 | + |
| 1325 | + private void onDrawBehindFade(Canvas canvas, float openPercent, int width) { |
| 1326 | + final int alpha = (int) (mFadeDegree * 255 * openPercent); |
| 1327 | + |
| 1328 | + if (alpha > 0) { |
| 1329 | + mBehindFadePaint.setColor(Color.argb(alpha, 0, 0, 0)); |
| 1330 | + canvas.drawRect(0, 0, width, getHeight(), mBehindFadePaint); |
| 1331 | + } |
| 1332 | + } |
| 1333 | + |
| 1334 | + public void setBehindFadeEnabled(boolean b) { |
| 1335 | + mFadeEnabled = b; |
| 1336 | + } |
| 1337 | + |
| 1338 | + public void setBehindFadeDegree(float f) { |
| 1339 | + mFadeDegree = f; |
| 1340 | + } |
1397 | 1341 |
|
1398 | 1342 | private void onSecondaryPointerUp(MotionEvent ev) {
|
1399 | 1343 | final int pointerIndex = MotionEventCompat.getActionIndex(ev);
|
|
0 commit comments