Search in sources :

Example 1 with ZoomOutPageTransformer

use of de.schildbach.wallet.util.ZoomOutPageTransformer in project bitcoin-wallet by bitcoin-wallet.

the class NetworkMonitorActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.network_monitor_content);
    final ViewPager2 pager = findViewById(R.id.network_monitor_pager);
    final ViewPagerTabs pagerTabs = findViewById(R.id.network_monitor_pager_tabs);
    pagerTabs.addTabLabels(TAB_LABELS);
    final boolean twoPanes = getResources().getBoolean(R.bool.network_monitor_two_panes);
    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 PagerAdapter());
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) ViewPagerTabs(de.schildbach.wallet.util.ViewPagerTabs) RecyclerView(androidx.recyclerview.widget.RecyclerView) ZoomOutPageTransformer(de.schildbach.wallet.util.ZoomOutPageTransformer)

Example 2 with ZoomOutPageTransformer

use of de.schildbach.wallet.util.ZoomOutPageTransformer 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

RecyclerView (androidx.recyclerview.widget.RecyclerView)2 ViewPager2 (androidx.viewpager2.widget.ViewPager2)2 ViewPagerTabs (de.schildbach.wallet.util.ViewPagerTabs)2 ZoomOutPageTransformer (de.schildbach.wallet.util.ZoomOutPageTransformer)2 FragmentManager (androidx.fragment.app.FragmentManager)1 ViewModelProvider (androidx.lifecycle.ViewModelProvider)1 Address (org.bitcoinj.core.Address)1