From dd28f598967153e18f27cfe974467e196a56678a Mon Sep 17 00:00:00 2001 From: Jaeho Choe Date: Mon, 6 Jul 2020 07:25:47 +0900 Subject: [PATCH 1/3] Made enable override indicator count for infinite loop viewpager. --- .../me/relex/circleindicator/CircleIndicator.java | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/circleindicator/src/main/java/me/relex/circleindicator/CircleIndicator.java b/circleindicator/src/main/java/me/relex/circleindicator/CircleIndicator.java index a030eff..a43d885 100644 --- a/circleindicator/src/main/java/me/relex/circleindicator/CircleIndicator.java +++ b/circleindicator/src/main/java/me/relex/circleindicator/CircleIndicator.java @@ -44,15 +44,12 @@ public void setViewPager(@Nullable ViewPager viewPager) { } } + protected int getCount() { + return mViewpager.getAdapter() != null ? mViewpager.getAdapter().getCount() : 0; + } + private void createIndicators() { - PagerAdapter adapter = mViewpager.getAdapter(); - int count; - if (adapter == null) { - count = 0; - } else { - count = adapter.getCount(); - } - createIndicators(count, mViewpager.getCurrentItem()); + createIndicators(getCount(), mViewpager.getCurrentItem()); } private final ViewPager.OnPageChangeListener mInternalPageChangeListener = From 84b0255e686145735baf074f9f1b1c7071f1ec9c Mon Sep 17 00:00:00 2001 From: Jaeho Choe Date: Mon, 6 Jul 2020 07:36:44 +0900 Subject: [PATCH 2/3] Made enable override initial position for infinite loop viewpager. --- .../java/me/relex/circleindicator/CircleIndicator.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/circleindicator/src/main/java/me/relex/circleindicator/CircleIndicator.java b/circleindicator/src/main/java/me/relex/circleindicator/CircleIndicator.java index a43d885..fcc02e9 100644 --- a/circleindicator/src/main/java/me/relex/circleindicator/CircleIndicator.java +++ b/circleindicator/src/main/java/me/relex/circleindicator/CircleIndicator.java @@ -44,12 +44,16 @@ public void setViewPager(@Nullable ViewPager viewPager) { } } - protected int getCount() { - return mViewpager.getAdapter() != null ? mViewpager.getAdapter().getCount() : 0; + protected int getCount(ViewPager viewPager) { + return viewPager.getAdapter() != null ? viewPager.getAdapter().getCount() : 0; + } + + protected int initialPosition(ViewPager viewPager) { + return viewPager.getCurrentItem(); } private void createIndicators() { - createIndicators(getCount(), mViewpager.getCurrentItem()); + createIndicators(getCount(mViewpager), initialPosition(mViewpager)); } private final ViewPager.OnPageChangeListener mInternalPageChangeListener = From a1b8e754e303bcce2e4b33fde467eedefc9984a3 Mon Sep 17 00:00:00 2001 From: Jaeho Choe Date: Mon, 6 Jul 2020 08:07:58 +0900 Subject: [PATCH 3/3] Made enable override current position onPageSelected for infinite loop viewpager. --- .../java/me/relex/circleindicator/CircleIndicator.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/circleindicator/src/main/java/me/relex/circleindicator/CircleIndicator.java b/circleindicator/src/main/java/me/relex/circleindicator/CircleIndicator.java index fcc02e9..acbcc06 100644 --- a/circleindicator/src/main/java/me/relex/circleindicator/CircleIndicator.java +++ b/circleindicator/src/main/java/me/relex/circleindicator/CircleIndicator.java @@ -5,6 +5,8 @@ import android.database.DataSetObserver; import android.os.Build; import android.util.AttributeSet; +import android.view.View; + import androidx.annotation.Nullable; import androidx.viewpager.widget.PagerAdapter; import androidx.viewpager.widget.ViewPager; @@ -56,6 +58,10 @@ private void createIndicators() { createIndicators(getCount(mViewpager), initialPosition(mViewpager)); } + protected int getCurrentPosition(ViewPager viewPager, int position) { + return position; + } + private final ViewPager.OnPageChangeListener mInternalPageChangeListener = new ViewPager.OnPageChangeListener() { @@ -64,12 +70,11 @@ private void createIndicators() { } @Override public void onPageSelected(int position) { - if (mViewpager.getAdapter() == null || mViewpager.getAdapter().getCount() <= 0) { return; } - animatePageSelected(position); + animatePageSelected(getCurrentPosition(mViewpager, position)); } @Override public void onPageScrollStateChanged(int state) {