Search in sources :

Example 1 with ViewPager2

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

the class Banner method init.

private void init(Context context) {
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop() / 2;
    mCompositePageTransformer = new CompositePageTransformer();
    mPageChangeCallback = new BannerOnPageChangeCallback();
    mLoopTask = new AutoLoopTask(this);
    mViewPager2 = new ViewPager2(context);
    mViewPager2.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    mViewPager2.setOffscreenPageLimit(2);
    mViewPager2.registerOnPageChangeCallback(mPageChangeCallback);
    mViewPager2.setPageTransformer(mCompositePageTransformer);
    ScrollSpeedManger.reflectLayoutManager(this);
    addView(mViewPager2);
    mRoundPaint = new Paint();
    mRoundPaint.setColor(Color.WHITE);
    mRoundPaint.setAntiAlias(true);
    mRoundPaint.setStyle(Paint.Style.FILL);
    mRoundPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
    mImagePaint = new Paint();
    mImagePaint.setXfermode(null);
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) PorterDuffXfermode(android.graphics.PorterDuffXfermode) CompositePageTransformer(androidx.viewpager2.widget.CompositePageTransformer) Paint(android.graphics.Paint)

Example 2 with ViewPager2

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

the class Vp2FragmentRecyclerviewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_vp2_fragment_recyclerview);
    ButterKnife.bind(this);
    viewPager2.setAdapter(new FragmentStateAdapter(this) {

        @NonNull
        @Override
        public Fragment createFragment(int position) {
            if (position == 0) {
                return BannerListFragment.newInstance(position);
            } else if (position == 1) {
                return BlankFragment.newInstance();
            } else {
                return BannerFragment.newInstance();
            }
        }

        @Override
        public int getItemCount() {
            return 3;
        }
    });
    new TabLayoutMediator(mTabLayout, viewPager2, (tab, position) -> {
        tab.setText("页面" + position);
    }).attach();
    mBanner.addBannerLifecycleObserver(this).setAdapter(new ImageAdapter(DataBean.getTestData())).setIntercept(false).setIndicator(new CircleIndicator(this));
}
Also used : R(com.test.banner.R) Bundle(android.os.Bundle) TabLayout(com.google.android.material.tabs.TabLayout) ButterKnife(butterknife.ButterKnife) NonNull(androidx.annotation.NonNull) TabLayoutMediator(com.test.banner.util.TabLayoutMediator) CircleIndicator(com.youth.banner.indicator.CircleIndicator) ViewPager2(androidx.viewpager2.widget.ViewPager2) AppCompatActivity(androidx.appcompat.app.AppCompatActivity) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) BindView(butterknife.BindView) DataBean(com.test.banner.bean.DataBean) Fragment(androidx.fragment.app.Fragment) Banner(com.youth.banner.Banner) ImageAdapter(com.test.banner.adapter.ImageAdapter) ImageAdapter(com.test.banner.adapter.ImageAdapter) NonNull(androidx.annotation.NonNull) CircleIndicator(com.youth.banner.indicator.CircleIndicator) TabLayoutMediator(com.test.banner.util.TabLayoutMediator) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) Fragment(androidx.fragment.app.Fragment)

Example 3 with ViewPager2

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

the class MZScaleInTransformer method transformPage.

@Override
public void transformPage(@NonNull View view, float position) {
    ViewPager2 viewPager = requireViewPager(view);
    float paddingLeft = viewPager.getPaddingLeft();
    float paddingRight = viewPager.getPaddingRight();
    float width = viewPager.getMeasuredWidth();
    float offsetPosition = paddingLeft / (width - paddingLeft - paddingRight);
    float currentPos = position - offsetPosition;
    float reduceX = 0;
    float itemWidth = view.getWidth();
    // 由于左右边的缩小而减小的x的大小的一半
    reduceX = (1.0f - mMinScale) * itemWidth / 2.0f;
    if (currentPos <= -1.0f) {
        view.setTranslationX(reduceX);
        view.setScaleX(mMinScale);
        view.setScaleY(mMinScale);
    } else if (currentPos <= 1.0) {
        float scale = (1.0f - mMinScale) * Math.abs(1.0f - Math.abs(currentPos));
        float translationX = currentPos * -reduceX;
        if (currentPos <= -0.5) {
            // 两个view中间的临界,这时两个view在同一层,左侧View需要往X轴正方向移动覆盖的值()
            view.setTranslationX(translationX + Math.abs(Math.abs(currentPos) - 0.5f) / 0.5f);
        } else if (currentPos <= 0.0f) {
            view.setTranslationX(translationX);
        } else if (currentPos >= 0.5) {
            // 两个view中间的临界,这时两个view在同一层
            view.setTranslationX(translationX - Math.abs(Math.abs(currentPos) - 0.5f) / 0.5f);
        } else {
            view.setTranslationX(translationX);
        }
        view.setScaleX(scale + mMinScale);
        view.setScaleY(scale + mMinScale);
    } else {
        view.setScaleX(mMinScale);
        view.setScaleY(mMinScale);
        view.setTranslationX(-reduceX);
    }
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2)

Example 4 with ViewPager2

use of androidx.viewpager2.widget.ViewPager2 in project AntennaPod by AntennaPod.

the class GpodnetMainFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View root = inflater.inflate(R.layout.pager_fragment, container, false);
    setupToolbar(root.findViewById(R.id.toolbar));
    ViewPager2 viewPager = root.findViewById(R.id.viewpager);
    GpodnetPagerAdapter pagerAdapter = new GpodnetPagerAdapter(this);
    viewPager.setAdapter(pagerAdapter);
    // Give the TabLayout the ViewPager
    TabLayout tabLayout = root.findViewById(R.id.sliding_tabs);
    new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
        switch(position) {
            case POS_TAGS:
                tab.setText(R.string.gpodnet_taglist_header);
                break;
            // Fall-through
            case POS_TOPLIST:
            default:
                tab.setText(R.string.gpodnet_toplist_header);
                break;
        }
    }).attach();
    return root;
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) Bundle(android.os.Bundle) TabLayout(com.google.android.material.tabs.TabLayout) LayoutInflater(android.view.LayoutInflater) NonNull(androidx.annotation.NonNull) R(de.danoeh.antennapod.R) OnlineSearchFragment(de.danoeh.antennapod.fragment.OnlineSearchFragment) ViewPager2(androidx.viewpager2.widget.ViewPager2) SearchView(androidx.appcompat.widget.SearchView) ViewGroup(android.view.ViewGroup) MenuItem(android.view.MenuItem) FragmentStateAdapter(androidx.viewpager2.adapter.FragmentStateAdapter) MainActivity(de.danoeh.antennapod.activity.MainActivity) GpodnetPodcastSearcher(de.danoeh.antennapod.discovery.GpodnetPodcastSearcher) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Toolbar(androidx.appcompat.widget.Toolbar) Activity(android.app.Activity) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) TabLayout(com.google.android.material.tabs.TabLayout) TabLayoutMediator(com.google.android.material.tabs.TabLayoutMediator) SearchView(androidx.appcompat.widget.SearchView) View(android.view.View)

Example 5 with ViewPager2

use of androidx.viewpager2.widget.ViewPager2 in project AntennaPod by AntennaPod.

the class AudioPlayerFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View root = inflater.inflate(R.layout.audioplayer_fragment, container, false);
    // Avoid clicks going through player to fragments below
    root.setOnTouchListener((v, event) -> true);
    toolbar = root.findViewById(R.id.toolbar);
    toolbar.setTitle("");
    toolbar.setNavigationOnClickListener(v -> ((MainActivity) getActivity()).getBottomSheet().setState(BottomSheetBehavior.STATE_COLLAPSED));
    toolbar.setOnMenuItemClickListener(this);
    ExternalPlayerFragment externalPlayerFragment = new ExternalPlayerFragment();
    getChildFragmentManager().beginTransaction().replace(R.id.playerFragment, externalPlayerFragment, ExternalPlayerFragment.TAG).commit();
    butPlaybackSpeed = root.findViewById(R.id.butPlaybackSpeed);
    txtvPlaybackSpeed = root.findViewById(R.id.txtvPlaybackSpeed);
    sbPosition = root.findViewById(R.id.sbPosition);
    txtvPosition = root.findViewById(R.id.txtvPosition);
    txtvLength = root.findViewById(R.id.txtvLength);
    butRev = root.findViewById(R.id.butRev);
    txtvRev = root.findViewById(R.id.txtvRev);
    butPlay = root.findViewById(R.id.butPlay);
    butFF = root.findViewById(R.id.butFF);
    txtvFF = root.findViewById(R.id.txtvFF);
    butSkip = root.findViewById(R.id.butSkip);
    progressIndicator = root.findViewById(R.id.progLoading);
    cardViewSeek = root.findViewById(R.id.cardViewSeek);
    txtvSeek = root.findViewById(R.id.txtvSeek);
    setupLengthTextView();
    setupControlButtons();
    butPlaybackSpeed.setOnClickListener(v -> new VariableSpeedDialog().show(getChildFragmentManager(), null));
    sbPosition.setOnSeekBarChangeListener(this);
    pager = root.findViewById(R.id.pager);
    pager.setAdapter(new AudioPlayerPagerAdapter(this));
    // Required for getChildAt(int) in ViewPagerBottomSheetBehavior to return the correct page
    pager.setOffscreenPageLimit((int) NUM_CONTENT_FRAGMENTS);
    pager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() {

        @Override
        public void onPageSelected(int position) {
            pager.post(() -> {
                if (getActivity() != null) {
                    // By the time this is posted, the activity might be closed again.
                    ((MainActivity) getActivity()).getBottomSheet().updateScrollingChild();
                }
            });
        }
    });
    return root;
}
Also used : ViewPager2(androidx.viewpager2.widget.ViewPager2) MainActivity(de.danoeh.antennapod.activity.MainActivity) VariableSpeedDialog(de.danoeh.antennapod.dialog.VariableSpeedDialog) View(android.view.View) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) PlaybackSpeedIndicatorView(de.danoeh.antennapod.ui.common.PlaybackSpeedIndicatorView)

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