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();
}
};
}
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();
}
};
}
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();
}
};
}
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);
}
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();
}
});
}
Aggregations