Search in sources :

Example 21 with ViewPager2

use of androidx.viewpager2.widget.ViewPager2 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 22 with ViewPager2

use of androidx.viewpager2.widget.ViewPager2 in project banner by youth5201314.

the class ScrollSpeedManger method reflectLayoutManager.

public static void reflectLayoutManager(Banner banner) {
    if (banner.getScrollTime() < 100)
        return;
    try {
        ViewPager2 viewPager2 = banner.getViewPager2();
        RecyclerView recyclerView = (RecyclerView) viewPager2.getChildAt(0);
        recyclerView.setOverScrollMode(RecyclerView.OVER_SCROLL_NEVER);
        ScrollSpeedManger speedManger = new ScrollSpeedManger(banner, (LinearLayoutManager) recyclerView.getLayoutManager());
        recyclerView.setLayoutManager(speedManger);
        Field LayoutMangerField = ViewPager2.class.getDeclaredField("mLayoutManager");
        LayoutMangerField.setAccessible(true);
        LayoutMangerField.set(viewPager2, speedManger);
        Field pageTransformerAdapterField = ViewPager2.class.getDeclaredField("mPageTransformerAdapter");
        pageTransformerAdapterField.setAccessible(true);
        Object mPageTransformerAdapter = pageTransformerAdapterField.get(viewPager2);
        if (mPageTransformerAdapter != null) {
            Class<?> aClass = mPageTransformerAdapter.getClass();
            Field layoutManager = aClass.getDeclaredField("mLayoutManager");
            layoutManager.setAccessible(true);
            layoutManager.set(mPageTransformerAdapter, speedManger);
        }
        Field scrollEventAdapterField = ViewPager2.class.getDeclaredField("mScrollEventAdapter");
        scrollEventAdapterField.setAccessible(true);
        Object mScrollEventAdapter = scrollEventAdapterField.get(viewPager2);
        if (mScrollEventAdapter != null) {
            Class<?> aClass = mScrollEventAdapter.getClass();
            Field layoutManager = aClass.getDeclaredField("mLayoutManager");
            layoutManager.setAccessible(true);
            layoutManager.set(mScrollEventAdapter, speedManger);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) Field(java.lang.reflect.Field) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 23 with ViewPager2

use of androidx.viewpager2.widget.ViewPager2 in project banner by youth5201314.

the class MZScaleInTransformer method requireViewPager.

private ViewPager2 requireViewPager(@NonNull View page) {
    ViewParent parent = page.getParent();
    ViewParent parentParent = parent.getParent();
    if (parent instanceof RecyclerView && parentParent instanceof ViewPager2) {
        return (ViewPager2) parentParent;
    }
    throw new IllegalStateException("Expected the page view to be managed by a ViewPager2 instance.");
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) ViewParent(android.view.ViewParent) RecyclerView(androidx.recyclerview.widget.RecyclerView)

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