Search in sources :

Example 66 with PagerAdapter

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();
}
Also used : PagerAdapter(android.support.v4.view.PagerAdapter)

Example 67 with PagerAdapter

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);
}
Also used : FrameLayout(android.widget.FrameLayout) GestureDetectorCompat(android.support.v4.view.GestureDetectorCompat) View(android.view.View) Fragment(android.support.v4.app.Fragment)

Example 68 with PagerAdapter

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");
    }
}
Also used : FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter) ScrollView(android.widget.ScrollView) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) WebView(android.webkit.WebView) Fragment(android.support.v4.app.Fragment) PagerAdapter(android.support.v4.view.PagerAdapter) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) FragmentStatePagerAdapter(android.support.v4.app.FragmentStatePagerAdapter)

Example 69 with PagerAdapter

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);
        }
    }
}
Also used : LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) HorizontalScrollView(android.widget.HorizontalScrollView) TextView(android.widget.TextView) View(android.view.View) PagerAdapter(android.support.v4.view.PagerAdapter) LinearLayout(android.widget.LinearLayout)

Example 70 with PagerAdapter

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;
}
Also used : ViewPager(android.support.v4.view.ViewPager) PagerAdapter(android.support.v4.view.PagerAdapter)

Aggregations

PagerAdapter (android.support.v4.view.PagerAdapter)111 View (android.view.View)47 ViewPager (android.support.v4.view.ViewPager)39 TextView (android.widget.TextView)33 HorizontalScrollView (android.widget.HorizontalScrollView)19 ViewGroup (android.view.ViewGroup)18 LinearLayout (android.widget.LinearLayout)13 Toolbar (android.support.v7.widget.Toolbar)11 ImageView (android.widget.ImageView)11 TabLayout (android.support.design.widget.TabLayout)8 RecyclerView (android.support.v7.widget.RecyclerView)8 ArrayList (java.util.ArrayList)8 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)6 AppBarLayout (android.support.design.widget.AppBarLayout)5 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)5 FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)5 ImageButton (android.widget.ImageButton)5 LargeTest (android.support.test.filters.LargeTest)4 MediumTest (android.support.test.filters.MediumTest)4 SmallTest (android.support.test.filters.SmallTest)4