Java Code Examples for org.greenrobot.eventbus.EventBus#getDefault()

The following examples show how to use org.greenrobot.eventbus.EventBus#getDefault() . 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: SampleActivity.java    From dialog-helper with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mDialogHelper = new DialogHelper(getSupportFragmentManager());
    mEventBus = EventBus.getDefault();

    setContentView(R.layout.activity_sample);

    mBtnShowInfoDialog = findViewById(R.id.btn_show_info_dialog);
    mBtnShowPromptDialog = findViewById(R.id.btn_show_prompt_dialog);
    mBtnShowDialogsChain = findViewById(R.id.btn_show_dialogs_chain);
    mBtnShowBouncePromptDialog = findViewById(R.id.btn_show_bounce_prompt_dialog);

    registerButtonListeners();
}
 
Example 2
Source File: ParticleDevice.java    From spark-sdk-android with Apache License 2.0 6 votes vote down vote up
/**
 * Subscribes to system events of current device. Events emitted to EventBus listener.
 *
 * @throws ParticleCloudException Failure to subscribe to system events.
 * @see <a href="https://github.com/greenrobot/EventBus">EventBus</a>
 */
@MainThread
public void subscribeToSystemEvents() throws ParticleCloudException {
    try {
        EventBus eventBus = EventBus.getDefault();
        subscriptions.add(subscribeToSystemEvent("spark/status", (eventName, particleEvent) ->
                sendUpdateStatusChange(eventBus, particleEvent.dataPayload)));
        subscriptions.add(subscribeToSystemEvent("spark/flash/status", (eventName, particleEvent) ->
                sendUpdateFlashChange(eventBus, particleEvent.dataPayload)));
        subscriptions.add(subscribeToSystemEvent("spark/device/app-hash", (eventName, particleEvent) ->
                sendSystemEventBroadcast(new DeviceStateChange(ParticleDevice.this,
                        ParticleDeviceState.APP_HASH_UPDATED), eventBus)));
        subscriptions.add(subscribeToSystemEvent("spark/status/safe-mode", (eventName, particleEvent) ->
                sendSystemEventBroadcast(new DeviceStateChange(ParticleDevice.this,
                        ParticleDeviceState.SAFE_MODE_UPDATER), eventBus)));
        subscriptions.add(subscribeToSystemEvent("spark/safe-mode-updater/updating", (eventName, particleEvent) ->
                sendSystemEventBroadcast(new DeviceStateChange(ParticleDevice.this,
                        ParticleDeviceState.ENTERED_SAFE_MODE), eventBus)));
    } catch (IOException e) {
        log.d("Failed to auto-subscribe to system events");
        throw new ParticleCloudException(e);
    }
}
 
Example 3
Source File: HotCodePushPlugin.java    From cordova-hot-code-push with MIT License 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();

    final EventBus eventBus = EventBus.getDefault();
    if (!eventBus.isRegistered(this)) {
        eventBus.register(this);
    }

    // ensure that www folder installed on external storage;
    // if not - install it
    isPluginReadyForWork = isPluginReadyForWork();
    if (!isPluginReadyForWork) {
        dontReloadOnStart = true;
        installWwwFolder();
        return;
    }

    // reload only if we on local storage
    if (!dontReloadOnStart) {
        dontReloadOnStart = true;
        redirectToLocalStorageIndexPage();
    }

    // install update if there is anything to install
    if (chcpXmlConfig.isAutoInstallIsAllowed() &&
            !UpdatesInstaller.isInstalling() &&
            !UpdatesLoader.isExecuting() &&
            !TextUtils.isEmpty(pluginInternalPrefs.getReadyForInstallationReleaseVersionName())) {
        installUpdate(null);
    }
}
 
Example 4
Source File: EventBusUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 注册 EventBus
 * @param subscriber 订阅者
 */
public static void register(final Object subscriber) {
    EventBus eventBus = EventBus.getDefault();
    if (!eventBus.isRegistered(subscriber)) {
        eventBus.register(subscriber);
    }
}
 
Example 5
Source File: BaseFragment.java    From Learning-Resources with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mEventBus = EventBus.getDefault();
    mApiClient = getApp().getApiClient();

    if (!mEventBus.isRegistered(this)) {
        mEventBus.register(this);
    }
}
 
Example 6
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 7
Source File: ExchangeRateUpdateTaskHandler.java    From android-wallet-app 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 8
Source File: BaseActivity.java    From Learning-Resources with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    mEventBus = EventBus.getDefault();
    mApiClient = getApp().getApiClient();

    if (!mEventBus.isRegistered(this)) {
        mEventBus.register(this);
    }
}
 
Example 9
Source File: UserManager.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
@Inject
public UserManager(@ApplicationContext Context context, UserDataStore userDataStore, GithubService service) {
    this.mContext = context;
    this.mUserDataStore = userDataStore;
    this.mEventBus = EventBus.getDefault();
    this.mGithubService = service;
}
 
Example 10
Source File: XEventBus.java    From XposedSmsCode with GNU General Public License v3.0 4 votes vote down vote up
private static EventBus get() {
    return EventBus.getDefault();
}
 
Example 11
Source File: AppModule.java    From syncapp with Apache License 2.0 4 votes vote down vote up
@Provides
@Singleton
EventBus eventBus() {
    return EventBus.getDefault();
}
 
Example 12
Source File: AppModule.java    From octoandroid with GNU General Public License v3.0 4 votes vote down vote up
@Provides
@Singleton
EventBus provideEventBus() {
    return EventBus.getDefault();
}
 
Example 13
Source File: RequestTask.java    From android-wallet-app with GNU General Public License v3.0 4 votes vote down vote up
public RequestTask(Context context) {
    this.context = new WeakReference<>(context);
    this.bus = EventBus.getDefault();
}
 
Example 14
Source File: MainActivity.java    From healthgo with GNU General Public License v3.0 4 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
//        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
//        CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) toolbar.getLayoutParams();
//        params.setMargins(0,getStatusBarHeight(), 0, 0);
//        toolbar.setLayoutParams(params);
        setSupportActionBar(toolbar);
        btn = (TextView) findViewById(R.id.bt);
        Typeface Font = Typeface.createFromAsset(this.getAssets(), "iconfont.ttf");
        btn.setText(getResources().getText(R.string.setting));
        btn.setTypeface(Font);

        Log.d("eee", "on create()");
        showSteps = (TextView) findViewById(R.id.showSteps);
        mLayout = findViewById(R.id.mylayout);
        on_off = (Switch) findViewById(R.id.on_off);
        foreground_model = (Switch) findViewById(R.id.foreground_model);


        sharedPreferences = getSharedPreferences("conf", MODE_PRIVATE);

        detectService();

        bus = EventBus.getDefault();
        bus.register(this);

        Realm realm = Realm.getDefaultInstance();
        StepModel result = realm.where(StepModel.class)
                .equalTo("date", DateTimeHelper.getToday())
                .findFirst();
        numSteps = result == null ? 0 : result.getNumSteps();
        bus.post(true);
        updateShowSteps();
        realm.close();

        drawChart();


    }
 
Example 15
Source File: TestAppModule.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
@Provides
@Singleton
EventBus provideEventBus() {
    return EventBus.getDefault();
}
 
Example 16
Source File: AppModule.java    From mvvm-template with GNU General Public License v3.0 4 votes vote down vote up
@Provides
@Singleton
EventBus provideEventBus() {
    return EventBus.getDefault();
}
 
Example 17
Source File: XEventBus.java    From SmsCode with GNU General Public License v3.0 4 votes vote down vote up
private static EventBus get() {
    return EventBus.getDefault();
}
 
Example 18
Source File: RequestTask.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
public RequestTask(Context context, Callback<Object> callback) {
    this.context = new WeakReference<>(context);
    this.bus = EventBus.getDefault();
    this.callback = callback;
}
 
Example 19
Source File: InfoDialog.java    From dialog-helper with Apache License 2.0 4 votes vote down vote up
@Override
public final void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mEventBus = EventBus.getDefault();
    mDialogHelper = new DialogHelper(requireActivity().getSupportFragmentManager());
}
 
Example 20
Source File: PromptDialog.java    From dialog-helper with Apache License 2.0 4 votes vote down vote up
@Override
public final void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mEventBus = EventBus.getDefault();
    mDialogHelper = new DialogHelper(requireActivity().getSupportFragmentManager());
}