本文整理匯總了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();
}
}