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();
}
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();
}
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);
}
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();
}
}
Aggregations