Java Code Examples for de.greenrobot.event.EventBus#getDefault()

The following examples show how to use de.greenrobot.event.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: NewVersionAvailableEventTest.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
/**
 * Get the event bus that's being used in the app.
 *
 * @return The event bus.
 * @throws AssumptionViolatedException If the default event bus can't be constructed because of
 * the Android framework not being loaded. This will stop the calling tests from being reported
 * as failures.
 */
@NonNull
private static EventBus getEventBus() {
    try {
        return EventBus.getDefault();
    } catch (RuntimeException e) {
        /* The event bus uses the Looper from the Android framework, so
         * initializing it would throw a runtime exception if the
         * framework is not loaded. Nor can RoboGuice be used to inject
         * a mocked instance to get around this issue, since customizing
         * RoboGuice injections requires a Context.
         *
         * Robolectric can't be used to solve this issue, because it
         * doesn't support parameterized testing. The only solution that
         * could work at the moment would be to make this an
         * instrumented test suite.
         *
         * TODO: Mock the event bus when RoboGuice is replaced with
         * another dependency injection framework, or when there is a
         * Robolectric test runner available that support parameterized
         * tests.
         */
        throw new AssumptionViolatedException(
                "Event bus requires Android framework", e, nullValue());
    }
}
 
Example 2
Source File: LinkFragment.java    From sharelock-android with MIT License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Bundle arguments = getArguments();
    if (arguments != null) {
        secret = arguments.getParcelable(LINK_FRAGMENT_SECRET_ARGUMENT);
    }
    bus = EventBus.getDefault();
}
 
Example 3
Source File: USBHIDTerminal.java    From USBHIDTerminal with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);
	try {
		eventBus = EventBus.builder().logNoSubscriberMessages(false).sendNoSubscriberEvent(false).installDefaultEventBus();
	} catch (EventBusException e) {
		eventBus = EventBus.getDefault();
	}
	sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
	sharedPreferences.registerOnSharedPreferenceChangeListener(listener);
	initUI();
}
 
Example 4
Source File: ComposeActivity.java    From sharelock-android with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Crashlytics());
    setContentView(R.layout.activity_compose);

    Toolbar toolbar = (Toolbar) findViewById(R.id.sharelock_toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(null);

    bus = EventBus.getDefault();
    handler = new Handler();

    Intent intent = getIntent();
    String action = intent.getAction();
    String type = intent.getType();

    String sharedText = null;
    if (Intent.ACTION_SEND.equals(action) && type != null) {
        if ("text/plain".equals(type)) {
            sharedText = intent.getStringExtra(Intent.EXTRA_TEXT);
        }
    }

    if (savedInstanceState == null) {
        final SecretInputFragment fragment = new SecretInputFragment();
        if (sharedText != null) {
            Bundle arguments = new Bundle();
            arguments.putString(SecretInputFragment.SECRET_INPUT_FRAGMENT_SECRET_ARGUMENT, sharedText);
            fragment.setArguments(arguments);
        }
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.sharelock_compose_container, fragment)
                .commit();
    } else {
        secret = savedInstanceState.getParcelable(COMPOSE_CREATED_SECRET);
    }
}
 
Example 5
Source File: StopWateringPopup.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
private void sendEvent(String event) {
    String deviceId = getArguments().getString(DEVICE_ID, "");
    bus = EventBus.getDefault();
    bus.postSticky(new IrrigationStopEvent(deviceId, event));

    Callback callback = callbackRef.get();
    if (callback != null) {
        callback.onIrrigationStopEvent(new IrrigationStopEvent(deviceId, event));
    }
    BackstackManager.getInstance().navigateBack();
}
 
Example 6
Source File: AppService.java    From NBAPlus with Apache License 2.0 5 votes vote down vote up
void initService() {
    sBus = EventBus.getDefault();
    sGson=new Gson();
    mCompositeSubByTaskId=new HashMap<Integer,CompositeSubscription>();
    //sSingleThreadExecutor= Executors.newSingleThreadExecutor();
    backGroundInit();
}
 
Example 7
Source File: AbstractCursorListFragment.java    From Kore with Apache License 2.0 5 votes vote down vote up
@TargetApi(16)
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
	View root = super.onCreateView(inflater, container, savedInstanceState);

	bus = EventBus.getDefault();

	if (savedInstanceState != null) {
		savedSearchFilter = savedInstanceState.getString(BUNDLE_KEY_SEARCH_QUERY);
	}
	searchFilter = savedSearchFilter;

	return root;
}
 
Example 8
Source File: BaseMvpPresenter.java    From XiaoxiaZhihu with Apache License 2.0 5 votes vote down vote up
/**
 * 所有子类通过此方法获取EventBus,这样子类可以通过复写此方法获取自己的EventBus
 *
 * @return eventBus
 */
public EventBus getEventBus() {
    if (eventBus == null) {
        eventBus = EventBus.getDefault();
    }
    return eventBus;
}
 
Example 9
Source File: RefreshItem.java    From Kore with Apache License 2.0 4 votes vote down vote up
public void register() {
    EventBus eventBus = EventBus.getDefault();
    if ( ! eventBus.isRegistered(this) ) {
        eventBus.register(this);
    }
}
 
Example 10
Source File: RefreshItem.java    From Kore with Apache License 2.0 4 votes vote down vote up
public void unregister() {
    EventBus eventBus = EventBus.getDefault();
    if ( eventBus.isRegistered(this) ) {
        eventBus.unregister(this);
    }
}
 
Example 11
Source File: MailModule.java    From mosby with Apache License 2.0 4 votes vote down vote up
@Singleton @Provides public EventBus providesEventBus() {
  return EventBus.getDefault();
}
 
Example 12
Source File: SecretInputFragment.java    From sharelock-android with MIT License 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    bus = EventBus.getDefault();
}
 
Example 13
Source File: ShareFragment.java    From sharelock-android with MIT License 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    bus = EventBus.getDefault();
}
 
Example 14
Source File: BusProvider.java    From rexxar-android with MIT License 4 votes vote down vote up
public static EventBus getInstance() {
    return EventBus.getDefault();
}
 
Example 15
Source File: AppModule.java    From android-aop-analytics with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton public EventBus provideEventBus() {
    return EventBus.getDefault();
}
 
Example 16
Source File: TestAppModule.java    From android-aop-analytics with Apache License 2.0 4 votes vote down vote up
@Provides @Singleton public EventBus provideEventBus() {
    return EventBus.getDefault();
}
 
Example 17
Source File: NewVersionAvailableEvent.java    From edx-app-android with Apache License 2.0 4 votes vote down vote up
/**
 * Post an instance of NewVersionAvailableEvent on the event bus, based on the provided
 * properties, if this hasn't been posted before. The sticky events will be queried for an
 * existing report, and a new one will only be posted if it has more urgent information than the
 * previous one. The events are posted and retained as sticky events in order to have a
 * conveniently and semantically accessible session-based singleton of it to compare against,
 * but this has the implication that they can't be removed from the event bus after consumption
 * by the subscribers. To address this restriction, this class defined methods to mark instances
 * as having being consumed, which can be used by subscribers for this purpose.
 *
 * If all the parameters are null or false (or in the case of the new version number parameter,
 * lesser than the current build's version number), then it wouldn't be a valid event, and
 * nothing would be posted on the event bus.
 *
 * @param newVersion        The version number of the latest release of the app.
 * @param lastSupportedDate The last date on which the current version of the app will be
 *                          supported.
 * @param isUnsupported     Whether the current version is unsupported. This is based on whether
 *                          we're getting HTTP 426 errors, and thus can't be inferred from the
 *                          last supported date (the two properties may not be consistent with
 *                          each other due to wrong local clock time or an inconsistency in the
 *                          server configurations).
 */
public static void post(@Nullable final Version newVersion,
                        @Nullable final Date lastSupportedDate,
                        final boolean isUnsupported) {
    final NewVersionAvailableEvent event;
    try {
        event = new NewVersionAvailableEvent(newVersion, lastSupportedDate, isUnsupported);
    } catch (IllegalArgumentException | IllegalStateException e) {
        // If the event is not valid, then do nothing.
        return;
    }
    final EventBus eventBus = EventBus.getDefault();
    final NewVersionAvailableEvent postedEvent =
            eventBus.getStickyEvent(NewVersionAvailableEvent.class);
    if (postedEvent == null || event.compareTo(postedEvent) > 0) {
        eventBus.postSticky(event);
    }
}
 
Example 18
Source File: AppController.java    From KAM with GNU General Public License v3.0 4 votes vote down vote up
public EventBus getBus() {
    return EventBus.getDefault();
}
 
Example 19
Source File: InjectHelp.java    From XiaoxiaZhihu with Apache License 2.0 4 votes vote down vote up
public static EventBus getEventBus() {
    return EventBus.getDefault();
}