Search in sources :

Example 11 with PtrHandler

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

the class WithWebView method createView.

@Override
public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHeaderTitle(R.string.ptr_demo_block_web_view);
    final View contentView = inflater.inflate(R.layout.fragment_classic_header_with_webview, null);
    mWebView = (WebView) contentView.findViewById(R.id.rotate_header_web_view);
    mWebView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            mPtrFrame.refreshComplete();
        }
    });
    mPtrFrame = (PtrClassicFrameLayout) contentView.findViewById(R.id.rotate_header_web_view_frame);
    mPtrFrame.setLastUpdateTimeRelateObject(this);
    mPtrFrame.setPtrHandler(new PtrHandler() {

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

        @Override
        public void onRefreshBegin(PtrFrameLayout frame) {
            updateData();
        }
    });
    // 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);
    return contentView;
}
Also used : PtrHandler(in.srain.cube.views.ptr.PtrHandler) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) WebView(android.webkit.WebView) View(android.view.View) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 12 with PtrHandler

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

the class StoreHouseUsingStringArray method createView.

@Override
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_storehouse_header, null);
    mTitlePre = getString(R.string.ptr_demo_storehouse_header_using_string_array_in_title);
    setHeaderTitle(mTitlePre + "R.array.storehouse");
    // loading image
    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);
    final StoreHouseHeader header = new StoreHouseHeader(getContext());
    header.setPadding(0, LocalDisplay.dp2px(15), 0, 0);
    // using string array from resource xml file
    header.initWithStringArray(R.array.storehouse);
    frame.setDurationToCloseHeader(1500);
    frame.setHeaderView(header);
    frame.addPtrUIHandler(header);
    frame.postDelayed(new Runnable() {

        @Override
        public void run() {
            frame.autoRefresh(false);
        }
    }, 100);
    // change header after loaded
    frame.addPtrUIHandler(new PtrUIHandler() {

        private int mLoadTime = 0;

        @Override
        public void onUIReset(PtrFrameLayout frame) {
            mLoadTime++;
            if (mLoadTime % 2 == 0) {
                header.setScale(1);
                header.initWithStringArray(R.array.storehouse);
            } else {
                header.setScale(0.5f);
                header.initWithStringArray(R.array.akta);
            }
        }

        @Override
        public void onUIRefreshPrepare(PtrFrameLayout frame) {
            if (mLoadTime % 2 == 0) {
                setHeaderTitle(mTitlePre + "R.array.storehouse");
            } else {
                setHeaderTitle(mTitlePre + "R.array.akta");
            }
        }

        @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.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 13 with PtrHandler

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

the class PtrDemoHomeFragment method createView.

@Override
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.createView(inflater, container, savedInstanceState);
    view.setBackgroundColor(getResources().getColor(R.color.cube_mints_333333));
    final PtrFrameLayout ptrFrameLayout = (PtrFrameLayout) view.findViewById(R.id.fragment_ptr_home_ptr_frame);
    StoreHouseHeader header = new StoreHouseHeader(getContext());
    header.setPadding(0, LocalDisplay.dp2px(20), 0, LocalDisplay.dp2px(20));
    header.initWithString("Ultra PTR");
    ptrFrameLayout.setDurationToCloseHeader(1500);
    ptrFrameLayout.setHeaderView(header);
    ptrFrameLayout.addPtrUIHandler(header);
    ptrFrameLayout.setPtrHandler(new PtrHandler() {

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

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

                @Override
                public void run() {
                    ptrFrameLayout.refreshComplete();
                }
            }, 1500);
        }
    });
    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) View(android.view.View)

Example 14 with PtrHandler

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

the class WithListView method createView.

@Override
public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHeaderTitle(R.string.ptr_demo_block_list_view);
    mImageLoader = ImageLoaderFactory.create(getContext());
    final View contentView = inflater.inflate(R.layout.fragment_classic_header_with_list_view, null);
    final ListView listView = (ListView) contentView.findViewById(R.id.rotate_header_list_view);
    listView.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>();
    mAdapter.setViewHolderClass(this, ViewHolder.class);
    listView.setAdapter(mAdapter);
    mPtrFrame = (PtrClassicFrameLayout) contentView.findViewById(R.id.rotate_header_list_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);
    return contentView;
}
Also used : PtrHandler(in.srain.cube.views.ptr.PtrHandler) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) CubeImageView(in.srain.cube.image.CubeImageView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) JsonData(in.srain.cube.request.JsonData) ListView(android.widget.ListView) MaterialStyleFragment(in.srain.cube.views.ptr.demo.ui.MaterialStyleFragment) AdapterView(android.widget.AdapterView)

Example 15 with PtrHandler

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

the class WithListViewAndEmptyView method createView.

@Override
public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHeaderTitle(R.string.ptr_demo_block_with_list_view_and_empty_view);
    mImageLoader = ImageLoaderFactory.create(getContext());
    final View contentView = inflater.inflate(R.layout.fragment_classic_header_with_list_view_and_empty_view, null);
    mTextView = (TextView) contentView.findViewById(R.id.list_view_with_empty_view_fragment_empty_view);
    mPtrFrame = (PtrClassicFrameLayout) contentView.findViewById(R.id.list_view_with_empty_view_fragment_ptr_frame);
    mTextView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            mPtrFrame.setVisibility(View.VISIBLE);
            mPtrFrame.autoRefresh();
        }
    });
    mListView = (ListView) contentView.findViewById(R.id.list_view_with_empty_view_fragment_list_view);
    mListView.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);
                }
            }
        }
    });
    // show empty view
    mPtrFrame.setVisibility(View.INVISIBLE);
    mTextView.setVisibility(View.VISIBLE);
    mAdapter = new ListViewDataAdapter<JsonData>();
    mAdapter.setViewHolderClass(this, ViewHolder.class);
    mListView.setAdapter(mAdapter);
    mPtrFrame.setLastUpdateTimeRelateObject(this);
    mPtrFrame.setPtrHandler(new PtrHandler() {

        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
            // here check $mListView instead of $content
            return PtrDefaultHandler.checkContentCanBePulledDown(frame, mListView, header);
        }

        @Override
        public void onRefreshBegin(PtrFrameLayout frame) {
            updateData();
        }
    });
    // 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);
    return contentView;
}
Also used : PtrHandler(in.srain.cube.views.ptr.PtrHandler) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) CubeImageView(in.srain.cube.image.CubeImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) JsonData(in.srain.cube.request.JsonData) MaterialStyleFragment(in.srain.cube.views.ptr.demo.ui.MaterialStyleFragment) AdapterView(android.widget.AdapterView)

Aggregations

View (android.view.View)17 PtrFrameLayout (in.srain.cube.views.ptr.PtrFrameLayout)17 PtrHandler (in.srain.cube.views.ptr.PtrHandler)17 CubeImageView (in.srain.cube.image.CubeImageView)8 StoreHouseHeader (in.srain.cube.views.ptr.header.StoreHouseHeader)7 ImageLoader (in.srain.cube.image.ImageLoader)5 AdapterView (android.widget.AdapterView)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 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 ImageTask (in.srain.cube.image.ImageTask)2