com.socks.jiandan.model.NetWorkEvent Java Examples

The following examples show how to use com.socks.jiandan.model.NetWorkEvent. 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 File: PictureFragment.java    From JianDan_OkHttpWithVolley with 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 File: MainActivity.java    From JianDan_OkHttpWithVolley with 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 File: PictureFragment.java    From JianDan with 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 File: MainActivity.java    From JianDan with 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 File: PictureFragment.java    From JianDanRxJava with 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 File: PictureFragment.java    From JianDan_OkHttp with 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 File: MainActivity.java    From JianDan_OkHttp with 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 File: NetStateReceiver.java    From JianDanRxJava with 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 #9
Source File: MainActivity.java    From JianDanRxJava with Apache License 2.0 5 votes vote down vote up
@Override
protected void onStart() {
    super.onStart();
    mRxBusComposite = new CompositeSubscription();
    Subscription sub = RxNetWorkEvent.toObserverable()
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(AndroidSchedulers.mainThread())
            .subscribe(netWorkEvent -> {
                if (netWorkEvent.getType() == NetWorkEvent.UNAVAILABLE) {
                    if (noNetWorkDialog == null) {
                        noNetWorkDialog = new MaterialDialog.Builder(MainActivity.this)
                                .title(R.string.no_network)
                                .content(R.string.open_network)
                                .backgroundColor(getResources().getColor(JDApplication.COLOR_OF_DIALOG))
                                .contentColor(JDApplication.COLOR_OF_DIALOG_CONTENT)
                                .positiveColor(JDApplication.COLOR_OF_DIALOG_CONTENT)
                                .negativeColor(JDApplication.COLOR_OF_DIALOG_CONTENT)
                                .titleColor(JDApplication.COLOR_OF_DIALOG_CONTENT)
                                .negativeText(R.string.no).positiveText(R.string.yes)
                                .onPositive((dialog, which) -> IntentHelper.toSettingActivity(mContext))
                                .cancelable(false)
                                .build();
                    }
                    if (!noNetWorkDialog.isShowing()) {
                        noNetWorkDialog.show();
                    }
                }
            });
    mRxBusComposite.add(sub);
}
 
Example #10
Source File: RxNetWorkEvent.java    From JianDanRxJava with Apache License 2.0 4 votes vote down vote up
public static void send(NetWorkEvent o) {
    bus.onNext(o);
}
 
Example #11
Source File: RxNetWorkEvent.java    From JianDanRxJava with Apache License 2.0 4 votes vote down vote up
public static Observable<NetWorkEvent> toObserverable() {
    return bus;
}