Skip to content

Commit

Permalink
Update 1.0.2.
Browse files Browse the repository at this point in the history
Fixes.
Auto scroll.
Disable scroll block.
  • Loading branch information
GIGAMOLE committed Aug 31, 2016
1 parent 6692d04 commit 5f67748
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 10 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ You can download a `.aar` from GitHub's [releases page](https://github.com/DevLi
Or use Gradle:

```groovy
compile 'com.github.devlight:infinitecycleviewpager:1.0.1'
compile 'com.github.devlight:infinitecycleviewpager:1.0.2'
```

Or Maven:
Expand All @@ -34,15 +34,15 @@ Or Maven:
<dependency>
<groupId>com.github.devlight</groupId>
<artifactId>infinitecycleviewpager</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<type>pom</type>
</dependency>
```

Or Ivy:

```groovy
<dependency org='com.github.devlight' name='infinitecycleviewpager' rev='1.0.1'>
<dependency org='com.github.devlight' name='infinitecycleviewpager' rev='1.0.2'>
<artifact name='$AID' ext='pom'></artifact>
</dependency>
```
Expand Down Expand Up @@ -94,6 +94,10 @@ For `InfiniteCycleViewPager` you can set such parameters as:
- page transform listener:

allows you to set page transform listener.

- auto scroll:

allows you to set auto scroll in positive and negative directions.

<b>Tips</b>

Expand Down Expand Up @@ -133,6 +137,14 @@ To update your ViewPager after some adapter update or else, you can call this me
infiniteCycleViewPager.notifyDataSetChanged();
```

If you want to start auto scroll or stop call this methods:
```java
// true - positive
// false - negative
infiniteCycleViewPager.startAutoScroll(...);
infiniteCycleViewPager.stopAutoScroll();
```

Other methods check out in sample.

And XML init:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@ public void onViewCreated(final View view, @Nullable final Bundle savedInstanceS
final VerticalInfiniteCycleViewPager verticalInfiniteCycleViewPager =
(VerticalInfiniteCycleViewPager) view.findViewById(R.id.vicvp);
verticalInfiniteCycleViewPager.setAdapter(new VerticalPagerAdapter(getContext(), null));

verticalInfiniteCycleViewPager.setScrollDuration(1000);
verticalInfiniteCycleViewPager.startAutoScroll(true);
}
}
4 changes: 2 additions & 2 deletions infinitecycleviewpager/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ apply plugin: "com.jfrog.bintray"
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'maven'

version = "1.0.1"
version = "1.0.2"

android {
compileSdkVersion 23
Expand All @@ -29,7 +29,7 @@ android {
minSdkVersion 11
targetSdkVersion 23
versionCode 1
versionName "1.0.1"
versionName "1.0.2"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Interpolator;

/**
Expand Down Expand Up @@ -150,6 +152,16 @@ public void setOverScrollMode(final int overScrollMode) {
super.setOverScrollMode(OVER_SCROLL_NEVER);
}

@Override
protected boolean addViewInLayout(final View child, final int index, final ViewGroup.LayoutParams params) {
return super.addViewInLayout(child, 0, params);
}

@Override
public void addView(final View child, final int index, final ViewGroup.LayoutParams params) {
super.addView(child, 0, params);
}

@Override
public void setAdapter(final PagerAdapter adapter) {
if (mInfiniteCycleManager == null) super.setAdapter(adapter);
Expand Down Expand Up @@ -193,6 +205,12 @@ public void onWindowFocusChanged(final boolean hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
}

@Override
protected void onDetachedFromWindow() {
if (mInfiniteCycleManager != null) mInfiniteCycleManager.stopAutoScroll();
super.onDetachedFromWindow();
}

@Override
public void setCurrentItem(final int item) {
setCurrentItem(item, true);
Expand Down Expand Up @@ -225,4 +243,12 @@ public void invalidateTransformer() {
public void postInvalidateTransformer() {
if (mInfiniteCycleManager != null) mInfiniteCycleManager.postInvalidateTransformer();
}

public void startAutoScroll(final boolean isAutoScrollPositive) {
if (mInfiniteCycleManager != null) mInfiniteCycleManager.startAutoScroll(isAutoScrollPositive);
}

public void stopAutoScroll() {
if (mInfiniteCycleManager != null) mInfiniteCycleManager.stopAutoScroll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.content.res.TypedArray;
import android.graphics.Rect;
import android.os.Build;
import android.os.Handler;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPager;
Expand Down Expand Up @@ -113,6 +114,20 @@ class InfiniteCycleManager implements OnNotifyDataSetChangedListener {
// Interpolator of snapping
private Interpolator mInterpolator;

// Auto scroll values
private boolean mIsAutoScroll;
private boolean mIsAutoScrollPositive;
// Auto scroll handlers
private final Handler mAutoScrollHandler = new Handler();
private final Runnable mAutoScrollRunnable = new Runnable() {
@Override
public void run() {
if (!mIsAutoScroll) return;
mViewPageable.setCurrentItem(getRealItem() + (mIsAutoScrollPositive ? 1 : -1));
mAutoScrollHandler.postDelayed(this, mScrollDuration);
}
};

public InfiniteCycleManager(
final Context context,
final ViewPageable viewPageable,
Expand Down Expand Up @@ -315,7 +330,7 @@ public PagerAdapter setAdapter(final PagerAdapter adapter) {
public boolean onTouchEvent(final MotionEvent event) {
if (mViewPageable.getAdapter() == null || mViewPageable.getAdapter().getCount() == 0)
return false;
if (mState == ViewPager.SCROLL_STATE_SETTLING || mViewPageable.isFakeDragging()) return false;
if (mIsAutoScroll || mIsInitialItem || mViewPageable.isFakeDragging()) return false;
if (event.getPointerCount() > MIN_POINTER_COUNT || !mViewPageable.hasWindowFocus())
event.setAction(MotionEvent.ACTION_UP);
checkHitRect(event);
Expand Down Expand Up @@ -343,8 +358,7 @@ public int setCurrentItem(final int item) {
if (mIsAdapterInitialPosition) {
mIsAdapterInitialPosition = false;
return ((mInfiniteCyclePagerAdapter.getCount() / 2) / count) * count;
} else return mViewPageable.getCurrentItem() +
(Math.max(0, Math.min(count, item))) - getRealItem();
} else return mViewPageable.getCurrentItem() + Math.min(count, item) - getRealItem();
}

// Need to get current position of original adapter. We cant override getCurrentItem() method,
Expand Down Expand Up @@ -448,6 +462,23 @@ private void resetScaleBy() {
mCenterScaleBy = (mMaxPageScale - mMinPageScale) * 0.5F;
}

// Start auto scroll
public void startAutoScroll(final boolean isAutoScrollPositive) {
if (mIsAutoScroll && isAutoScrollPositive == mIsAutoScrollPositive) return;
mIsAutoScroll = true;
mIsAutoScrollPositive = isAutoScrollPositive;

mAutoScrollHandler.removeCallbacks(mAutoScrollRunnable);
mAutoScrollHandler.post(mAutoScrollRunnable);
}

// Stop auto scroll
public void stopAutoScroll() {
if (!mIsAutoScroll) return;
mIsAutoScroll = false;
mAutoScrollHandler.removeCallbacks(mAutoScrollRunnable);
}

@Override
public void onChanged() {
mIsDataSetChanged = true;
Expand Down Expand Up @@ -705,8 +736,6 @@ public void onPageScrolled(

// We need to rewrite states when is dragging and when setCurrentItem() from idle
if (mState != ViewPager.SCROLL_STATE_SETTLING || mIsInitialItem) {
mIsInitialItem = false;

// Detect first state from idle
if (mOuterPageScrolledState == PageScrolledState.IDLE && positionOffset > 0) {
mPageScrolledPosition = mViewPageable.getCurrentItem();
Expand Down Expand Up @@ -740,6 +769,8 @@ else if (mOuterPageScrolledState == PageScrolledState.GOING_RIGHT && goingRight)
mWasPlusOne = false;
mIsLeftPageBringToFront = false;
mIsRightPageBringToFront = false;

mIsInitialItem = false;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Interpolator;

/**
Expand Down Expand Up @@ -150,6 +152,16 @@ public void setOverScrollMode(final int overScrollMode) {
super.setOverScrollMode(OVER_SCROLL_NEVER);
}

@Override
protected boolean addViewInLayout(final View child, final int index, final ViewGroup.LayoutParams params) {
return super.addViewInLayout(child, 0, params);
}

@Override
public void addView(final View child, final int index, final ViewGroup.LayoutParams params) {
super.addView(child, 0, params);
}

@Override
public void setAdapter(final PagerAdapter adapter) {
if (mInfiniteCycleManager == null) super.setAdapter(adapter);
Expand Down Expand Up @@ -193,6 +205,12 @@ public void onWindowFocusChanged(final boolean hasWindowFocus) {
super.onWindowFocusChanged(hasWindowFocus);
}

@Override
protected void onDetachedFromWindow() {
if (mInfiniteCycleManager != null) mInfiniteCycleManager.stopAutoScroll();
super.onDetachedFromWindow();
}

@Override
public void setCurrentItem(final int item) {
setCurrentItem(item, true);
Expand Down Expand Up @@ -225,4 +243,12 @@ public void invalidateTransformer() {
public void postInvalidateTransformer() {
if (mInfiniteCycleManager != null) mInfiniteCycleManager.postInvalidateTransformer();
}

public void startAutoScroll(final boolean isAutoScrollPositive) {
if (mInfiniteCycleManager != null) mInfiniteCycleManager.startAutoScroll(isAutoScrollPositive);
}

public void stopAutoScroll() {
if (mInfiniteCycleManager != null) mInfiniteCycleManager.stopAutoScroll();
}
}

0 comments on commit 5f67748

Please sign in to comment.