Search in sources :

Example 1 with TabLayout

use of com.google.android.material.tabs.TabLayout in project Timber by naman14.

the class MainFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_main, container, false);
    Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
    ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
    final ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar();
    ab.setHomeAsUpIndicator(R.drawable.ic_menu);
    ab.setDisplayHomeAsUpEnabled(true);
    viewPager = (ViewPager) rootView.findViewById(R.id.viewpager);
    if (viewPager != null) {
        setupViewPager(viewPager);
        viewPager.setOffscreenPageLimit(2);
    }
    TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.tabs);
    tabLayout.setupWithViewPager(viewPager);
    return rootView;
}
Also used : TabLayout(com.google.android.material.tabs.TabLayout) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) View(android.view.View) ActionBar(androidx.appcompat.app.ActionBar) Toolbar(androidx.appcompat.widget.Toolbar)

Example 2 with TabLayout

use of com.google.android.material.tabs.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(com.google.android.material.tabs.TabLayout) Preferences(io.github.hidroh.materialistic.Preferences)

Example 3 with TabLayout

use of com.google.android.material.tabs.TabLayout in project materialistic by hidroh.

the class UserActivity method onCreate.

@SuppressWarnings("ConstantConditions")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mUsername = getIntent().getStringExtra(EXTRA_USERNAME);
    if (TextUtils.isEmpty(mUsername)) {
        mUsername = AppUtils.getDataUriId(getIntent(), PARAM_ID);
    }
    if (TextUtils.isEmpty(mUsername)) {
        finish();
        return;
    }
    setTaskTitle(mUsername);
    AppUtils.setStatusBarDim(getWindow(), true);
    setContentView(R.layout.activity_user);
    findViewById(R.id.touch_outside).setOnClickListener(v -> finish());
    mBottomSheetBehavior = BottomSheetBehavior.from(findViewById(R.id.bottom_sheet));
    mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {

        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
            switch(newState) {
                case BottomSheetBehavior.STATE_HIDDEN:
                    finish();
                    break;
                case BottomSheetBehavior.STATE_EXPANDED:
                    AppUtils.setStatusBarDim(getWindow(), false);
                    mRecyclerView.setLayoutFrozen(false);
                    break;
                case BottomSheetBehavior.STATE_COLLAPSED:
                case BottomSheetBehavior.STATE_DRAGGING:
                case BottomSheetBehavior.STATE_HALF_EXPANDED:
                case BottomSheetBehavior.STATE_SETTLING:
                default:
                    AppUtils.setStatusBarDim(getWindow(), true);
                    break;
            }
        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        // no op
        }
    });
    mTitle = (TextView) findViewById(R.id.title);
    mTitle.setText(mUsername);
    mInfo = (TextView) findViewById(R.id.user_info);
    mAbout = (TextView) findViewById(R.id.about);
    mEmpty = findViewById(R.id.empty);
    mTabLayout = (TabLayout) findViewById(R.id.tab_layout);
    mTabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {

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

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

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
            scrollToTop();
        }
    });
    mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(new SnappyLinearLayoutManager(this, true));
    mRecyclerView.addItemDecoration(new CommentItemDecoration(this));
    mScrollableHelper = new KeyDelegate.RecyclerViewHelper(mRecyclerView, KeyDelegate.RecyclerViewHelper.SCROLL_ITEM);
    if (savedInstanceState != null) {
        mUser = savedInstanceState.getParcelable(STATE_USER);
    }
    if (mUser == null) {
        load();
    } else {
        bind();
    }
    if (!AppUtils.hasConnection(this)) {
        Snackbar.make(findViewById(R.id.content_frame), R.string.offline_notice, Snackbar.LENGTH_LONG).show();
    }
}
Also used : CommentItemDecoration(io.github.hidroh.materialistic.widget.CommentItemDecoration) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) BottomSheetBehavior(com.google.android.material.bottomsheet.BottomSheetBehavior) TabLayout(com.google.android.material.tabs.TabLayout) SnappyLinearLayoutManager(io.github.hidroh.materialistic.widget.SnappyLinearLayoutManager)

Example 4 with TabLayout

use of com.google.android.material.tabs.TabLayout in project AntennaPod by AntennaPod.

the class GpodnetMainFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View root = inflater.inflate(R.layout.pager_fragment, container, false);
    setupToolbar(root.findViewById(R.id.toolbar));
    ViewPager2 viewPager = root.findViewById(R.id.viewpager);
    GpodnetPagerAdapter pagerAdapter = new GpodnetPagerAdapter(this);
    viewPager.setAdapter(pagerAdapter);
    // Give the TabLayout the ViewPager
    TabLayout tabLayout = root.findViewById(R.id.sliding_tabs);
    new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
        switch(position) {
            case POS_TAGS:
                tab.setText(R.string.gpodnet_taglist_header);
                break;
            // Fall-through
            case POS_TOPLIST:
            default:
                tab.setText(R.string.gpodnet_toplist_header);
                break;
        }
    }).attach();
    return root;
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) Bundle(android.os.Bundle) TabLayout(com.google.android.material.tabs.TabLayout) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) R(de.danoeh.antennapod.R) OnlineSearchFragment(de.danoeh.antennapod.fragment.OnlineSearchFragment) ViewPager2(androidx.viewpager2.widget.ViewPager2) SearchView(androidx.appcompat.widget.SearchView) ViewGroup(android.view.ViewGroup) MenuItem(android.view.MenuItem) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) MainActivity(de.danoeh.antennapod.activity.MainActivity) GpodnetPodcastSearcher(de.danoeh.antennapod.discovery.GpodnetPodcastSearcher) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar) Activity(android.app.Activity) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) TabLayout(com.google.android.material.tabs.TabLayout) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) SearchView(androidx.appcompat.widget.SearchView) View(android.view.View)

Example 5 with TabLayout

use of com.google.android.material.tabs.TabLayout in project AntennaPod by AntennaPod.

the class EpisodesFragment method onCreateView.

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View rootView = inflater.inflate(R.layout.pager_fragment, container, false);
    Toolbar toolbar = rootView.findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.episodes_label);
    toolbar.inflateMenu(R.menu.episodes);
    displayUpArrow = getParentFragmentManager().getBackStackEntryCount() != 0;
    if (savedInstanceState != null) {
        displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW);
    }
    ((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow);
    ViewPager2 viewPager = rootView.findViewById(R.id.viewpager);
    viewPager.setAdapter(new EpisodesPagerAdapter(this));
    viewPager.setOffscreenPageLimit(2);
    super.setupPagedToolbar(toolbar, viewPager);
    // Give the TabLayout the ViewPager
    tabLayout = rootView.findViewById(R.id.sliding_tabs);
    new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
        switch(position) {
            case POS_NEW_EPISODES:
                tab.setText(R.string.new_episodes_label);
                break;
            case POS_ALL_EPISODES:
                tab.setText(R.string.all_episodes_short_label);
                break;
            case POS_FAV_EPISODES:
                tab.setText(R.string.favorite_episodes_label);
                break;
            default:
                break;
        }
    }).attach();
    // restore our last position
    SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE);
    int lastPosition = prefs.getInt(PREF_LAST_TAB_POSITION, 0);
    viewPager.setCurrentItem(lastPosition, false);
    return rootView;
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) Context(android.content.Context) Bundle(android.os.Bundle) TabLayout(com.google.android.material.tabs.TabLayout) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) R(de.danoeh.antennapod.R) ViewPager2(androidx.viewpager2.widget.ViewPager2) ViewGroup(android.view.ViewGroup) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) MainActivity(de.danoeh.antennapod.activity.MainActivity) SharedPreferences(android.content.SharedPreferences) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) SharedPreferences(android.content.SharedPreferences) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) MainActivity(de.danoeh.antennapod.activity.MainActivity) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar)

Aggregations

TabLayout (com.google.android.material.tabs.TabLayout)25 View (android.view.View)14 Bundle (android.os.Bundle)10 Toolbar (androidx.appcompat.widget.Toolbar)10 NonNull (androidx.annotation.NonNull)9 ViewPager2 (androidx.viewpager2.widget.ViewPager2)9 TabLayoutMediator (com.google.android.material.tabs.TabLayoutMediator)9 Intent (android.content.Intent)7 LayoutInflater (android.view.LayoutInflater)7 ViewGroup (android.view.ViewGroup)7 Fragment (androidx.fragment.app.Fragment)7 TextView (android.widget.TextView)6 FragmentStateAdapter (androidx.viewpager2.adapter.FragmentStateAdapter)6 ViewPager (androidx.viewpager.widget.ViewPager)5 R (de.danoeh.antennapod.R)5 Context (android.content.Context)4 SharedPreferences (android.content.SharedPreferences)3 MenuItem (android.view.MenuItem)3 ImageView (android.widget.ImageView)3 Nullable (androidx.annotation.Nullable)3