1818import java .lang .annotation .Annotation ;
1919import java .util .ArrayList ;
2020import java .util .List ;
21- import java .util .concurrent .Executor ;
22- import java .util .concurrent .Executors ;
2321
2422import javax .lang .model .element .Element ;
2523import javax .lang .model .element .ExecutableElement ;
2624import javax .lang .model .element .VariableElement ;
2725
2826import com .googlecode .androidannotations .annotations .Background ;
29- import com .googlecode .androidannotations .helper . AndroidManifest ;
27+ import com .googlecode .androidannotations .api . BackgroundExecutor_ ;
3028import com .sun .codemodel .JBlock ;
3129import com .sun .codemodel .JCatchBlock ;
3230import com .sun .codemodel .JClass ;
3533import com .sun .codemodel .JDefinedClass ;
3634import com .sun .codemodel .JExpr ;
3735import com .sun .codemodel .JExpression ;
38- import com .sun .codemodel .JFieldVar ;
3936import com .sun .codemodel .JInvocation ;
4037import com .sun .codemodel .JMethod ;
4138import com .sun .codemodel .JMod ;
4441
4542public class BackgroundProcessor implements ElementProcessor {
4643
47- private final AndroidManifest androidManifest ;
48-
49- public BackgroundProcessor (AndroidManifest androidManifest ) {
50- this .androidManifest = androidManifest ;
51- }
52-
5344 @ Override
5445 public Class <? extends Annotation > getTarget () {
5546 return Background .class ;
@@ -60,17 +51,6 @@ public void process(Element element, JCodeModel codeModel, ActivitiesHolder acti
6051
6152 ActivityHolder holder = activitiesHolder .getEnclosingActivityHolder (element );
6253
63- if (activitiesHolder .backgroundExecutor == null ) {
64- activitiesHolder .backgroundExecutor = codeModel ._class (androidManifest .getApplicationPackage () + ".BackgroundExecutor_" );
65-
66- JInvocation newCachedThreadPool = codeModel .ref (Executors .class ).staticInvoke ("newCachedThreadPool" );
67-
68- JFieldVar executorStaticField = activitiesHolder .backgroundExecutor .field (JMod .STATIC | JMod .PRIVATE | JMod .FINAL , codeModel .ref (Executor .class ), "executor" , newCachedThreadPool );
69- activitiesHolder .executorMethod = activitiesHolder .backgroundExecutor .method (JMod .PUBLIC | JMod .STATIC , codeModel .VOID , "execute" );
70- JVar runnableParam = activitiesHolder .executorMethod .param (Runnable .class , "runnable" );
71- activitiesHolder .executorMethod .body ().invoke (executorStaticField , "execute" ).arg (runnableParam );
72- }
73-
7454 // Method
7555 String backgroundMethodName = element .getSimpleName ().toString ();
7656 JMethod backgroundMethod = holder .activity .method (JMod .PUBLIC , codeModel .VOID , backgroundMethodName );
@@ -115,7 +95,9 @@ public void process(Element element, JCodeModel codeModel, ActivitiesHolder acti
11595
11696 JBlock backgroundBody = backgroundMethod .body ();
11797
118- JInvocation executeCall = activitiesHolder .backgroundExecutor .staticInvoke (activitiesHolder .executorMethod ).arg (JExpr ._new (anonymousRunnableClass ));
98+ JClass backgroundExecutorClass = codeModel .ref (BackgroundExecutor_ .class );
99+
100+ JInvocation executeCall = backgroundExecutorClass .staticInvoke ("execute" ).arg (JExpr ._new (anonymousRunnableClass ));
119101
120102 backgroundBody .add (executeCall );
121103 }
0 commit comments