use of android.support.v4.view.PagerAdapter in project little-bear-dictionary by daimajia.
the class TabPageIndicator method notifyDataSetChanged.
public void notifyDataSetChanged() {
mTabLayout.removeAllViews();
PagerAdapter adapter = mViewPager.getAdapter();
IconPagerAdapter iconAdapter = null;
if (adapter instanceof IconPagerAdapter) {
iconAdapter = (IconPagerAdapter) adapter;
}
final int count = adapter.getCount();
for (int i = 0; i < count; i++) {
CharSequence title = adapter.getPageTitle(i);
if (title == null) {
title = EMPTY_TITLE;
}
int iconResId = 0;
if (iconAdapter != null) {
iconResId = iconAdapter.getIconResId(i);
}
addTab(i, title, iconResId);
}
if (mSelectedTabIndex > count) {
mSelectedTabIndex = count - 1;
}
setCurrentItem(mSelectedTabIndex);
requestLayout();
}
use of android.support.v4.view.PagerAdapter in project AppIntro by apl-devs.
the class AppIntroBase method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(getLayoutId());
gestureDetector = new GestureDetectorCompat(this, new WindowGestureListener());
nextButton = findViewById(R.id.next);
doneButton = findViewById(R.id.done);
skipButton = findViewById(R.id.skip);
backButton = findViewById(R.id.back);
checkButton(nextButton, "next");
checkButton(doneButton, "done");
checkButton(skipButton, "skip");
checkButton(backButton, "back");
FrameLayout frameLayout = (FrameLayout) findViewById(R.id.bottomContainer);
if (frameLayout != null && isRtl()) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
frameLayout.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
}
if (isRtl()) {
(nextButton).setScaleX(-1);
}
mVibrator = (Vibrator) this.getSystemService(VIBRATOR_SERVICE);
mPagerAdapter = new PagerAdapter(getSupportFragmentManager(), fragments);
pager = (AppIntroViewPager) findViewById(R.id.view_pager);
if (doneButton != null) {
doneButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(@NonNull View v) {
if (isVibrateOn) {
mVibrator.vibrate(vibrateIntensity);
}
Fragment currentFragment = mPagerAdapter.getItem(pager.getCurrentItem());
boolean isSlideChangingAllowed = handleBeforeSlideChanged();
if (isSlideChangingAllowed) {
handleSlideChanged(currentFragment, null);
onDonePressed(currentFragment);
} else {
handleIllegalSlideChangeAttempt();
}
}
});
}
if (skipButton != null) {
skipButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(@NonNull View v) {
if (isVibrateOn) {
mVibrator.vibrate(vibrateIntensity);
}
onSkipPressed(mPagerAdapter.getItem(pager.getCurrentItem()));
}
});
}
if (nextButton != null) {
nextButton.setOnClickListener(new NextButtonOnClickListener());
}
if (backButton != null) {
backButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (pager.getCurrentItem() > 0) {
pager.setCurrentItem(pager.getCurrentItem() - 1);
}
}
});
}
pager.setAdapter(this.mPagerAdapter);
pager.addOnPageChangeListener(new PagerOnPageChangeListener());
pager.setOnNextPageRequestedListener(this);
setScrollDurationFactor(DEFAULT_SCROLL_DURATION_FACTOR);
}
use of android.support.v4.view.PagerAdapter in project BGARefreshLayout-Android by bingoogolapple.
the class BGAStickyNavLayout method regetNestedContentView.
/**
* 重新获取嵌套的内容视图
*/
private void regetNestedContentView() {
int currentItem = mDirectViewPager.getCurrentItem();
PagerAdapter adapter = mDirectViewPager.getAdapter();
if (adapter instanceof FragmentPagerAdapter || adapter instanceof FragmentStatePagerAdapter) {
Fragment item = (Fragment) adapter.instantiateItem(mDirectViewPager, currentItem);
mNestedContentView = item.getView();
// 清空之前的
mNestedNormalView = null;
mNestedAbsListView = null;
mNestedRecyclerView = null;
mNestedScrollView = null;
mNestedWebView = null;
if (mNestedContentView instanceof AbsListView) {
mNestedAbsListView = (AbsListView) mNestedContentView;
mNestedAbsListView.setOnScrollListener(mLvOnScrollListener);
if (!isHeaderViewCompleteInvisible()) {
mNestedAbsListView.setSelection(0);
}
} else if (mNestedContentView instanceof RecyclerView) {
mNestedRecyclerView = (RecyclerView) mNestedContentView;
mNestedRecyclerView.removeOnScrollListener(mRvOnScrollListener);
mNestedRecyclerView.addOnScrollListener(mRvOnScrollListener);
if (!isHeaderViewCompleteInvisible()) {
mNestedRecyclerView.scrollToPosition(0);
}
} else if (mNestedContentView instanceof ScrollView) {
mNestedScrollView = (ScrollView) mNestedContentView;
if (!isHeaderViewCompleteInvisible()) {
mNestedScrollView.scrollTo(mNestedScrollView.getScrollX(), 0);
}
} else if (mNestedContentView instanceof WebView) {
mNestedWebView = (WebView) mNestedContentView;
if (!isHeaderViewCompleteInvisible()) {
mNestedWebView.scrollTo(mNestedWebView.getScrollX(), 0);
}
} else {
mNestedNormalView = mNestedContentView;
}
} else {
throw new IllegalStateException(BGAStickyNavLayout.class.getSimpleName() + "的第三个子控件为ViewPager时,其adapter必须是FragmentPagerAdapter或者FragmentStatePagerAdapter");
}
}
use of android.support.v4.view.PagerAdapter in project SimplifyReader by chentao0707.
the class SmartTabLayout method populateTabStrip.
private void populateTabStrip() {
final PagerAdapter adapter = mViewPager.getAdapter();
final OnClickListener tabClickListener = new TabClickListener();
final LayoutInflater inflater = LayoutInflater.from(getContext());
for (int i = 0; i < adapter.getCount(); i++) {
View tabView = null;
TextView tabTitleView = null;
if (mTabViewLayoutId != NO_ID) {
// If there is a custom tab view layout id set, try and inflate it
tabView = inflater.inflate(mTabViewLayoutId, mTabStrip, false);
}
if (mTabViewTextViewId != NO_ID && tabView != null) {
tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
}
if (tabView == null) {
tabView = createDefaultTabView(getContext());
}
if (tabTitleView == null && TextView.class.isInstance(tabView)) {
tabTitleView = (TextView) tabView;
}
if (tabTitleView == null) {
throw new IllegalStateException("tabTitleView not found.");
}
if (mDistributeEvenly) {
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
lp.width = 0;
lp.weight = 1;
}
tabTitleView.setText(adapter.getPageTitle(i));
tabView.setOnClickListener(tabClickListener);
mTabStrip.addView(tabView);
if (i == mViewPager.getCurrentItem()) {
tabView.setSelected(true);
}
}
}
use of android.support.v4.view.PagerAdapter in project Android-PullToRefresh by chrisbanes.
the class PullToRefreshViewPager method isReadyForPullStart.
@Override
protected boolean isReadyForPullStart() {
ViewPager refreshableView = getRefreshableView();
PagerAdapter adapter = refreshableView.getAdapter();
if (null != adapter) {
return refreshableView.getCurrentItem() == 0;
}
return false;
}
Aggregations