Search in sources :

Example 1 with TabLayoutMediator

use of com.google.android.material.tabs.TabLayoutMediator 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 2 with TabLayoutMediator

use of com.google.android.material.tabs.TabLayoutMediator 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)

Example 3 with TabLayoutMediator

use of com.google.android.material.tabs.TabLayoutMediator in project Signal-Android by WhisperSystems.

the class ReactionsBottomSheetDialogFragment method setUpTabMediator.

private void setUpTabMediator(@Nullable Bundle savedInstanceState) {
    if (savedInstanceState == null) {
        FrameLayout container = requireDialog().findViewById(R.id.container);
        LayoutInflater layoutInflater = LayoutInflater.from(requireContext());
        View statusBarShader = layoutInflater.inflate(R.layout.react_with_any_emoji_status_fade, container, false);
        TabLayout emojiTabs = (TabLayout) layoutInflater.inflate(R.layout.reactions_bottom_sheet_dialog_fragment_tabs, container, false);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewUtil.getStatusBarHeight(container));
        statusBarShader.setLayoutParams(params);
        container.addView(statusBarShader, 0);
        container.addView(emojiTabs);
        ViewCompat.setOnApplyWindowInsetsListener(container, (v, insets) -> insets.consumeSystemWindowInsets());
        new TabLayoutMediator(emojiTabs, recipientPagerView, (tab, position) -> {
            tab.setCustomView(R.layout.reactions_bottom_sheet_dialog_fragment_emoji_item);
            View customView = Objects.requireNonNull(tab.getCustomView());
            EmojiImageView emoji = customView.findViewById(R.id.reactions_bottom_view_emoji_item_emoji);
            TextView text = customView.findViewById(R.id.reactions_bottom_view_emoji_item_text);
            EmojiCount emojiCount = recipientsAdapter.getEmojiCount(position);
            if (position != 0) {
                emoji.setVisibility(View.VISIBLE);
                emoji.setImageEmoji(emojiCount.getDisplayEmoji());
                text.setText(String.valueOf(emojiCount.getCount()));
            } else {
                emoji.setVisibility(View.GONE);
                text.setText(customView.getContext().getString(R.string.ReactionsBottomSheetDialogFragment_all, emojiCount.getCount()));
            }
        }).attach();
    }
}
Also used : ViewCompat(androidx.core.view.ViewCompat) Context(android.content.Context) Bundle(android.os.Bundle) MessageId(org.thoughtcrime.securesms.database.model.MessageId) ViewModelProvider(androidx.lifecycle.ViewModelProvider) TabLayout(com.google.android.material.tabs.TabLayout) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) LifecycleDisposable(org.thoughtcrime.securesms.util.LifecycleDisposable) FrameLayout(android.widget.FrameLayout) ViewPager2(androidx.viewpager2.widget.ViewPager2) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) EmojiImageView(org.thoughtcrime.securesms.components.emoji.EmojiImageView) R(org.thoughtcrime.securesms.R) ViewGroup(android.view.ViewGroup) Objects(java.util.Objects) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ThemeUtil(org.thoughtcrime.securesms.util.ThemeUtil) BottomSheetDialogFragment(com.google.android.material.bottomsheet.BottomSheetDialogFragment) View(android.view.View) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) DialogInterface(android.content.DialogInterface) DialogFragment(androidx.fragment.app.DialogFragment) TabLayout(com.google.android.material.tabs.TabLayout) ViewGroup(android.view.ViewGroup) FrameLayout(android.widget.FrameLayout) LayoutInflater(android.view.LayoutInflater) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) TextView(android.widget.TextView) EmojiImageView(org.thoughtcrime.securesms.components.emoji.EmojiImageView) TextView(android.widget.TextView) View(android.view.View) EmojiImageView(org.thoughtcrime.securesms.components.emoji.EmojiImageView)

Example 4 with TabLayoutMediator

use of com.google.android.material.tabs.TabLayoutMediator in project Signal-Android by WhisperSystems.

the class ManagePendingAndRequestingMembersActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState, boolean ready) {
    super.onCreate(savedInstanceState, ready);
    setContentView(R.layout.group_pending_and_requesting_member_activity);
    if (savedInstanceState == null) {
        GroupId.V2 groupId = GroupId.parseOrThrow(getIntent().getStringExtra(GROUP_ID)).requireV2();
        ViewPager2 viewPager = findViewById(R.id.pending_and_requesting_pager);
        TabLayout tabLayout = findViewById(R.id.pending_and_requesting_tabs);
        viewPager.setAdapter(new ViewPagerAdapter(this, groupId));
        new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
            switch(position) {
                case 0:
                    tab.setText(R.string.PendingMembersActivity_requests);
                    break;
                case 1:
                    tab.setText(R.string.PendingMembersActivity_invites);
                    break;
                default:
                    throw new AssertionError();
            }
        }).attach();
    }
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    requireSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) Context(android.content.Context) Bundle(android.os.Bundle) TabLayout(com.google.android.material.tabs.TabLayout) PendingMemberInvitesFragment(org.thoughtcrime.securesms.groups.ui.invitesandrequests.invited.PendingMemberInvitesFragment) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent) ViewPager2(androidx.viewpager2.widget.ViewPager2) RequestingMembersFragment(org.thoughtcrime.securesms.groups.ui.invitesandrequests.requesting.RequestingMembersFragment) R(org.thoughtcrime.securesms.R) FragmentActivity(androidx.fragment.app.FragmentActivity) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) DynamicTheme(org.thoughtcrime.securesms.util.DynamicTheme) PassphraseRequiredActivity(org.thoughtcrime.securesms.PassphraseRequiredActivity) DynamicNoActionBarTheme(org.thoughtcrime.securesms.util.DynamicNoActionBarTheme) Fragment(androidx.fragment.app.Fragment) GroupId(org.thoughtcrime.securesms.groups.GroupId) Toolbar(androidx.appcompat.widget.Toolbar) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) TabLayout(com.google.android.material.tabs.TabLayout) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) GroupId(org.thoughtcrime.securesms.groups.GroupId) Toolbar(androidx.appcompat.widget.Toolbar)

Example 5 with TabLayoutMediator

use of com.google.android.material.tabs.TabLayoutMediator in project collect by opendatakit.

the class DeleteSavedFormActivity method setUpViewPager.

private void setUpViewPager() {
    String[] tabNames = { getString(R.string.data), getString(R.string.forms) };
    ViewPager2 viewPager = findViewById(R.id.viewPager);
    TabLayout tabLayout = findViewById(R.id.tabLayout);
    viewPager.setAdapter(new DeleteFormsTabsAdapter(this, viewModel.isMatchExactlyEnabled()));
    new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> tab.setText(tabNames[position])).attach();
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) BlankFormsListViewModel(org.odk.collect.android.formmanagement.BlankFormsListViewModel) AppBarUtils(org.odk.collect.androidshared.utils.AppBarUtils) Bundle(android.os.Bundle) ViewModelProvider(androidx.lifecycle.ViewModelProvider) TabLayout(com.google.android.material.tabs.TabLayout) ViewPager2(androidx.viewpager2.widget.ViewPager2) DeleteFormsTabsAdapter(org.odk.collect.android.adapters.DeleteFormsTabsAdapter) Inject(javax.inject.Inject) DaggerUtils(org.odk.collect.android.injection.DaggerUtils) Configuration(android.content.res.Configuration) R(org.odk.collect.android.R) Toolbar(androidx.appcompat.widget.Toolbar) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) TabLayout(com.google.android.material.tabs.TabLayout) DeleteFormsTabsAdapter(org.odk.collect.android.adapters.DeleteFormsTabsAdapter) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator)

Aggregations

TabLayoutMediator (com.google.android.material.tabs.TabLayoutMediator)11 Bundle (android.os.Bundle)10 ViewPager2 (androidx.viewpager2.widget.ViewPager2)9 TabLayout (com.google.android.material.tabs.TabLayout)9 NonNull (androidx.annotation.NonNull)8 LayoutInflater (android.view.LayoutInflater)7 View (android.view.View)7 ViewGroup (android.view.ViewGroup)7 Fragment (androidx.fragment.app.Fragment)7 FragmentStateAdapter (androidx.viewpager2.adapter.FragmentStateAdapter)7 Toolbar (androidx.appcompat.widget.Toolbar)6 R (de.danoeh.antennapod.R)5 Context (android.content.Context)4 MenuItem (android.view.MenuItem)3 Nullable (androidx.annotation.Nullable)3 MainActivity (de.danoeh.antennapod.activity.MainActivity)3 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 Menu (android.view.Menu)2 ViewModelProvider (androidx.lifecycle.ViewModelProvider)2