Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Add method to setInfiniteRatio
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyu.hy committed Apr 10, 2017
1 parent cd42d1b commit f303188
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ protected void onCreate(Bundle savedInstanceState) {
ultraViewPager.setScrollMode(UltraViewPager.ScrollMode.HORIZONTAL);
adapter = new UltraPagerAdapter(false);
ultraViewPager.setAdapter(adapter);
ultraViewPager.setInfiniteRatio(100);
gravity_indicator = UltraViewPager.Orientation.HORIZONTAL;
break;
case 2:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ interface IUltraViewPagerFeature {
IUltraIndicatorBuilder initIndicator(int focusResId, int normalResId, int gravity);

/**
*
* @param focusBitmap defines the bitmap when indicator is focused
* @param normalBitmap defines the bitmap when indicator is in the default state (not focused).
* @param gravity specifies how to align the indicator. for example, using Gravity.BOTTOM | Gravity.RIGHT
Expand All @@ -79,14 +78,14 @@ interface IUltraViewPagerFeature {
IUltraIndicatorBuilder initIndicator(Bitmap focusBitmap, Bitmap normalBitmap, int gravity);

/**
* Remove indicator
* Remove indicator
*/
void disableIndicator();

/**
* Enable auto-scroll mode
*
* @param intervalInMillis The interval time to scroll in milliseconds.
* @param intervalInMillis The interval time to scroll in milliseconds.
*/
void setAutoScroll(int intervalInMillis);

Expand All @@ -105,7 +104,7 @@ interface IUltraViewPagerFeature {
/**
* Supply a maximum width for this ViewPager.
*
* @param width width
* @param width width
*/
void setMaxWidth(int width);

Expand Down Expand Up @@ -148,7 +147,7 @@ interface IUltraViewPagerFeature {
void setMultiScreen(float ratio);

/**
* Adjust the height of the ViewPager to the height of child automatically.
* Adjust the height of the ViewPager to the height of child automatically.
*/
void setAutoMeasureHeight(boolean status);

Expand All @@ -172,8 +171,15 @@ interface IUltraViewPagerFeature {
/**
* Set margins for this ViewPager
*
* @param left the left margin in pixels
* @param left the left margin in pixels
* @param right the right margin in pixels
*/
void setScrollMargin(int left, int right);

/**
* The items.size() would be scale to item.size()*infiniteRatio in fact
*
* @param infiniteRatio
*/
void setInfiniteRatio(int infiniteRatio);
}
Original file line number Diff line number Diff line change
Expand Up @@ -448,4 +448,12 @@ private void stopTimer() {
timer.removeCallbacksAndMessages(null);
timer.listener = null;
}

@Override
public void setInfiniteRatio(int infiniteRatio) {
if (viewPager.getAdapter() != null
&& viewPager.getAdapter() instanceof UltraViewPagerAdapter) {
((UltraViewPagerAdapter) viewPager.getAdapter()).setInfiniteRatio(infiniteRatio);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ interface UltraViewPagerCenterListener {
private float multiScrRatio = Float.NaN;
private boolean hasCentered; //ensure that the first item is in the middle when enabling loop-mode
private int scrWidth;
private int infiniteRatio;
private UltraViewPagerCenterListener centerListener;

private SparseArray viewArray = new SparseArray();

public UltraViewPagerAdapter(PagerAdapter adapter) {
this.adapter = adapter;
infiniteRatio = INFINITE_RATIO;
}

@Override
Expand All @@ -72,7 +74,7 @@ public int getCount() {
if (adapter.getCount() == 0) {
count = 0;
} else {
count = adapter.getCount() *INFINITE_RATIO;
count = adapter.getCount() * infiniteRatio;
}
} else {
count = adapter.getCount();
Expand Down Expand Up @@ -262,4 +264,8 @@ boolean isEnableMultiScr() {
void setCenterListener(UltraViewPagerCenterListener listener) {
centerListener = listener;
}

void setInfiniteRatio(int infiniteRatio) {
this.infiniteRatio = infiniteRatio;
}
}

0 comments on commit f303188

Please sign in to comment.