Search in sources :

Example 1 with MaterialHeader

use of in.srain.cube.views.ptr.header.MaterialHeader in project UltimateRecyclerView by cymcsg.

the class PullToRefreshActivity method refreshingMaterial.

//    void refreshingRental() {
//        rentalsSunHeaderView = new RentalsSunHeaderView(this);
//        rentalsSunHeaderView.setUp(ultimateRecyclerView.mPtrFrameLayout);
//
//        ultimateRecyclerView.mPtrFrameLayout.removePtrUIHandler(materialHeader);
//        ultimateRecyclerView.mPtrFrameLayout.removePtrUIHandler(storeHouseHeader);
//        ultimateRecyclerView.mPtrFrameLayout.setHeaderView(rentalsSunHeaderView);
//        ultimateRecyclerView.mPtrFrameLayout.addPtrUIHandler(rentalsSunHeaderView);
//        ultimateRecyclerView.mPtrFrameLayout.autoRefresh(false);
//        ultimateRecyclerView.mPtrFrameLayout.setPtrHandler(new PtrHandler() {
//            @Override
//            public boolean checkCanDoRefresh(PtrFrameLayout ptrFrameLayout, View view, View view2) {
//                boolean canbePullDown = PtrDefaultHandler.checkContentCanBePulledDown(ptrFrameLayout, view, view2);
//                return canbePullDown;
//            }
//
//            @Override
//            public void onRefreshBegin(PtrFrameLayout ptrFrameLayout) {
//                ptrFrameLayout.postDelayed(new Runnable() {
//                    @Override
//                    public void run() {
//                        simpleRecyclerViewAdapter.insert("Refresh things", 0);
//                        //   ultimateRecyclerView.scrollBy(0, -50);
//                        linearLayoutManager.scrollToPosition(0);
//                        ultimateRecyclerView.mPtrFrameLayout.refreshComplete();
//                        changeHeaderHandler.sendEmptyMessageDelayed(3, 500);
//                    }
//                }, 1800);
//            }
//        });
//
//    }
void refreshingMaterial() {
    materialHeader = new MaterialHeader(this);
    int[] colors = getResources().getIntArray(R.array.google_colors);
    materialHeader.setColorSchemeColors(colors);
    materialHeader.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
    materialHeader.setPadding(0, 15, 0, 10);
    materialHeader.setPtrFrameLayout(ultimateRecyclerView.mPtrFrameLayout);
    ultimateRecyclerView.mPtrFrameLayout.autoRefresh(false);
    ultimateRecyclerView.mPtrFrameLayout.removePtrUIHandler(storeHouseHeader);
    ultimateRecyclerView.mPtrFrameLayout.setHeaderView(materialHeader);
    ultimateRecyclerView.mPtrFrameLayout.addPtrUIHandler(materialHeader);
    ultimateRecyclerView.mPtrFrameLayout.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() {
                    //  simpleRecyclerViewAdapter.insertLast("Refresh things");
                    //   ultimateRecyclerView.scrollBy(0, -50);
                    //   linearLayoutManager.scrollToPosition(0);
                    ultimateRecyclerView.mPtrFrameLayout.refreshComplete();
                //   changeHeaderHandler.sendEmptyMessageDelayed(2, 500);
                }
            }, 1800);
        }
    });
}
Also used : MaterialHeader(in.srain.cube.views.ptr.header.MaterialHeader) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) PtrHandler(in.srain.cube.views.ptr.PtrHandler) UltimateRecyclerView(com.marshalchen.ultimaterecyclerview.UltimateRecyclerView) View(android.view.View)

Example 2 with MaterialHeader

use of in.srain.cube.views.ptr.header.MaterialHeader in project MVCHelper by LuckyJayce.

the class UltraActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_ultra);
    /*
		 * 配置PtrClassicFrameLayout的刷新样式
		 */
    PtrClassicFrameLayout mPtrFrameLayout = (PtrClassicFrameLayout) findViewById(R.id.rotate_header_list_view_frame);
    final MaterialHeader header = new MaterialHeader(this);
    header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
    header.setPadding(0, dipToPix(this, 15), 0, dipToPix(this, 10));
    header.setPtrFrameLayout(mPtrFrameLayout);
    mPtrFrameLayout.setLoadingMinTime(800);
    mPtrFrameLayout.setDurationToCloseHeader(800);
    mPtrFrameLayout.setHeaderView(header);
    mPtrFrameLayout.addPtrUIHandler(header);
    mvcHelper = new MVCUltraHelper<List<Book>>(mPtrFrameLayout);
    // 设置数据源
    mvcHelper.setDataSource(new BooksDataSource());
    // 设置适配器
    mvcHelper.setAdapter(new BooksAdapter(this));
    // 加载数据
    mvcHelper.refresh();
}
Also used : BooksAdapter(com.shizhefei.test.view.adapters.BooksAdapter) PtrClassicFrameLayout(in.srain.cube.views.ptr.PtrClassicFrameLayout) MaterialHeader(in.srain.cube.views.ptr.header.MaterialHeader) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) List(java.util.List) BooksDataSource(com.shizhefei.test.models.datasource.BooksDataSource)

Example 3 with MaterialHeader

use of in.srain.cube.views.ptr.header.MaterialHeader 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)

Aggregations

PtrFrameLayout (in.srain.cube.views.ptr.PtrFrameLayout)3 MaterialHeader (in.srain.cube.views.ptr.header.MaterialHeader)3 View (android.view.View)2 PtrHandler (in.srain.cube.views.ptr.PtrHandler)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 TransitionDrawable (android.graphics.drawable.TransitionDrawable)1 UltimateRecyclerView (com.marshalchen.ultimaterecyclerview.UltimateRecyclerView)1 BooksDataSource (com.shizhefei.test.models.datasource.BooksDataSource)1 BooksAdapter (com.shizhefei.test.view.adapters.BooksAdapter)1 CubeImageView (in.srain.cube.image.CubeImageView)1 ImageLoader (in.srain.cube.image.ImageLoader)1 ImageTask (in.srain.cube.image.ImageTask)1 ImageLoadHandler (in.srain.cube.image.iface.ImageLoadHandler)1 PtrClassicFrameLayout (in.srain.cube.views.ptr.PtrClassicFrameLayout)1 List (java.util.List)1