Java Code Examples for com.socks.jiandan.model.NetWorkEvent

The following examples show how to use com.socks.jiandan.model.NetWorkEvent. 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   Source 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   Source 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   Source 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   Source 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   Source 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   Source 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   Source 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: JianDanRxJava   Source 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 9
Source Project: JianDanRxJava   Source File: MainActivity.java    License: 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 Project: JianDanRxJava   Source File: RxNetWorkEvent.java    License: Apache License 2.0 4 votes vote down vote up
public static void send(NetWorkEvent o) {
    bus.onNext(o);
}
 
Example 11
Source Project: JianDanRxJava   Source File: RxNetWorkEvent.java    License: Apache License 2.0 4 votes vote down vote up
public static Observable<NetWorkEvent> toObserverable() {
    return bus;
}