Search in sources :

Example 16 with PtrFrameLayout

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

the class WithLongPressFragment method createView.

@Override
protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mImageLoader = ImageLoaderFactory.create(getActivity());
    View view = inflater.inflate(R.layout.fragment_with_long_press, null);
    setHeaderTitle(R.string.ptr_demo_block_with_long_press);
    final PtrFrameLayout ptrFrameLayout = (PtrFrameLayout) view.findViewById(R.id.with_long_press_list_view_frame);
    ListView listView = (ListView) view.findViewById(R.id.with_long_press_list_view);
    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Toast.makeText(getContext(), "Long Pressed: " + id, Toast.LENGTH_SHORT).show();
            return true;
        }
    });
    final ListViewDataAdapter<String> listViewDataAdapter = new ListViewDataAdapter<String>();
    listViewDataAdapter.setViewHolderClass(this, ViewHolder.class);
    ptrFrameLayout.setPtrHandler(new PtrDefaultHandler() {

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

                @Override
                public void run() {
                    listViewDataAdapter.getDataList().clear();
                    listViewDataAdapter.getDataList().addAll(Arrays.asList(Images.imageUrls));
                    listViewDataAdapter.notifyDataSetChanged();
                    ptrFrameLayout.refreshComplete();
                }
            }, 2000);
        }
    });
    ptrFrameLayout.postDelayed(new Runnable() {

        @Override
        public void run() {
            ptrFrameLayout.autoRefresh();
        }
    }, 100);
    listView.setAdapter(listViewDataAdapter);
    return view;
}
Also used : PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) CubeImageView(in.srain.cube.image.CubeImageView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ListView(android.widget.ListView) ListViewDataAdapter(in.srain.cube.views.list.ListViewDataAdapter) AdapterView(android.widget.AdapterView) PtrDefaultHandler(in.srain.cube.views.ptr.PtrDefaultHandler)

Example 17 with PtrFrameLayout

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

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

Example 19 with PtrFrameLayout

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

the class WithScrollView method createView.

@Override
public View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setHeaderTitle(R.string.ptr_demo_block_scroll_view);
    final View contentView = inflater.inflate(R.layout.fragment_classic_header_with_scroll_view, null);
    mScrollView = (ScrollView) contentView.findViewById(R.id.rotate_header_scroll_view);
    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, mScrollView, header);
        }

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

                @Override
                public void run() {
                    mPtrFrame.refreshComplete();
                }
            }, 100);
        }
    });
    // 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) ScrollView(android.widget.ScrollView) View(android.view.View)

Example 20 with PtrFrameLayout

use of in.srain.cube.views.ptr.PtrFrameLayout in project UltimateAndroid by cymcsg.

the class UltraPullToRefreshStoreHouseActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //  setContentView(R.layout);
    setContentView(R.layout.ultra_pull_refresh_store_house_activity_main);
    mPtrFrameLayout = (PtrFrameLayout) findViewById(R.id.store_house_ptr_frame);
    // the following are default settings
    mPtrFrameLayout.setResistance(1.7f);
    mPtrFrameLayout.setRatioOfHeaderHeightToRefresh(1.2f);
    mPtrFrameLayout.setDurationToClose(200);
    mPtrFrameLayout.setDurationToCloseHeader(1000);
    // default is false
    mPtrFrameLayout.setPullToRefresh(false);
    // default is true
    mPtrFrameLayout.setKeepHeaderWhenRefresh(true);
    final StoreHouseHeader header = new StoreHouseHeader(this);
    header.setPadding(0, BasicUiUtils.dip2px(this, 15.0f), 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("Marshal Chen");
    //  header.initWithStringArray(R.array.akta);
    mPtrFrameLayout.setHeaderView(header);
    mPtrFrameLayout.addPtrUIHandler(header);
    //        mPtrFrameLayout.postDelayed(new Runnable() {
    //            @Override
    //            public void run() {
    //                // ptrFrame.autoRefresh();
    //            }
    //        }, 150);
    mPtrFrameLayout.setPtrHandler(new PtrHandler() {

        @Override
        public boolean checkCanDoRefresh(PtrFrameLayout ptrFrameLayout, View view, View view2) {
            boolean canbePullDown = PtrDefaultHandler.checkContentCanBePulledDown(ptrFrameLayout, view, view2);
            Logs.d("canbepull----" + canbePullDown);
            return canbePullDown;
        }

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

                @Override
                public void run() {
                    mPtrFrameLayout.refreshComplete();
                }
            }, 1800);
        }
    });
}
Also used : PtrHandler(in.srain.cube.views.ptr.PtrHandler) PtrFrameLayout(in.srain.cube.views.ptr.PtrFrameLayout) StoreHouseHeader(in.srain.cube.views.ptr.header.StoreHouseHeader) View(android.view.View)

Aggregations

View (android.view.View)20 PtrFrameLayout (in.srain.cube.views.ptr.PtrFrameLayout)20 PtrHandler (in.srain.cube.views.ptr.PtrHandler)17 CubeImageView (in.srain.cube.image.CubeImageView)9 StoreHouseHeader (in.srain.cube.views.ptr.header.StoreHouseHeader)7 ImageLoader (in.srain.cube.image.ImageLoader)5 AdapterView (android.widget.AdapterView)4 ListView (android.widget.ListView)3 UltimateRecyclerView (com.marshalchen.ultimaterecyclerview.UltimateRecyclerView)3 JsonData (in.srain.cube.request.JsonData)3 PtrDefaultHandler (in.srain.cube.views.ptr.PtrDefaultHandler)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 TextView (android.widget.TextView)2