@@ -73,15 +73,11 @@ public float getInterpolation(float t) {
73
73
private ItemInfo mWindow ;
74
74
private ItemInfo mContent ;
75
75
76
- private int mCurItem ; // Index of currently displayed page.
77
- private int mRestoredCurItem = -1 ;
78
- private Parcelable mRestoredAdapterState = null ;
79
- private ClassLoader mRestoredClassLoader = null ;
76
+ private int mCurItem ;
80
77
private Scroller mScroller ;
81
- private PagerObserver mObserver ;
82
78
83
- private int mPageMargin ;
84
- private Drawable mMarginDrawable ;
79
+ private int mShadowWidth ;
80
+ private Drawable mShadowDrawable ;
85
81
private int mTopPageBounds ;
86
82
private int mBottomPageBounds ;
87
83
@@ -228,7 +224,7 @@ public CustomViewAbove(Context context, AttributeSet attrs, boolean isAbove) {
228
224
super (context , attrs );
229
225
initCustomViewAbove (isAbove );
230
226
}
231
-
227
+
232
228
void initCustomViewAbove () {
233
229
initCustomViewAbove (false );
234
230
}
@@ -388,37 +384,37 @@ OnPageChangeListener setInternalPageChangeListener(OnPageChangeListener listener
388
384
/**
389
385
* Set the margin between pages.
390
386
*
391
- * @param marginPixels Distance between adjacent pages in pixels
392
- * @see #getPageMargin ()
393
- * @see #setPageMarginDrawable (Drawable)
394
- * @see #setPageMarginDrawable (int)
387
+ * @param shadowWidth Distance between adjacent pages in pixels
388
+ * @see #getShadowWidth ()
389
+ * @see #setShadowDrawable (Drawable)
390
+ * @see #setShadowDrawable (int)
395
391
*/
396
- public void setPageMargin (int marginPixels ) {
397
- final int oldMargin = mPageMargin ;
398
- mPageMargin = marginPixels ;
399
-
400
- final int width = getWidth ();
401
- recomputeScrollPosition (width , width , marginPixels , oldMargin );
392
+ public void setShadowWidth (int shadowWidth ) {
393
+ final int oldWidth = mShadowWidth ;
394
+ mShadowWidth = shadowWidth ;
402
395
403
- requestLayout ();
396
+ // final int width = getWidth();
397
+ // recomputeScrollPosition(width, width, shadowWidth, oldWidth);
398
+ //
399
+ // requestLayout();
404
400
}
405
401
406
402
/**
407
403
* Return the margin between pages.
408
404
*
409
405
* @return The size of the margin in pixels
410
406
*/
411
- public int getPageMargin () {
412
- return mPageMargin ;
407
+ public int getShadowWidth () {
408
+ return mShadowWidth ;
413
409
}
414
410
415
411
/**
416
412
* Set a drawable that will be used to fill the margin between pages.
417
413
*
418
414
* @param d Drawable to display between pages
419
415
*/
420
- public void setPageMarginDrawable (Drawable d ) {
421
- mMarginDrawable = d ;
416
+ public void setShadowDrawable (Drawable d ) {
417
+ mShadowDrawable = d ;
422
418
if (d != null ) refreshDrawableState ();
423
419
setWillNotDraw (d == null );
424
420
invalidate ();
@@ -429,19 +425,19 @@ public void setPageMarginDrawable(Drawable d) {
429
425
*
430
426
* @param resId Resource ID of a drawable to display between pages
431
427
*/
432
- public void setPageMarginDrawable (int resId ) {
433
- setPageMarginDrawable (getContext ().getResources ().getDrawable (resId ));
428
+ public void setShadowDrawable (int resId ) {
429
+ setShadowDrawable (getContext ().getResources ().getDrawable (resId ));
434
430
}
435
431
436
432
437
433
protected boolean verifyDrawable (Drawable who ) {
438
- return super .verifyDrawable (who ) || who == mMarginDrawable ;
434
+ return super .verifyDrawable (who ) || who == mShadowDrawable ;
439
435
}
440
436
441
437
442
438
protected void drawableStateChanged () {
443
439
super .drawableStateChanged ();
444
- final Drawable d = mMarginDrawable ;
440
+ final Drawable d = mShadowDrawable ;
445
441
if (d != null && d .isStateful ()) {
446
442
d .setState (getDrawableState ());
447
443
}
@@ -555,7 +551,7 @@ void smoothScrollTo(int x, int y, int velocity) {
555
551
if (velocity > 0 ) {
556
552
duration = 4 * Math .round (1000 * Math .abs (distance / velocity ));
557
553
} else {
558
- final float pageDelta = (float ) Math .abs (dx ) / (width + mPageMargin );
554
+ final float pageDelta = (float ) Math .abs (dx ) / (width + mShadowWidth );
559
555
duration = (int ) ((pageDelta + 1 ) * 100 );
560
556
// TODO set custom duration!
561
557
duration = MAX_SETTLE_DURATION ;
@@ -661,75 +657,75 @@ void populate() {
661
657
* state, in which case it should implement a subclass of this which
662
658
* contains that state.
663
659
*/
664
- // public static class SavedState extends BaseSavedState {
665
- // int position;
666
- // Parcelable adapterState;
667
- // ClassLoader loader;
668
- //
669
- // public SavedState(Parcelable superState) {
670
- // super(superState);
671
- // }
672
- //
673
- //
674
- // public void writeToParcel(Parcel out, int flags) {
675
- // super.writeToParcel(out, flags);
676
- // out.writeInt(position);
677
- // out.writeParcelable(adapterState, flags);
678
- // }
679
- //
680
- //
681
- // public String toString() {
682
- // return "FragmentPager.SavedState{"
683
- // + Integer.toHexString(System.identityHashCode(this))
684
- // + " position=" + position + "}";
685
- // }
686
- //
687
- // public static final Parcelable.Creator<SavedState> CREATOR
688
- // = ParcelableCompat.newCreator(new ParcelableCompatCreatorCallbacks<SavedState>() {
689
- //
690
- // public SavedState createFromParcel(Parcel in, ClassLoader loader) {
691
- // return new SavedState(in, loader);
692
- // }
693
- //
694
- // public SavedState[] newArray(int size) {
695
- // return new SavedState[size];
696
- // }
697
- // });
698
- //
699
- // SavedState(Parcel in, ClassLoader loader) {
700
- // super(in);
701
- // if (loader == null) {
702
- // loader = getClass().getClassLoader();
703
- // }
704
- // position = in.readInt();
705
- // adapterState = in.readParcelable(loader);
706
- // this.loader = loader;
707
- // }
708
- // }
709
- //
710
- //
711
- // public Parcelable onSaveInstanceState() {
712
- // Parcelable superState = super.onSaveInstanceState();
713
- // SavedState ss = new SavedState(superState);
714
- // ss.position = mCurItem;
715
- // return ss;
716
- // }
717
- //
718
- //
719
- // public void onRestoreInstanceState(Parcelable state) {
720
- // if (!(state instanceof SavedState)) {
721
- // super.onRestoreInstanceState(state);
722
- // return;
723
- // }
724
- //
725
- // SavedState ss = (SavedState)state;
726
- // super.onRestoreInstanceState(ss.getSuperState());
727
- //
728
- // setCurrentItemInternal(ss.position, false, true);
729
- // mRestoredCurItem = ss.position;
730
- // mRestoredAdapterState = ss.adapterState;
731
- // mRestoredClassLoader = ss.loader;
732
- // }
660
+ // public static class SavedState extends BaseSavedState {
661
+ // int position;
662
+ // Parcelable adapterState;
663
+ // ClassLoader loader;
664
+ //
665
+ // public SavedState(Parcelable superState) {
666
+ // super(superState);
667
+ // }
668
+ //
669
+ //
670
+ // public void writeToParcel(Parcel out, int flags) {
671
+ // super.writeToParcel(out, flags);
672
+ // out.writeInt(position);
673
+ // out.writeParcelable(adapterState, flags);
674
+ // }
675
+ //
676
+ //
677
+ // public String toString() {
678
+ // return "FragmentPager.SavedState{"
679
+ // + Integer.toHexString(System.identityHashCode(this))
680
+ // + " position=" + position + "}";
681
+ // }
682
+ //
683
+ // public static final Parcelable.Creator<SavedState> CREATOR
684
+ // = ParcelableCompat.newCreator(new ParcelableCompatCreatorCallbacks<SavedState>() {
685
+ //
686
+ // public SavedState createFromParcel(Parcel in, ClassLoader loader) {
687
+ // return new SavedState(in, loader);
688
+ // }
689
+ //
690
+ // public SavedState[] newArray(int size) {
691
+ // return new SavedState[size];
692
+ // }
693
+ // });
694
+ //
695
+ // SavedState(Parcel in, ClassLoader loader) {
696
+ // super(in);
697
+ // if (loader == null) {
698
+ // loader = getClass().getClassLoader();
699
+ // }
700
+ // position = in.readInt();
701
+ // adapterState = in.readParcelable(loader);
702
+ // this.loader = loader;
703
+ // }
704
+ // }
705
+ //
706
+ //
707
+ // public Parcelable onSaveInstanceState() {
708
+ // Parcelable superState = super.onSaveInstanceState();
709
+ // SavedState ss = new SavedState(superState);
710
+ // ss.position = mCurItem;
711
+ // return ss;
712
+ // }
713
+ //
714
+ //
715
+ // public void onRestoreInstanceState(Parcelable state) {
716
+ // if (!(state instanceof SavedState)) {
717
+ // super.onRestoreInstanceState(state);
718
+ // return;
719
+ // }
720
+ //
721
+ // SavedState ss = (SavedState)state;
722
+ // super.onRestoreInstanceState(ss.getSuperState());
723
+ //
724
+ // setCurrentItemInternal(ss.position, false, true);
725
+ // mRestoredCurItem = ss.position;
726
+ // mRestoredAdapterState = ss.adapterState;
727
+ // mRestoredClassLoader = ss.loader;
728
+ // }
733
729
734
730
protected void setMenu (View v ) {
735
731
ItemInfo ii = new ItemInfo ();
@@ -892,7 +888,7 @@ protected void onSizeChanged(int w, int h, int oldw, int oldh) {
892
888
893
889
// Make sure scroll position is set correctly.
894
890
if (w != oldw ) {
895
- recomputeScrollPosition (w , oldw , mPageMargin , mPageMargin );
891
+ recomputeScrollPosition (w , oldw , mShadowWidth , mShadowWidth );
896
892
}
897
893
}
898
894
@@ -933,13 +929,10 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) {
933
929
for (int i = 0 ; i < count ; i ++) {
934
930
final View child = getChildAt (i );
935
931
if (child .getVisibility () != GONE ) {
936
- final LayoutParams lp = (LayoutParams ) child .getLayoutParams ();
937
932
int pos = infoForChild (child ).position ;
938
933
int childLeft = 0 ;
939
934
int childTop = 0 ;
940
935
childLeft = getChildLeft (pos );
941
- Log .v (TAG , "Child#" + i + " left:" + childLeft +
942
- " right:" + (childLeft + child .getMeasuredWidth ()));
943
936
child .layout (childLeft , childTop ,
944
937
childLeft + child .getMeasuredWidth (),
945
938
childTop + child .getMeasuredHeight ());
@@ -978,7 +971,7 @@ public void computeScroll() {
978
971
979
972
private void pageScrolled (int xpos ) {
980
973
// TODO
981
- final int widthWithMargin = getChildWidth (mCurItem ) + mPageMargin ;
974
+ final int widthWithMargin = getChildWidth (mCurItem ) + mShadowWidth ;
982
975
final int position = xpos / widthWithMargin ;
983
976
final int offsetPixels = xpos % widthWithMargin ;
984
977
final float offset = (float ) offsetPixels / widthWithMargin ;
@@ -1322,7 +1315,7 @@ public boolean onTouchEvent(MotionEvent ev) {
1322
1315
int initialVelocity = (int ) VelocityTrackerCompat .getXVelocity (
1323
1316
velocityTracker , mActivePointerId );
1324
1317
mPopulatePending = true ;
1325
- final int widthWithMargin = getChildWidth (mCurItem ) + mPageMargin ;
1318
+ final int widthWithMargin = getChildWidth (mCurItem ) + mShadowWidth ;
1326
1319
final int scrollX = getScrollX ();
1327
1320
final int currentPage = scrollX / widthWithMargin ;
1328
1321
final float pageOffset = (float ) (scrollX % widthWithMargin ) / widthWithMargin ;
@@ -1382,6 +1375,7 @@ public void scrollTo(int x, int y) {
1382
1375
if (mCustomViewBehind2 != null && mEnabled ) {
1383
1376
mCustomViewBehind2 .scrollTo ((int )(x *mScrollScale ), y );
1384
1377
}
1378
+ invalidate ();
1385
1379
}
1386
1380
1387
1381
private int determineTargetPage (int currentPage , float pageOffset , int velocity , int deltaX ) {
@@ -1396,19 +1390,12 @@ private int determineTargetPage(int currentPage, float pageOffset, int velocity,
1396
1390
1397
1391
protected void onDraw (Canvas canvas ) {
1398
1392
super .onDraw (canvas );
1399
-
1400
1393
// Draw the margin drawable if needed.
1401
- if (mPageMargin > 0 && mMarginDrawable != null ) {
1402
- final int scrollX = getDestScrollX ();
1403
- final int width = getChildWidth (mCurItem );
1404
- final int offset = scrollX % (width + mPageMargin );
1405
- if (offset != 0 ) {
1406
- // Pages fit completely when settled; we only need to draw when in between
1407
- final int left = scrollX - offset + width ;
1408
- mMarginDrawable .setBounds (left , mTopPageBounds , left + mPageMargin ,
1409
- mBottomPageBounds );
1410
- mMarginDrawable .draw (canvas );
1411
- }
1394
+ if (mShadowWidth > 0 && mShadowDrawable != null ) {
1395
+ final int left = this .getBehindWidth () - mShadowWidth ;
1396
+ mShadowDrawable .setBounds (left , mTopPageBounds , left + mShadowWidth ,
1397
+ mBottomPageBounds );
1398
+ mShadowDrawable .draw (canvas );
1412
1399
}
1413
1400
}
1414
1401
0 commit comments