use of androidx.viewpager2.widget.ViewPager2 in project AntennaPod by AntennaPod.
the class ViewPagerBottomSheetBehavior method findScrollingChild.
@Override
View findScrollingChild(View view) {
if (ViewCompat.isNestedScrollingEnabled(view)) {
return view;
}
if (view instanceof ViewPager2) {
ViewPager2 viewPager = (ViewPager2) view;
RecyclerView recycler = (RecyclerView) viewPager.getChildAt(0);
View currentViewPagerChild = recycler.getChildAt(viewPager.getCurrentItem());
if (currentViewPagerChild != null) {
return findScrollingChild(currentViewPagerChild);
}
} else if (view instanceof ViewGroup) {
ViewGroup group = (ViewGroup) view;
for (int i = 0, count = group.getChildCount(); i < count; i++) {
View scrollingChild = findScrollingChild(group.getChildAt(i));
if (scrollingChild != null) {
return scrollingChild;
}
}
}
return null;
}
use of androidx.viewpager2.widget.ViewPager2 in project AntennaPod by AntennaPod.
the class ItemPagerFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View layout = inflater.inflate(R.layout.feeditem_pager_fragment, container, false);
toolbar = layout.findViewById(R.id.toolbar);
toolbar.setTitle("");
toolbar.inflateMenu(R.menu.feeditem_options);
toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack());
toolbar.setOnMenuItemClickListener(this);
feedItems = getArguments().getLongArray(ARG_FEEDITEMS);
int feedItemPos = getArguments().getInt(ARG_FEEDITEM_POS);
pager = layout.findViewById(R.id.pager);
// FragmentStatePagerAdapter documentation:
// > When using FragmentStatePagerAdapter the host ViewPager must have a valid ID set.
// When opening multiple ItemPagerFragments by clicking "item" -> "visit podcast" -> "item" -> etc,
// the ID is no longer unique and FragmentStatePagerAdapter does not display any pages.
int newId = View.generateViewId();
if (savedInstanceState != null && savedInstanceState.getInt(KEY_PAGER_ID, 0) != 0) {
// Restore state by using the same ID as before. ID collisions are prevented in MainActivity.
newId = savedInstanceState.getInt(KEY_PAGER_ID, 0);
}
pager.setId(newId);
pager.setAdapter(new ItemPagerAdapter(this));
pager.setCurrentItem(feedItemPos, false);
pager.setOffscreenPageLimit(1);
loadItem(feedItems[feedItemPos]);
pager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
loadItem(feedItems[position]);
}
});
EventBus.getDefault().register(this);
return layout;
}
use of androidx.viewpager2.widget.ViewPager2 in project AntennaPod by AntennaPod.
the class PagedToolbarFragment method setupPagedToolbar.
protected void setupPagedToolbar(Toolbar toolbar, ViewPager2 viewPager) {
this.toolbar = toolbar;
this.viewPager = viewPager;
toolbar.setOnMenuItemClickListener(item -> {
Fragment child = getChildFragmentManager().findFragmentByTag("f" + viewPager.getCurrentItem());
if (child != null) {
return child.onOptionsItemSelected(item);
}
return false;
});
viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {
@Override
public void onPageSelected(int position) {
Fragment child = getChildFragmentManager().findFragmentByTag("f" + position);
if (child != null) {
child.onPrepareOptionsMenu(toolbar.getMenu());
}
}
});
}
use of androidx.viewpager2.widget.ViewPager2 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;
}
use of androidx.viewpager2.widget.ViewPager2 in project bitcoin-wallet by bitcoin-wallet.
the class AddressBookActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final FragmentManager fragmentManager = getSupportFragmentManager();
setContentView(R.layout.address_book_content);
final ViewPager2 pager = findViewById(R.id.address_book_pager);
final ViewPagerTabs pagerTabs = findViewById(R.id.address_book_pager_tabs);
pagerTabs.addTabLabels(TAB_LABELS);
final boolean twoPanes = getResources().getBoolean(R.bool.address_book_two_panes);
walletActivityViewModel = new ViewModelProvider(this).get(AbstractWalletActivityViewModel.class);
walletActivityViewModel.wallet.observe(this, wallet -> invalidateOptionsMenu());
viewModel = new ViewModelProvider(this).get(AddressBookViewModel.class);
viewModel.pageTo.observe(this, new Event.Observer<Integer>() {
@Override
protected void onEvent(final Integer position) {
if (!twoPanes)
pager.setCurrentItem(position, true);
}
});
viewModel.showEditAddressBookEntryDialog.observe(this, new Event.Observer<Address>() {
@Override
protected void onEvent(final Address address) {
EditAddressBookEntryFragment.edit(fragmentManager, address);
}
});
viewModel.showScanOwnAddressDialog.observe(this, new Event.Observer<Void>() {
@Override
protected void onEvent(final Void v) {
final DialogBuilder dialog = DialogBuilder.dialog(AddressBookActivity.this, R.string.address_book_options_scan_title, R.string.address_book_options_scan_own_address);
dialog.singleDismissButton(null);
dialog.show();
}
});
viewModel.showScanInvalidDialog.observe(this, new Event.Observer<Void>() {
@Override
protected void onEvent(final Void v) {
final DialogBuilder dialog = DialogBuilder.dialog(AddressBookActivity.this, R.string.address_book_options_scan_title, R.string.address_book_options_scan_invalid);
dialog.singleDismissButton(null);
dialog.show();
}
});
if (twoPanes) {
final RecyclerView recyclerView = (RecyclerView) pager.getChildAt(0);
recyclerView.setClipToPadding(false);
recyclerView.getViewTreeObserver().addOnGlobalLayoutListener(() -> {
final int width = recyclerView.getWidth();
recyclerView.setPadding(0, 0, width / 2, 0);
pager.setCurrentItem(0);
});
pager.setUserInputEnabled(false);
pagerTabs.setMode(ViewPagerTabs.Mode.STATIC);
} else {
pager.setPageTransformer(new ZoomOutPageTransformer());
pager.registerOnPageChangeCallback(pagerTabs.getPageChangeCallback());
pagerTabs.setMode(ViewPagerTabs.Mode.DYNAMIC);
}
pager.setOffscreenPageLimit(1);
pager.setAdapter(new AddressBookActivity.PagerAdapter());
}
Aggregations