Java Code Examples for com.socks.jiandan.utils.NetWorkUtil

The following examples show how to use com.socks.jiandan.utils.NetWorkUtil. 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
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   File: PictureFragment.java    License: Apache License 2.0 6 votes vote down vote up
public void onEventMainThread(NetWorkEvent event) {

        if (event.getType() == NetWorkEvent.AVAILABLE) {
            if (NetWorkUtil.isWifiConnected(getActivity())) {
                mAdapter.setIsWifi(true);
                if (!isFirstChange && (System.currentTimeMillis() - lastShowTime) > 3000) {
                    ShowToast.Short("已切换为WIFI模式,自动加载GIF图片");
                    lastShowTime = System.currentTimeMillis();
                }
            } else {
                mAdapter.setIsWifi(false);
                if (!isFirstChange && (System.currentTimeMillis() - lastShowTime) > 3000) {
                    ShowToast.Short("已切换为省流量模式,只加载GIF缩略图");
                    lastShowTime = System.currentTimeMillis();
                }
            }
            isFirstChange = false;
        }
    }
 
Example #2
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   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   Author: ZhaoKaiQiang   File: PictureFragment.java    License: Apache License 2.0 6 votes vote down vote up
public void onEventMainThread(NetWorkEvent event) {

        if (event.getType() == NetWorkEvent.AVAILABLE) {
            if (NetWorkUtil.isWifiConnected(getActivity())) {
                mAdapter.setIsWifi(true);
                if (!isFirstChange && (System.currentTimeMillis() - lastShowTime) > 3000) {
                    ShowToast.Short("已切换为WIFI模式,自动加载GIF图片");
                    lastShowTime = System.currentTimeMillis();
                }
            } else {
                mAdapter.setIsWifi(false);
                if (!isFirstChange && (System.currentTimeMillis() - lastShowTime) > 3000) {
                    ShowToast.Short("已切换为省流量模式,只加载GIF缩略图");
                    lastShowTime = System.currentTimeMillis();
                }
            }
            isFirstChange = false;
        }
    }
 
Example #4
Source Project: JianDan   Author: ZhaoKaiQiang   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 #5
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   File: PictureFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onStart() {
    super.onStart();

    Subscription subscribe = RxNetWorkEvent.toObserverable().subscribe(netWorkEvent -> {
        if (netWorkEvent.getType() == NetWorkEvent.AVAILABLE) {
            if (NetWorkUtil.isWifiConnected(getActivity())) {
                mAdapter.setIsWifi(true);
                if (!isFirstChange && (System.currentTimeMillis() - lastShowTime) > 3000) {
                    ToastHelper.Short(R.string.load_mode_wifi);
                    lastShowTime = System.currentTimeMillis();
                }
            } else {
                mAdapter.setIsWifi(false);
                if (!isFirstChange && (System.currentTimeMillis() - lastShowTime) > 3000) {
                    ToastHelper.Short(R.string.load_mode_3g);
                    lastShowTime = System.currentTimeMillis();
                }
            }
            isFirstChange = false;
        }
    });

    mRxBusComposite.add(subscribe);
}
 
Example #6
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: PictureFragment.java    License: Apache License 2.0 6 votes vote down vote up
public void onEventMainThread(NetWorkEvent event) {

        if (event.getType() == NetWorkEvent.AVAILABLE) {
            if (NetWorkUtil.isWifiConnected(getActivity())) {
                mAdapter.setIsWifi(true);
                if (!isFirstChange && (System.currentTimeMillis() - lastShowTime) > 3000) {
                    ShowToast.Short("已切换为WIFI模式,自动加载GIF图片");
                    lastShowTime = System.currentTimeMillis();
                }
            } else {
                mAdapter.setIsWifi(false);
                if (!isFirstChange && (System.currentTimeMillis() - lastShowTime) > 3000) {
                    ShowToast.Short("已切换为省流量模式,只加载GIF缩略图");
                    lastShowTime = System.currentTimeMillis();
                }
            }
            isFirstChange = false;
        }
    }
 
Example #7
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   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 #8
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   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 #9
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public PictureAdapter(Activity activity, LoadResultCallBack loadResultCallBack, LoadFinishCallBack loadFinisCallBack, Picture.PictureType type) {
    mActivity = activity;
    mType = type;
    mLoadFinisCallBack = loadFinisCallBack;
    mLoadResultCallBack = loadResultCallBack;
    pictures = new ArrayList<>();
    isWifiConnected = NetWorkUtil.isWifiConnected(mActivity);
}
 
Example #10
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   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 #11
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   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 #12
Source Project: JianDan   Author: ZhaoKaiQiang   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 #13
Source Project: JianDan   Author: ZhaoKaiQiang   File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public PictureAdapter(Activity activity, LoadResultCallBack loadResultCallBack, LoadFinishCallBack loadFinisCallBack, Picture.PictureType type) {
    mActivity = activity;
    mType = type;
    mLoadFinisCallBack = loadFinisCallBack;
    mLoadResultCallBack = loadResultCallBack;
    pictures = new ArrayList<>();
    isWifiConnected = NetWorkUtil.isWifiConnected(mActivity);
}
 
Example #14
Source Project: JianDan   Author: ZhaoKaiQiang   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 #15
Source Project: JianDan   Author: ZhaoKaiQiang   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 #16
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   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 #17
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   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 #18
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public PictureAdapter(BaseActivity activity, LoadResultCallBack loadResultCallBack, LoadFinishCallBack<Object> loadFinisCallBack, int type) {
    mActivity = activity;
    mType = type;
    mLoadFinisCallBack = loadFinisCallBack;
    mLoadResultCallBack = loadResultCallBack;
    mPictures = new ArrayList<>();
    isWifiConnected = NetWorkUtil.isWifiConnected(mActivity);
}
 
Example #19
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   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 #20
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   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 #21
Source Project: JianDanRxJava   Author: ZhaoKaiQiang   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 #22
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   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 #23
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   File: PictureAdapter.java    License: Apache License 2.0 5 votes vote down vote up
public PictureAdapter(Activity activity, LoadResultCallBack loadResultCallBack, LoadFinishCallBack loadFinisCallBack, Picture.PictureType type) {
    mActivity = activity;
    mType = type;
    mLoadFinisCallBack = loadFinisCallBack;
    mLoadResultCallBack = loadResultCallBack;
    pictures = new ArrayList<>();
    isWifiConnected = NetWorkUtil.isWifiConnected(mActivity);
}
 
Example #24
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   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 #25
Source Project: JianDan_OkHttp   Author: ZhaoKaiQiang   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 #26
Source Project: JianDan_OkHttpWithVolley   Author: ZhaoKaiQiang   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();
        }

    }
 
Example #27
Source Project: JianDan   Author: ZhaoKaiQiang   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();
        }

    }