Java Code Examples for com.socks.jiandan.utils.NetWorkUtil#isNetWorkConnected()

The following examples show how to use com.socks.jiandan.utils.NetWorkUtil#isNetWorkConnected() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
protected void initData() {

    netStateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(
                    ConnectivityManager.CONNECTIVITY_ACTION)) {
                if (NetWorkUtil.isNetWorkConnected(MainActivity.this)) {
                    EventBus.getDefault().post(new NetWorkEvent(NetWorkEvent.AVAILABLE));
                } else {
                    EventBus.getDefault().post(new NetWorkEvent(NetWorkEvent.UNAVAILABLE));
                }
            }
        }
    };

    registerReceiver(netStateReceiver, new IntentFilter(
            ConnectivityManager.CONNECTIVITY_ACTION));
}
 
Example 2
Source Project: JianDan   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void initData() {

    netStateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(
                    ConnectivityManager.CONNECTIVITY_ACTION)) {
                if (NetWorkUtil.isNetWorkConnected(MainActivity.this)) {
                    EventBus.getDefault().post(new NetWorkEvent(NetWorkEvent.AVAILABLE));
                } else {
                    EventBus.getDefault().post(new NetWorkEvent(NetWorkEvent.UNAVAILABLE));
                }
            }
        }
    };

    registerReceiver(netStateReceiver, new IntentFilter(
            ConnectivityManager.CONNECTIVITY_ACTION));
}
 
Example 3
Source Project: JianDan_OkHttp   File: MainActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void initData() {

    netStateReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(
                    ConnectivityManager.CONNECTIVITY_ACTION)) {
                if (NetWorkUtil.isNetWorkConnected(MainActivity.this)) {
                    EventBus.getDefault().post(new NetWorkEvent(NetWorkEvent.AVAILABLE));
                } else {
                    EventBus.getDefault().post(new NetWorkEvent(NetWorkEvent.UNAVAILABLE));
                }
            }
        }
    };

    registerReceiver(netStateReceiver, new IntentFilter(
            ConnectivityManager.CONNECTIVITY_ACTION));
}
 
Example 4
private void loadDataByNetworkType() {

        if (NetWorkUtil.isNetWorkConnected(mActivity)) {
            loadData();
        } else {
            loadCache();
        }

    }
 
Example 5
private void loadDataByNetworkType() {

        if (NetWorkUtil.isNetWorkConnected(mActivity)) {
            loadData();
        } else {
            loadCache();
        }

    }
 
Example 6
private void loadDataByNetworkType() {
    if (NetWorkUtil.isNetWorkConnected(mActivity)) {
        loadData();
    } else {
        loadCache();
    }
}
 
Example 7
Source Project: JianDan   File: JokeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadDataByNetworkType() {

        if (NetWorkUtil.isNetWorkConnected(mActivity)) {
            loadData();
        } else {
            loadCache();
        }

    }
 
Example 8
Source Project: JianDan   File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadDataByNetworkType() {

        if (NetWorkUtil.isNetWorkConnected(mActivity)) {
            loadData();
        } else {
            loadCache();
        }

    }
 
Example 9
Source Project: JianDan   File: VideoAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadDataByNetworkType() {
    if (NetWorkUtil.isNetWorkConnected(mActivity)) {
        loadData();
    } else {
        loadCache();
    }
}
 
Example 10
Source Project: JianDanRxJava   File: NetStateReceiver.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (intent.getAction().equals(
            ConnectivityManager.CONNECTIVITY_ACTION)) {
        if (NetWorkUtil.isNetWorkConnected(context)) {
            RxNetWorkEvent.send(new NetWorkEvent(NetWorkEvent.AVAILABLE));
        } else {
            RxNetWorkEvent.send(new NetWorkEvent(NetWorkEvent.UNAVAILABLE));
        }
    }
}
 
Example 11
Source Project: JianDanRxJava   File: JokeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadDataByNetworkType() {
    if (NetWorkUtil.isNetWorkConnected(mActivity)) {
        loadData();
    } else {
        loadCache();
    }
}
 
Example 12
Source Project: JianDanRxJava   File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadDataByNetworkType() {
    if (NetWorkUtil.isNetWorkConnected(mActivity)) {
        loadData();
    } else {
        loadCache();
    }
}
 
Example 13
Source Project: JianDanRxJava   File: FreshNewsAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadDataByNetworkType() {

        if (NetWorkUtil.isNetWorkConnected(mActivity)) {
            loadDate();
        } else {
            loadFromCache();
        }
    }
 
Example 14
Source Project: JianDanRxJava   File: VideoAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadDataByNetworkType() {
    if (NetWorkUtil.isNetWorkConnected(mActivity)) {
        loadData();
    } else {
        loadCache();
    }
}
 
Example 15
Source Project: JianDan_OkHttp   File: JokeAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadDataByNetworkType() {

        if (NetWorkUtil.isNetWorkConnected(mActivity)) {
            loadData();
        } else {
            loadCache();
        }

    }
 
Example 16
Source Project: JianDan_OkHttp   File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadDataByNetworkType() {

        if (NetWorkUtil.isNetWorkConnected(mActivity)) {
            loadData();
        } else {
            loadCache();
        }

    }
 
Example 17
Source Project: JianDan_OkHttp   File: VideoAdapter.java    License: Apache License 2.0 5 votes vote down vote up
private void loadDataByNetworkType() {
    if (NetWorkUtil.isNetWorkConnected(mActivity)) {
        loadData();
    } else {
        loadCache();
    }
}
 
Example 18
private void loadDataByNetworkType() {

        if (NetWorkUtil.isNetWorkConnected(mActivity)) {
            RequestManager.addRequest(new Request4FreshNews(FreshNews.getUrlFreshNews(page),
                    new Response.Listener<ArrayList<FreshNews>>() {
                        @Override
                        public void onResponse(ArrayList<FreshNews> response) {

                            mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                            mLoadFinisCallBack.loadFinish(null);

                            if (page == 1) {
                                mFreshNews.clear();
                                FreshNewsCache.getInstance(mActivity).clearAllCache();
                            }

                            mFreshNews.addAll(response);
                            notifyDataSetChanged();

                            FreshNewsCache.getInstance(mActivity).addResultCache(JSONParser.toString(response),
                                    page);
                        }
                    }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
                    mLoadFinisCallBack.loadFinish(null);
                }
            }), mActivity);
        } else {
            mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
            mLoadFinisCallBack.loadFinish(null);

            if (page == 1) {
                mFreshNews.clear();
                ShowToast.Short(ConstantString.LOAD_NO_NETWORK);
            }

            mFreshNews.addAll(FreshNewsCache.getInstance(mActivity).getCacheByPage(page));
            notifyDataSetChanged();
        }

    }
 
Example 19
Source Project: JianDan   File: FreshNewsAdapter.java    License: Apache License 2.0 4 votes vote down vote up
private void loadDataByNetworkType() {

        if (NetWorkUtil.isNetWorkConnected(mActivity)) {
            RequestManager.addRequest(new Request4FreshNews(FreshNews.getUrlFreshNews(page),
                    new Response.Listener<ArrayList<FreshNews>>() {
                        @Override
                        public void onResponse(ArrayList<FreshNews> response) {

                            mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
                            mLoadFinisCallBack.loadFinish(null);

                            if (page == 1) {
                                mFreshNews.clear();
                                FreshNewsCache.getInstance(mActivity).clearAllCache();
                            }

                            mFreshNews.addAll(response);
                            notifyDataSetChanged();

                            FreshNewsCache.getInstance(mActivity).addResultCache(JSONParser.toString(response),
                                    page);
                        }
                    }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    mLoadResultCallBack.onError(LoadResultCallBack.ERROR_NET, error.getMessage());
                    mLoadFinisCallBack.loadFinish(null);
                }
            }), mActivity);
        } else {
            mLoadResultCallBack.onSuccess(LoadResultCallBack.SUCCESS_OK, null);
            mLoadFinisCallBack.loadFinish(null);

            if (page == 1) {
                mFreshNews.clear();
                ShowToast.Short(ConstantString.LOAD_NO_NETWORK);
            }

            mFreshNews.addAll(FreshNewsCache.getInstance(mActivity).getCacheByPage(page));
            notifyDataSetChanged();
        }

    }