Search in sources :

Example 16 with ViewPager2

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;
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) ViewGroup(android.view.ViewGroup) RecyclerView(androidx.recyclerview.widget.RecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 17 with ViewPager2

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;
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) View(android.view.View)

Example 18 with ViewPager2

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());
            }
        }
    });
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) Fragment(androidx.fragment.app.Fragment)

Example 19 with ViewPager2

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

Example 20 with ViewPager2

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());
}
Also used : ViewPagerTabs(de.schildbach.wallet.util.ViewPagerTabs) Address(org.bitcoinj.core.Address) FragmentManager(androidx.fragment.app.FragmentManager) ViewPager2(androidx.viewpager2.widget.ViewPager2) RecyclerView(androidx.recyclerview.widget.RecyclerView) ViewModelProvider(androidx.lifecycle.ViewModelProvider) ZoomOutPageTransformer(de.schildbach.wallet.util.ZoomOutPageTransformer)

Aggregations

ViewPager2 (androidx.viewpager2.widget.ViewPager2)23 View (android.view.View)9 NonNull (androidx.annotation.NonNull)9 Bundle (android.os.Bundle)8 Fragment (androidx.fragment.app.Fragment)8 TabLayout (com.google.android.material.tabs.TabLayout)8 RecyclerView (androidx.recyclerview.widget.RecyclerView)7 FragmentStateAdapter (androidx.viewpager2.adapter.FragmentStateAdapter)7 TabLayoutMediator (com.google.android.material.tabs.TabLayoutMediator)7 ViewGroup (android.view.ViewGroup)6 Context (android.content.Context)5 Toolbar (androidx.appcompat.widget.Toolbar)5 R (org.thoughtcrime.securesms.R)4 Intent (android.content.Intent)3 LayoutInflater (android.view.LayoutInflater)3 MenuItem (android.view.MenuItem)3 TextView (android.widget.TextView)3 MainActivity (de.danoeh.antennapod.activity.MainActivity)3 ColorMatrix (android.graphics.ColorMatrix)2 ColorMatrixColorFilter (android.graphics.ColorMatrixColorFilter)2