移除ConnectiveChangedReceiver(没用到且有内存泄漏)
This commit is contained in:
@@ -78,7 +78,6 @@ import com.yizhuan.erban.module_hall.HallDataManager;
|
||||
import com.yizhuan.erban.other.activity.SplashActivity;
|
||||
import com.yizhuan.erban.quick_pass.QuickPassLoginAct;
|
||||
import com.yizhuan.erban.radish.wallet.RadishWalletManager;
|
||||
import com.yizhuan.erban.reciever.ConnectiveChangedReceiver;
|
||||
import com.yizhuan.erban.utils.PushMessageHandler;
|
||||
import com.yizhuan.xchat_android_constants.XChatConstants;
|
||||
import com.yizhuan.xchat_android_core.Constants;
|
||||
@@ -593,7 +592,6 @@ public class XChatApplication extends Application {
|
||||
|
||||
initRxNet(BasicConfig.INSTANCE.getAppContext(), UriProvider.JAVA_WEB_URL);
|
||||
|
||||
ConnectiveChangedReceiver.getInstance().init(BasicConfig.INSTANCE.getAppContext());
|
||||
/**
|
||||
* 使用到realm 数据库,这里配置数据库 这里必须先于模块初始化前进行初始化配置
|
||||
*/
|
||||
|
@@ -1,19 +1,17 @@
|
||||
package com.yizhuan.erban.avroom.ktv;
|
||||
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
|
||||
import com.yizhuan.erban.BR;
|
||||
import com.yizhuan.erban.R;
|
||||
import com.yizhuan.erban.avroom.activity.AVRoomActivity;
|
||||
import com.yizhuan.erban.base.BaseBindingFragment;
|
||||
import com.yizhuan.erban.bindadapter.BaseAdapter;
|
||||
import com.yizhuan.erban.databinding.FragmentRecyclerViewBindNoBgBinding;
|
||||
import com.yizhuan.erban.reciever.ConnectiveChangedReceiver;
|
||||
import com.yizhuan.xchat_android_core.room.ktv.bean.KtvRoomInfo;
|
||||
import com.yizhuan.xchat_android_library.annatation.ActLayoutRes;
|
||||
|
||||
@@ -44,18 +42,6 @@ public class KtvRoomListFragment extends BaseBindingFragment<FragmentRecyclerVie
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ConnectiveChangedReceiver.getInstance().registerConnectiveChange(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
ConnectiveChangedReceiver.getInstance().unRegisterConnectiveChange(this);
|
||||
}
|
||||
|
||||
private void loadData(boolean isLoad) {
|
||||
ktvRoomListVm.loadData(isLoad)
|
||||
.compose(bindToLifecycle())
|
||||
@@ -89,20 +75,4 @@ public class KtvRoomListFragment extends BaseBindingFragment<FragmentRecyclerVie
|
||||
loadData(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change2NoConnection() {
|
||||
super.change2NoConnection();
|
||||
if (adapter!=null) adapter.setEmptyView(KtvHelper.createKtvEmptyView(getContext(),KtvHelper.NO_NET));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectiveMobileData() {
|
||||
connectiveWifi();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectiveWifi() {
|
||||
if (adapter!=null) adapter.setEmptyView(KtvHelper.createKtvEmptyView(getContext(),KtvHelper.NO_ROOM));
|
||||
}
|
||||
}
|
||||
|
@@ -3,9 +3,6 @@ package com.yizhuan.erban.avroom.ktv;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
@@ -16,16 +13,16 @@ import android.view.ViewGroup;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||
import com.coorchice.library.SuperTextView;
|
||||
import com.google.android.flexbox.FlexboxLayout;
|
||||
|
||||
import com.yizhuan.erban.BR;
|
||||
import com.yizhuan.erban.R;
|
||||
import com.yizhuan.erban.base.BaseBindingActivity;
|
||||
import com.yizhuan.erban.bindadapter.BaseAdapter;
|
||||
import com.yizhuan.erban.databinding.ActivityKtvSearchSongBinding;
|
||||
import com.yizhuan.erban.reciever.ConnectiveChangedReceiver;
|
||||
import com.yizhuan.erban.ui.widget.magicindicator.buildins.UIUtil;
|
||||
import com.yizhuan.erban.utils.UserUtils;
|
||||
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
|
||||
@@ -191,34 +188,4 @@ public class KtvSearchSongActivity extends BaseBindingActivity<ActivityKtvSearch
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ConnectiveChangedReceiver.getInstance().registerConnectiveChange(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
ConnectiveChangedReceiver.getInstance().unRegisterConnectiveChange(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void change2NoConnection() {
|
||||
super.change2NoConnection();
|
||||
if (adapter!=null)
|
||||
adapter.setEmptyView(KtvHelper.createKtvEmptyView(context,KtvHelper.NO_NET));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectiveMobileData() {
|
||||
connectiveWifi();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectiveWifi() {
|
||||
if (adapter!=null)
|
||||
adapter.setEmptyView(KtvHelper.createKtvEmptyView(context,KtvHelper.NO_DATA));
|
||||
}
|
||||
}
|
||||
|
@@ -1,22 +1,24 @@
|
||||
package com.yizhuan.erban.avroom.ktv;
|
||||
|
||||
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_KTV_DELETE;
|
||||
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_KTV_TOP;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import android.view.View;
|
||||
|
||||
import com.trello.rxlifecycle3.android.ActivityEvent;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import com.trello.rxlifecycle3.android.ActivityEvent;
|
||||
import com.yizhuan.erban.BR;
|
||||
import com.yizhuan.erban.R;
|
||||
import com.yizhuan.erban.base.BaseBindingActivity;
|
||||
import com.yizhuan.erban.base.TitleBar;
|
||||
import com.yizhuan.erban.bindadapter.BaseAdapter;
|
||||
import com.yizhuan.erban.databinding.ActivityKtvSongListBinding;
|
||||
import com.yizhuan.erban.reciever.ConnectiveChangedReceiver;
|
||||
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
|
||||
import com.yizhuan.xchat_android_core.room.ktv.bean.MusicInfo;
|
||||
import com.yizhuan.xchat_android_core.room.ktv.event.KtvEvent;
|
||||
@@ -29,9 +31,6 @@ import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_KTV_DELETE;
|
||||
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_KTV_TOP;
|
||||
|
||||
/**
|
||||
* <p> KTV房间已点列表</p>
|
||||
*
|
||||
@@ -143,27 +142,11 @@ public class KtvSongListActivity extends BaseBindingActivity<ActivityKtvSongList
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
ConnectiveChangedReceiver.getInstance().registerConnectiveChange(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
ConnectiveChangedReceiver.getInstance().unRegisterConnectiveChange(this);
|
||||
}
|
||||
@Override
|
||||
public void change2NoConnection() {
|
||||
super.change2NoConnection();
|
||||
if (adapter!=null) adapter.setEmptyView(KtvHelper.createKtvEmptyView(context,KtvHelper.NO_NET));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectiveMobileData() {
|
||||
connectiveWifi();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectiveWifi() {
|
||||
if (adapter!=null) adapter.setEmptyView(KtvHelper.createKtvEmptyView(context,KtvHelper.NO_SONG));
|
||||
}
|
||||
}
|
||||
|
@@ -14,7 +14,6 @@ import android.annotation.SuppressLint;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
@@ -34,7 +33,6 @@ import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
@@ -66,7 +64,6 @@ import com.yizhuan.erban.common.permission.PermissionActivity;
|
||||
import com.yizhuan.erban.common.widget.StatusLayout;
|
||||
import com.yizhuan.erban.common.widget.dialog.DialogManager;
|
||||
import com.yizhuan.erban.common.widget.dialog.DialogUiHelper;
|
||||
import com.yizhuan.erban.reciever.ConnectiveChangedReceiver;
|
||||
import com.yizhuan.erban.ui.im.avtivity.NimP2PMessageActivity;
|
||||
import com.yizhuan.erban.ui.login.AddUserInfoActivity;
|
||||
import com.yizhuan.erban.ui.login.LoginCodeActivity;
|
||||
@@ -94,7 +91,6 @@ import com.yizhuan.xchat_android_core.room.model.AvRoomModel;
|
||||
import com.yizhuan.xchat_android_core.statistic.StatisticManager;
|
||||
import com.yizhuan.xchat_android_core.statistic.protocol.StatisticsProtocol;
|
||||
import com.yizhuan.xchat_android_core.user.UserModel;
|
||||
import com.yizhuan.xchat_android_core.user.bean.UserInfo;
|
||||
import com.yizhuan.xchat_android_core.utils.net.RxHelper;
|
||||
import com.yizhuan.xchat_android_core.vip.VipMessageInfo;
|
||||
import com.yizhuan.xchat_android_library.rxbus.RxBus;
|
||||
@@ -117,15 +113,13 @@ import java.util.List;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.functions.Consumer;
|
||||
|
||||
|
||||
/**
|
||||
* @author alvin hwang
|
||||
*/
|
||||
public abstract class BaseActivity extends RxAppCompatActivity
|
||||
implements IDataStatus, ConnectiveChangedReceiver.ConnectiveChangedListener,
|
||||
DialogManagerInterface {
|
||||
implements IDataStatus, DialogManagerInterface {
|
||||
|
||||
/**
|
||||
* --------------------------------------------------
|
||||
@@ -500,8 +494,6 @@ public abstract class BaseActivity extends RxAppCompatActivity
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
//add connective changed broadcast receiver
|
||||
// ConnectiveChangedReceiver.getInstance().registerConnectiveChange(this);
|
||||
StatisticManager.Instance().onResume(this);
|
||||
//GlideApp.with(this).resumeRequests();
|
||||
RxBus.get().toFlowable(String.class)
|
||||
@@ -532,50 +524,7 @@ public abstract class BaseActivity extends RxAppCompatActivity
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
//remove connective changed broadcast receiver
|
||||
// ConnectiveChangedReceiver.getInstance().unRegisterConnectiveChange(this);
|
||||
StatisticManager.Instance().onPause(this);
|
||||
//GlideApp.with(this).pauseRequests();
|
||||
}
|
||||
|
||||
/**
|
||||
* wifi 转 2G/3G/4G
|
||||
*/
|
||||
public void wifiChange2MobileData() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 有网络变为无网络
|
||||
*/
|
||||
public void change2NoConnection() {
|
||||
if (isTopActive()) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连上wifi
|
||||
*/
|
||||
public void connectiveWifi() {
|
||||
if (isTopActive()) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连上移动数据网络
|
||||
*/
|
||||
public void connectiveMobileData() {
|
||||
if (isTopActive()) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动数据网络 改为连上wifi
|
||||
*/
|
||||
public void mobileDataChange2Wifi() {
|
||||
|
||||
}
|
||||
|
||||
protected boolean checkActivityValid() {
|
||||
|
@@ -5,10 +5,6 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
@@ -16,10 +12,14 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.tbruyelle.rxpermissions2.RxPermissions;
|
||||
import com.trello.rxlifecycle3.components.support.RxFragment;
|
||||
import com.yizhuan.erban.R;
|
||||
import com.yizhuan.erban.application.XChatApplication;
|
||||
import com.yizhuan.erban.common.AbsStatusFragment;
|
||||
import com.yizhuan.erban.common.LoadingFragment;
|
||||
import com.yizhuan.erban.common.NetworkErrorFragment;
|
||||
@@ -27,7 +27,6 @@ import com.yizhuan.erban.common.NoDataFragment;
|
||||
import com.yizhuan.erban.common.ReloadFragment;
|
||||
import com.yizhuan.erban.common.widget.StatusLayout;
|
||||
import com.yizhuan.erban.common.widget.dialog.DialogManager;
|
||||
import com.yizhuan.erban.reciever.ConnectiveChangedReceiver;
|
||||
import com.yizhuan.xchat_android_library.utils.NetworkUtils;
|
||||
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
|
||||
import com.yizhuan.xchat_android_library.utils.UIUtils;
|
||||
@@ -44,7 +43,7 @@ import io.reactivex.disposables.CompositeDisposable;
|
||||
* @author alvin hwang
|
||||
*/
|
||||
public abstract class BaseFragment extends RxFragment implements KeyEvent.Callback, IDataStatus,
|
||||
ConnectiveChangedReceiver.ConnectiveChangedListener, FragmentManager.OnBackStackChangedListener, IAcitivityBase {
|
||||
FragmentManager.OnBackStackChangedListener, IAcitivityBase {
|
||||
|
||||
protected CompositeDisposable mCompositeDisposable;
|
||||
|
||||
@@ -165,51 +164,6 @@ public abstract class BaseFragment extends RxFragment implements KeyEvent.Callba
|
||||
super.onHiddenChanged(hidden);
|
||||
}
|
||||
|
||||
/**
|
||||
* 网络连接变化
|
||||
*/
|
||||
/**
|
||||
* wifi 转 2G/3G/4G
|
||||
*/
|
||||
public void wifiChange2MobileData() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 有网络变为无网络
|
||||
*/
|
||||
public void change2NoConnection() {
|
||||
if (isTopActive()) {
|
||||
MLog.debug(this, "change2NoConnection");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连上wifi
|
||||
*/
|
||||
public void connectiveWifi() {
|
||||
if (isTopActive()) {
|
||||
MLog.debug(this, "connectiveWifi");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 连上移动数据网络
|
||||
*/
|
||||
public void connectiveMobileData() {
|
||||
if (isTopActive()) {
|
||||
MLog.debug(this, "connectiveMobileData");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移动数据网络 改为连上wifi
|
||||
*/
|
||||
public void mobileDataChange2Wifi() {
|
||||
if (isTopActive()) {
|
||||
MLog.debug(this, "mobileDataChange2Wifi");
|
||||
}
|
||||
}
|
||||
|
||||
public Stack<Integer> activityForResult = new Stack<Integer>();
|
||||
|
||||
/**
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package com.yizhuan.erban.base;
|
||||
|
||||
import com.yizhuan.erban.reciever.ConnectiveChangedReceiver;
|
||||
import com.yizhuan.xchat_android_library.base.IMvpBaseView;
|
||||
import com.yizhuan.xchat_android_library.base.factory.AbstractMvpPresenter;
|
||||
|
||||
@@ -8,6 +7,6 @@ import com.yizhuan.xchat_android_library.base.factory.AbstractMvpPresenter;
|
||||
* @author alvin hwang
|
||||
*/
|
||||
public abstract class BaseMvpActivity<V extends IMvpBaseView, P extends AbstractMvpPresenter<V>> extends AbstractMvpActivity<V, P>
|
||||
implements IDataStatus, ConnectiveChangedReceiver.ConnectiveChangedListener, DialogManagerInterface {
|
||||
implements IDataStatus, DialogManagerInterface {
|
||||
|
||||
}
|
@@ -4,13 +4,12 @@ import android.view.KeyEvent;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.yizhuan.erban.reciever.ConnectiveChangedReceiver;
|
||||
import com.yizhuan.xchat_android_library.base.IMvpBaseView;
|
||||
import com.yizhuan.xchat_android_library.base.factory.AbstractMvpPresenter;
|
||||
|
||||
/**
|
||||
* @author alvin hwang
|
||||
*/
|
||||
public abstract class BaseMvpFragment<V extends IMvpBaseView, P extends AbstractMvpPresenter<V>> extends AbstractMvpFragment<V, P> implements KeyEvent.Callback, IDataStatus,
|
||||
ConnectiveChangedReceiver.ConnectiveChangedListener, FragmentManager.OnBackStackChangedListener, IAcitivityBase {
|
||||
public abstract class BaseMvpFragment<V extends IMvpBaseView, P extends AbstractMvpPresenter<V>> extends AbstractMvpFragment<V, P>
|
||||
implements KeyEvent.Callback, IDataStatus, FragmentManager.OnBackStackChangedListener, IAcitivityBase {
|
||||
}
|
@@ -1,199 +0,0 @@
|
||||
package com.yizhuan.erban.reciever;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.Handler;
|
||||
|
||||
import com.yizhuan.xchat_android_library.utils.BlankUtil;
|
||||
import com.yizhuan.xchat_android_library.utils.NetworkUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Creator: 舒强睿
|
||||
* Date:2015/2/12
|
||||
* Time:20:21
|
||||
* <p/>
|
||||
* Description:监听网络状态改变
|
||||
*/
|
||||
public class ConnectiveChangedReceiver extends BroadcastReceiver {
|
||||
|
||||
public static final String ACTION = "android.net.conn.CONNECTIVITY_CHANGE";
|
||||
|
||||
private Context context;
|
||||
|
||||
int currentState;//当前网络状态 第一次初始化
|
||||
boolean hasChanged;//网络类型是否已经通知改变(interval时间后会重置为false)
|
||||
final long interval = 2000L;//检验网络变化时间间隔为interval (毫秒)
|
||||
|
||||
private static ConnectiveChangedReceiver receiver = new ConnectiveChangedReceiver();
|
||||
private IntentFilter intentFilter;
|
||||
private Handler handler;
|
||||
|
||||
private List<ConnectiveChangedListener> listeners;//观察者(观察网络变化对象)列表
|
||||
|
||||
private ConnectiveChangedReceiver() {
|
||||
}
|
||||
|
||||
public int getCurrentState() {
|
||||
return currentState;
|
||||
}
|
||||
|
||||
public void init(Context context) {
|
||||
this.context = context;
|
||||
this.currentState = NetworkUtils.getNetworkType(context);
|
||||
|
||||
intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(ConnectiveChangedReceiver.ACTION);
|
||||
}
|
||||
|
||||
public static ConnectiveChangedReceiver getInstance() {
|
||||
return receiver;
|
||||
}
|
||||
|
||||
public void registerConnectiveChange(ConnectiveChangedListener listener) {
|
||||
|
||||
if (listener != null) {
|
||||
|
||||
if (listeners == null) {
|
||||
listeners = new ArrayList<ConnectiveChangedListener>();
|
||||
}
|
||||
|
||||
listeners.add(listener);
|
||||
|
||||
tryOpenObserver();
|
||||
}
|
||||
}
|
||||
|
||||
public void unRegisterConnectiveChange(ConnectiveChangedListener listener) {
|
||||
|
||||
if (listener != null && listeners != null && listeners.size() > 0) {
|
||||
|
||||
listeners.remove(listener);
|
||||
|
||||
tryClosedObserver();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 可能listeners 对象变成 null了,这里交给引用的地方 unRegisterConnectiveChange(..)
|
||||
*/
|
||||
private void tryOpenObserver() {
|
||||
|
||||
if (listeners != null && listeners.size() == 1) {
|
||||
context.registerReceiver(this, intentFilter);
|
||||
}
|
||||
}
|
||||
|
||||
private void tryClosedObserver() {
|
||||
|
||||
if (BlankUtil.isBlank(listeners)) {
|
||||
context.unregisterReceiver(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, Intent intent) {
|
||||
|
||||
/*int afterChanged = NetworkUtils.getNetworkType(context);//检测通知时网络链接是否真的有变化*/
|
||||
if (!hasChanged) {
|
||||
hasChanged = true;
|
||||
|
||||
if (handler == null) {
|
||||
handler = new Handler();
|
||||
}
|
||||
|
||||
handler.postDelayed(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
hasChanged = false;
|
||||
int networkState = NetworkUtils.getNetworkType(context);
|
||||
|
||||
if (networkState != currentState) {//通知网络发生变化
|
||||
if (!BlankUtil.isBlank(listeners)) {
|
||||
|
||||
if (currentState == NetworkUtils.NET_WIFI) {//wifi
|
||||
if (networkState == NetworkUtils.NET_3G
|
||||
|| networkState == NetworkUtils.NET_2G) {
|
||||
int size = listeners.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
listeners.get(i).wifiChange2MobileData();
|
||||
}
|
||||
} else {//wifi转无网络
|
||||
int size = listeners.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
listeners.get(i).change2NoConnection();
|
||||
}
|
||||
}
|
||||
} else if (currentState == NetworkUtils.NET_3G
|
||||
|| currentState == NetworkUtils.NET_2G) { //手机流量
|
||||
if (networkState == NetworkUtils.NET_WIFI) {//3G->wifi
|
||||
int size = listeners.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
listeners.get(i).mobileDataChange2Wifi();
|
||||
}
|
||||
} else {//3G转无网络
|
||||
int size = listeners.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
listeners.get(i).change2NoConnection();
|
||||
}
|
||||
}
|
||||
} else {//无网络
|
||||
if (networkState == NetworkUtils.NET_WIFI) {
|
||||
int size = listeners.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
listeners.get(i).connectiveWifi();
|
||||
}
|
||||
} else if (networkState == NetworkUtils.NET_3G
|
||||
|| networkState == NetworkUtils.NET_2G) {
|
||||
int size = listeners.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
listeners.get(i).connectiveMobileData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
currentState = networkState;
|
||||
}
|
||||
}
|
||||
}, interval);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 网络连接改变
|
||||
*/
|
||||
public static interface ConnectiveChangedListener {
|
||||
/* public void onConnectiveChange(int previousNetType, int currentNetType);*/
|
||||
|
||||
/**
|
||||
* wifi 转 2G/3G/4G
|
||||
*/
|
||||
public void wifiChange2MobileData();
|
||||
|
||||
/**
|
||||
* 有网络变为无网络
|
||||
*/
|
||||
public void change2NoConnection();
|
||||
|
||||
/**
|
||||
* 无网络连上wifi
|
||||
*/
|
||||
public void connectiveWifi();
|
||||
|
||||
/**
|
||||
* 无网络连上移动数据网络
|
||||
*/
|
||||
public void connectiveMobileData();
|
||||
|
||||
/**
|
||||
* 移动数据网络 改为连上wifi
|
||||
*/
|
||||
public void mobileDataChange2Wifi();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user