I am using Mortar and Flow to power my app. If I have the following View:
public class MyView extends LinearLayout {
@Inject MyScreen.Presenter presenter;
private EditText someText;
public MyView(Context context) {
super(context);
Mortar.inject(context, this);
}
@Override protected void onFinishInflate() {
super.onFinishInflate();
presenter.takeView(this);
}
@Override protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
presenter.dropView(this);
}
}
And the following screen:
@Layout(R.layout.my_view)
public class MyScreen implements Blueprint {
@Override public String getMortarScopeName() {
return getClass().getName();
}
@Override public Object getDaggerModule() {
return new Module();
}
@dagger.Module(injects = MyView.class, addsTo = MyActivity.Module.class)
public class Module {
}
@Singleton
public class Presenter extends ViewPresenter<MyView> {
private final SomeAsyncService service;
@Inject
Presenter() { }
@Override public void onLoad(Bundle savedInstanceState) {
}
@Override public void onSave(Bundle outState) {
}
}
}
Now I would like to get access to Activity which is using this Screen and View. I would to have access to some of the Activity methods like:
getWindow()
finish()
getLayoutInflater()
getFragmentManager()
etc
I have tried to cast a Context like this inside my Screen:
Activity activity = (Activity)getView.getContext;
But this of course throws the following exception:
java.lang.ClassCastException: mortar.MortarContextWrapper cannot be cast to
android.app.Activity
How to get that activity? Thank you.