Java Code Examples for android.support.v4.view.ViewPager#getAdapter()

The following examples show how to use android.support.v4.view.ViewPager#getAdapter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnderlinePageIndicator.java    From Noyze with Apache License 2.0 6 votes vote down vote up
@Override
public void setViewPager(ViewPager viewPager) {
    if (mViewPager == viewPager) {
        return;
    }
    if (mViewPager != null) {
        //Clear us from the old pager.
        mViewPager.setOnPageChangeListener(null);
    }
    if (viewPager.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = viewPager;
    mViewPager.setOnPageChangeListener(this);
    invalidate();
    post(new Runnable() {
        @Override public void run() {
            if (mFades) {
                post(mFadeRunnable);
            }
        }
    });
}
 
Example 2
Source File: TabPageIndicator.java    From letv with Apache License 2.0 6 votes vote down vote up
public void setViewPager(ViewPager view) {
    if (view == null) {
        removeAllViews();
        this.mViewPager = null;
    } else if (this.mViewPager != view) {
        if (this.mViewPager != null) {
            this.mViewPager.setOnPageChangeListener(null);
        }
        if (view.getAdapter() == null) {
            throw new IllegalStateException("ViewPager does not have adapter instance.");
        }
        this.mViewPager = view;
        view.setOnPageChangeListener(this);
        notifyDataSetChanged();
    }
}
 
Example 3
Source File: TabPageIndicator.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    final PagerAdapter adapter = view.getAdapter();
    if (adapter == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    view.setOnPageChangeListener(this);
    notifyDataSetChanged();
}
 
Example 4
Source File: CustomIconTabLayout.java    From mvvm-template with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setupWithViewPager(@Nullable ViewPager viewPager) {
    super.setupWithViewPager(viewPager);
    if (viewPager != null) {
        PagerAdapter adapter = viewPager.getAdapter();
        if (adapter != null && adapter instanceof BasePagerAdapterWithIcon) {
            int n = getTabCount();
            titleViews = new CustomTabTitleView[n];
            for (int i = 0; i < n; i++) {
                titleViews[i] = new CustomTabTitleView(getContext());
                titleViews[i].setTitle(adapter.getPageTitle(i).toString());
                titleViews[i].setImageResource(((BasePagerAdapterWithIcon) adapter).getPageIcon(i));
                // noinspection ConstantConditions
                getTabAt(i).setCustomView(titleViews[i]);
            }
        }
    } else {
        titleViews = null;
    }
}
 
Example 5
Source File: UnderlinePageIndicator.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
@Override
public void setViewPager(ViewPager viewPager) {
    if (mViewPager == viewPager) {
        return;
    }
    if (mViewPager != null) {
        //Clear us from the old pager.
        mViewPager.setOnPageChangeListener(null);
    }
    if (viewPager.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = viewPager;
    mViewPager.setOnPageChangeListener(this);
    invalidate();
    post(new Runnable() {
        @Override public void run() {
            if (mFades) {
                post(mFadeRunnable);
            }
        }
    });
}
 
Example 6
Source File: TabPageIndicator.java    From KlyphMessenger with MIT License 6 votes vote down vote up
@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    final PagerAdapter adapter = view.getAdapter();
    if (adapter == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    view.setOnPageChangeListener(this);
    notifyDataSetChanged();
}
 
Example 7
Source File: IconPageIndicator.java    From barterli_android with Apache License 2.0 6 votes vote down vote up
@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    PagerAdapter adapter = view.getAdapter();
    if (adapter == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    view.setOnPageChangeListener(this);
    notifyDataSetChanged();
}
 
Example 8
Source File: GroupSceneUIUtility.java    From scene with Apache License 2.0 6 votes vote down vote up
public static void setupWithViewPager(@NonNull final ViewPager viewPager,
                                      @NonNull final GroupScene groupScene,
                                      @NonNull final List<UserVisibleHintGroupScene> children) {
    if (viewPager.getAdapter() != null) {
        throw new IllegalArgumentException("ViewPager already have a adapter");
    }

    ScenePageAdapter scenePageAdapter = new ScenePageAdapter(groupScene) {

        @Override
        public int getCount() {
            return children.size();
        }

        @Override
        public UserVisibleHintGroupScene getItem(int position) {
            return children.get(position);
        }
    };
    viewPager.setAdapter(scenePageAdapter);
}
 
Example 9
Source File: LinePageIndicator.java    From Klyph with MIT License 6 votes vote down vote up
@Override
public void setViewPager(ViewPager viewPager) {
    if (mViewPager == viewPager) {
        return;
    }
    if (mViewPager != null) {
        //Clear us from the old pager.
        mViewPager.setOnPageChangeListener(null);
    }
    if (viewPager.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = viewPager;
    mViewPager.setOnPageChangeListener(this);
    invalidate();
}
 
Example 10
Source File: ConversationTitlePageIndicator.java    From Atomic with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void setViewPager(ViewPager view) {
  if( mViewPager == view ) {
    return;
  }
  if( mViewPager != null ) {
    mViewPager.setOnPageChangeListener(null);
  }
  mPagerAdapter = view.getAdapter();

  if( !(mPagerAdapter instanceof ConversationStateProvider) ) {
    throw new IllegalStateException("Adapter has to implement ConversationStateProvider.");
  }

  mStateProvider = (ConversationStateProvider)mPagerAdapter;

  if( mPagerAdapter == null ) {
    throw new IllegalStateException("ViewPager does not have adapter instance.");
  }
  mViewPager = view;
  mViewPager.setOnPageChangeListener(this);
  invalidate();
}
 
Example 11
Source File: TitlePageIndicator.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void setViewPager(ViewPager view) {
	if (mViewPager == view) {
		return;
	}
	if (mViewPager != null) {
		mViewPager.setOnPageChangeListener(null);
	}
	if (view.getAdapter() == null) {
		throw new IllegalStateException("ViewPager does not have adapter instance.");
	}
	mViewPager = view;
	mViewPager.setOnPageChangeListener(this);
	invalidate();
}
 
Example 12
Source File: TitlePageIndicator.java    From narrate-android with Apache License 2.0 5 votes vote down vote up
@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    if (view.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    mViewPager.setOnPageChangeListener(this);
    invalidate();
}
 
Example 13
Source File: CirclePageIndicator.java    From AndroidCacheFoundation with Apache License 2.0 5 votes vote down vote up
@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    if (view.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    mViewPager.setOnPageChangeListener(this);
    invalidate();
}
 
Example 14
Source File: CirclePageIndicator.java    From VideoOS-Android-SDK with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setViewPager(ViewPager view, int initialPosition) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    if(view==null)
    {
        mViewPager = null;
        return;
    }
    if (view.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    mViewPager.setOnPageChangeListener(this);
    //setViewPager(view);
    mIsCycleScroll = mViewPager.getAdapter() != null && mViewPager.getAdapter() instanceof CycleIconPagerAdapter;
    if (mIsCycleScroll) {
        // force snap
        mSnap = true;
        int count = mViewPager.getAdapter().getCount();
        int actualCount = ((CycleIconPagerAdapter) mViewPager.getAdapter()).getActualCount();
        if (actualCount != 0) {
            initialPosition += (count / 2) / actualCount * actualCount;
        } else {
            initialPosition = 0;
        }
    }
    setCurrentItem(initialPosition);
}
 
Example 15
Source File: PagerSlidingTabStrip.java    From ScrollableLayout with MIT License 5 votes vote down vote up
public void setViewPager(ViewPager pager) {
	this.pager = pager;

	if (pager.getAdapter() == null) {
		throw new IllegalStateException("ViewPager does not have adapter instance.");
	}

	pager.setOnPageChangeListener(pageListener);

	notifyDataSetChanged();
}
 
Example 16
Source File: SlidingTabLayout.java    From AndroidUiKit with Apache License 2.0 5 votes vote down vote up
/** 关联ViewPager */
public void setViewPager(ViewPager vp) {
    if (vp == null || vp.getAdapter() == null) {
        throw new IllegalStateException("ViewPager or ViewPager adapter can not be NULL !");
    }

    this.mViewPager = vp;

    this.mViewPager.removeOnPageChangeListener(this);
    this.mViewPager.addOnPageChangeListener(this);
    notifyDataSetChanged();
}
 
Example 17
Source File: TitlePageIndicator.java    From BigApp_WordPress_Android with Apache License 2.0 5 votes vote down vote up
@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    if (view.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    mViewPager.setOnPageChangeListener(this);
    invalidate();
}
 
Example 18
Source File: StepperIndicator.java    From stepper-indicator with MIT License 5 votes vote down vote up
/**
 * Set the {@link ViewPager} associated with this widget indicator.
 *
 * @param pager {@link ViewPager} to attach
 */
@SuppressWarnings("unused")
public void setViewPager(ViewPager pager) {
    if (pager.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    setViewPager(pager, pager.getAdapter().getCount());
}
 
Example 19
Source File: TitlePageIndicator.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
@Override
public void setViewPager(ViewPager view) {
    if (mViewPager == view) {
        return;
    }
    if (mViewPager != null) {
        mViewPager.setOnPageChangeListener(null);
    }
    if (view.getAdapter() == null) {
        throw new IllegalStateException("ViewPager does not have adapter instance.");
    }
    mViewPager = view;
    mViewPager.setOnPageChangeListener(this);
    invalidate();
}
 
Example 20
Source File: ScrollAwareFABBehavior.java    From SteamGifts with MIT License 4 votes vote down vote up
@Override
public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
    super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);

    if (child.getTag() == null) {
        return;
    }

    // try to get the current page, if there's any.
    View view = coordinatorLayout;
    ViewPager viewPager = (ViewPager) coordinatorLayout.findViewById(R.id.viewPager);
    if (viewPager != null && viewPager.getAdapter() instanceof FragmentAdapter) {
        int currentPage = viewPager.getCurrentItem();
        FragmentAdapter pagerAdapter = (FragmentAdapter) viewPager.getAdapter();

        Fragment currentItem = pagerAdapter.getItem(currentPage);

        view = currentItem.getView();
    }

    if (view == null) {
        // We do not have a view we can immediately find.
        child.hide();
        return;
    }

    // Hide if we're over the first item
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list);
    if (recyclerView != null && recyclerView.getLayoutManager() instanceof LinearLayoutManager) {
        LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        if (layoutManager.findFirstVisibleItemPosition() == 0) {
            child.hide();
        } else if (dyConsumed > 1 && child.getVisibility() == View.VISIBLE)
            child.hide();
        else if (dyConsumed < 1 && child.getVisibility() != View.VISIBLE)
            child.show();
    } else {
        // no recyclerview to attach to?
        child.hide();
    }
}