Java Code Examples for org.greenrobot.eventbus.EventBus

The following examples show how to use org.greenrobot.eventbus.EventBus. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: NMSAlphabetAndroidApp   Source File: App.java    License: MIT License 7 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    CustomActivityOnCrash.install(this);
    EventBus.getDefault().register(this);
    EasyImage.configuration(this)
            .saveInRootPicturesDirectory()
            .setImagesFolderName(getString(R.string.app_name));
    Nammu.init(this);
    Paper.init(this);
    Typekit.getInstance()
            .addNormal(Typekit.createFromAsset(this, "fonts/LatoLatin-Regular.ttf"))
            .addBold(Typekit.createFromAsset(this, "fonts/LatoLatin-Bold.ttf"))
            .addItalic(Typekit.createFromAsset(this, "fonts/LatoLatin-Italic.ttf"))
            .addBoldItalic(Typekit.createFromAsset(this, "fonts/LatoLatin-BoldItalic.ttf"))
            .addCustom1(Typekit.createFromAsset(this, "fonts/Geomanist-Regular.otf"))
            .addCustom2(Typekit.createFromAsset(this, "fonts/Handlee-Regular.ttf"));

    initFabric();
    initParse();
}
 
Example 2
Source Project: AssistantBySDK   Source File: TingPlayProcessor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 合成并显示回复文本
 **/
private void synthesizeAndShowResp(final List<Track> tracks, String content, final int finalPlayIndex) {
    EventBus.getDefault().post(new ChatMsgEvent(new ResponseMsg(content), null, null, null));
    SynthesizerBase.get().startSpeakAbsolute(content)
            .doOnNext(new Consumer<SpeechMsg>() {
                @Override
                public void accept(SpeechMsg speechMsg) throws Exception {
                    if (speechMsg.state() == SpeechMsg.State.OnBegin)
                        EventBus.getDefault().post(new SynthesizeEvent(SynthesizeEvent.SYNTH_START));
                }
            })
            .doOnComplete(new Action() {
                @Override
                public void run() throws Exception {
                    EventBus.getDefault().post(new SynthesizeEvent(SynthesizeEvent.SYNTH_END));
                    if (tracks != null)
                        XmlyManager.get().getPlayer().playList(tracks, finalPlayIndex);
                }
            })
            .subscribeOn(Schedulers.io())
            .observeOn(Schedulers.computation())
            .subscribe();

}
 
Example 3
Source Project: AndroidDownload   Source File: SelectFileByScanActivity.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Fragment中选择文件后
 *
 * @param event event
 */
@Subscribe
public void onFragSelectFile(FileScanFragEvent event) {
    if (event.isAdd()) {
        if (SelectOptions.getInstance().isSingle) {
            mSelectedFileList.add(event.getSelectedFile());
            Intent result = new Intent();
            result.putParcelableArrayListExtra(Const.EXTRA_RESULT_SELECTION, mSelectedFileList);
            setResult(RESULT_OK, result);
            super.onBackPressed();
            return;
        }
        mSelectedFileList.add(event.getSelectedFile());
    } else {
        mSelectedFileList.remove(event.getSelectedFile());
    }
    mCountMenuItem.setTitle(String.format(getString(R.string.selected_file_count), String.valueOf(mSelectedFileList.size()), String.valueOf(SelectOptions.getInstance().maxCount)));
    EventBus.getDefault().post(new FileScanActEvent(SelectOptions.getInstance().maxCount - mSelectedFileList.size()));
}
 
Example 4
Source Project: Focus   Source File: RequireListPopupView.java    License: GNU General Public License v3.0 6 votes vote down vote up
private void saveFeedToFeedFolder(final Feed feed){
    //显示feedFolderList 弹窗
    new ShowFeedFolderListDialogTask(new DialogCallback() {
        @Override
        public void onFinish(MaterialDialog dialog, View view, int which, CharSequence text, int targetId) {
            //移动到指定的目录下
            feed.setFeedFolderId(targetId);
            feed.setTimeout(Feed.DEFAULT_TIMEOUT);
            try{
                feed.saveThrows();
                Toasty.success(UIUtil.getContext(),"订阅成功").show();
                EventBus.getDefault().post(new EventMessage(EventMessage.ADD_FEED));
            }catch (LitePalSupportException exception){
                Toasty.info(getContext(),"该订阅已经存在了哦!").show();
            }
        }
    }, getContext(),"添加到指定的文件夹下","").execute();
}
 
Example 5
Source Project: Dream-Catcher   Source File: ServerManager.java    License: MIT License 6 votes vote down vote up
private void startServer(final LocalSocketServer server) {
  Thread listener = new Thread(THREAD_PREFIX + "-" + server.getName()) {
    @Override
    public void run() {
      try {
        SimpleConnectorLifecycleManager.setCurrentState(Lifecycle.LOCAL_SERVER_SOCKET_OPENING);
        CaptureEvent.send("Local socket is open");
        EventBus.getDefault().post(new OperateEvent(OperateEvent.TARGET_CONNECTOR, true));
        server.run();
      } catch (IOException e) {
        LogUtil.e("Could not start DreamCatcher server: " + server.getName() +
                ", cause: " + e.toString());
        SimpleConnectorLifecycleManager.setCurrentState(Lifecycle.SHUTDOWN);
        CaptureEvent.send("Exception on bind local socket");
        EventBus.getDefault().post(new OperateEvent(OperateEvent.TARGET_CONNECTOR, false, true, e.getMessage()));
      }
    }
  };
  listener.start();
  listenerThread = listener;
}
 
Example 6
Source Project: memoir   Source File: MediaChooserActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {

        if (requestCode == MediaAction.PICK_PICTURE.requestCode() && data != null) {
            mMediaChooserMgr.processMedia(MediaAction.PICK_PICTURE, data);
        } else if (requestCode == MediaAction.CAPTURE_PICTURE.requestCode()) {
            mMediaChooserMgr.processMedia(MediaAction.CAPTURE_PICTURE, data);    // data may be null here
        } else if (requestCode == Constants.CROP_IMAGE) {
            String path = data.getStringExtra(CropImageActivity.IMAGE_DESTINATION_FILE);
            if (path != null && mSelectedMedia instanceof RTImage) {
                EventBus.getDefault().postSticky( new MediaEvent(mSelectedMedia) );
                finish();
            }
        }

    } else {
        setResult(RESULT_CANCELED);
        finish();
    }
}
 
Example 7
@Override
public void delete(String themeName) {
    new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialogTheme)
            .setTitle(R.string.delete_theme)
            .setMessage(getString(R.string.delete_theme_dialog_message, themeName))
            .setPositiveButton(R.string.yes, (dialogInterface, i)
                    -> new DeleteThemeAsyncTask(redditDataRoomDatabase, themeName, (isLightTheme, isDarkTheme, isAmoledTheme) -> {
                        if (isLightTheme) {
                            CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(
                                    CustomThemeWrapper.getIndigo(CustomThemeListingActivity.this), lightThemeSharedPreferences);
                        }
                        if (isDarkTheme) {
                            CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(
                                    CustomThemeWrapper.getIndigoDark(CustomThemeListingActivity.this), darkThemeSharedPreferences);
                        }
                        if (isAmoledTheme) {
                            CustomThemeSharedPreferencesUtils.insertThemeToSharedPreferences(
                                    CustomThemeWrapper.getIndigoAmoled(CustomThemeListingActivity.this), amoledThemeSharedPreferences);
                        }
                        EventBus.getDefault().post(new RecreateActivityEvent());
                    }).execute())
            .setNegativeButton(R.string.no, null)
            .show();
}
 
Example 8
Source Project: CoolChat   Source File: UserProfileActivity.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == NameActivity.REQUEST_REMARK_NAME && resultCode == NameActivity.REQUEST_REMARK_NAME) {
        LogUtils.e("修改后的备注名为", data.getStringExtra("name"));
        String name = data.getStringExtra("name");
        contact.setRemarkName(name);
        contactDao.update(contact);
        initData();

        //通知主页聊天页面用户昵称更新
        EventBus.getDefault().post(new Conversation());
    } else {
        LogUtils.e("修改后的备注名为", "未修改");
    }
}
 
Example 9
Source Project: AssistantBySDK   Source File: VoiceMediator.java    License: Apache License 2.0 6 votes vote down vote up
private void speak(SpeechMsgBuilder msgBuilder, final boolean isAnim) {
    SynthesizerBase.get().startSpeakAbsolute(msgBuilder.build())
            .doOnNext(new Consumer<SpeechMsg>() {
                @Override
                public void accept(SpeechMsg speechMsg) throws Exception {
                    if (speechMsg.state() == SpeechMsg.State.OnBegin && isAnim)
                        EventBus.getDefault().post(new SynthesizeEvent(SynthesizeEvent.SYNTH_START));
                }
            })
            .doOnComplete(new Action() {
                @Override
                public void run() throws Exception {
                    EventBus.getDefault().post(new SynthesizeEvent(SynthesizeEvent.SYNTH_END));
                }
            })
            .subscribeOn(Schedulers.io())
            .observeOn(Schedulers.computation())
            .subscribe();
}
 
Example 10
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    if(bluetoothAdapter == null) {
        grblToast(getString(R.string.text_no_bluetooth_adapter));
        restartInUsbMode();
    }else{
        Intent intent = new Intent(getApplicationContext(), GrblBluetoothSerialService.class);
        bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
    }

    grblServiceMessageHandler = new BluetoothConnectionActivity.GrblServiceMessageHandler(this);

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            if(grblBluetoothSerialService != null && grblBluetoothSerialService.getState() == GrblBluetoothSerialService.STATE_NONE && bluetoothAdapter.isEnabled() && sharedPref.getBoolean(getString(R.string.preference_auto_connect), false)){
                String lastAddress = sharedPref.getString(getString(R.string.preference_last_connected_device), null);
                connectToDevice(lastAddress);
            }
        }
    }, 1500);

    EventBus.getDefault().register(this);
}
 
Example 11
Source Project: Android   Source File: NewFriendActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_contact_add_friend);
    ButterKnife.bind(this);
    EventBus.getDefault().register(this);
    initView();
}
 
Example 12
Source Project: ClassSchedule   Source File: SignActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void signInSucceed(BaseBean bean) {
    toast("登录成功");
    String email = mEtEmail.getText().toString();
    Cache.instance().setEmail(email);

    EventBus.getDefault().post(new SignEvent());
    finish();
}
 
Example 13
Source Project: NetworkEvents   Source File: MainActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  connectivityStatus = (TextView) findViewById(R.id.connectivity_status);
  mobileNetworkType = (TextView) findViewById(R.id.mobile_network_type);
  accessPoints = (ListView) findViewById(R.id.access_points);
  final EventBus bus = new EventBus();
  busWrapper = getGreenRobotBusWrapper(bus);
  networkEvents = new NetworkEvents(getApplicationContext(), busWrapper).enableInternetCheck()
      .enableWifiScan();
}
 
Example 14
Source Project: openwebnet-android   Source File: ProfileAdapter.java    License: MIT License 5 votes vote down vote up
private void deleteProfile(UserProfileModel profile) {
    EventBus.getDefault().post(new ProfileActivity.OnRequestActionEvent<>(
        () -> firebaseService.deleteProfile(profile.getProfileRef())
            .flatMap(profileId -> firebaseService.getProfiles()), profiles -> {
        log.info("deleteProfile succeeded: refreshing");
        EventBus.getDefault().post(new ProfileActivity.OnUpdateProfilesEvent(profiles));
    }));
}
 
Example 15
Source Project: AssistantBySDK   Source File: VoiceWaveComponent.java    License: Apache License 2.0 5 votes vote down vote up
public void onRecord() {
    if (rLock.tryLock()) {
        try {
            EventBus.getDefault().post(new IntroduceShowEvent(false));
            if (recording) {
                stopRecord();
            } else {
                stopWakeup();
                prepareToRecord();
            }
        } finally {
            rLock.unlock();
        }
    }
}
 
Example 16
@Override
public void call() {
    EventBusCarrier eventBusCarrier = new EventBusCarrier();
    eventBusCarrier.setEventType(EventTypeGlobal.SHOW_BUY_ORDER_PASSWORD_VERIFY_DIALOG);
    eventBusCarrier.setObject(nhOrderBean);
    EventBus.getDefault().post(eventBusCarrier);
}
 
Example 17
Source Project: Android-RTEditor   Source File: LinkFragment.java    License: Apache License 2.0 5 votes vote down vote up
private void validate(DialogInterface dialog, TextView addressView, TextView textView) {
    // retrieve link address and do some cleanup
    final String address = addressView.getText().toString().trim();

    boolean isEmail = sEmailValidator.isValid(address);
    boolean isUrl = sUrlValidator.isValid(address);
    if (requiredFieldValid(addressView) && (isUrl || isEmail)) {
        // valid url or email address

        // encode address
        String newAddress = Helper.encodeUrl(address);

        // add mailto: for email addresses
        if (isEmail && !startsWithMailto(newAddress)) {
            newAddress = "mailto:" + newAddress;
        }

        // use the original address text as link text if the user didn't enter anything
        String linkText = textView.getText().toString();
        if (linkText.length() == 0) {
            linkText = address;
        }

        EventBus.getDefault().post(new LinkEvent(LinkFragment.this, new Link(linkText, newAddress), false));
        try { dialog.dismiss(); } catch (Exception ignore) {}
    } else {
        // invalid address (neither a url nor an email address
        String errorMessage = getString(R.string.rte_invalid_link, address);
        addressView.setError(errorMessage);
    }
}
 
Example 18
Source Project: openwebnet-android   Source File: MainActivityTest.java    License: MIT License 5 votes vote down vote up
@Test
public void handleEvent_onChangePreferenceDeviceDebugEvent() {
    setupActivity();
    MenuItem menuDebug = activity.toolbar.getMenu().findItem(R.id.action_settings);

    assertFalse("invalid state", menuDebug.isVisible());

    EventBus.getDefault().post(new MainActivity.OnChangePreferenceDeviceDebugEvent(true));
    assertTrue("invalid state", menuDebug.isVisible());

    EventBus.getDefault().post(new MainActivity.OnChangePreferenceDeviceDebugEvent(false));
    assertFalse("invalid state", menuDebug.isVisible());
}
 
Example 19
public void initSeekbar() {
    // Set the duration.
    final int duration = mMediaPlayer.getDuration();
    EventBus.getDefault().post(
            new LocalEventFromMediaPlayerHolder.PlaybackDuration(duration));
    logToUI(String.format("setting seekbar max %d sec",
                          TimeUnit.MILLISECONDS.toSeconds(duration)));
}
 
Example 20
@Override
    public void messageReceived(IoSession session, Object message)
            throws Exception {
        Log.e(TAG, "接收到服务器端消息:" + message.toString());

//        Message msg = new Message();
//        msg.what = 100;
//        msg.arg1 = ((MessageBase)message).getMessageType();
//        msg.obj = message;
//        _uiHandler.sendMessage(msg);

        EventBus.getDefault().post(new ServerMessageEvent((MessageBase) message));
    }
 
Example 21
Source Project: android-auto-call-recorder   Source File: ActionModeSupport.java    License: MIT License 5 votes vote down vote up
public ActionModeSupport(String mTitle,
                         EventBus mEventBus,
                         boolean mIsForBroadcast,
                         ActionBar mActionBar,
                         Toolbar mToolbar,
                         RecordsAdapter mAdapter) {
    this.mEventBus = mEventBus;
    this.mTitle = mTitle;
    this.mIsForBroadcast = mIsForBroadcast;
    this.mActionBar = mActionBar;
    this.mToolbar = mToolbar;
    this.mAdapter = mAdapter;

    mEventBus.register(this);
}
 
Example 22
Source Project: EMQ-Android-Toolkit   Source File: MessageListActivity.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onPause() {
    super.onPause();
    if (mIsDelete) {
        EventBus.getDefault().postSticky(new DeleteTopicMessageEvent(new EmqMessage(mSubscription.getTopic(), null), mDeleteTime));
    }
}
 
Example 23
Source Project: Android-Plugin-Framework   Source File: MainActivity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
       EventBus.getDefault().register(this);
	setContentView(R.layout.main_activity);
       ButterKnife.bind(this);

	setTitle("插件列表");

	initView();

       // 监听插件安装 安装新插件后刷新当前页面
       registerReceiver(pluginInstallEvent, new IntentFilter(PluginCallback.ACTION_PLUGIN_CHANGED));

       refreshListView();

       PackageManager manager = getPackageManager();
       Intent intent = new Intent(Intent.ACTION_MAIN, null);
       intent.addCategory(Intent.CATEGORY_LAUNCHER);
       List<ResolveInfo> infos = manager.queryIntentActivities(intent, 0);

       Log.e("xx", "launcher intent size =" + (infos==null?"0":infos.size()));
       Log.e("xx", "btnText=" + butterTest.getText().toString());
       Log.e("xx", "stringFromJNI " + CxxTest.stringFromJNI());
       testUseLibray();
       CxxTest.println(LOG_ID_MAIN, Log.ERROR, "MainActivity", "end onCreate ");
   }
 
Example 24
Source Project: Place-Search-Service   Source File: PlacesSearchResultActivtity.java    License: MIT License 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.places_search_result_activity);
    EventBus.getDefault().register(this);
    mBack = findViewById(R.id.back);
    mList = findViewById(R.id.listview);
    mPrevious = findViewById(R.id.previous);
    mNext = findViewById(R.id.next);
    map = new HashMap<>();
    dialog = new ProgressDialog(this);
    dialog.setCancelable(false);
    dialog.setIndeterminate(true);
    dialog.setMessage("Fetching Next page");
    dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);

    mBack.setOnClickListener(this);
    mPrevious.setOnClickListener(this);
    mNext.setOnClickListener(this);
    obj = (PlacesSearchResultObj) getIntent().getSerializableExtra("data");
    searchUrl = getIntent().getStringExtra("url");
    if (obj.getResults() == null || obj.getResults().size() == 0) {
        getSupportFragmentManager().beginTransaction().replace(R.id.search_layout, new PlacesSearchNoneResultFragment()).commit();
        findViewById(R.id.btn_layout).setVisibility(View.GONE);
    }
    adapter = new PlacesSearchResultAdapter(this, obj.getResults());
    adapter.setListener(this);
    mList.setHasFixedSize(true);
    mList.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
    mList.setAdapter(adapter);
    map.put(currentIndex, obj);
    if (currentIndex == 0) mPrevious.setEnabled(false);
    if (TextUtils.isEmpty(map.get(currentIndex).getNext_page_token())){
        mNext.setEnabled(false);
    }else {
        mNext.setEnabled(true);
    }
}
 
Example 25
Source Project: PokeFaker   Source File: LocationService.java    License: MIT License 5 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    EventBus.getDefault().unregister(this);
    LocationHolder.getInstance(this).stop();
    for (MockProvider m : mMockProviders) {
        m.remove();
    }
    mHandler.removeCallbacks(null);
}
 
Example 26
Source Project: AccountBook   Source File: MainFragment.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroy() {
    if (EventBus.getDefault().isRegistered(this)) {
        EventBus.getDefault().unregister(this);
    }
    super.onDestroy();
}
 
Example 27
Source Project: Dream-Catcher   Source File: ProxyService.java    License: MIT License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    new AsyncTask<Void, Void, Boolean>() {
        @Override
        protected Boolean doInBackground(Void... params) {
            postEvent("Prepare to turn on proxy……");
            proxy.setTrustAllServers(true);
            try {
                proxy.start(9999);
            } catch (Exception e) {
                proxy.start();
            }
            ((DCApplication) getApplication()).setPort(proxy.getPort());
            postEvent("Proxy is bound to port " + proxy.getPort());
            proxy.enableHarCaptureTypes(CaptureType.REQUEST_HEADERS, CaptureType.REQUEST_COOKIES,
                    CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_HEADERS, CaptureType.RESPONSE_COOKIES,
                    CaptureType.RESPONSE_CONTENT, CaptureType.RESPONSE_BINARY_CONTENT, CaptureType.REQUEST_BINARY_CONTENT);
            Log.e("ProxyService", "Serve on port: " + proxy.getPort());
            postEvent("Start monitoring");
            proxy.newHar();
            EventBus.getDefault().post(new OperateEvent(OperateEvent.TARGET_PROXY, true));
            SimpleConnectorLifecycleManager.setProxyEnabled(true);
            Log.e("ProxyService", "Start monitoring");
            return Boolean.TRUE;
        }
    }.execute();
}
 
Example 28
@Override
public void call() {
    EventBusCarrier eventBusCarrier = new EventBusCarrier();
    eventBusCarrier.setEventType(EventTypeGlobal.DIALOG_DISMISS_TYPE);
    eventBusCarrier.setObject(nhOrderBean);
    EventBus.getDefault().post(eventBusCarrier);
}
 
Example 29
Source Project: Anago   Source File: RepoListItemViewModel.java    License: Apache License 2.0 5 votes vote down vote up
@Inject
public RepoListItemViewModel(BaseFragment fragment,
                             StarUseCase starUseCase,
                             UnstarUseCase unstarUseCase,
                             EventBus eventBus) {
    super(fragment);
    this.starUseCase = starUseCase;
    this.unstarUseCase = unstarUseCase;
    this.eventBus = eventBus;

    this.repo = new ObservableField<>();
    this.starred = new ObservableBoolean(false);
}
 
Example 30
private void processIntent(@NonNull Intent intent) {
  if (ANSWER_ACTION.equals(intent.getAction())) {
    viewModel.setRecipient(EventBus.getDefault().getStickyEvent(WebRtcViewModel.class).getRecipient());
    handleAnswerWithAudio();
  } else if (DENY_ACTION.equals(intent.getAction())) {
    handleDenyCall();
  } else if (END_CALL_ACTION.equals(intent.getAction())) {
    handleEndCall();
  }
}