Search in sources :

Example 1 with JsonData

use of in.srain.cube.request.JsonData 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 2 with JsonData

use of in.srain.cube.request.JsonData in project android-Ultra-Pull-To-Refresh by liaohuqiu.

the class ViewPagerFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mImageLoader = ImageLoaderFactory.create(getContext()).tryToAttachToContainer(getContext());
    View view = inflater.inflate(R.layout.fragment_view_pager, null);
    mListView = (ListView) view.findViewById(R.id.view_pager_list_view);
    View headerView = inflater.inflate(R.layout.view_pager_fragment_list_view_header, null);
    TextView mHeaderTextView = (TextView) headerView.findViewById(R.id.view_pager_fragment_list_view_header_title);
    mHeaderTextView.setBackgroundColor(0xff4d90fe * mPage / 30);
    mHeaderTextView.setText("Page: " + mPage);
    mListView.addHeaderView(headerView);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position >= 0) {
                JsonData js = mAdapter.getItem(position);
                final String url = js != null ? js.optString("pic") : null;
                if (!TextUtils.isEmpty(url)) {
                    getContext().pushFragmentToBackStack(MaterialStyleFragment.class, url);
                }
            }
        }
    });
    mAdapter = new ListViewDataAdapter<JsonData>();
    mAdapter.setViewHolderClass(this, ImageListViewHolder.class, mImageLoader);
    mListView.setAdapter(mAdapter);
    return view;
}
Also used : MaterialStyleFragment(in.srain.cube.views.ptr.demo.ui.MaterialStyleFragment) TextView(android.widget.TextView) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) JsonData(in.srain.cube.request.JsonData)

Example 3 with JsonData

use of in.srain.cube.request.JsonData 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 4 with JsonData

use of in.srain.cube.request.JsonData 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 5 with JsonData

use of in.srain.cube.request.JsonData in project cube-sdk by liaohuqiu.

the class CacheManager method requestCacheSync.

/**
     * Request cache synchronously.
     * If there is not cache data available, return null,
     * and {@link ICacheAble#onNoCacheData} will not no be called.
     *
     * @param cacheAble
     * @param <T>
     * @return if not cache data available, return null, {@link ICacheAble#onNoCacheData} will not no be called.
     */
@SuppressWarnings({ "unused" })
public <T> T requestCacheSync(ICacheAble<T> cacheAble) {
    if (cacheAble.cacheIsDisabled()) {
        return null;
    }
    // try to find in runtime cache
    String cacheKey = cacheAble.getCacheKey();
    CacheMetaData mRawData = mMemoryCache.get(cacheKey);
    if (mRawData != null) {
        if (DEBUG) {
            CLog.d(LOG_TAG, "key: %s, exist in list", cacheKey);
        }
    }
    // try read from cache data
    if (mRawData == null) {
        boolean hasFileCache = mFileCache.getDiskCache().has(cacheKey);
        if (hasFileCache) {
            String cacheContent = mFileCache.read(cacheKey);
            JsonData jsonData = JsonData.create(cacheContent);
            mRawData = CacheMetaData.createFromJson(jsonData);
        }
    }
    // try to read from assets cache file
    if (mRawData == null) {
        String assertInitDataPath = cacheAble.getAssertInitDataPath();
        if (assertInitDataPath != null && assertInitDataPath.length() > 0) {
            String cacheContent = DiskFileUtils.readAssert(mContext, assertInitDataPath);
            if (!TextUtils.isEmpty(cacheContent)) {
                mRawData = CacheMetaData.createInvalidated(cacheContent);
                putDataToMemoryCache(cacheKey, mRawData);
            }
        }
    }
    if (mRawData != null) {
        boolean outOfDate = mRawData.isOutOfDateFor(cacheAble);
        if (outOfDate && !cacheAble.useCacheAnyway()) {
            return null;
        }
        JsonData data = JsonData.create(mRawData.getData());
        T ret = cacheAble.processRawDataFromCache(data);
        cacheAble.onCacheData(CacheResultType.FROM_INIT_FILE, ret, outOfDate);
        return ret;
    }
    if (DEBUG) {
        CLog.d(LOG_TAG, "key: %s, cache file not exist", cacheKey);
    }
    return null;
}
Also used : JsonData(in.srain.cube.request.JsonData)

Aggregations

JsonData (in.srain.cube.request.JsonData)5 View (android.view.View)4 AdapterView (android.widget.AdapterView)4 MaterialStyleFragment (in.srain.cube.views.ptr.demo.ui.MaterialStyleFragment)4 ListView (android.widget.ListView)3 CubeImageView (in.srain.cube.image.CubeImageView)3 PtrFrameLayout (in.srain.cube.views.ptr.PtrFrameLayout)3 PtrHandler (in.srain.cube.views.ptr.PtrHandler)3 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 GridView (android.widget.GridView)1 ViewHolderCreator (in.srain.cube.views.list.ViewHolderCreator)1