Search in sources :

Example 11 with TabLayout

use of android.support.design.widget.TabLayout in project ZhihuDailyPurify by izzyleung.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    layoutResID = R.layout.activity_main;
    super.onCreate(savedInstanceState);
    TabLayout tabs = (TabLayout) findViewById(R.id.main_pager_tabs);
    ViewPager viewPager = (ViewPager) findViewById(R.id.main_pager);
    assert tabs != null;
    assert viewPager != null;
    viewPager.setOffscreenPageLimit(PAGE_COUNT);
    MainPagerAdapter adapter = new MainPagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(adapter);
    tabs.setupWithViewPager(viewPager);
    FloatingActionButton floatingActionButton = (FloatingActionButton) findViewById(R.id.fab_pick_date);
    assert floatingActionButton != null;
    floatingActionButton.setOnClickListener(v -> prepareIntent(PickDateActivity.class));
}
Also used : TabLayout(android.support.design.widget.TabLayout) FloatingActionButton(android.support.design.widget.FloatingActionButton) ViewPager(android.support.v4.view.ViewPager)

Example 12 with TabLayout

use of android.support.design.widget.TabLayout in project chuck by jgilfelt.

the class TransactionActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.chuck_activity_transaction);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    title = (TextView) findViewById(R.id.toolbar_title);
    final ActionBar ab = getSupportActionBar();
    ab.setDisplayHomeAsUpEnabled(true);
    ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
    if (viewPager != null) {
        setupViewPager(viewPager);
    }
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
    transactionId = getIntent().getLongExtra(ARG_TRANSACTION_ID, 0);
    getSupportLoaderManager().initLoader(0, null, this);
}
Also used : TabLayout(android.support.design.widget.TabLayout) ViewPager(android.support.v4.view.ViewPager) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 13 with TabLayout

use of android.support.design.widget.TabLayout in project materialistic by hidroh.

the class ItemActivityTest method testScrollToTop.

@Config(shadows = ShadowRecyclerView.class)
@Test
public void testScrollToTop() {
    Intent intent = new Intent();
    intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {

        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }

        @Override
        public String getId() {
            return "1";
        }

        @Override
        public boolean isStoryType() {
            return true;
        }

        @Override
        public int getKidCount() {
            return 10;
        }

        @Override
        public String getUrl() {
            return "http://example.com";
        }
    });
    controller.withIntent(intent).create().start().resume();
    // see https://github.com/robolectric/robolectric/issues/1326
    ShadowLooper.pauseMainLooper();
    controller.visible();
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
    RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view);
    recyclerView.smoothScrollToPosition(1);
    assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(1);
    TabLayout tabLayout = (TabLayout) activity.findViewById(R.id.tab_layout);
    assertThat(tabLayout.getTabCount()).isEqualTo(2);
    tabLayout.getTabAt(1).select();
    tabLayout.getTabAt(0).select();
    tabLayout.getTabAt(0).select();
    assertThat(customShadowOf(recyclerView).getScrollPosition()).isEqualTo(0);
}
Also used : TabLayout(android.support.design.widget.TabLayout) NonNull(android.support.annotation.NonNull) Intent(android.content.Intent) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) TestItem(io.github.hidroh.materialistic.test.TestItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 14 with TabLayout

use of android.support.design.widget.TabLayout in project materialistic by hidroh.

the class HelpLazyLoadView method onFinishInflate.

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    tabLayout.addTab(tabLayout.newTab().setText(R.string.comments));
    tabLayout.addTab(tabLayout.newTab().setText(R.string.article));
    Preferences.StoryViewMode defaultView = Preferences.getDefaultStoryView(getContext());
    int defaultTab;
    switch(defaultView) {
        case Comment:
        default:
            defaultTab = 0;
            break;
        case Article:
        case Readability:
            defaultTab = 1;
            break;
    }
    //noinspection ConstantConditions
    tabLayout.getTabAt(defaultTab).select();
}
Also used : TabLayout(android.support.design.widget.TabLayout) Preferences(io.github.hidroh.materialistic.Preferences)

Example 15 with TabLayout

use of android.support.design.widget.TabLayout 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)

Aggregations

TabLayout (android.support.design.widget.TabLayout)75 View (android.view.View)33 ViewPager (android.support.v4.view.ViewPager)28 Toolbar (android.support.v7.widget.Toolbar)17 TextView (android.widget.TextView)13 Intent (android.content.Intent)12 ActionBar (android.support.v7.app.ActionBar)10 RecyclerView (android.support.v7.widget.RecyclerView)10 Fragment (android.support.v4.app.Fragment)8 ImageView (android.widget.ImageView)8 Test (org.junit.Test)8 FloatingActionButton (android.support.design.widget.FloatingActionButton)7 UiController (android.support.test.espresso.UiController)7 ViewAction (android.support.test.espresso.ViewAction)7 AppBarLayout (android.support.design.widget.AppBarLayout)6 NavigationView (android.support.design.widget.NavigationView)6 ViewGroup (android.view.ViewGroup)6 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)5 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)5 PagerAdapter (android.support.v4.view.PagerAdapter)4