Search in sources :

Example 11 with TabLayoutMediator

use of com.google.android.material.tabs.TabLayoutMediator in project quickstart-android by firebase.

the class MainFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    setHasOptionsMenu(true);
    // Create the adapter that will return a fragment for each section
    FragmentStateAdapter mPagerAdapter = new FragmentStateAdapter(getParentFragmentManager(), getViewLifecycleOwner().getLifecycle()) {

        private final Fragment[] mFragments = new Fragment[] { new RecentPostsFragment(), new MyPostsFragment(), new MyTopPostsFragment() };

        @NonNull
        @Override
        public Fragment createFragment(int position) {
            return mFragments[position];
        }

        @Override
        public int getItemCount() {
            return mFragments.length;
        }
    };
    // Set up the ViewPager with the sections adapter.
    binding.container.setAdapter(mPagerAdapter);
    String[] mFragmentNames = new String[] { getString(R.string.heading_recent), getString(R.string.heading_my_posts), getString(R.string.heading_my_top_posts) };
    new TabLayoutMediator(binding.tabs, binding.container, (tab, position) -> tab.setText(mFragmentNames[position])).attach();
}
Also used : MyTopPostsFragment(com.google.firebase.quickstart.database.java.listfragments.MyTopPostsFragment) Bundle(android.os.Bundle) MyPostsFragment(com.google.firebase.quickstart.database.java.listfragments.MyPostsFragment) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) ViewGroup(android.view.ViewGroup) MenuItem(android.view.MenuItem) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) Nullable(androidx.annotation.Nullable) MyTopPostsFragment(com.google.firebase.quickstart.database.java.listfragments.MyTopPostsFragment) R(com.google.firebase.quickstart.database.R) MenuInflater(android.view.MenuInflater) Menu(android.view.Menu) Fragment(androidx.fragment.app.Fragment) RecentPostsFragment(com.google.firebase.quickstart.database.java.listfragments.RecentPostsFragment) View(android.view.View) FragmentMainBinding(com.google.firebase.quickstart.database.databinding.FragmentMainBinding) NavHostFragment(androidx.navigation.fragment.NavHostFragment) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) FirebaseAuth(com.google.firebase.auth.FirebaseAuth) RecentPostsFragment(com.google.firebase.quickstart.database.java.listfragments.RecentPostsFragment) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) MyPostsFragment(com.google.firebase.quickstart.database.java.listfragments.MyPostsFragment)

Example 12 with TabLayoutMediator

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

the class QRCodeTabsActivity method setupViewPager.

private void setupViewPager() {
    fragmentTitleList = new String[] { getString(R.string.scan_qr_code_fragment_title), getString(R.string.view_qr_code_fragment_title) };
    ViewPager2 viewPager = findViewById(R.id.viewPager);
    TabLayout tabLayout = findViewById(R.id.tabLayout);
    QRCodeTabsAdapter adapter = new QRCodeTabsAdapter(this);
    viewPager.setAdapter(adapter);
    new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> tab.setText(fragmentTitleList[position])).attach();
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) Analytics(org.odk.collect.analytics.Analytics) AppBarUtils(org.odk.collect.androidshared.utils.AppBarUtils) Bundle(android.os.Bundle) TabLayout(com.google.android.material.tabs.TabLayout) Intent(android.content.Intent) ViewPager2(androidx.viewpager2.widget.ViewPager2) ODKAppSettingsImporter(org.odk.collect.settings.ODKAppSettingsImporter) PermissionListener(org.odk.collect.permissions.PermissionListener) MenuItem(android.view.MenuItem) FileProvider(org.odk.collect.android.utilities.FileProvider) Inject(javax.inject.Inject) DaggerUtils(org.odk.collect.android.injection.DaggerUtils) CurrentProjectProvider(org.odk.collect.android.projects.CurrentProjectProvider) CollectAbstractActivity(org.odk.collect.android.activities.CollectAbstractActivity) MultiClickGuard(org.odk.collect.androidshared.ui.multiclicksafe.MultiClickGuard) Menu(android.view.Menu) R(org.odk.collect.android.R) IntentLauncher(org.odk.collect.androidshared.system.IntentLauncher) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) Scheduler(org.odk.collect.async.Scheduler) TabLayout(com.google.android.material.tabs.TabLayout) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator)

Example 13 with TabLayoutMediator

use of com.google.android.material.tabs.TabLayoutMediator in project kdeconnect-android by KDE.

the class MprisActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ThemeUtil.setUserPreferredTheme(this);
    activityMprisBinding = ActivityMprisBinding.inflate(getLayoutInflater());
    setContentView(activityMprisBinding.getRoot());
    String deviceId = getIntent().getStringExtra(MprisPlugin.DEVICE_ID_KEY);
    mprisPagerAdapter = new MprisPagerAdapter(this, deviceId);
    activityMprisBinding.mprisPager.setAdapter(mprisPagerAdapter);
    TabLayoutMediator tabLayoutMediator = new TabLayoutMediator(activityMprisBinding.mprisTabs, activityMprisBinding.mprisPager, (tab, position) -> tab.setText(mprisPagerAdapter.getTitle(position)));
    activityMprisBinding.mprisTabs.getSelectedTabPosition();
    tabLayoutMediator.attach();
    setSupportActionBar(activityMprisBinding.toolbar);
    Objects.requireNonNull(getSupportActionBar()).setDisplayHomeAsUpEnabled(true);
}
Also used : TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator)

Example 14 with TabLayoutMediator

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

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)

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