本文整理汇总了Java中org.greenrobot.eventbus.EventBus类的典型用法代码示例。如果您正苦于以下问题:Java EventBus类的具体用法?Java EventBus怎么用?Java EventBus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventBus类属于org.greenrobot.eventbus包,在下文中一共展示了EventBus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listen
import org.greenrobot.eventbus.EventBus; //导入依赖的package包/类
/**
* Listen for client connections
*
* @throws IOException server socket cannot be created on port
*/
private void listen() throws IOException {
try {
Log.d(TAG, "listen: Create server socket");
ServerSocket rtspServerSocket = new ServerSocket();
rtspServerSocket.setReuseAddress(true);
rtspServerSocket.bind(new InetSocketAddress(port));
while (!Thread.interrupted()) {
Log.d(TAG, "listening");
// Blocking
EventBus.getDefault().post(new RtspServerEvent.Connection(this, rtspServerSocket.accept()));
}
} catch (IOException e) {
e.printStackTrace();
}
}
示例2: onEvent
import org.greenrobot.eventbus.EventBus; //导入依赖的package包/类
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
public void onEvent(SyncEvent event) {
switch (event.getCode()) {
case SyncEvent.START_SYNC:
showLoading();
break;
case SyncEvent.END_SYNC:
hideLoading();
EventBus.getDefault().post(new SyncEvent(SyncEvent.UPDATE_SYNC, ""));
EventBus.getDefault().removeStickyEvent(event);
break;
}
if(!event.getStatus().isEmpty()){
Toast.makeText(this, event.getStatus(), Toast.LENGTH_SHORT).show();
}
}
示例3: onHandleIntent
import org.greenrobot.eventbus.EventBus; //导入依赖的package包/类
@Override
protected void onHandleIntent(@Nullable Intent intent) {
isRunning = true;
showForegroundNotification();
name = intent.getStringExtra(EXTRA_ACTIVITY_TYPE);
storage = new StorageUtil(name);
startAccelerometer();
try {
Thread.sleep(Config.LENGTH_RECORDING_IN_MINUTES * 60 * 1000);
} catch (InterruptedException e) {
}
stopAccelerometer();
storage.close();
RecorderFinishedEvent event = new RecorderFinishedEvent();
event.activityType = name;
EventBus.getDefault().post(event);
isRunning = false;
hideForegroundNotification();
ToneGenerator beep = new ToneGenerator(AudioManager.STREAM_MUSIC, 500);
beep.startTone(ToneGenerator.TONE_CDMA_HIGH_L, 1000);
}
示例4: onProgressChanged
import org.greenrobot.eventbus.EventBus; //导入依赖的package包/类
@Override
public void onProgressChanged(final SeekBar seekBar,
final int progress,
final boolean fromUser) {
if (!fromUser) {
// Ignore all changes if they are not from user
return;
}
// Ignore the next status update to avoid the seek bar to
// be updated from a response sent before this request
skipNextStatus = true;
// Send request
EventBus.getDefault().post(new RequestEvent(Cmd.VOLUME,
String.valueOf(progress), true));
}
示例5: onDestroy
import org.greenrobot.eventbus.EventBus; //导入依赖的package包/类
@Override
public void onDestroy() {
isRun = false;
EventBus.getDefault().post(new MessageEvent(MessageEvent.QHB_SERVICE_STATE, false));
EventBus.getDefault().unregister(this);
mQHBNotificationManager.stopNotification();
unregisterReceiver(mBroadcastReceiver);
super.onDestroy();
LogUtils.printOut(TAG, "QHBService onDestroy");
if(mPkgAccessibilityJobMap != null) {
mPkgAccessibilityJobMap.clear();
}
if(mAccessibilityJobs != null && !mAccessibilityJobs.isEmpty()) {
for (IAccessibilityJob job : mAccessibilityJobs) {
job.onDestroy();
}
mAccessibilityJobs.clear();
}
mAccessibilityJobs = null;
mPkgAccessibilityJobMap = null;
}
示例6: GpioHandler
import org.greenrobot.eventbus.EventBus; //导入依赖的package包/类
private GpioHandler() {
EventBus.getDefault().register(this);
mContext = ContextHolder.getAppContext();
manager = new PeripheralManagerService();
try {
mAlarmGpio = manager.openGpio(GPIO_ALARM_TRIGGER);
mAlarmGpio.setDirection(Gpio.DIRECTION_OUT_INITIALLY_LOW);
mMotion = new Button(GPIO_ALARM_MOTION,
Button.LogicState.PRESSED_WHEN_HIGH
);
mMotion.setOnButtonEventListener(this);
} catch (IOException e) {
Log.e(BurglarAlarmConstants.LOG_TAG, "IOException :" + e);
}
}
示例7: onCreateDialog
import org.greenrobot.eventbus.EventBus; //导入依赖的package包/类
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
DateTime currentDateTime = new DateTime();
int currentHour = currentDateTime.getHourOfDay();
int currentMinute = currentDateTime.getMinuteOfHour();
final Bundle args = getArguments();
MinTimePickerDialog timePickerDialog = new MinTimePickerDialog(getActivity(), R.style.MyPicker,
(view, hourOfDay, minute) -> {
DateTime dateTime = new DateTime(
args.getInt(ARGUMENT_PICKED_YEAR),
args.getInt(ARGUMENT_PICKED_MONTH) + 1,
args.getInt(ARGUMENT_PICKED_DAY), hourOfDay, minute);
EventBus.getDefault().post(new ReminderSetEvent(dateTime.getMillis()));
}, currentHour, currentMinute, DateFormat.is24HourFormat(getActivity()));
if (args.getBoolean(ARGUMENT_IS_TODAY)) {
timePickerDialog.setMin(currentHour, currentMinute);
}
return timePickerDialog;
}
示例8: streamLine
import org.greenrobot.eventbus.EventBus; //导入依赖的package包/类
private void streamLine(GcodeCommand gcodeCommand){
String command = gcodeCommand.getCommandString();
int commandSize = command.length() + 1;
if(commandSize <= 1) return;
// Wait until there is room, if necessary.
while (MAX_RX_SERIAL_BUFFER < (CURRENT_RX_SERIAL_BUFFER + command.length() + 1)) {
try {
completedCommands.take();
if(activeCommandSizes.size() > 0) CURRENT_RX_SERIAL_BUFFER -= activeCommandSizes.removeFirst();
} catch (InterruptedException e) {
Log.e(TAG, e.getMessage(), e);
return;
}
if(!shouldContinue) return;
}
if(shouldContinue){
activeCommandSizes.offer(commandSize);
CURRENT_RX_SERIAL_BUFFER += commandSize;
EventBus.getDefault().post(gcodeCommand);
}
}
示例9: onCreate
import org.greenrobot.eventbus.EventBus; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// If you want to handle sticky message, please comment out the following code
EventBus.getDefault().register(this);
}
示例10: onClick
import org.greenrobot.eventbus.EventBus; //导入依赖的package包/类
public void onClick(View view) {
switch (view.getId()) {
case R.id.intent_to_second_button:
startActivity(new Intent(MainActivity.this, SecondActivity.class));
break;
case R.id.handle_sticky_button:
EventBus.getDefault().register(this);
break;
}
startActivity(new Intent(MainActivity.this, SecondActivity.class));
}
示例11: execute
import org.greenrobot.eventbus.EventBus; //导入依赖的package包/类
private static void execute(final WorkerTask task) {
isInstalling = true;
new Thread(new Runnable() {
@Override
public void run() {
task.run();
isInstalling = false;
// dispatch resulting event
EventBus.getDefault().post(task.result());
}
}).start();
}
示例12: setDataList
import org.greenrobot.eventbus.EventBus; //导入依赖的package包/类
public void setDataList(final List<OnlineModel> modelss, final int position) {
Observable.just(models)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Action1<List<OnlineModel>>() {
@Override
public void call(List<OnlineModel> onlineModels) {
synchronized (models) {
if (models.size() == modelss.size()) {
models.clear();
models.addAll(modelss);
notifyItemChanged(position);
} else if (models.size() < modelss.size()) {
models.clear();
models.addAll(modelss);
notifyItemInserted(0);
} else if (models.size() > modelss.size()) { //删除
notifyItemRemoved(position);
models.clear();
models.addAll(modelss);
}
EventBus.getDefault().post(new OnlineEvent(1, models.size(), 0));
}
}
});
}
示例13: close
import org.greenrobot.eventbus.EventBus; //导入依赖的package包/类
public void close() throws IOException {
if (mSocket != null) {
mSocket.close();
mExecutor.shutdownNow();
mSocket = null;
mOutputStream = null;
mExecutor = null;
EventBus.getDefault().post(new ConnectionStateChangeEvent(false));
}
}
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:11,代码来源:SublimePluginClient.java
示例14: onCreate
import org.greenrobot.eventbus.EventBus; //导入依赖的package包/类
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
EventBus.getDefault().register(this);
init();
initUIandEvent();
}
示例15: channelInactive
import org.greenrobot.eventbus.EventBus; //导入依赖的package包/类
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
super.channelInactive(ctx);
try {
EventBus.getDefault().post(new ChannelEvent(EventType.ON_INACTIVE, null));
}catch (Exception e){
e.printStackTrace();
}
}