Skip to content

Commit

Permalink
add delay function on OnUi annotation.
Browse files Browse the repository at this point in the history
  • Loading branch information
Minkyu Ko committed Jan 3, 2016
1 parent c66da99 commit 2e642c1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion teaspoon-processor/src/main/java/teaspoon/TeaSpoon.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void initialize() {
}

public static void onUi(Runnable runnable) {
threadManager.runOnUiThread(runnable);
onUi(runnable, 0);
}

public static void onUi(Runnable runnable, int delay) {
Expand Down
4 changes: 0 additions & 4 deletions teaspoon-processor/src/main/java/teaspoon/ThreadManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ public static teaspoon.ThreadManager getInstance() {
uiExecutor = new Handler(Looper.getMainLooper());
}

public void runOnUiThread(Runnable runnable) {
runOnUiThread(runnable, 0);
}

public void runOnUiThread(Runnable runnable, int delay) {
uiExecutor.postDelayed(runnable, delay);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package teaspoon.processor;

import android.util.Log;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;

import teaspoon.TeaSpoon;
import teaspoon.annotations.OnUi;

@Aspect
public class TeaSpoonProcessor {
Expand All @@ -20,32 +20,33 @@ public void methodWithOnBackgroundAnnotation() { }
public void methodWithOnUiAnnotation() { }

@Around("methodWithOnBackgroundAnnotation()")
public void executeOnBackground(final ProceedingJoinPoint joinPoint) throws Throwable {
Log.i(TAG, joinPoint.getSignature().getName() + "execute on background thread.");
public void executeOnBackground(final ProceedingJoinPoint joinPoint) throws Exception{
TeaSpoon.onBackground(new Runnable() {
@Override
public void run() {
@Override public void run() {
try {
joinPoint.proceed();
} catch (Throwable throwable) {
throwable.printStackTrace();
throw new IllegalStateException(throwable);
}
}
});
}

@Around("methodWithOnUiAnnotation()")
public void methodWithOnUiAnnotation(final ProceedingJoinPoint joinPoint) throws Throwable {
Log.i(TAG, joinPoint.getSignature().getName() + "execute on ui thread.");
TeaSpoon.onUi(new Runnable() {
@Override
public void run() {
Runnable runnableJoinPoint = new Runnable() {
@Override public void run() {
try {
joinPoint.proceed();
} catch (Throwable throwable) {
throwable.printStackTrace();
throw new IllegalStateException(throwable);
}
}
});
};

MethodSignature targetMethodSignature = (MethodSignature) joinPoint.getSignature();
OnUi annotation = targetMethodSignature.getMethod().getAnnotation(OnUi.class);

TeaSpoon.onUi(runnableJoinPoint, annotation.delay());
}
}

0 comments on commit 2e642c1

Please sign in to comment.