org.greenrobot.eventbus.EventBus Java Examples

The following examples show how to use org.greenrobot.eventbus.EventBus. 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 File: SelectFileByScanActivity.java    From AndroidDownload with 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 #2
Source File: TingPlayProcessor.java    From AssistantBySDK with 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 File: MediaChooserActivity.java    From memoir with 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 #4
Source File: VoiceMediator.java    From AssistantBySDK with 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 #5
Source File: RequireListPopupView.java    From Focus with 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 #6
Source File: ServerManager.java    From Dream-Catcher with 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 #7
Source File: UserProfileActivity.java    From CoolChat with 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 #8
Source File: CustomThemeListingActivity.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 6 votes vote down vote up
@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 #9
Source File: App.java    From NMSAlphabetAndroidApp with MIT License 6 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 #10
Source File: HandleActivity.java    From DMusic with Apache License 2.0 5 votes vote down vote up
@Override
public void finish() {
    EventBus.getDefault().post(new MusicModelEvent(type, models));
    // 按自定义排序
    EventBus.getDefault().post(new SortTypeEvent(type, AppDB.ORDER_TYPE_CUSTOM));
    if (type == AppDB.COLLECTION_MUSIC) {
        SyncManager.unCollected(getApplicationContext(), modelsFav);
    }
    super.finish();
}
 
Example #11
Source File: ActionModeSupport.java    From android-auto-call-recorder with 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 #12
Source File: NetworkBroadcastReceiver.java    From Capstone-Project with MIT License 5 votes vote down vote up
@SuppressLint("LongLogTag")
@Override
public void onReceive(Context context, Intent intent) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    boolean isConnected = networkInfo != null &&
            networkInfo.isConnectedOrConnecting();
    int networkType = networkInfo != null ? networkInfo.getType() : -1;
    Logger.d(TAG, "onReceive: Connection status: " + isConnected);
    EventBus.getDefault().post(new NetworkEvent(isConnected, networkType));
}
 
Example #13
Source File: NewFolderViewHolder.java    From android-notepad with MIT License 5 votes vote down vote up
private void add(){
	if (TextUtils.isEmpty(folderName.getText())) return;
	Folder folder = new Folder();
	folder.setCreatedAt(new Date());
	folder.setName(folderName.getText().toString().trim());
	folder.save();
	EventBus.getDefault().post(new FolderCreatedEvent(folder));
}
 
Example #14
Source File: ExchangeRateUpdateTaskHandler.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onPostExecute(String result) {
    EventBus bus = EventBus.getDefault();

    if (networkError) {
        NetworkError error = new NetworkError();
        error.setErrorType(NetworkErrorType.EXCHANGE_RATE_ERROR);
        bus.post(error);
    } else
        bus.post(new ExchangeRateUpdateCompleted());
}
 
Example #15
Source File: MinaClientHandler.java    From QuickerAndroid with GNU General Public License v3.0 5 votes vote down vote up
@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 #16
Source File: GameActivity.java    From landlord_client with Apache License 2.0 5 votes vote down vote up
/**
 * 最终确认的加倍请求
 */
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
@SuppressWarnings("unused")
public void onMultipleWagerResponse(MultipleWagerResponse response) {
    EventBus.getDefault().removeStickyEvent(response);
    wagerMultipleNum = response.getMultipleNum();
    doubleNum.setText(String.format("当前倍数是:%s", wagerMultipleNum));
    if (meSeatNum == landlordSeatNum) { //我是地主,我先出牌
        throwCards(true);
    } else { //我不是地主,我等上家出牌
        gone(meStatusChoose);
    }
}
 
Example #17
Source File: ScanFragment.java    From AndroidBleManager with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    EventBus.getDefault().register(this);
    mBluetoothUtils = new BluetoothUtils(getActivity());
    mLeDeviceListAdapter = new DeviceListAdapter(getActivity());
}
 
Example #18
Source File: SignActivity.java    From ClassSchedule with 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 #19
Source File: LinkFragment.java    From Android-RTEditor with 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 #20
Source File: MessageListActivity.java    From EMQ-Android-Toolkit with 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 #21
Source File: UserFeedUpdateContentFragment.java    From Focus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroyView() {
    super.onDestroyView();
    if (getActivity()!=null && isconnet){//当活动被回收的时候,服务也必须停止
        getActivity().unbindService(connection);
    }
    unbinder.unbind();
    EventBus.getDefault().unregister(this);
}
 
Example #22
Source File: RepoListItemViewModel.java    From Anago with 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 #23
Source File: MainActivity.java    From Android-Plugin-Framework with 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 File: PlacesSearchResultActivtity.java    From Place-Search-Service with 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 File: LocationService.java    From PokeFaker with 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 File: MainFragment.java    From AccountBook with 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 File: BuyOrderConfirmViewModel.java    From AndroidWallet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void call() {
    EventBusCarrier eventBusCarrier = new EventBusCarrier();
    eventBusCarrier.setEventType(EventTypeGlobal.DIALOG_DISMISS_TYPE);
    eventBusCarrier.setObject(nhOrderBean);
    EventBus.getDefault().post(eventBusCarrier);
}
 
Example #28
Source File: ContactFragment.java    From Android-ContactPicker with Apache License 2.0 5 votes vote down vote up
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEventMainThread(ContactsLoaded event) {
    EventBus.getDefault().removeStickyEvent(event);

    mContacts = event.getContacts();
    mFilteredContacts = mContacts;
    mAdapter.setData(mFilteredContacts);

    updateEmptyViewVisibility(mContacts);
}
 
Example #29
Source File: ProxyService.java    From Dream-Catcher with 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 #30
Source File: PostsFragment.java    From Capstone-Project with MIT License 5 votes vote down vote up
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    setPresenter(new PostsPresenter(this));
    mPostsPresenter.subscribe();
    EventBus.getDefault().register(this);
}