Search in sources :

Example 11 with PagerAdapter

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) {
        }
    });
}
Also used : ViewGroup(android.view.ViewGroup) PhotoView(com.github.chrisbanes.photoview.PhotoView) View(android.view.View) ViewPager(androidx.viewpager.widget.ViewPager) PagerAdapter(androidx.viewpager.widget.PagerAdapter) PhotoView(com.github.chrisbanes.photoview.PhotoView) NonNull(androidx.annotation.NonNull)

Example 12 with PagerAdapter

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());
}
Also used : ArrayList(java.util.ArrayList) PagerAdapter(androidx.viewpager.widget.PagerAdapter)

Aggregations

PagerAdapter (androidx.viewpager.widget.PagerAdapter)12 View (android.view.View)7 ViewGroup (android.view.ViewGroup)4 TextView (android.widget.TextView)4 LinearLayout (android.widget.LinearLayout)3 NonNull (androidx.annotation.NonNull)3 ViewPager (androidx.viewpager.widget.ViewPager)3 HorizontalScrollView (android.widget.HorizontalScrollView)2 FragmentPagerAdapter (androidx.fragment.app.FragmentPagerAdapter)2 ValueAnimator (android.animation.ValueAnimator)1 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 Context (android.content.Context)1 Intent (android.content.Intent)1 TypedArray (android.content.res.TypedArray)1 Canvas (android.graphics.Canvas)1 Paint (android.graphics.Paint)1 Build (android.os.Build)1 Bundle (android.os.Bundle)1 Parcel (android.os.Parcel)1