org.greenrobot.eventbus.ThreadMode Java Examples

The following examples show how to use org.greenrobot.eventbus.ThreadMode. 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: MainActivity.java    From ml with Apache License 2.0 6 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onImageDetectionEvent(ImageDetectionEvent event) {
    Logger.debug("new detection state: %s", event.state);

    switch (event.state) {
        case DECODING:
            showPrompt(getString(R.string.prompt_decoding));
            break;

        case DETECTING:
            showPrompt(getString(R.string.prompt_detecting));
            break;

        case TAGGING:
            showPrompt(getString(R.string.prompt_tagging));
            break;

        case DONE:
            hidePrompt();
            break;

    }
}
 
Example #2
Source File: MenuListActivity.java    From financisto with GNU General Public License v2.0 6 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onDriveList(DriveFileList event) {
    dismissProgressDialog();
    final List<DriveFileInfo> files = event.files;
    final String[] fileNames = getFileNames(files);
    final MenuListActivity context = this;
    final DriveFileInfo[] selectedDriveFile = new DriveFileInfo[1];
    new AlertDialog.Builder(context)
            .setTitle(R.string.restore_database_online_google_drive)
            .setPositiveButton(R.string.restore, (dialog, which) -> {
                if (selectedDriveFile[0] != null) {
                    progressDialog = ProgressDialog.show(context, null, getString(R.string.google_drive_restore_in_progress), true);
                    bus.post(new DoDriveRestore(selectedDriveFile[0]));
                }
            })
            .setSingleChoiceItems(fileNames, -1, (dialog, which) -> {
                if (which >= 0 && which < files.size()) {
                    selectedDriveFile[0] = files.get(which);
                }
            })
            .show();
}
 
Example #3
Source File: ChatActivity.java    From Socket.io-FLSocketIM-Android with MIT License 6 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventBus(MessageEvent event) {

    switch (event.getType()){
        case EventMessage: // 收到新消息


            MessageModel message = (MessageModel) event.getMsg();

            if (!message.getFrom_user().equals(friendsUserName) && !message.getTo_user().equals(friendsUserName)) { // 不属于该会话的消息
                return;
            }
            messageList.add(message);
            adapter.notifyDataSetChanged();
            listView.smoothScrollToPosition(messageList.size() - 1);
            break;
    }
}
 
Example #4
Source File: ContactFragment.java    From FamilyChat with Apache License 2.0 6 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void userProfileUpdated(ProfileUpdateEventBean eventBean)
{
    int flag = eventBean.getFlag();
    //如果是头像更新只需要找到对应的那条数据即可
    if (flag == ProfileUpdateEventBean.FLAG_UPDATE_HEAD)
    {
        UserBean userBean = eventBean.getUserBean();
        if (userBean != null)
            mAdapter.updateUserProfile(userBean);
    }
    //如果是姓名更新需要全刷数据
    else
    {
        mPresenter.refreshContactDataInDb(false);
    }
}
 
Example #5
Source File: InstallerFragment.java    From BusyBox with Apache License 2.0 6 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(Installer.FinishedEvent event) {
  installing = false;
  progressItem.setVisible(false);
  uninstallButton.setEnabled(true);
  installButton.setEnabled(true);

  busybox = BusyBox.newInstance(new LocalFile(event.installer.path, event.installer.filename).path);

  Analytics.newEvent("successfully_installed_busybox")
      .put("is_ads_removed", String.valueOf(Monetize.isAdsRemoved()))
      .put("path", busybox.path)
      .log();

  new BusyBoxMetaTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, busybox);

  if (Monetize.isAdsRemoved()) {
    showMessage(R.string.successfully_installed_s, busybox.name);
  } else {
    BusyboxSuccessDialog dialog = new BusyboxSuccessDialog();
    dialog.show(getActivity().getFragmentManager(), "BusyboxSuccessDialog");
  }
}
 
Example #6
Source File: MainActivity.java    From Focus with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true)
    public void refreshUI(EventMessage eventBusMessage) {
        if (EventMessage.feedAndFeedFolderAndItemOperation.contains(eventBusMessage.getType())) {//更新整个左侧边栏
//            ALog.d("收到新的订阅添加,更新!" + eventBusMessage);
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    ALog.d("重构");
                    updateDrawer();
                }
            }, 100); // 延迟一下,因为数据异步存储需要时间
        }else if (EventMessage.updateBadge.contains(eventBusMessage.getType())){//只需要修改侧边栏阅读书目
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    //打印map
                    ALog.d("更新左侧边栏");
                    updateDrawer();
                }
            }, 100); // 延迟一下,因为数据异步存储需要时间

        } else if (Objects.equals(eventBusMessage.getType(), EventMessage.FEED_PULL_DATA_ERROR)) {
//            ALog.d("收到错误FeedId List");
//            errorFeedIdList = eventBusMessage.getIds();
        }
    }
 
Example #7
Source File: FriendAcceptActivity.java    From Android with MIT License 6 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(MsgNoticeBean notice) {
    Object[] objs = null;
    if (notice.object != null) {
        objs = (Object[]) notice.object;
    }
    switch (notice.ntEnum) {
        case MSG_SEND_SUCCESS:
            MsgSendBean sendBean = (MsgSendBean) objs[0];
            if (sendBean.getType() == MsgSendBean.SendType.TypeAcceptFriendQuest) {
                requestEntity.setRead(1);
                requestEntity.setStatus(2);
                ContactHelper.getInstance().inserFriendQuestEntity(requestEntity);
                ToastEUtil.makeText(mActivity,R.string.Link_Add_Successful).show();
                ActivityUtil.goBack(mActivity);
            }
            break;
        case MSG_SEND_FAIL:
            ToastEUtil.makeText(mActivity,R.string.Link_Add_Failed,ToastEUtil.TOAST_STATUS_FAILE).show();
            break;
    }
}
 
Example #8
Source File: FullImageActivity.java    From chatui with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Subscribe(threadMode = ThreadMode.MAIN, sticky = true) //在ui线程执行
public void onDataSynEvent(final FullImageInfo fullImageInfo) {
    final int left = fullImageInfo.getLocationX();
    final int top = fullImageInfo.getLocationY();
    final int width = fullImageInfo.getWidth();
    final int height = fullImageInfo.getHeight();
    mBackground = new ColorDrawable(Color.BLACK);
    fullLay.setBackground(mBackground);
    fullImage.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            fullImage.getViewTreeObserver().removeOnPreDrawListener(this);
            int location[] = new int[2];
            fullImage.getLocationOnScreen(location);
            mLeft = left - location[0];
            mTop = top - location[1];
            mScaleX = width * 1.0f / fullImage.getWidth();
            mScaleY = height * 1.0f / fullImage.getHeight();
            activityEnterAnim();
            return true;
        }
    });
    Glide.with(this).load(fullImageInfo.getImageUrl()).into(fullImage);
}
 
Example #9
Source File: BluetoothConnectionActivity.java    From grblcontroller with GNU General Public License v3.0 6 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onGrblSettingMessageEvent(GrblSettingMessageEvent event){

    if(event.getSetting().equals("$10") && !event.getValue().equals("2")){
        onGcodeCommandReceived("$10=2");
    }

    if(event.getSetting().equals("$110") || event.getSetting().equals("$111") || event.getSetting().equals("$112")){
        Double maxFeedRate = Double.parseDouble(event.getValue());
        if(maxFeedRate > sharedPref.getDouble(getString(R.string.preference_jogging_max_feed_rate), machineStatus.getJogging().feed)){
            sharedPref.edit().putDouble(getString(R.string.preference_jogging_max_feed_rate), maxFeedRate).apply();
        }
    }

    if(event.getSetting().equals("$32")){
        machineStatus.setLaserModeEnabled(event.getValue().equals("1"));
    }

}
 
Example #10
Source File: MainActivity.java    From music_player with Open Software License 3.0 6 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(UIChangeEvent event) {
        FloatingActionButton floatingActionButton = (FloatingActionButton) findViewById(R.id.play_or_pause);
        switch (event.event) {
            case MyConstant.initialize:
                mLayout.setPanelHeight((int) (60 * getResources().getDisplayMetrics().density + 0.5f)+ImmersionBar.getNavigationBarHeight(MainActivity.this));
                random_play.hide();
                return;
            case MyConstant.pauseAction:
                floatingActionButton.setImageResource(R.drawable.ic_play_arrow_black_24dp);
                play_pause_button.setImageResource(R.drawable.ic_play_arrow_black_24dp);
                return;
            case MyConstant.playAction:
                floatingActionButton.setImageResource(R.drawable.ic_pause_black_24dp);
                play_pause_button.setImageResource(R.drawable.ic_pause_black_24dp);
                return;
            case MyConstant.mediaChangeAction:
                ChangeScrollingUpPanel(MyApplication.getPositionNow());
                return;
                //???
            case MyConstant.DestoryAction:
                this.finish();
//                MainActivity.this.onDestroy();
//                finish();
        }
    }
 
Example #11
Source File: ThreadListFragment.java    From hipda with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unused")
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEvent(ThreadUpdatedEvent event) {
    if (event.mFid == mForumId && event.mTid != null) {
        for (int i = 0; i < mThreadListAdapter.getDatas().size(); i++) {
            ThreadBean bean = mThreadListAdapter.getItem(mThreadListAdapter.getHeaderCount() + i);
            if (event.mTid.equals(bean.getTid())) {
                bean.setTitle(event.mTitle);
                bean.setCountCmts(String.valueOf(event.mReplyCount));
                mThreadListAdapter.notifyItemChanged(mThreadListAdapter.getHeaderCount() + i);
                break;
            }
        }
    }
}
 
Example #12
Source File: MainActivity.java    From AndroidPlusJava with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onScrollChange(ScrollEvent scrollEvent) {
    if (scrollEvent.getDirection() == ScrollEvent.Direction.UP) {
        hideNavigationView();
    } else {
        showNavigationView();
    }
}
 
Example #13
Source File: MainActivity.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onDialogEvent(DialogEvent event) {
    switch (event.getEventType()) {
        case DialogEvent.CANCEL_TOGGLE_TYPE:
            assistPresenter.cancelToggleDialog();
            break;
        case DialogEvent.SHOW_WALK_TYPE:
            mCommonDialog = new CommonDialog(this, "距离较近,是否用步行导航", "选择“是”则跳转到百度地图应用", "否", "是")
                    .setOnCancelListener(new CommonDialog.OnCancelListener() {
                        @Override
                        public void onCancel() {
                            sendMessageToRobot("否");
                        }
                    })
                    .setOnConfirmListener(new CommonDialog.OnConfirmListener() {
                        @Override
                        public void onConfirm() {
                            sendMessageToRobot("是");
                        }
                    });
            mCommonDialog.show();
            break;
        case DialogEvent.CANCEL_WALK_TYPE:
            if (mCommonDialog != null) {
                mCommonDialog.dismiss();
                mCommonDialog = null;
            }
            break;
    }
}
 
Example #14
Source File: MainActivity.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(RecentsRetrievedEvent event) {
    updateLyricsFragment(R.animator.none, R.animator.none,
            true, false, event.lyrics);
    LyricsViewFragment lyricsViewFragment =
            ((LyricsViewFragment) getFragmentManager().findFragmentByTag(LYRICS_FRAGMENT_TAG));
    if (lyricsViewFragment != null)
        lyricsViewFragment.stopRefreshAnimation();
}
 
Example #15
Source File: AuroraIMUIModule.java    From aurora-imui with MIT License 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(GetTextEvent event) {
    if (event.getAction().equals(GET_INPUT_TEXT_EVENT)) {
        getReactApplicationContext().getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
                .emit(GET_INPUT_TEXT_EVENT, event.getText());
    }
}
 
Example #16
Source File: GirlBookDiscussionFragment.java    From BookReader with Apache License 2.0 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void initCategoryList(SelectionEvent event) {
    mRecyclerView.setRefreshing(true);
    sort = event.sort;
    distillate = event.distillate;
    onRefresh();
}
 
Example #17
Source File: ToolbarActionMode.java    From GPSLogger with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe (threadMode = ThreadMode.MAIN)
public void onEvent(Short msg) {
    switch (msg) {
        case EventBusMSG.UPDATE_ACTIONBAR:
        case EventBusMSG.UPDATE_TRACKLIST:
            EvaluateVisibility();
    }
}
 
Example #18
Source File: MainPresenterImpl.java    From mirror with Apache License 2.0 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
@SuppressWarnings("unused")
public void onEvent(ArtikEvent event) {
    switch (event.getType()) {
        case ArtikEvent.TYPE_ACTION_DOWN:
            mSoundManager.volumeDown();
            break;
        case ArtikEvent.TYPE_ACTION_UP:
            mSoundManager.volumeUp();
            break;
        case ArtikEvent.TYPE_ACTION_LEFT:
            if (mView.getMainPresenterClass() != null) {
                mView.moveCenterToLeftContainer();
            } else {
                mView.moveRightToCenterContainer();
            }
            break;
        case ArtikEvent.TYPE_ACTION_RIGHT:
            if (mView.getMainPresenterClass() != null) {
                mView.moveCenterToRightContainer();
            } else {
                mView.moveLeftToCenterContainer();
            }
            break;
        case ArtikEvent.TYPE_ACTION_HOME:
            mFeature.hideCurrentPresenter();
            break;
    }
}
 
Example #19
Source File: SampleActivity.java    From dialog-helper with Apache License 2.0 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEvent(InfoDialogDismissedEvent event) {
    switch (event.getDialogId()) {
        case DIALOG_ID_INFO:
            Toast.makeText(this, "Info dialog dismissed", Toast.LENGTH_LONG).show();
            break;
        case DIALOG_ID_SECOND_IN_CHAIN:
            Toast.makeText(this, "Last dialog in chain dismissed", Toast.LENGTH_LONG).show();
            break;
    }
}
 
Example #20
Source File: MainActivity.java    From android-app with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onUpdateArticlesFinishedEvent(UpdateArticlesFinishedEvent event) {
    Log.d(TAG, "onUpdateArticlesFinishedEvent");

    if (event.getResult().isSuccess()) {
        firstSyncDone = true;
        tryToUpdateOnResume = false;
    }

    updateLastUpdateTime();

    updateStateChanged(false);
}
 
Example #21
Source File: BitBaseFragment.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 进行关闭页面
 */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onClose(CloseEvent closeEvent) {
    if (isSameView(closeEvent.getViewId()) && getActivity() != null) {
        getActivity().finish();
    }
}
 
Example #22
Source File: EditAddedArticleActivity.java    From android-app with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onLocalArticleReplacedEvent(LocalArticleReplacedEvent event) {
    Log.d(TAG, "onLocalArticleReplacedEvent() started");

    if (TextUtils.equals(url, event.getGivenUrl())) {
        articleId = event.getArticleId();

        init();

        openIfPending();
    }
}
 
Example #23
Source File: RTManager.java    From Android-RTEditor with Apache License 2.0 5 votes vote down vote up
/**
 * Media file was picked -> process the result.
 */
@Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
public void onEventMainThread(MediaEvent event) {
    RTEditText editor = mEditors.get(mActiveEditor);
    RTMedia media = event.getMedia();
    if (editor != null && media instanceof RTImage) {
        insertImage(editor, (RTImage) media);
        EventBus.getDefault().removeStickyEvent(event);
        mActiveEditor = Integer.MAX_VALUE;
    }
}
 
Example #24
Source File: SocketService.java    From Android with MIT License 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(PushMessage pushMessage) {
    LogManager.getLogger().d(Tag, "send ack:" + pushMessage.getServiceAck().getAck());
    ByteBuffer byteBuffer = pushMessage.getByteBuffer();
    try {
        pushBinder.connectMessage(pushMessage.getServiceAck().getAck(), pushMessage.getbAck(), byteBuffer.array());
    } catch (RemoteException e) {
        e.printStackTrace();
        LogManager.getLogger().d(Tag,e.getMessage());
    }
}
 
Example #25
Source File: RecentTracksFragment.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(RecentsAddedEvent event) {
    int top = mLayoutManager.findFirstCompletelyVisibleItemPosition();
    mAdapter.notifyItemInserted(event.index);
    if (top == 0)
        mLayoutManager.scrollToPosition(0);
    chooseView();
}
 
Example #26
Source File: ConfigActivity.java    From QuickerAndroid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 更新连接状态显示
 *
 * @param event
 */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(ConnectionStatusChangedEvent event) {
    updateConnectionStatus(event.status, event.message);

    if (event.status == ConnectionStatus.LoggedIn) {

        showToast("连接成功!");

        NavUtils.navigateUpFromSameTask(this);
    }
}
 
Example #27
Source File: PlayActivity.java    From DMusic with Apache License 2.0 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
@SuppressWarnings("unused")
public void onEventMainThread(MusicInfoEvent event) {
    if (event == null || isFinishing() || mPresenter == null || !mPresenter.isViewAttached()) {
        return;
    }
    final MusicModel model = control.getModel();
    tvTitle.setText(model != null ? model.songName : "");
    resetFav(model != null ? model.isCollected : false);
    LrcCache.with(mContext).load(model)
            .placeholder("")
            .error("")
            .into(lrc);
    togglePlay(model != null && event.status == Constants.PlayStatus.PLAY_STATUS_PLAYING);
}
 
Example #28
Source File: FragmentLikeIllust.java    From Pixiv-Shaft with MIT License 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onMessageEvent(Channel event) {
    if (event.getReceiver().contains(starType)) {
        tag = (String) event.getObject();
        baseBind.refreshLayout.autoRefresh();
    }
}
 
Example #29
Source File: SetFavoriteMapActivity.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(NaviShowPointsEvent e) {
    Log.i(TAG, "onEventMainThread>>NaviShowPointsEvent");
    if (e.getType() != NaviShowPointsEvent.CLOSE_ACTIVITY) {
        mAmosfPoiListBox.setAllowDrag(false);
        if (e.getPoints() != null) {
            aList.clear();
            aList.addAll(e.getPoints());
            setListReverse();
            mListAdapter.notifyDataSetChanged();
            mPagerAdapter.notifyDataSetChanged();
            mAmosfPoiBox.setVisibility(View.VISIBLE);

            if (poiOverlay != null) {
                poiOverlay.removeFromMap();
            }
            if (poiOverlay == null || !(poiOverlay instanceof ConfirmCustomPoiOverlay)) {
                poiOverlay = new ConfirmCustomPoiOverlay(baiduMap);
                baiduMap.setOnMarkerClickListener(poiOverlay);
            }

            ((ConfirmCustomPoiOverlay) poiOverlay).setOverlayOptions(aList);
            poiOverlay.addToMap();
            setPoiPosition();
        }
    } else if (e.getType() == NaviShowPointsEvent.CLOSE_ACTIVITY) {
        onFinish();
    } else if (e.getType() == NaviShowPointsEvent.CANCEL_TASK) {
        onBackPressed();
    }
}
 
Example #30
Source File: QueueFragment.java    From Hentoid with Apache License 2.0 5 votes vote down vote up
/**
 * Service destroyed event handler
 *
 * @param event Broadcasted event
 */
@Subscribe(threadMode = ThreadMode.MAIN)
public void onServiceDestroyed(ServiceDestroyedEvent event) {
    if (event.service != ServiceDestroyedEvent.Service.DOWNLOAD) return;

    isPaused = true;
    updateProgressFirstItem(true);
    updateControlBar();
}