Skip to content

Commit a5c4b7f

Browse files
committed
added Propagation enum instead of boolean
1 parent acd3972 commit a5c4b7f

2 files changed

Lines changed: 15 additions & 9 deletions

File tree

  • AndroidAnnotations

‎AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/annotations/UiThread.java‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,27 @@
2222

2323
/**
2424
* Should be used on method that must be run in the Ui thread
25-
*
25+
*
2626
* The annotation parameter delay is the delay (in milliseconds) until the
2727
* method will be executed. The default is 0 (no delay).
28-
*
28+
*
2929
*/
3030
@Retention(RetentionPolicy.CLASS)
3131
@Target(ElementType.METHOD)
3232
public @interface UiThread {
3333
long delay() default 0;
3434

3535
/**
36-
* If useDirect = true, the method will check first if it is inside the UI
37-
* thread already. If so, it will directly call the method instead of using
36+
* If propagation = REUSE, the method will check first if it is inside the
37+
* UI thread already. If so, it will directly call the method instead of
38+
* using the handler. The default value is ENQUEUE, which will always call
3839
* the handler.
39-
*
40+
*
4041
* @return
4142
*/
42-
boolean useDirect() default false;
43+
Propagation propagation() default Propagation.ENQUEUE;
44+
45+
public enum Propagation {
46+
ENQUEUE, REUSE
47+
}
4348
}

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/UiThreadProcessor.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import javax.lang.model.element.ExecutableElement;
2323

2424
import org.androidannotations.annotations.UiThread;
25+
import org.androidannotations.annotations.UiThread.Propagation;
2526
import org.androidannotations.helper.APTCodeModelHelper;
2627

2728
import android.os.Looper;
@@ -57,12 +58,12 @@ public void process(Element element, JCodeModel codeModel, EBeanHolder holder) t
5758

5859
ExecutableElement executableElement = (ExecutableElement) element;
5960
UiThread annotation = element.getAnnotation(UiThread.class);
60-
boolean useDirect = annotation.useDirect();
61+
Propagation propagation = annotation.propagation();
6162

6263
JMethod delegatingMethod = helper.overrideAnnotatedMethod(executableElement, holder);
6364
JBlock clonedBody = null;
6465

65-
if (useDirect) {
66+
if (propagation == Propagation.REUSE) {
6667
// Need to clone the body to be put in the check. This is done here
6768
// because the next line
6869
// will remove the body from the method.
@@ -80,7 +81,7 @@ public void process(Element element, JCodeModel codeModel, EBeanHolder holder) t
8081
holder.handler = holder.generatedClass.field(JMod.PRIVATE, handlerClass, "handler_", JExpr._new(handlerClass));
8182
}
8283

83-
if (useDirect) {
84+
if (propagation == Propagation.REUSE) {
8485
// Put in the check for the UI thread.
8586
addUIThreadCheck(delegatingMethod, clonedBody, codeModel);
8687
}

0 commit comments

Comments
 (0)