Search in sources :

Example 61 with ViewPager

use of android.support.v4.view.ViewPager in project philm by chrisbanes.

the class BasePhilmTabFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_viewpager, container, false);
    mAdapter = new TabPagerAdapter(getChildFragmentManager());
    mViewPager = (ViewPager) view.findViewById(R.id.viewpager);
    mViewPager.setAdapter(mAdapter);
    mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.spacing_minor));
    mTabLayout = (TabLayout) view.findViewById(R.id.viewpager_tabs);
    mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

        @Override
        public void onTabSelected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            final Fragment fragment = mAdapter.getItem(tab.getPosition());
            if (fragment instanceof ListFragment) {
                ((ListFragment) fragment).smoothScrollTo(0);
            }
        }
    });
    if (savedInstanceState != null) {
        mCurrentItem = savedInstanceState.getInt(SAVE_SELECTED_TAB);
    }
    return view;
}
Also used : TabLayout(android.support.design.widget.TabLayout) View(android.view.View) Fragment(android.support.v4.app.Fragment)

Example 62 with ViewPager

use of android.support.v4.view.ViewPager in project cheesesquare by chrisbanes.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    final ActionBar ab = getSupportActionBar();
    ab.setHomeAsUpIndicator(R.drawable.ic_menu);
    ab.setDisplayHomeAsUpEnabled(true);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    if (navigationView != null) {
        setupDrawerContent(navigationView);
    }
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    if (viewPager != null) {
        setupViewPager(viewPager);
    }
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Here's a Snackbar", Snackbar.LENGTH_LONG).setAction("Action", null).show();
        }
    });
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
}
Also used : NavigationView(android.support.design.widget.NavigationView) TabLayout(android.support.design.widget.TabLayout) FloatingActionButton(android.support.design.widget.FloatingActionButton) ViewPager(android.support.v4.view.ViewPager) NavigationView(android.support.design.widget.NavigationView) View(android.view.View) AdapterView(android.widget.AdapterView) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 63 with ViewPager

use of android.support.v4.view.ViewPager in project cw-omnibus by commonsguy.

the class PagerFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View result = inflater.inflate(R.layout.pager, container, false);
    ViewPager pager = (ViewPager) result.findViewById(R.id.pager);
    pager.setAdapter(buildAdapter());
    return (result);
}
Also used : View(android.view.View) ViewPager(android.support.v4.view.ViewPager)

Example 64 with ViewPager

use of android.support.v4.view.ViewPager in project materialistic by hidroh.

the class BaseListActivityLandTest method testScrollItemToTop.

@Config(shadows = ShadowRecyclerView.class)
@Test
public void testScrollItemToTop() {
    activity.onItemSelected(new TestHnItem(1L) {

        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }
    });
    TabLayout tabLayout = (TabLayout) activity.findViewById(R.id.tab_layout);
    assertThat(tabLayout.getTabCount()).isEqualTo(2);
    tabLayout.getTabAt(0).select();
    ViewPager viewPager = (ViewPager) activity.findViewById(R.id.content);
    viewPager.getAdapter().instantiateItem(viewPager, 0);
    viewPager.getAdapter().finishUpdate(viewPager);
    RecyclerView itemRecyclerView = (RecyclerView) viewPager.findViewById(R.id.recycler_view);
    itemRecyclerView.smoothScrollToPosition(1);
    assertThat(customShadowOf(itemRecyclerView).getScrollPosition()).isEqualTo(1);
    tabLayout.getTabAt(1).select();
    tabLayout.getTabAt(0).select();
    tabLayout.getTabAt(0).select();
    assertThat(customShadowOf(itemRecyclerView).getScrollPosition()).isEqualTo(0);
}
Also used : TabLayout(android.support.design.widget.TabLayout) NonNull(android.support.annotation.NonNull) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) ViewPager(android.support.v4.view.ViewPager) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Config(org.robolectric.annotation.Config)

Example 65 with ViewPager

use of android.support.v4.view.ViewPager in project materialistic by hidroh.

the class BaseListActivityLandTest method testDefaultReadabilityView.

@Test
public void testDefaultReadabilityView() {
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putString(activity.getString(R.string.pref_story_display), activity.getString(R.string.pref_story_display_value_readability)).apply();
    controller.pause().resume();
    activity.onItemSelected(new TestHnItem(1L) {

        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }
    });
    ViewPager viewPager = (ViewPager) activity.findViewById(R.id.content);
    viewPager.getAdapter().instantiateItem(viewPager, viewPager.getCurrentItem());
    assertStoryMode();
}
Also used : NonNull(android.support.annotation.NonNull) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) ViewPager(android.support.v4.view.ViewPager) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

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