下面列出了android.support.annotation.RestrictTo#com.squareup.otto.ThreadEnforcer 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onCreate() {
super.onCreate();
bus = new Bus(ThreadEnforcer.ANY);
list = new ArrayList<>();
StringBuffer buffer = new StringBuffer();
try (BufferedReader input = new BufferedReader(
new InputStreamReader(
openFileInput(RSS_FILE)))) {
String line;
while ((line = input.readLine()) != null) {
buffer.append(line);
}
} catch (Exception ex) {
// do nothing
}
if (buffer!=null && buffer.length()>0 )
{
Gson gson = new Gson();
Type type = new TypeToken<List<RssItem>>() {}.getType();
List<RssItem> fromJson = gson.fromJson(buffer.toString(), type);
list.addAll(fromJson);
}
}
/**
* 提供全局单例的event bus
*/
@Provides
@Singleton
public Bus provideBus() {
// our event bus running on any thread
return new Bus(ThreadEnforcer.ANY);
}
@Before public void setUp() throws Exception {
this.busWrapper = new OttoBusWrapper(new Bus(ThreadEnforcer.ANY));
Logger logger = Mockito.mock(Logger.class);
Context context = Mockito.mock(Context.class);
OnlineChecker onlineChecker = Mockito.mock(OnlineChecker.class);
this.receiver = new NetworkConnectionChangeReceiver(busWrapper, logger, context, onlineChecker);
this.connectivityChangeEvents = new ArrayList<>();
}
@Before public void setUp() throws Exception {
this.busWrapper = new OttoBusWrapper(new Bus(ThreadEnforcer.ANY));
Logger logger = Mockito.mock(Logger.class);
Context context = Mockito.mock(Context.class);
this.receiver = new InternetConnectionChangeReceiver(busWrapper, logger, context);
this.connectivityChangeEvents = new ArrayList<>();
}
public static void initialize() {
mBus = new Bus(ThreadEnforcer.MAIN);
mHandler = new Handler();
// Activity and fragment lifecycle events make it difficult to reliably
// make register and unregister calls in a 1-to-1 way. So we're going
// to make sure that things only get registered once and unregistered if
// they're actually registered.
mRegisteredObjects = new HashSet<Object>();
}
private EventBusProvider() {
mBus = new Bus(ThreadEnforcer.MAIN);
}
@RestrictTo(RestrictTo.Scope.TESTS)
public static void setupForTesting() {
sBus = new Bus(ThreadEnforcer.ANY);
}
public DataBus() {
super(ThreadEnforcer.MAIN);
}
public DataBus(ThreadEnforcer thread) {
super(thread);
}
@Inject
public ActionBus() {
super(ThreadEnforcer.ANY);
}
@Before
public void setup() {
actionBus = new ActionBus();
dataBus = new DataBus(ThreadEnforcer.ANY);
store = new TodosActivityStore(actionBus, dataBus);
}
@Before
public void setup() {
actionBus = new ActionBus();
dataBus = new DataBus(ThreadEnforcer.ANY);
list = new TodoListManager(actionBus, dataBus);
}
private EventBus() {
super(ThreadEnforcer.ANY);
}
@Provides
@Singleton
public Bus provideBus() {
return new Bus(ThreadEnforcer.ANY);
}
public AndroidBus() {
super(ThreadEnforcer.MAIN);
}
public void onCreate() {
super.onCreate();
instance = this;
bus = new Bus(ThreadEnforcer.ANY);
}
@Before public void setUp() throws Exception {
this.busWrapper = new OttoBusWrapper(new Bus(ThreadEnforcer.ANY));
Logger logger = Mockito.mock(Logger.class);
Context context = Mockito.mock(Context.class);
this.receiver = new WifiSignalStrengthChangeReceiver(busWrapper, logger, context);
}
public BleEventBus(ThreadEnforcer enforcer) {
super(enforcer, "Indy-Ble-LowLevel");
}
@Provides @Singleton
Bus providesBus() { return new MainThreadBus(new Bus(ThreadEnforcer.ANY)); }
public UIBus() {
// events will be fired on the main thread
this.bus = new Bus(ThreadEnforcer.MAIN);
}
public ChatBus() {
// events will be fired on the main thread
this.bus = new Bus(ThreadEnforcer.MAIN);
}