Search in sources :

Example 51 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project NavigationTabBar by Devlight.

the class HorizontalCoordinatorNtbActivity method initUI.

private void initUI() {
    final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_horizontal_ntb);
    viewPager.setAdapter(new PagerAdapter() {

        @Override
        public int getCount() {
            return 5;
        }

        @Override
        public boolean isViewFromObject(final View view, final Object object) {
            return view.equals(object);
        }

        @Override
        public void destroyItem(final View container, final int position, final Object object) {
            ((ViewPager) container).removeView((View) object);
        }

        @Override
        public Object instantiateItem(final ViewGroup container, final int position) {
            final View view = LayoutInflater.from(getBaseContext()).inflate(R.layout.item_vp_list, null, false);
            final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.rv);
            recyclerView.setHasFixedSize(true);
            recyclerView.setLayoutManager(new LinearLayoutManager(getBaseContext(), LinearLayoutManager.VERTICAL, false));
            recyclerView.setAdapter(new RecycleAdapter());
            container.addView(view);
            return view;
        }
    });
    final String[] colors = getResources().getStringArray(R.array.default_preview);
    final NavigationTabBar navigationTabBar = (NavigationTabBar) findViewById(R.id.ntb_horizontal);
    final ArrayList<NavigationTabBar.Model> models = new ArrayList<>();
    models.add(new NavigationTabBar.Model.Builder(getResources().getDrawable(R.drawable.ic_first), Color.parseColor(colors[0])).title("Heart").build());
    models.add(new NavigationTabBar.Model.Builder(getResources().getDrawable(R.drawable.ic_second), Color.parseColor(colors[1])).title("Cup").build());
    models.add(new NavigationTabBar.Model.Builder(getResources().getDrawable(R.drawable.ic_third), Color.parseColor(colors[2])).title("Diploma").build());
    models.add(new NavigationTabBar.Model.Builder(getResources().getDrawable(R.drawable.ic_fourth), Color.parseColor(colors[3])).title("Flag").build());
    models.add(new NavigationTabBar.Model.Builder(getResources().getDrawable(R.drawable.ic_fifth), Color.parseColor(colors[4])).title("Medal").build());
    navigationTabBar.setModels(models);
    navigationTabBar.setViewPager(viewPager, 2);
    //IMPORTANT: ENABLE SCROLL BEHAVIOUR IN COORDINATOR LAYOUT
    navigationTabBar.setBehaviorEnabled(true);
    navigationTabBar.setOnTabBarSelectedIndexListener(new NavigationTabBar.OnTabBarSelectedIndexListener() {

        @Override
        public void onStartTabSelected(final NavigationTabBar.Model model, final int index) {
        }

        @Override
        public void onEndTabSelected(final NavigationTabBar.Model model, final int index) {
            model.hideBadge();
        }
    });
    navigationTabBar.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(final int position) {
        }

        @Override
        public void onPageScrollStateChanged(final int state) {
        }
    });
    final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.parent);
    findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(final View v) {
            for (int i = 0; i < navigationTabBar.getModels().size(); i++) {
                final NavigationTabBar.Model model = navigationTabBar.getModels().get(i);
                navigationTabBar.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        final String title = String.valueOf(new Random().nextInt(15));
                        if (!model.isBadgeShowed()) {
                            model.setBadgeTitle(title);
                            model.showBadge();
                        } else
                            model.updateBadgeTitle(title);
                    }
                }, i * 100);
            }
            coordinatorLayout.postDelayed(new Runnable() {

                @Override
                public void run() {
                    final Snackbar snackbar = Snackbar.make(navigationTabBar, "Coordinator NTB", Snackbar.LENGTH_SHORT);
                    snackbar.getView().setBackgroundColor(Color.parseColor("#9b92b3"));
                    ((TextView) snackbar.getView().findViewById(R.id.snackbar_text)).setTextColor(Color.parseColor("#423752"));
                    snackbar.show();
                }
            }, 1000);
        }
    });
    final CollapsingToolbarLayout collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.toolbar);
    collapsingToolbarLayout.setExpandedTitleColor(Color.parseColor("#009F90AF"));
    collapsingToolbarLayout.setCollapsedTitleTextColor(Color.parseColor("#9f90af"));
}
Also used : ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) PagerAdapter(android.support.v4.view.PagerAdapter) Random(java.util.Random) CollapsingToolbarLayout(android.support.design.widget.CollapsingToolbarLayout) TextView(android.widget.TextView) NavigationTabBar(devlight.io.library.ntb.NavigationTabBar) ViewGroup(android.view.ViewGroup) ViewPager(android.support.v4.view.ViewPager) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) CoordinatorLayout(android.support.design.widget.CoordinatorLayout) RecyclerView(android.support.v7.widget.RecyclerView) Snackbar(android.support.design.widget.Snackbar)

Example 52 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project NavigationTabBar by Devlight.

the class HorizontalNtbActivity method initUI.

private void initUI() {
    final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_horizontal_ntb);
    viewPager.setAdapter(new PagerAdapter() {

        @Override
        public int getCount() {
            return 5;
        }

        @Override
        public boolean isViewFromObject(final View view, final Object object) {
            return view.equals(object);
        }

        @Override
        public void destroyItem(final View container, final int position, final Object object) {
            ((ViewPager) container).removeView((View) object);
        }

        @Override
        public Object instantiateItem(final ViewGroup container, final int position) {
            final View view = LayoutInflater.from(getBaseContext()).inflate(R.layout.item_vp, null, false);
            final TextView txtPage = (TextView) view.findViewById(R.id.txt_vp_item_page);
            txtPage.setText(String.format("Page #%d", position));
            container.addView(view);
            return view;
        }
    });
    final String[] colors = getResources().getStringArray(R.array.default_preview);
    final NavigationTabBar navigationTabBar = (NavigationTabBar) findViewById(R.id.ntb_horizontal);
    final ArrayList<NavigationTabBar.Model> models = new ArrayList<>();
    models.add(new NavigationTabBar.Model.Builder(getResources().getDrawable(R.drawable.ic_first), Color.parseColor(colors[0])).selectedIcon(getResources().getDrawable(R.drawable.ic_sixth)).title("Heart").badgeTitle("NTB").build());
    models.add(new NavigationTabBar.Model.Builder(getResources().getDrawable(R.drawable.ic_second), Color.parseColor(colors[1])).title("Cup").badgeTitle("with").build());
    models.add(new NavigationTabBar.Model.Builder(getResources().getDrawable(R.drawable.ic_third), Color.parseColor(colors[2])).selectedIcon(getResources().getDrawable(R.drawable.ic_seventh)).title("Diploma").badgeTitle("state").build());
    models.add(new NavigationTabBar.Model.Builder(getResources().getDrawable(R.drawable.ic_fourth), Color.parseColor(colors[3])).title("Flag").badgeTitle("icon").build());
    models.add(new NavigationTabBar.Model.Builder(getResources().getDrawable(R.drawable.ic_fifth), Color.parseColor(colors[4])).selectedIcon(getResources().getDrawable(R.drawable.ic_eighth)).title("Medal").badgeTitle("777").build());
    navigationTabBar.setModels(models);
    navigationTabBar.setViewPager(viewPager, 2);
    navigationTabBar.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(final int position) {
            navigationTabBar.getModels().get(position).hideBadge();
        }

        @Override
        public void onPageScrollStateChanged(final int state) {
        }
    });
    navigationTabBar.postDelayed(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < navigationTabBar.getModels().size(); i++) {
                final NavigationTabBar.Model model = navigationTabBar.getModels().get(i);
                navigationTabBar.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        model.showBadge();
                    }
                }, i * 100);
            }
        }
    }, 500);
}
Also used : NavigationTabBar(devlight.io.library.ntb.NavigationTabBar) ViewGroup(android.view.ViewGroup) ArrayList(java.util.ArrayList) ViewPager(android.support.v4.view.ViewPager) TextView(android.widget.TextView) View(android.view.View) PagerAdapter(android.support.v4.view.PagerAdapter) TextView(android.widget.TextView)

Example 53 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project NavigationTabStrip by Devlight.

the class MainActivity method setUI.

private void setUI() {
    mViewPager.setAdapter(new PagerAdapter() {

        @Override
        public int getCount() {
            return 3;
        }

        @Override
        public boolean isViewFromObject(final View view, final Object object) {
            return view.equals(object);
        }

        @Override
        public void destroyItem(final View container, final int position, final Object object) {
            ((ViewPager) container).removeView((View) object);
        }

        @Override
        public Object instantiateItem(final ViewGroup container, final int position) {
            final View view = new View(getBaseContext());
            container.addView(view);
            return view;
        }
    });
    mTopNavigationTabStrip.setTabIndex(1, true);
    mCenterNavigationTabStrip.setViewPager(mViewPager, 1);
    mBottomNavigationTabStrip.setTabIndex(1, true);
//        final NavigationTabStrip navigationTabStrip = (NavigationTabStrip) findViewById(R.id.nts);
//        navigationTabStrip.setTitles("Nav", "Tab", "Strip");
//        navigationTabStrip.setTabIndex(0, true);
//        navigationTabStrip.setTitleSize(15);
//        navigationTabStrip.setStripColor(Color.RED);
//        navigationTabStrip.setStripWeight(6);
//        navigationTabStrip.setStripFactor(2);
//        navigationTabStrip.setStripType(NavigationTabStrip.StripType.LINE);
//        navigationTabStrip.setStripGravity(NavigationTabStrip.StripGravity.BOTTOM);
//        navigationTabStrip.setTypeface("fonts/typeface.ttf");
//        navigationTabStrip.setCornersRadius(3);
//        navigationTabStrip.setAnimationDuration(300);
//        navigationTabStrip.setInactiveColor(Color.GRAY);
//        navigationTabStrip.setActiveColor(Color.WHITE);
//        navigationTabStrip.setOnPageChangeListener(...);
//        navigationTabStrip.setOnTabStripSelectedIndexListener(...);
}
Also used : ViewGroup(android.view.ViewGroup) View(android.view.View) PagerAdapter(android.support.v4.view.PagerAdapter)

Example 54 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project ViewPagerIndicator by JakeWharton.

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 55 with PagerAdapter

use of android.support.v4.view.PagerAdapter in project ZXVerticalViewPager by zhaoxin1943.

the class VerticalViewPager method setAdapter.

/**
     * Set a PagerAdapter that will supply views for this pager as needed.
     *
     * @param adapter Adapter to use
     */
public void setAdapter(PagerAdapter adapter) {
    if (mAdapter != null) {
        mAdapter.unregisterDataSetObserver(mObserver);
        mAdapter.startUpdate(this);
        for (int i = 0; i < mItems.size(); i++) {
            final ItemInfo ii = mItems.get(i);
            mAdapter.destroyItem(this, ii.position, ii.object);
        }
        mAdapter.finishUpdate(this);
        mItems.clear();
        removeNonDecorViews();
        mCurItem = 0;
        scrollTo(0, 0);
    }
    final PagerAdapter oldAdapter = mAdapter;
    mAdapter = adapter;
    mExpectedAdapterCount = 0;
    if (mAdapter != null) {
        if (mObserver == null) {
            mObserver = new PagerObserver();
        }
        mAdapter.registerDataSetObserver(mObserver);
        mPopulatePending = false;
        final boolean wasFirstLayout = mFirstLayout;
        mFirstLayout = true;
        mExpectedAdapterCount = mAdapter.getCount();
        if (mRestoredCurItem >= 0) {
            mAdapter.restoreState(mRestoredAdapterState, mRestoredClassLoader);
            setCurrentItemInternal(mRestoredCurItem, false, true);
            mRestoredCurItem = -1;
            mRestoredAdapterState = null;
            mRestoredClassLoader = null;
        } else if (!wasFirstLayout) {
            populate();
        } else {
            requestLayout();
        }
    }
    if (mAdapterChangeListener != null && oldAdapter != adapter) {
        mAdapterChangeListener.onAdapterChanged(oldAdapter, adapter);
    }
}
Also used : PagerAdapter(android.support.v4.view.PagerAdapter)

Aggregations

PagerAdapter (android.support.v4.view.PagerAdapter)111 View (android.view.View)49 ViewPager (android.support.v4.view.ViewPager)44 TextView (android.widget.TextView)33 ViewGroup (android.view.ViewGroup)19 HorizontalScrollView (android.widget.HorizontalScrollView)19 LinearLayout (android.widget.LinearLayout)13 Toolbar (android.support.v7.widget.Toolbar)12 ImageView (android.widget.ImageView)11 TabLayout (android.support.design.widget.TabLayout)10 ArrayList (java.util.ArrayList)9 RecyclerView (android.support.v7.widget.RecyclerView)8 FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)7 AppBarLayout (android.support.design.widget.AppBarLayout)6 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)6 MenuItem (android.view.MenuItem)5 ImageButton (android.widget.ImageButton)5 CoordinatorLayout (android.support.design.widget.CoordinatorLayout)4 LargeTest (android.support.test.filters.LargeTest)4 MediumTest (android.support.test.filters.MediumTest)4