Search in sources :

Example 6 with TabLayoutMediator

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

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 7 with TabLayoutMediator

use of com.google.android.material.tabs.TabLayoutMediator in project nextcloud-notes by stefan-niedermann.

the class AboutActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    binding = ActivityAboutBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    setSupportActionBar(binding.toolbar);
    binding.pager.setAdapter(new TabsStateAdapter(this));
    // generate title based on given position
    new TabLayoutMediator(binding.tabs, binding.pager, (tab, position) -> {
        switch(position) {
            // Fall-through to credits tab
            default:
            case POS_CREDITS:
                tab.setText(R.string.about_credits_tab_title);
                break;
            case POS_CONTRIB:
                tab.setText(R.string.about_contribution_tab_title);
                break;
            case POS_LICENSE:
                tab.setText(R.string.about_license_tab_title);
                break;
        }
    }).attach();
}
Also used : Bundle(android.os.Bundle) LockedActivity(it.niedermann.owncloud.notes.LockedActivity) BrandingUtil(it.niedermann.owncloud.notes.branding.BrandingUtil) ActivityAboutBinding(it.niedermann.owncloud.notes.databinding.ActivityAboutBinding) NonNull(androidx.annotation.NonNull) R(it.niedermann.owncloud.notes.R) Fragment(androidx.fragment.app.Fragment) ColorInt(androidx.annotation.ColorInt) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) FragmentActivity(androidx.fragment.app.FragmentActivity) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator)

Example 8 with TabLayoutMediator

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

the class DownloadsFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View root = inflater.inflate(R.layout.pager_fragment, container, false);
    Toolbar toolbar = root.findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.downloads_label);
    toolbar.inflateMenu(R.menu.downloads);
    displayUpArrow = getParentFragmentManager().getBackStackEntryCount() != 0;
    if (savedInstanceState != null) {
        displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW);
    }
    ((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow);
    viewPager = root.findViewById(R.id.viewpager);
    viewPager.setAdapter(new DownloadsPagerAdapter(this));
    viewPager.setOffscreenPageLimit(2);
    super.setupPagedToolbar(toolbar, viewPager);
    // Give the TabLayout the ViewPager
    tabLayout = root.findViewById(R.id.sliding_tabs);
    new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
        switch(position) {
            case POS_COMPLETED:
                tab.setText(R.string.downloads_completed_label);
                break;
            case POS_LOG:
                tab.setText(R.string.downloads_log_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 root;
}
Also used : 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) Nullable(androidx.annotation.Nullable) 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 9 with TabLayoutMediator

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

the class StatisticsFragment method onCreateView.

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    setHasOptionsMenu(true);
    View rootView = inflater.inflate(R.layout.pager_fragment, container, false);
    viewPager = rootView.findViewById(R.id.viewpager);
    toolbar = rootView.findViewById(R.id.toolbar);
    viewPager.setAdapter(new StatisticsPagerAdapter(this));
    // Give the TabLayout the ViewPager
    tabLayout = rootView.findViewById(R.id.sliding_tabs);
    new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
        switch(position) {
            case POS_LISTENED_HOURS:
                tab.setText(R.string.playback_statistics_label);
                break;
            case POS_SPACE_TAKEN:
                tab.setText(R.string.download_statistics_label);
                break;
            default:
                break;
        }
    }).attach();
    if (getActivity().getClass() == PreferenceActivity.class) {
        rootView.findViewById(R.id.toolbar).setVisibility(View.GONE);
    } else {
        toolbar.setTitle(getString(R.string.statistics_label));
        toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack());
    }
    return rootView;
}
Also used : 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) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) View(android.view.View)

Example 10 with TabLayoutMediator

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

the class ContributorsPagerFragment method onCreateView.

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    setHasOptionsMenu(true);
    View rootView = inflater.inflate(R.layout.pager_fragment, container, false);
    ViewPager2 viewPager = rootView.findViewById(R.id.viewpager);
    viewPager.setAdapter(new StatisticsPagerAdapter(this));
    // Give the TabLayout the ViewPager
    TabLayout tabLayout = rootView.findViewById(R.id.sliding_tabs);
    new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
        switch(position) {
            case POS_DEVELOPERS:
                tab.setText(R.string.developers);
                break;
            case POS_TRANSLATORS:
                tab.setText(R.string.translators);
                break;
            case POS_SPECIAL_THANKS:
                tab.setText(R.string.special_thanks);
                break;
            default:
                break;
        }
    }).attach();
    rootView.findViewById(R.id.toolbar).setVisibility(View.GONE);
    return rootView;
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) Bundle(android.os.Bundle) PreferenceActivity(de.danoeh.antennapod.activity.PreferenceActivity) TabLayout(com.google.android.material.tabs.TabLayout) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) R(de.danoeh.antennapod.R) Fragment(androidx.fragment.app.Fragment) View(android.view.View) ViewPager2(androidx.viewpager2.widget.ViewPager2) ViewGroup(android.view.ViewGroup) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) TabLayout(com.google.android.material.tabs.TabLayout) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) View(android.view.View)

Aggregations

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