78 lines
2.5 KiB
Java
78 lines
2.5 KiB
Java
package cn.com.magnity.magnitycx.sdk;
|
|
|
|
import android.content.BroadcastReceiver;
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.content.IntentFilter;
|
|
import android.os.Parcelable;
|
|
import android.support.v4.content.LocalBroadcastManager;
|
|
import cn.com.magnity.magnitycx.MagApplication;
|
|
|
|
/* loaded from: classes.dex */
|
|
public class MsgBus {
|
|
private static MsgBus mInstance;
|
|
private static LocalBroadcastManager mLocalBroadcastManager;
|
|
|
|
public static synchronized MsgBus getInstance() {
|
|
MsgBus msgBus;
|
|
synchronized (MsgBus.class) {
|
|
if (mInstance == null) {
|
|
mInstance = new MsgBus(MagApplication.getInstance());
|
|
}
|
|
msgBus = mInstance;
|
|
}
|
|
return msgBus;
|
|
}
|
|
|
|
public MsgBus(Context context) {
|
|
mLocalBroadcastManager = LocalBroadcastManager.getInstance(context.getApplicationContext());
|
|
}
|
|
|
|
public void register(BroadcastReceiver receiver, String action) {
|
|
IntentFilter intentFilter = new IntentFilter();
|
|
intentFilter.addAction(action);
|
|
mLocalBroadcastManager.registerReceiver(receiver, intentFilter);
|
|
}
|
|
|
|
public void register(BroadcastReceiver receiver, String[] actions) {
|
|
IntentFilter intentFilter = new IntentFilter();
|
|
for (String msg : actions) {
|
|
intentFilter.addAction(msg);
|
|
}
|
|
mLocalBroadcastManager.registerReceiver(receiver, intentFilter);
|
|
}
|
|
|
|
public void unregister(BroadcastReceiver receiver) {
|
|
mLocalBroadcastManager.unregisterReceiver(receiver);
|
|
}
|
|
|
|
public void postEmptytMsg(String msg) {
|
|
mLocalBroadcastManager.sendBroadcast(new Intent(msg));
|
|
}
|
|
|
|
public void postMsg(String msg, String tag, int val) {
|
|
Intent intent = new Intent(msg);
|
|
intent.putExtra(tag, val);
|
|
mLocalBroadcastManager.sendBroadcast(intent);
|
|
}
|
|
|
|
public void postMsg(String msg, String tag, String val) {
|
|
Intent intent = new Intent(msg);
|
|
intent.putExtra(tag, val);
|
|
mLocalBroadcastManager.sendBroadcast(intent);
|
|
}
|
|
|
|
public void postMsg(String msg, String tag, Parcelable parcel) {
|
|
Intent intent = new Intent(msg);
|
|
intent.putExtra(tag, parcel);
|
|
mLocalBroadcastManager.sendBroadcast(intent);
|
|
}
|
|
|
|
public void postMsg(String msg, String tag1, Parcelable parcel, String tag2, int val) {
|
|
Intent intent = new Intent();
|
|
intent.putExtra(tag1, parcel);
|
|
intent.putExtra(tag2, val);
|
|
mLocalBroadcastManager.sendBroadcast(intent);
|
|
}
|
|
}
|