Skip to content

Instantly share code, notes, and snippets.

@ljanzik
Last active December 20, 2015 01:29
Show Gist options
  • Save ljanzik/6049950 to your computer and use it in GitHub Desktop.
Save ljanzik/6049950 to your computer and use it in GitHub Desktop.
SImple example for View Injection for a Android Application by using AspectJ
@Aspect
public class ActivityInjectionAspect {
@Before("execution(* android.app.Activity.onCreate(..)) && within(@com.thoughtsonmobile.example.aspectj.Layout *)")
public void beforeOnCreate(JoinPoint joinPoint) {
Activity activity = (Activity)joinPoint.getTarget();
Layout layout = activity.getClass().getAnnotation(Layout.class);
activity.setContentView(layout.value());
}
}
@Layout(R.layout.dashboard)
public class DashboardActivity extends Activity {
[..]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment