use of androidx.viewpager.widget.PagerAdapter in project CloudReader by youlookwhat.
the class BigImagePagerActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_big_image);
mViewPager = (ViewPager) findViewById(R.id.very_image_viewpager);
// 延迟动画
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
postponeEnterTransition();
}
mEnterIndex = getIntent().getIntExtra(KEY_ENTER_INDEX, 0);
mImageUrls = getIntent().getStringArrayListExtra(KEY_IMAGE_URLS);
if (mImageUrls == null) {
return;
}
mPhotoViewMap = new SparseArray<>();
// imageView.setLayoutParams(new ViewGroup.LayoutParams(
// ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
// View view = getLayoutInflater().inflate(R.layout.dialog_save_image, null);
//
// AlertDialog alertDialog = new AlertDialog.Builder(BigImagePagerActivity.this)
// .setView(view)
// .create();
//
// TextView textView = (TextView) view.findViewById(R.id.save_image_tv);
// textView.setOnClickListener(v1 -> {
// saveImage(pv.getDrawable(), imageUrl);
// alertDialog.dismiss();
// });
// alertDialog.show();
PagerAdapter mPagerAdapter = new PagerAdapter() {
@Override
public int getCount() {
return mImageUrls.size();
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view.equals(object);
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
PhotoView photoView = new PhotoView(container.getContext());
// imageView.setLayoutParams(new ViewGroup.LayoutParams(
// ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
String imageUrl = mImageUrls.get(position);
Glide.with(BigImagePagerActivity.this).load(imageUrl).into(photoView);
if (mPhotoViewMap.get(position) != null) {
mPhotoViewMap.remove(position);
}
mPhotoViewMap.put(position, photoView);
photoView.setOnViewTapListener((view, x, y) -> {
onBackPressed();
});
photoView.setOnLongClickListener(v -> {
PhotoView pv = (PhotoView) v;
if (pv.getDrawable() == null) {
return false;
}
// alertDialog.show();
return true;
});
if (position == mEnterIndex) {
ViewCompat.setTransitionName(photoView, mImageUrls.get(position));
setStartPostTransition(photoView);
}
container.addView(photoView);
return photoView;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
if (mPhotoViewMap.get(position) != null) {
mPhotoViewMap.remove(position);
}
container.removeView((View) object);
}
};
mViewPager.setAdapter(mPagerAdapter);
mViewPager.setCurrentItem(mEnterIndex);
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int i, float v, int i1) {
}
@Override
public void onPageSelected(int i) {
RxBus.getDefault().post(RxCodeConstants.JUMP_CURRENT_POSITION, i);
}
@Override
public void onPageScrollStateChanged(int i) {
}
});
}
use of androidx.viewpager.widget.PagerAdapter in project wire-android by wireapp.
the class TabIndicatorLayout method setViewPager.
public void setViewPager(ViewPager viewPager) {
if (this.viewPager != null) {
this.viewPager.removeOnPageChangeListener(this);
}
this.viewPager = viewPager;
this.viewPager.addOnPageChangeListener(this);
PagerAdapter adapter = this.viewPager.getAdapter();
int count = adapter.getCount();
List<String> labels = new ArrayList<>();
for (int i = 0; i < count; i++) {
labels.add(adapter.getPageTitle(i).toString());
}
setLabels(labels);
setSelected(viewPager.getCurrentItem());
}
Aggregations