Android Open Source - AspectJ-Android-Example Logging Aspect






From Project

Back to project page AspectJ-Android-Example.

License

The source code is released under:

Apache License

If you think the Android project AspectJ-Android-Example listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package android.mobile.peakgames.net.aspectjandroid.aspect;
//from  www . j  a v a2s .  c o m
import android.util.Log;
import android.widget.Button;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

@Aspect
public class LoggingAspect {
    private static final String TAG = LoggingAspect.class.getName();

    @Pointcut("execution(* android.view.View.OnClickListener.onClick(..))")
    public void onClickEntryPoint() {
    }

    @Before("onClickEntryPoint()")
    public void onClickBefore(JoinPoint joinPoint) {
        Log.d(TAG, "Before Advice ==> Clicked on : " + ((Button)joinPoint.getArgs()[0]).getText());
    }

    @Around("onClickEntryPoint()")
    public void onClickAround(ProceedingJoinPoint joinPoint) {
        Log.d(TAG, "Around Advice ==> Clicked on : " + ((Button)joinPoint.getArgs()[0]).getText());

        try {
            joinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
    }

    @After("onClickEntryPoint()")
    public void onClickAfter(JoinPoint joinPoint) {
        Log.d(TAG, "After Advice ==> Clicked on : " + ((Button)joinPoint.getArgs()[0]).getText());
    }

    @AfterReturning(pointcut = "onClickEntryPoint()")
    public void onClickAfterReturning() {
        Log.d(TAG, "AfterReturning Advice ==>");
    }
}




Java Source Code List

android.mobile.peakgames.net.aspectjandroid.ApplicationTest.java
android.mobile.peakgames.net.aspectjandroid.AspectActivity.java
android.mobile.peakgames.net.aspectjandroid.SecureMethod.java
android.mobile.peakgames.net.aspectjandroid.Session.java
android.mobile.peakgames.net.aspectjandroid.aspect.AuthenticationAspect.java
android.mobile.peakgames.net.aspectjandroid.aspect.CachingAspect.java
android.mobile.peakgames.net.aspectjandroid.aspect.ExceptionHandlingAspect.java
android.mobile.peakgames.net.aspectjandroid.aspect.LoggingAspect.java
android.mobile.peakgames.net.aspectjandroid.aspect.ProfilingAspect.java
android.mobile.peakgames.net.aspectjandroid.exception.AuthenticationException.java