@RootContext void methodInjectedContext(Context methodInjectedContext) { this.methodInjectedContext = methodInjectedContext; }
void multiInjectedContext(@RootContext Context multiInjectedContext, @RootContext Context multiInjectedContext2) { this.multiInjectedContext = multiInjectedContext; } }
@EBean public class SomeBean { @RootContext public Context context; Context methodInjectedContext; Context multiInjectedContext; @RootContext void methodInjectedContext(Context methodInjectedContext) { this.methodInjectedContext = methodInjectedContext; } void multiInjectedContext(@RootContext Context multiInjectedContext, @RootContext Context multiInjectedContext2) { this.multiInjectedContext = multiInjectedContext; } }
@EBean public abstract class AbstractBean { @RootContext Context context; public AbstractBean(String param) { } @Background void backgroundMethod() { } }
@EBean(scope = Scope.Singleton) public class SomeSingleton { @RootContext public Context context; /* * Should not be injected (singleton) */ @ViewById public View myTextView; @Bean public BeanWithView beanWithView; }
SecondDependency secondDependency; @RootContext Activity activity; @RootContext Context context; @RootContext Service service; @RootContext ThreadActivity threadActivity;
@RootContext Context context;
@EBean public abstract class StringResources { @RootContext public Context context; @NonNull public final String getString(@android.support.annotation.StringRes int resId) { return context.getString(resId); } @NonNull public final String getString(@android.support.annotation.StringRes int resId, Object... formatArgs) { return context.getString(resId, formatArgs); } }
@EBean public class RatingDialogHelper { private static final String TAG_SUGGEST = "suggest"; private static final String TAG_RATING = "rating"; @RootContext Activity activity; public void displaySuggestDialog() { show(SuggestDialog_.builder().build(), TAG_SUGGEST); } public void displayRatingDialog() { show(RatingDialog_.builder().build(), TAG_RATING); } private void show(DialogFragment dialogFragment, String tag) { FragmentManager fragmentManager = activity.getFragmentManager(); Fragment fragmentByTag = fragmentManager.findFragmentByTag(tag); if (fragmentByTag == null) { dialogFragment.show(fragmentManager, tag); } } }
@EBean(scope = EBean.Scope.Singleton) public class UriDependencies { @RootContext Context context; @AfterInject void init() { for (final UriDependency dependency : UriMatcher.getUriDependencies()) { context.getContentResolver().registerContentObserver(dependency.observe, true, new ContentObserver(null) { @Override public void onChange(boolean selfChange) { super.onChange(selfChange); context.getContentResolver().notifyChange(dependency.notify, null); } }); } } static class UriDependency { private Uri observe; private Uri notify; UriDependency(Uri observe, Uri notify) { this.observe = observe; this.notify = notify; } } }
@EBean public class LoginErrorHandler extends DefaultResponseErrorHandler { @RootContext Context context; @Override public boolean hasError(ClientHttpResponse response) throws IOException { return super.hasError(response) || response.getStatusCode().series() == HttpStatus.Series.REDIRECTION; } @Override public void handleError(ClientHttpResponse response) throws IOException { HttpStatus code = response.getStatusCode(); switch (code.series()) { case REDIRECTION: URI location = URIUtils.getURIWithoutParameters(response.getHeaders().getLocation()); String message = context.getString(R.string.login_server_send_redirect, (location == null ? "" : location.toString())); throw new LoginRedirectException(code, message); default: super.handleError(response); break; } } }
@RootContext Context context;
@RootContext Activity context;
@RootContext Context mContext;
@RootContext Context context;
@RootContext Context context;
@EBean(scope = EBean.Scope.Singleton) public class CommonSharedPreferencesHelper { @RootContext Context context;
private static final int THRESHOLD = 3; @RootContext Activity activity;
GameManager gameManager; @RootContext MainActivity activity;
private static final String TAG = DbUpdater.class.getSimpleName(); @RootContext Context context;