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