Search in sources :

Example 1 with CubeImageView

use of in.srain.cube.image.CubeImageView in project android-Ultra-Pull-To-Refresh by liaohuqiu.

the class StoreHouseUsingPointList method createView.

@Override
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHeaderTitle(R.string.ptr_demo_storehouse_header_using_point_list);
    View view = inflater.inflate(R.layout.fragment_storehouse_header, null);
    CubeImageView imageView = (CubeImageView) view.findViewById(R.id.store_house_ptr_image);
    ImageLoader imageLoader = ImageLoaderFactory.create(getContext());
    String pic = "http://img5.duitang.com/uploads/item/201406/28/20140628122218_fLQyP.thumb.jpeg";
    imageView.loadImage(imageLoader, pic);
    final PtrFrameLayout frame = (PtrFrameLayout) view.findViewById(R.id.store_house_ptr_frame);
    // header
    final StoreHouseHeader header = new StoreHouseHeader(getContext());
    header.setPadding(0, LocalDisplay.dp2px(15), 0, 0);
    header.initWithPointList(getPointList());
    frame.setDurationToCloseHeader(3000);
    frame.setHeaderView(header);
    frame.addPtrUIHandler(header);
    frame.postDelayed(new Runnable() {

        @Override
        public void run() {
            frame.autoRefresh(false);
        }
    }, 100);
    frame.setPtrHandler(new PtrHandler() {

        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            return true;
        }

        @Override
        public void onRefreshBegin(final PtrFrameLayout frame) {
            frame.postDelayed(new Runnable() {

                @Override
                public void run() {
                    frame.refreshComplete();
                }
            }, 2000);
        }
    });
    return view;
}
Also used : PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) PtrHandler(in.srain.cube.views.ptr.PtrHandler) StoreHouseHeader(in.srain.cube.views.ptr.header.StoreHouseHeader) CubeImageView(in.srain.cube.image.CubeImageView) ImageLoader(in.srain.cube.image.ImageLoader) CubeImageView(in.srain.cube.image.CubeImageView) View(android.view.View)

Example 2 with CubeImageView

use of in.srain.cube.image.CubeImageView in project android-Ultra-Pull-To-Refresh by liaohuqiu.

the class StoreHouseUsingString method createView.

@Override
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_storehouse_header, null);
    mTitlePre = getString(R.string.ptr_demo_storehouse_header_using_string_in_title);
    CubeImageView imageView = (CubeImageView) view.findViewById(R.id.store_house_ptr_image);
    ImageLoader imageLoader = ImageLoaderFactory.create(getContext());
    String pic = "http://img5.duitang.com/uploads/item/201406/28/20140628122218_fLQyP.thumb.jpeg";
    imageView.loadImage(imageLoader, pic);
    final PtrFrameLayout frame = (PtrFrameLayout) view.findViewById(R.id.store_house_ptr_frame);
    // header
    final StoreHouseHeader header = new StoreHouseHeader(getContext());
    header.setPadding(0, LocalDisplay.dp2px(15), 0, 0);
    /**
     * using a string, support: A-Z 0-9 - .
     * you can add more letters by {@link in.srain.cube.views.ptr.header.StoreHousePath#addChar}
     */
    header.initWithString(mStringList[0]);
    setHeaderTitle(mTitlePre + mStringList[0]);
    // for changing string
    frame.addPtrUIHandler(new PtrUIHandler() {

        private int mLoadTime = 0;

        @Override
        public void onUIReset(PtrFrameLayout frame) {
            mLoadTime++;
            String string = mStringList[mLoadTime % mStringList.length];
            header.initWithString(string);
        }

        @Override
        public void onUIRefreshPrepare(PtrFrameLayout frame) {
            String string = mStringList[mLoadTime % mStringList.length];
            setHeaderTitle(mTitlePre + string);
        }

        @Override
        public void onUIRefreshBegin(PtrFrameLayout frame) {
        }

        @Override
        public void onUIRefreshComplete(PtrFrameLayout frame) {
        }

        @Override
        public void onUIPositionChange(PtrFrameLayout frame, boolean isUnderTouch, byte status, PtrIndicator ptrIndicator) {
        }
    });
    frame.setDurationToCloseHeader(3000);
    frame.setHeaderView(header);
    frame.addPtrUIHandler(header);
    frame.postDelayed(new Runnable() {

        @Override
        public void run() {
            frame.autoRefresh(false);
        }
    }, 100);
    frame.setPtrHandler(new PtrHandler() {

        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            return true;
        }

        @Override
        public void onRefreshBegin(final PtrFrameLayout frame) {
            frame.postDelayed(new Runnable() {

                @Override
                public void run() {
                    frame.refreshComplete();
                }
            }, 2000);
        }
    });
    return view;
}
Also used : PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) PtrUIHandler(in.srain.cube.views.ptr.PtrUIHandler) PtrHandler(in.srain.cube.views.ptr.PtrHandler) CubeImageView(in.srain.cube.image.CubeImageView) View(android.view.View) StoreHouseHeader(in.srain.cube.views.ptr.header.StoreHouseHeader) CubeImageView(in.srain.cube.image.CubeImageView) PtrIndicator(in.srain.cube.views.ptr.indicator.PtrIndicator) ImageLoader(in.srain.cube.image.ImageLoader)

Example 3 with CubeImageView

use of in.srain.cube.image.CubeImageView in project android-Ultra-Pull-To-Refresh by liaohuqiu.

the class MaterialStyleFragment method createView.

@Override
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_materail_style, null);
    setHeaderTitle(R.string.ptr_demo_material_style);
    final CubeImageView imageView = (CubeImageView) view.findViewById(R.id.material_style_image_view);
    final ImageLoader imageLoader = ImageLoaderFactory.create(getContext());
    mPtrFrameLayout = (PtrFrameLayout) view.findViewById(R.id.material_style_ptr_frame);
    // header
    final MaterialHeader header = new MaterialHeader(getContext());
    int[] colors = getResources().getIntArray(R.array.google_colors);
    header.setColorSchemeColors(colors);
    header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
    header.setPadding(0, LocalDisplay.dp2px(15), 0, LocalDisplay.dp2px(10));
    header.setPtrFrameLayout(mPtrFrameLayout);
    mPtrFrameLayout.setLoadingMinTime(1000);
    mPtrFrameLayout.setDurationToCloseHeader(1500);
    mPtrFrameLayout.setHeaderView(header);
    mPtrFrameLayout.addPtrUIHandler(header);
    mPtrFrameLayout.postDelayed(new Runnable() {

        @Override
        public void run() {
            mPtrFrameLayout.autoRefresh(false);
        }
    }, 100);
    mPtrFrameLayout.setPtrHandler(new PtrHandler() {

        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            return true;
        }

        @Override
        public void onRefreshBegin(final PtrFrameLayout frame) {
            if (mImageHasLoaded) {
                long delay = (long) (1000 + Math.random() * 2000);
                delay = Math.max(0, delay);
                delay = 0;
                frame.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        frame.refreshComplete();
                    }
                }, delay);
            } else {
                mStartLoadingTime = System.currentTimeMillis();
                imageView.loadImage(imageLoader, mUrl);
            }
        }
    });
    ImageLoadHandler imageLoadHandler = new ImageLoadHandler() {

        @Override
        public void onLoading(ImageTask imageTask, CubeImageView cubeImageView) {
        }

        @Override
        public void onLoadFinish(ImageTask imageTask, final CubeImageView cubeImageView, final BitmapDrawable bitmapDrawable) {
            mImageHasLoaded = true;
            long delay = Math.max(0, 1000 - (System.currentTimeMillis() - mStartLoadingTime));
            delay = 0;
            mPtrFrameLayout.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (cubeImageView != null && bitmapDrawable != null) {
                        TransitionDrawable w1 = new TransitionDrawable(new Drawable[] { new ColorDrawable(Color.WHITE), (Drawable) bitmapDrawable });
                        imageView.setImageDrawable(w1);
                        w1.startTransition(200);
                    }
                    mPtrFrameLayout.refreshComplete();
                }
            }, delay);
        }

        @Override
        public void onLoadError(ImageTask imageTask, CubeImageView cubeImageView, int i) {
        }
    };
    imageLoader.setImageLoadHandler(imageLoadHandler);
    return view;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) PtrHandler(in.srain.cube.views.ptr.PtrHandler) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ImageLoadHandler(in.srain.cube.image.iface.ImageLoadHandler) BitmapDrawable(android.graphics.drawable.BitmapDrawable) CubeImageView(in.srain.cube.image.CubeImageView) View(android.view.View) MaterialHeader(in.srain.cube.views.ptr.header.MaterialHeader) ColorDrawable(android.graphics.drawable.ColorDrawable) CubeImageView(in.srain.cube.image.CubeImageView) ImageTask(in.srain.cube.image.ImageTask) ImageLoader(in.srain.cube.image.ImageLoader)

Example 4 with CubeImageView

use of in.srain.cube.image.CubeImageView in project android-Ultra-Pull-To-Refresh by liaohuqiu.

the class ImageListViewHolder method createView.

@Override
public View createView(LayoutInflater inflater) {
    View v = inflater.inflate(R.layout.list_view_item, null);
    mImageView = (CubeImageView) v.findViewById(R.id.list_view_item_image_view);
    mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    return v;
}
Also used : CubeImageView(in.srain.cube.image.CubeImageView) ImageView(android.widget.ImageView) View(android.view.View)

Example 5 with CubeImageView

use of in.srain.cube.image.CubeImageView in project android-Ultra-Pull-To-Refresh by liaohuqiu.

the class RentalsStyleFragment method createView.

@Override
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_materail_style, null);
    setHeaderTitle(R.string.ptr_demo_rentals_style);
    final CubeImageView imageView = (CubeImageView) view.findViewById(R.id.material_style_image_view);
    final ImageLoader imageLoader = ImageLoaderFactory.create(getContext());
    final PtrFrameLayout frame = (PtrFrameLayout) view.findViewById(R.id.material_style_ptr_frame);
    // header
    final RentalsSunHeaderView header = new RentalsSunHeaderView(getContext());
    header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
    header.setPadding(0, LocalDisplay.dp2px(15), 0, LocalDisplay.dp2px(10));
    header.setUp(frame);
    frame.setLoadingMinTime(1000);
    frame.setDurationToCloseHeader(1500);
    frame.setHeaderView(header);
    frame.addPtrUIHandler(header);
    // frame.setPullToRefresh(true);
    frame.postDelayed(new Runnable() {

        @Override
        public void run() {
            frame.autoRefresh(true);
        }
    }, 100);
    frame.setPtrHandler(new PtrHandler() {

        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            return true;
        }

        @Override
        public void onRefreshBegin(final PtrFrameLayout frame) {
            if (mImageHasLoaded) {
                long delay = 1500;
                frame.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        frame.refreshComplete();
                    }
                }, delay);
            } else {
                mStartLoadingTime = System.currentTimeMillis();
                imageView.loadImage(imageLoader, mUrl);
            }
        }
    });
    ImageLoadHandler imageLoadHandler = new ImageLoadHandler() {

        @Override
        public void onLoading(ImageTask imageTask, CubeImageView cubeImageView) {
        }

        @Override
        public void onLoadFinish(ImageTask imageTask, final CubeImageView cubeImageView, final BitmapDrawable bitmapDrawable) {
            mImageHasLoaded = true;
            long delay = 1500;
            frame.postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (cubeImageView != null && bitmapDrawable != null) {
                        TransitionDrawable w1 = new TransitionDrawable(new Drawable[] { new ColorDrawable(Color.WHITE), (Drawable) bitmapDrawable });
                        imageView.setImageDrawable(w1);
                        w1.startTransition(200);
                    }
                    frame.refreshComplete();
                }
            }, delay);
        }

        @Override
        public void onLoadError(ImageTask imageTask, CubeImageView cubeImageView, int i) {
        }
    };
    imageLoader.setImageLoadHandler(imageLoadHandler);
    return view;
}
Also used : TransitionDrawable(android.graphics.drawable.TransitionDrawable) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) PtrHandler(in.srain.cube.views.ptr.PtrHandler) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) TransitionDrawable(android.graphics.drawable.TransitionDrawable) ImageLoadHandler(in.srain.cube.image.iface.ImageLoadHandler) BitmapDrawable(android.graphics.drawable.BitmapDrawable) CubeImageView(in.srain.cube.image.CubeImageView) RentalsSunHeaderView(in.srain.cube.views.ptr.demo.ui.header.RentalsSunHeaderView) View(android.view.View) ColorDrawable(android.graphics.drawable.ColorDrawable) CubeImageView(in.srain.cube.image.CubeImageView) ImageTask(in.srain.cube.image.ImageTask) ImageLoader(in.srain.cube.image.ImageLoader) RentalsSunHeaderView(in.srain.cube.views.ptr.demo.ui.header.RentalsSunHeaderView)

Aggregations

View (android.view.View)6 CubeImageView (in.srain.cube.image.CubeImageView)6 ImageLoader (in.srain.cube.image.ImageLoader)5 PtrFrameLayout (in.srain.cube.views.ptr.PtrFrameLayout)5 PtrHandler (in.srain.cube.views.ptr.PtrHandler)5 StoreHouseHeader (in.srain.cube.views.ptr.header.StoreHouseHeader)3 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 ColorDrawable (android.graphics.drawable.ColorDrawable)2 Drawable (android.graphics.drawable.Drawable)2 TransitionDrawable (android.graphics.drawable.TransitionDrawable)2 ImageTask (in.srain.cube.image.ImageTask)2 ImageLoadHandler (in.srain.cube.image.iface.ImageLoadHandler)2 PtrUIHandler (in.srain.cube.views.ptr.PtrUIHandler)2 PtrIndicator (in.srain.cube.views.ptr.indicator.PtrIndicator)2 ImageView (android.widget.ImageView)1 RentalsSunHeaderView (in.srain.cube.views.ptr.demo.ui.header.RentalsSunHeaderView)1 MaterialHeader (in.srain.cube.views.ptr.header.MaterialHeader)1