Is there any way to bind with provider which interprets target's annotation value in Google Guice?
Example:
bind(Resource.class)
.annotatedWith(MyAnnotation.class)
.toProvider(new MyProvider<MyAnnotation, Resource>{
public Resource get(MyAnnotation anno){
return resolveResourceByAnnoValue(anno.value());
}
});
I want to initialize field of an Android Activity class by annotated binding. It should have to take multiple resources by it's unique Id.
Original Way:
public class TestActivity extends Activity{
private TextView textView;
private Button testButton;
public void onAfterCreate(...){
// set UI declaration resource.
setContentView(R.layout.activity_test);
// initialize fields, it must be done after setting ui definition.
textView = (TextView) findViewById(R.id.textView);
.... initialize other fields, hook them...
...
}
I want to bind UI and it's field in declarative way, not pragmatically likes above:
@ResourceID(R.layout.activity_test)
public class TestActivity extends InjectiveActivity{
@ResourceID(R.id.textView) // Auto generated static resource id constant
private TextView textView;
@ResourceID(R.id.testButton)
private Button testButton;
...
}