I write the Android app, and I want to use custom fonts. So, I decided to use Calligraphy for that.
To use this library I need to override base method attachBaseContext
in every Activity
:
public class MainActivity extends AppCompatActivity {
...
@Override
protected void attachBaseContext(Context newBase) {
super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}
...
}
Of course I can use OOP for that, but I want to do it using AspectJ
.
To incude AspectJ
in my gradle
project I use gradle-android-aspectj-plugin.
Here is code of my aspect:
@Aspect
public class MyAspect {
@Before("execution(void com.youtubeplaylist.app.ui.activity.*+.attachBaseContext(context))")
public void beforeCalligraphy(ProceedingJoinPoint thisJoinPoint) throws Throwable {
Object[] args = thisJoinPoint.getArgs();
Context c = (Context) args[0];
c = CalligraphyContextWrapper.wrap(c);
args[0] = c;
thisJoinPoint.proceed(args);
System.out.println("Aspect finished successfully");
}
}
So, "Aspect finished successfully" never prints. Please, help me understand what's the problem.