Search in sources :

Example 1 with MaterialProgressBar

use of com.shiqkuangsan.mycustomviews.ui.custom.MaterialProgressBar in project CustomViews by AndroidStudy233.

the class ViewPagerFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    viewPager = (OverScrollViewPager) view.findViewById(R.id.viewpager_piclooker);
    tips = (TextView) view.findViewById(R.id.tv_piclooker_index);
    mask = view.findViewById(R.id.view_piclooker_back);
    runEnterAnimation();
    Bundle bundle = getArguments();
    imgs = bundle.getStringArrayList("imgs");
    imageInfo = bundle.getParcelable("info");
    imageInfos = bundle.getParcelableArrayList("infos");
    position = bundle.getInt("position", 0);
    tips.setText((position + 1) + "/" + imgs.size());
    viewPager.setpagerCount(imgs.size());
    viewPager.setAdapter(new PagerAdapter() {

        @Override
        public int getCount() {
            return imgs.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int pos) {
            View view = LayoutInflater.from(getActivity()).inflate(R.layout.layout_view_detail, null, false);
            final PhotoView myPhotoView = (PhotoView) view.findViewById(R.id.iv_piclooker_detail);
            final MaterialProgressBar progressBar = (MaterialProgressBar) view.findViewById(R.id.pb_piclooker);
            if (position == pos && ImageLoader.getInstance().getDiscCache().get(imgs.get(pos)) != null) {
                // only animate when position equals u click in pre layout
                myPhotoView.animaFrom(imageInfo);
            }
            // load pic from remote
            ImageLoader.getInstance().displayImage(imgs.get(pos), myPhotoView, new DisplayImageOptions.Builder().cacheInMemory(true).cacheOnDisc(true).build(), new SimpleImageLoadingListener() {

                @Override
                public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                    progressBar.setVisibility(View.GONE);
                }
            });
            // force to get focal point,to listen key listener
            myPhotoView.setFocusableInTouchMode(true);
            myPhotoView.requestFocus();
            // add key listener to listen back press
            myPhotoView.setOnKeyListener(pressKeyListener);
            myPhotoView.setOnClickListener(onClickListener);
            myPhotoView.setTag(pos);
            myPhotoView.enable();
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    });
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            tips.setText((position + 1) + "/" + imgs.size());
            viewPager.updateCurrentIndex(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    // set current position
    // viewPager.getOverscrollView().setCurrentItem(position);
    viewPager.setCurrentItem(position);
}
Also used : Bundle(android.os.Bundle) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) View(android.view.View) ViewPager(android.support.v4.view.ViewPager) OverScrollViewPager(com.shiqkuangsan.mycustomviews.ui.custom.OverScrollViewPager) PagerAdapter(android.support.v4.view.PagerAdapter) SimpleImageLoadingListener(com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener) Bitmap(android.graphics.Bitmap) MaterialProgressBar(com.shiqkuangsan.mycustomviews.ui.custom.MaterialProgressBar) DisplayImageOptions(com.nostra13.universalimageloader.core.DisplayImageOptions)

Aggregations

Bitmap (android.graphics.Bitmap)1 Bundle (android.os.Bundle)1 PagerAdapter (android.support.v4.view.PagerAdapter)1 ViewPager (android.support.v4.view.ViewPager)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 DisplayImageOptions (com.nostra13.universalimageloader.core.DisplayImageOptions)1 SimpleImageLoadingListener (com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener)1 MaterialProgressBar (com.shiqkuangsan.mycustomviews.ui.custom.MaterialProgressBar)1 OverScrollViewPager (com.shiqkuangsan.mycustomviews.ui.custom.OverScrollViewPager)1