Search in sources :

Example 26 with ViewPager

use of android.support.v4.view.ViewPager in project material-components-android by material-components.

the class ViewPagerActions method scrollToLast.

/** Moves <code>ViewPager</code> to the last page. */
public static ViewAction scrollToLast() {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isDisplayingAtLeast(90);
        }

        @Override
        public String getDescription() {
            return "ViewPager scroll to last page";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            ViewPager viewPager = (ViewPager) view;
            int size = viewPager.getAdapter().getCount();
            if (size > 0) {
                viewPager.setCurrentItem(size - 1, false);
            }
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) View(android.view.View) ViewPager(android.support.v4.view.ViewPager)

Example 27 with ViewPager

use of android.support.v4.view.ViewPager in project material-components-android by material-components.

the class ViewPagerActions method setAdapter.

/** Sets the specified adapter on <code>ViewPager</code>. */
public static ViewAction setAdapter(@Nullable final PagerAdapter adapter) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(ViewPager.class);
        }

        @Override
        public String getDescription() {
            return "ViewPager set adapter";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            ViewPager viewPager = (ViewPager) view;
            viewPager.setAdapter(adapter);
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) View(android.view.View) ViewPager(android.support.v4.view.ViewPager)

Example 28 with ViewPager

use of android.support.v4.view.ViewPager in project material-components-android by material-components.

the class TabLayoutWithViewPagerTest method addItemToPager.

private static <Q> ViewAction addItemToPager(final String title, final Q content) {
    return new ViewAction() {

        @Override
        public Matcher<View> getConstraints() {
            return isAssignableFrom(ViewPager.class);
        }

        @Override
        public String getDescription() {
            return "Add item and notify on content change";
        }

        @Override
        public void perform(UiController uiController, View view) {
            uiController.loopMainThreadUntilIdle();
            final ViewPager viewPager = (ViewPager) view;
            // no way to avoid this cast
            @SuppressWarnings("unchecked") final BasePagerAdapter<Q> viewPagerAdapter = (BasePagerAdapter<Q>) viewPager.getAdapter();
            viewPagerAdapter.add(title, content);
            viewPagerAdapter.notifyDataSetChanged();
            uiController.loopMainThreadUntilIdle();
        }
    };
}
Also used : ViewAction(android.support.test.espresso.ViewAction) UiController(android.support.test.espresso.UiController) HorizontalScrollView(android.widget.HorizontalScrollView) View(android.view.View) TextView(android.widget.TextView) Espresso.onView(android.support.test.espresso.Espresso.onView) ViewPager(android.support.v4.view.ViewPager) TabLayoutActions.setupWithViewPager(android.support.design.testutils.TabLayoutActions.setupWithViewPager)

Example 29 with ViewPager

use of android.support.v4.view.ViewPager in project JieCaoVideoPlayer by lipangit.

the class ListViewViewpagerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_listview_viewpager);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    getSupportActionBar().setDisplayShowTitleEnabled(true);
    getSupportActionBar().setDisplayUseLogoEnabled(false);
    getSupportActionBar().setTitle("ViewPagerAndListView");
    List<View> listViews = new ArrayList<>();
    ListView listView1 = (ListView) getLayoutInflater().inflate(R.layout.layout_list, null);
    ListView listView2 = (ListView) getLayoutInflater().inflate(R.layout.layout_list, null);
    ListView listView3 = (ListView) getLayoutInflater().inflate(R.layout.layout_list, null);
    listView1.setAdapter(new VideoListAdapter(this, 0));
    listView2.setAdapter(new VideoListAdapter(this, 1));
    listView3.setAdapter(new VideoListAdapter(this, 2));
    listViews.add(listView1);
    listViews.add(listView2);
    listViews.add(listView3);
    MyAdapter myAdapter = new MyAdapter(listViews);
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setAdapter(myAdapter);
    viewPager.setOnPageChangeListener(this);
}
Also used : ListView(android.widget.ListView) ArrayList(java.util.ArrayList) View(android.view.View) ListView(android.widget.ListView) ViewPager(android.support.v4.view.ViewPager)

Example 30 with ViewPager

use of android.support.v4.view.ViewPager in project StatusBarUtil by laobie.

the class UseInFragmentActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_use_in_fragment);
    mVpHome = (ViewPager) findViewById(R.id.vp_home);
    mBottomNavigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);
    mBottomNavigationBar.addItem(new BottomNavigationItem(R.drawable.ic_favorite, "One")).addItem(new BottomNavigationItem(R.drawable.ic_gavel, "Two")).addItem(new BottomNavigationItem(R.drawable.ic_grade, "Three")).addItem(new BottomNavigationItem(R.drawable.ic_group_work, "Four")).initialise();
    mBottomNavigationBar.setTabSelectedListener(new BottomNavigationBar.OnTabSelectedListener() {

        @Override
        public void onTabSelected(int position) {
            mVpHome.setCurrentItem(position);
        }

        @Override
        public void onTabUnselected(int position) {
        }

        @Override
        public void onTabReselected(int position) {
        }
    });
    mFragmentList.add(new ImageFragment());
    mFragmentList.add(new SimpleFragment());
    mFragmentList.add(new SimpleFragment());
    mFragmentList.add(new SimpleFragment());
    mVpHome.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

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

        @Override
        public void onPageSelected(int position) {
            mBottomNavigationBar.selectTab(position);
            switch(position) {
                case 0:
                    break;
                default:
                    Random random = new Random();
                    int color = 0xff000000 | random.nextInt(0xffffff);
                    if (mFragmentList.get(position) instanceof SimpleFragment) {
                        ((SimpleFragment) mFragmentList.get(position)).setTvTitleBackgroundColor(color);
                    }
                    break;
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    mVpHome.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            return mFragmentList.get(position);
        }

        @Override
        public int getCount() {
            return mFragmentList.size();
        }
    });
}
Also used : FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) ViewPager(android.support.v4.view.ViewPager) Fragment(android.support.v4.app.Fragment) BottomNavigationBar(com.ashokvarma.bottomnavigation.BottomNavigationBar) Random(java.util.Random) BottomNavigationItem(com.ashokvarma.bottomnavigation.BottomNavigationItem)

Aggregations

ViewPager (android.support.v4.view.ViewPager)246 View (android.view.View)95 PagerAdapter (android.support.v4.view.PagerAdapter)55 Fragment (android.support.v4.app.Fragment)44 TabLayout (android.support.design.widget.TabLayout)37 TextView (android.widget.TextView)35 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)34 Toolbar (android.support.v7.widget.Toolbar)30 Bundle (android.os.Bundle)28 ViewGroup (android.view.ViewGroup)27 FragmentStatePagerAdapter (android.support.v4.app.FragmentStatePagerAdapter)21 ImageView (android.widget.ImageView)20 ArrayList (java.util.ArrayList)20 Intent (android.content.Intent)17 ActionBar (android.support.v7.app.ActionBar)15 RecyclerView (android.support.v7.widget.RecyclerView)11 ViewTreeObserver (android.view.ViewTreeObserver)9 AdapterView (android.widget.AdapterView)9 LinearLayout (android.widget.LinearLayout)9 UiController (android.support.test.espresso.UiController)8