Search in sources :

Example 1 with PtrHandler

use of in.srain.cube.views.ptr.PtrHandler in project CustomViews by AndroidStudy233.

the class PtrDemoActivity method initPtrLayout.

public void initPtrLayout() {
    // header 设置头布局
    final MaterialHeader header = new MaterialHeader(this);
    int[] colors = { Color.RED, Color.BLUE, Color.YELLOW, Color.GREEN };
    header.setColorSchemeColors(colors);
    header.setLayoutParams(new PtrFrameLayout.LayoutParams(-1, -2));
    header.setPadding(0, UIUitl.dip2px(this, 15), 0, UIUitl.dip2px(this, 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(true);
        }
    }, 100);
    mPtrFrameLayout.setPtrHandler(new PtrHandler() {

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

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

                @Override
                public void run() {
                    dataList.add("刷新数据" + dataList.size());
                    frame.refreshComplete();
                    adapter.notifyDataSetChanged();
                }
            }, 1500);
        }
    });
}
Also used : MaterialHeader(in.srain.cube.views.ptr.header.MaterialHeader) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) PtrHandler(in.srain.cube.views.ptr.PtrHandler) TextView(android.widget.TextView) View(android.view.View) ListView(android.widget.ListView)

Example 2 with PtrHandler

use of in.srain.cube.views.ptr.PtrHandler in project android-Ultra-Pull-To-Refresh by liaohuqiu.

the class WithGridView method createView.

@Override
public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHeaderTitle(R.string.ptr_demo_block_grid_view);
    mImageLoader = ImageLoaderFactory.create(getContext());
    final View contentView = inflater.inflate(R.layout.fragment_classic_header_with_gridview, null);
    final GridView gridListView = (GridView) contentView.findViewById(R.id.rotate_header_grid_view);
    gridListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position >= 0) {
                final String url = mAdapter.getItem(position).optString("pic");
                if (!TextUtils.isEmpty(url)) {
                    getContext().pushFragmentToBackStack(MaterialStyleFragment.class, url);
                }
            }
        }
    });
    mAdapter = new ListViewDataAdapter<JsonData>(new ViewHolderCreator<JsonData>() {

        @Override
        public ViewHolderBase<JsonData> createViewHolder(int position) {
            return new ViewHolder();
        }
    });
    gridListView.setAdapter(mAdapter);
    mPtrFrame = (PtrClassicFrameLayout) contentView.findViewById(R.id.rotate_header_grid_view_frame);
    mPtrFrame.setLastUpdateTimeRelateObject(this);
    mPtrFrame.setPtrHandler(new PtrHandler() {

        @Override
        public void onRefreshBegin(PtrFrameLayout frame) {
            updateData();
        }

        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            return PtrDefaultHandler.checkContentCanBePulledDown(frame, content, header);
        }
    });
    // the following are default settings
    mPtrFrame.setResistance(1.7f);
    mPtrFrame.setRatioOfHeaderHeightToRefresh(1.2f);
    mPtrFrame.setDurationToClose(200);
    mPtrFrame.setDurationToCloseHeader(1000);
    // default is false
    mPtrFrame.setPullToRefresh(false);
    // default is true
    mPtrFrame.setKeepHeaderWhenRefresh(true);
    mPtrFrame.postDelayed(new Runnable() {

        @Override
        public void run() {
        // mPtrFrame.autoRefresh();
        }
    }, 100);
    // updateData();
    setupViews(mPtrFrame);
    return contentView;
}
Also used : PtrHandler(in.srain.cube.views.ptr.PtrHandler) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) GridView(android.widget.GridView) CubeImageView(in.srain.cube.image.CubeImageView) View(android.view.View) AdapterView(android.widget.AdapterView) JsonData(in.srain.cube.request.JsonData) MaterialStyleFragment(in.srain.cube.views.ptr.demo.ui.MaterialStyleFragment) AdapterView(android.widget.AdapterView) GridView(android.widget.GridView) ViewHolderCreator(in.srain.cube.views.list.ViewHolderCreator)

Example 3 with PtrHandler

use of in.srain.cube.views.ptr.PtrHandler in project android-Ultra-Pull-To-Refresh by liaohuqiu.

the class WithTextViewInFrameLayoutFragment method createView.

@Override
public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHeaderTitle(R.string.ptr_demo_block_frame_layout);
    final View contentView = inflater.inflate(R.layout.fragment_classic_header_with_viewgroup, container, false);
    final PtrClassicFrameLayout ptrFrame = (PtrClassicFrameLayout) contentView.findViewById(R.id.fragment_rotate_header_with_view_group_frame);
    ptrFrame.setPtrHandler(new PtrHandler() {

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

                @Override
                public void run() {
                    ptrFrame.refreshComplete();
                }
            }, 1800);
        }

        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            return true;
        }
    });
    ptrFrame.setLastUpdateTimeRelateObject(this);
    // the following are default settings
    ptrFrame.setResistance(1.7f);
    ptrFrame.setRatioOfHeaderHeightToRefresh(1.2f);
    ptrFrame.setDurationToClose(200);
    ptrFrame.setDurationToCloseHeader(1000);
    // default is false
    ptrFrame.setPullToRefresh(false);
    // default is true
    ptrFrame.setKeepHeaderWhenRefresh(true);
    // scroll then refresh
    // comment in base fragment
    ptrFrame.postDelayed(new Runnable() {

        @Override
        public void run() {
        // ptrFrame.autoRefresh();
        }
    }, 150);
    setupViews(ptrFrame);
    return contentView;
}
Also used : PtrClassicFrameLayout(in.srain.cube.views.ptr.PtrClassicFrameLayout) PtrHandler(in.srain.cube.views.ptr.PtrHandler) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) View(android.view.View)

Example 4 with PtrHandler

use of in.srain.cube.views.ptr.PtrHandler 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 5 with PtrHandler

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

Aggregations

View (android.view.View)19 PtrFrameLayout (in.srain.cube.views.ptr.PtrFrameLayout)19 PtrHandler (in.srain.cube.views.ptr.PtrHandler)19 CubeImageView (in.srain.cube.image.CubeImageView)8 StoreHouseHeader (in.srain.cube.views.ptr.header.StoreHouseHeader)7 ImageLoader (in.srain.cube.image.ImageLoader)5 MaterialHeader (in.srain.cube.views.ptr.header.MaterialHeader)4 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 TextView (android.widget.TextView)3 UltimateRecyclerView (com.marshalchen.ultimaterecyclerview.UltimateRecyclerView)3 JsonData (in.srain.cube.request.JsonData)3 PtrUIHandler (in.srain.cube.views.ptr.PtrUIHandler)3 MaterialStyleFragment (in.srain.cube.views.ptr.demo.ui.MaterialStyleFragment)3 PtrIndicator (in.srain.cube.views.ptr.indicator.PtrIndicator)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 ImageView (android.widget.ImageView)2