Skip to content
This repository has been archived by the owner on Mar 19, 2022. It is now read-only.

Commit

Permalink
Fixed crash, added convenience method
Browse files Browse the repository at this point in the history
  • Loading branch information
badoualy committed Jun 16, 2016
1 parent 9856f2b commit e2b5c01
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ public int getCurrentStep() {
/**
* Sets the current step
*
* @param currentStep a value between 0 (inclusive) and stepCount (exclusive)
* @param currentStep a value between 0 (inclusive) and stepCount (inclusive)
*/
@UiThread
public void setCurrentStep(int currentStep) {
if (currentStep < 0 || currentStep >= stepCount)
if (currentStep < 0 || currentStep > stepCount)
throw new IllegalArgumentException("Invalid step value " + currentStep);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
Expand Down Expand Up @@ -356,11 +356,23 @@ public void setViewPager(ViewPager pager) {
setViewPager(pager, pager.getAdapter().getCount());
}

/**
* Sets the pager associated with this indicator
*
* @param pager viewpager to attach
* @param keepLastPage true if should not create an indicator for the last page, to use it as the final page
*/
public void setViewPager(ViewPager pager, boolean keepLastPage) {
if (pager.getAdapter() == null)
throw new IllegalStateException("ViewPager does not have adapter instance.");
setViewPager(pager, pager.getAdapter().getCount() - (keepLastPage ? 1 : 0));
}

/**
* Sets the pager associated with this indicator
*
* @param pager viewpager to attach
* @param stepCount the real page count to display (use this if you are using looped viewpager)
* @param stepCount the real page count to display (use this if you are using looped viewpager to indicate the real number of pages)
*/
public void setViewPager(ViewPager pager, int stepCount) {
if (this.pager == pager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

StepperIndicator indicator = (StepperIndicator) findViewById(R.id.stepper_indicator);
assert indicator != null;
indicator.setViewPager(pager, pager.getAdapter().getCount() - 1);
// We keep last page for a "finishing" page
indicator.setViewPager(pager, true);
}

public static class PageFragment extends Fragment {
Expand Down

0 comments on commit e2b5c01

Please sign in to comment.