This repository has been archived by the owner on Feb 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
EActivityHolder.java
787 lines (672 loc) · 27.9 KB
/
EActivityHolder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
/**
* Copyright (C) 2010-2015 eBusiness Information, Excilys Group
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed To in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package org.androidannotations.holder;
import static com.sun.codemodel.JExpr.FALSE;
import static com.sun.codemodel.JExpr.TRUE;
import static com.sun.codemodel.JExpr._new;
import static com.sun.codemodel.JExpr._null;
import static com.sun.codemodel.JExpr._super;
import static com.sun.codemodel.JExpr._this;
import static com.sun.codemodel.JExpr.cast;
import static com.sun.codemodel.JExpr.invoke;
import static com.sun.codemodel.JMod.PRIVATE;
import static com.sun.codemodel.JMod.PUBLIC;
import static org.androidannotations.helper.ModelConstants.GENERATION_SUFFIX;
import java.util.ArrayList;
import java.util.List;
import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.ElementFilter;
import org.androidannotations.api.SdkVersionHelper;
import org.androidannotations.helper.ActionBarSherlockHelper;
import org.androidannotations.helper.ActivityIntentBuilder;
import org.androidannotations.helper.AndroidManifest;
import org.androidannotations.helper.AnnotationHelper;
import org.androidannotations.helper.CanonicalNameConstants;
import org.androidannotations.helper.IntentBuilder;
import org.androidannotations.helper.OrmLiteHelper;
import org.androidannotations.holder.ReceiverRegistrationHolder.IntentFilterData;
import org.androidannotations.process.ProcessHolder;
import com.sun.codemodel.JBlock;
import com.sun.codemodel.JClass;
import com.sun.codemodel.JClassAlreadyExistsException;
import com.sun.codemodel.JDefinedClass;
import com.sun.codemodel.JExpr;
import com.sun.codemodel.JExpression;
import com.sun.codemodel.JFieldVar;
import com.sun.codemodel.JInvocation;
import com.sun.codemodel.JMethod;
import com.sun.codemodel.JMod;
import com.sun.codemodel.JType;
import com.sun.codemodel.JVar;
public class EActivityHolder extends EComponentWithViewSupportHolder implements HasIntentBuilder, HasExtras, HasInstanceState, HasOptionsMenu, HasOnActivityResult, HasReceiverRegistration {
private static final String ON_CONTENT_CHANGED_JAVADOC = "We cannot simply copy the " + "code from RoboActivity, because that can cause classpath issues. " + "For further details see issue #1116.";
private ActivityIntentBuilder intentBuilder;
private JMethod onCreate;
private JMethod setIntent;
private JMethod onNewIntentMethod;
private JMethod setContentViewLayout;
private JVar initSavedInstanceParam;
private JDefinedClass intentBuilderClass;
private InstanceStateHolder instanceStateHolder;
private OnActivityResultHolder onActivityResultHolder;
private ReceiverRegistrationHolder receiverRegistrationHolder;
private RoboGuiceHolder roboGuiceHolder;
private JMethod injectExtrasMethod;
private JBlock injectExtrasBlock;
private JVar injectExtras;
private JBlock onCreateOptionsMenuMethodBody;
private JVar onCreateOptionsMenuMenuInflaterVar;
private JVar onCreateOptionsMenuMenuParam;
private JVar onOptionsItemSelectedItem;
private JVar onOptionsItemSelectedItemId;
private JBlock onOptionsItemSelectedIfElseBlock;
private NonConfigurationHolder nonConfigurationHolder;
private JBlock initIfNonConfigurationNotNullBlock;
private JVar initNonConfigurationInstance;
private JMethod getLastNonConfigurationInstance;
private JBlock onRetainNonConfigurationInstanceBindBlock;
private JVar onRetainNonConfigurationInstance;
private JBlock onDestroyBeforeSuperBlock;
private JBlock onDestroyAfterSuperBlock;
private JBlock onResumeAfterSuperBlock;
private JBlock onStartAfterSuperBlock;
private JBlock onStopBeforeSuperBlock;
private JBlock onPauseBeforeSuperBlock;
private JMethod getParcelableArray;
public EActivityHolder(ProcessHolder processHolder, TypeElement annotatedElement, AndroidManifest androidManifest) throws Exception {
super(processHolder, annotatedElement);
instanceStateHolder = new InstanceStateHolder(this);
onActivityResultHolder = new OnActivityResultHolder(this);
receiverRegistrationHolder = new ReceiverRegistrationHolder(this);
setSetContentView();
intentBuilder = new ActivityIntentBuilder(this, androidManifest);
intentBuilder.build();
handleBackPressed();
}
@Override
protected void setContextRef() {
contextRef = _this();
}
@Override
protected void setInit() {
init = generatedClass.method(PRIVATE, codeModel().VOID, "init_");
JClass bundleClass = classes().BUNDLE;
initSavedInstanceParam = init.param(bundleClass, "savedInstanceState");
getOnCreate();
}
public JMethod getOnCreate() {
if (onCreate == null) {
setOnCreate();
}
return onCreate;
}
public JMethod getSetIntent() {
if (setIntent == null) {
setSetIntent();
}
return setIntent;
}
protected void setOnCreate() {
onCreate = generatedClass.method(PUBLIC, codeModel().VOID, "onCreate");
onCreate.annotate(Override.class);
JClass bundleClass = classes().BUNDLE;
JVar onCreateSavedInstanceState = onCreate.param(bundleClass, "savedInstanceState");
JBlock onCreateBody = onCreate.body();
JVar previousNotifier = viewNotifierHelper.replacePreviousNotifier(onCreateBody);
onCreateBody.invoke(getInit()).arg(onCreateSavedInstanceState);
onCreateBody.invoke(_super(), onCreate).arg(onCreateSavedInstanceState);
viewNotifierHelper.resetPreviousNotifier(onCreateBody, previousNotifier);
}
// CHECKSTYLE:OFF
protected void setOnStart() {
JMethod method = generatedClass.method(JMod.PUBLIC, codeModel().VOID, "onStart");
method.annotate(Override.class);
JBlock body = method.body();
getRoboGuiceHolder().onStartBeforeSuperBlock = body.block();
body.invoke(_super(), method);
onStartAfterSuperBlock = body.block();
}
protected void setOnRestart() {
JMethod method = generatedClass.method(JMod.PUBLIC, codeModel().VOID, "onRestart");
method.annotate(Override.class);
JBlock body = method.body();
getRoboGuiceHolder().onRestartBeforeSuperBlock = body.block();
body.invoke(_super(), method);
getRoboGuiceHolder().onRestartAfterSuperBlock = body.block();
}
protected void setOnResume() {
JMethod method = generatedClass.method(JMod.PUBLIC, codeModel().VOID, "onResume");
method.annotate(Override.class);
JBlock body = method.body();
getRoboGuiceHolder().onResumeBeforeSuperBlock = body.block();
body.invoke(_super(), method);
onResumeAfterSuperBlock = body.block();
}
protected void setOnPause() {
JMethod method = generatedClass.method(JMod.PUBLIC, codeModel().VOID, "onPause");
method.annotate(Override.class);
JBlock body = method.body();
onPauseBeforeSuperBlock = body.block();
body.invoke(_super(), method);
getRoboGuiceHolder().onPauseAfterSuperBlock = body.block();
}
protected void setOnNewIntent() {
onNewIntentMethod = generatedClass.method(JMod.PUBLIC, codeModel().VOID, "onNewIntent");
onNewIntentMethod.annotate(Override.class);
JVar intent = onNewIntentMethod.param(classes().INTENT, "intent");
JBlock body = onNewIntentMethod.body();
body.invoke(_super(), onNewIntentMethod).arg(intent);
body.invoke(getSetIntent()).arg(intent);
getRoboGuiceHolder().onNewIntentAfterSuperBlock = body.block();
}
private void setSetIntent() {
setIntent = generatedClass.method(PUBLIC, codeModel().VOID, "setIntent");
setIntent.annotate(Override.class);
JVar methodParam = setIntent.param(classes().INTENT, "newIntent");
JBlock setIntentBody = setIntent.body();
setIntentBody.invoke(_super(), setIntent).arg(methodParam);
}
protected void setOnStop() {
JMethod method = generatedClass.method(JMod.PUBLIC, codeModel().VOID, "onStop");
method.annotate(Override.class);
JBlock body = method.body();
onStopBeforeSuperBlock = body.block();
body.invoke(_super(), method);
getRoboGuiceHolder().onStop = method;
}
protected void setOnDestroy() {
JMethod method = generatedClass.method(JMod.PUBLIC, codeModel().VOID, "onDestroy");
method.annotate(Override.class);
JBlock body = method.body();
getRoboGuiceHolder().onDestroy = method;
onDestroyBeforeSuperBlock = body.block();
body.invoke(_super(), method);
onDestroyAfterSuperBlock = body.block();
}
protected void setOnConfigurationChanged() {
JMethod method = generatedClass.method(JMod.PUBLIC, codeModel().VOID, "onConfigurationChanged");
method.annotate(Override.class);
JClass configurationClass = classes().CONFIGURATION;
JVar newConfig = method.param(configurationClass, "newConfig");
getRoboGuiceHolder().newConfig = newConfig;
JBlock body = method.body();
getRoboGuiceHolder().currentConfig = body.decl(configurationClass, "currentConfig", JExpr.invoke("getResources").invoke("getConfiguration"));
body.invoke(_super(), method).arg(newConfig);
getRoboGuiceHolder().onConfigurationChangedAfterSuperBlock = body.block();
}
protected void setOnContentChanged() {
JMethod method = generatedClass.method(JMod.PUBLIC, codeModel().VOID, "onContentChanged");
method.annotate(Override.class);
method.javadoc().append(ON_CONTENT_CHANGED_JAVADOC);
JBlock body = method.body();
body.invoke(_super(), method);
getRoboGuiceHolder().onContentChangedAfterSuperBlock = body.block();
}
private void setOnCreateOptionsMenu() {
JClass menuClass = classes().MENU;
JClass menuInflaterClass = classes().MENU_INFLATER;
String getMenuInflaterMethodName = "getMenuInflater";
if (usesActionBarSherlock()) {
menuClass = classes().SHERLOCK_MENU;
menuInflaterClass = classes().SHERLOCK_MENU_INFLATER;
getMenuInflaterMethodName = "getSupportMenuInflater";
}
JMethod method = generatedClass.method(PUBLIC, codeModel().BOOLEAN, "onCreateOptionsMenu");
method.annotate(Override.class);
JBlock methodBody = method.body();
onCreateOptionsMenuMenuParam = method.param(menuClass, "menu");
onCreateOptionsMenuMenuInflaterVar = methodBody.decl(menuInflaterClass, "menuInflater", invoke(getMenuInflaterMethodName));
onCreateOptionsMenuMethodBody = methodBody.block();
methodBody._return(_super().invoke(method).arg(onCreateOptionsMenuMenuParam));
}
private void setOnOptionsItemSelected() {
JClass menuItemClass = classes().MENU_ITEM;
if (usesActionBarSherlock()) {
menuItemClass = classes().SHERLOCK_MENU_ITEM;
}
JMethod method = generatedClass.method(JMod.PUBLIC, codeModel().BOOLEAN, "onOptionsItemSelected");
method.annotate(Override.class);
JBlock methodBody = method.body();
onOptionsItemSelectedItem = method.param(menuItemClass, "item");
JVar handled = methodBody.decl(codeModel().BOOLEAN, "handled", invoke(_super(), method).arg(onOptionsItemSelectedItem));
methodBody._if(handled)._then()._return(TRUE);
onOptionsItemSelectedItemId = methodBody.decl(codeModel().INT, "itemId_", onOptionsItemSelectedItem.invoke("getItemId"));
onOptionsItemSelectedIfElseBlock = methodBody.block();
methodBody._return(FALSE);
}
private boolean usesActionBarSherlock() {
return new ActionBarSherlockHelper(new AnnotationHelper(processingEnvironment())).usesActionBarSherlock(this);
}
@Override
protected void setFindNativeFragmentById() {
JMethod method = generatedClass.method(PRIVATE, classes().FRAGMENT, "findNativeFragmentById");
JVar idParam = method.param(codeModel().INT, "id");
JBlock body = method.body();
body._return(invoke("getFragmentManager").invoke("findFragmentById").arg(idParam));
findNativeFragmentById = method;
}
@Override
protected void setFindSupportFragmentById() {
JMethod method = generatedClass.method(PRIVATE, classes().SUPPORT_V4_FRAGMENT, "findSupportFragmentById");
JVar idParam = method.param(codeModel().INT, "id");
JBlock body = method.body();
body._return(invoke("getSupportFragmentManager").invoke("findFragmentById").arg(idParam));
findSupportFragmentById = method;
}
@Override
protected void setFindNativeFragmentByTag() {
JMethod method = generatedClass.method(PRIVATE, classes().FRAGMENT, "findNativeFragmentByTag");
JVar tagParam = method.param(classes().STRING, "tag");
JBlock body = method.body();
body._return(invoke("getFragmentManager").invoke("findFragmentByTag").arg(tagParam));
findNativeFragmentByTag = method;
}
@Override
protected void setFindSupportFragmentByTag() {
JMethod method = generatedClass.method(PRIVATE, classes().SUPPORT_V4_FRAGMENT, "findSupportFragmentByTag");
JVar tagParam = method.param(classes().STRING, "tag");
JBlock body = method.body();
body._return(invoke("getSupportFragmentManager").invoke("findFragmentByTag").arg(tagParam));
findSupportFragmentByTag = method;
}
public JMethod getSetContentViewLayout() {
if (setContentViewLayout == null) {
setSetContentView();
}
return setContentViewLayout;
}
private void setSetContentView() {
getOnCreate();
JClass layoutParamsClass = classes().VIEW_GROUP_LAYOUT_PARAMS;
setContentViewLayout = setContentViewMethod(new JType[] { codeModel().INT }, new String[] { "layoutResID" });
setContentViewMethod(new JType[] { classes().VIEW, layoutParamsClass }, new String[] { "view", "params" });
setContentViewMethod(new JType[] { classes().VIEW }, new String[] { "view" });
}
private JMethod setContentViewMethod(JType[] paramTypes, String[] paramNames) {
JMethod method = generatedClass.method(JMod.PUBLIC, codeModel().VOID, "setContentView");
method.annotate(Override.class);
List<JVar> params = new ArrayList<JVar>();
for (int i = 0; i < paramTypes.length; i++) {
JVar param = method.param(paramTypes[i], paramNames[i]);
params.add(param);
}
JBlock body = method.body();
JInvocation superCall = body.invoke(JExpr._super(), method);
for (JVar arg : params) {
superCall.arg(arg);
}
viewNotifierHelper.invokeViewChanged(body);
return method;
}
public JVar getInitSavedInstanceParam() {
return initSavedInstanceParam;
}
private void handleBackPressed() {
Element declaredOnBackPressedMethod = getOnBackPressedMethod(annotatedElement);
if (declaredOnBackPressedMethod != null) {
JMethod onKeyDownMethod = generatedClass.method(PUBLIC, codeModel().BOOLEAN, "onKeyDown");
onKeyDownMethod.annotate(Override.class);
JVar keyCodeParam = onKeyDownMethod.param(codeModel().INT, "keyCode");
JClass keyEventClass = classes().KEY_EVENT;
JVar eventParam = onKeyDownMethod.param(keyEventClass, "event");
JClass versionHelperClass = refClass(SdkVersionHelper.class);
JInvocation sdkInt = versionHelperClass.staticInvoke("getSdkInt");
JBlock onKeyDownBody = onKeyDownMethod.body();
onKeyDownBody._if( //
sdkInt.lt(JExpr.lit(5)) //
.cand(keyCodeParam.eq(keyEventClass.staticRef("KEYCODE_BACK"))) //
.cand(eventParam.invoke("getRepeatCount").eq(JExpr.lit(0)))) //
._then() //
.invoke("onBackPressed");
onKeyDownBody._return( //
JExpr._super().invoke(onKeyDownMethod) //
.arg(keyCodeParam) //
.arg(eventParam));
}
}
private ExecutableElement getOnBackPressedMethod(TypeElement activityElement) {
AnnotationHelper annotationHelper = new AnnotationHelper(processingEnvironment());
List<? extends Element> allMembers = annotationHelper.getElementUtils().getAllMembers(activityElement);
List<ExecutableElement> activityInheritedMethods = ElementFilter.methodsIn(allMembers);
for (ExecutableElement activityInheritedMethod : activityInheritedMethods) {
if (isCustomOnBackPressedMethod(activityInheritedMethod)) {
return activityInheritedMethod;
}
}
return null;
}
private boolean isCustomOnBackPressedMethod(ExecutableElement method) {
TypeElement methodClass = (TypeElement) method.getEnclosingElement();
boolean methodBelongsToActivityClass = methodClass.getQualifiedName().toString().equals(CanonicalNameConstants.ACTIVITY);
return !methodBelongsToActivityClass //
&& method.getSimpleName().toString().equals("onBackPressed") //
&& method.getThrownTypes().size() == 0 //
&& method.getModifiers().contains(Modifier.PUBLIC) //
&& method.getReturnType().getKind().equals(TypeKind.VOID) //
&& method.getParameters().size() == 0;
}
@Override
public IntentBuilder getIntentBuilder() {
return intentBuilder;
}
@Override
public void setIntentBuilderClass(JDefinedClass intentBuilderClass) {
this.intentBuilderClass = intentBuilderClass;
}
@Override
public JDefinedClass getIntentBuilderClass() {
return intentBuilderClass;
}
public RoboGuiceHolder getRoboGuiceHolder() {
if (roboGuiceHolder == null) {
roboGuiceHolder = new RoboGuiceHolder(this);
}
return roboGuiceHolder;
}
protected void setScopedObjectsField() {
JClass keyWildCard = classes().KEY.narrow(codeModel().wildcard());
JClass scopedHashMap = classes().HASH_MAP.narrow(keyWildCard, classes().OBJECT);
getRoboGuiceHolder().scopedObjects = getGeneratedClass().field(JMod.PROTECTED, scopedHashMap, "scopedObjects" + GENERATION_SUFFIX);
getRoboGuiceHolder().scopedObjects.assign(JExpr._new(scopedHashMap));
}
protected void setEventManagerField() {
getRoboGuiceHolder().eventManager = generatedClass.field(JMod.PROTECTED, classes().EVENT_MANAGER, "eventManager" + GENERATION_SUFFIX);
}
protected void setContentViewListenerField() {
getRoboGuiceHolder().contentViewListenerField = generatedClass.field(JMod.NONE, classes().CONTENT_VIEW_LISTENER, "ignored" + GENERATION_SUFFIX);
getRoboGuiceHolder().contentViewListenerField.annotate(classes().INJECT);
}
protected void setScopeField() {
getRoboGuiceHolder().scope = getGeneratedClass().field(JMod.PRIVATE, classes().CONTEXT_SCOPE, "scope_");
}
// CHECKSTYLE:ON
@Override
public JMethod getInjectExtrasMethod() {
if (injectExtrasMethod == null) {
setInjectExtras();
}
return injectExtrasMethod;
}
@Override
public JBlock getInjectExtrasBlock() {
if (injectExtrasBlock == null) {
setInjectExtras();
}
return injectExtrasBlock;
}
@Override
public JVar getInjectExtras() {
if (injectExtras == null) {
setInjectExtras();
}
return injectExtras;
}
private void setInjectExtras() {
injectExtrasMethod = generatedClass.method(PRIVATE, codeModel().VOID, "injectExtras_");
JBlock injectExtrasBody = injectExtrasMethod.body();
injectExtras = injectExtrasBody.decl(classes().BUNDLE, "extras_", invoke("getIntent").invoke("getExtras"));
injectExtrasBlock = injectExtrasBody._if(injectExtras.ne(_null()))._then();
getSetIntent().body().invoke(injectExtrasMethod);
getInitBody().invoke(injectExtrasMethod);
}
public JMethod getOnNewIntent() {
if (onNewIntentMethod == null) {
setOnNewIntent();
}
return onNewIntentMethod;
}
@Override
public JBlock getSaveStateMethodBody() {
return instanceStateHolder.getSaveStateMethodBody();
}
@Override
public JVar getSaveStateBundleParam() {
return instanceStateHolder.getSaveStateBundleParam();
}
@Override
public JMethod getRestoreStateMethod() {
return instanceStateHolder.getRestoreStateMethod();
}
@Override
public JVar getRestoreStateBundleParam() {
return instanceStateHolder.getRestoreStateBundleParam();
}
@Override
public JBlock getOnCreateOptionsMenuMethodBody() {
if (onCreateOptionsMenuMethodBody == null) {
setOnCreateOptionsMenu();
}
return onCreateOptionsMenuMethodBody;
}
@Override
public JVar getOnCreateOptionsMenuMenuInflaterVar() {
if (onCreateOptionsMenuMenuInflaterVar == null) {
setOnCreateOptionsMenu();
}
return onCreateOptionsMenuMenuInflaterVar;
}
@Override
public JVar getOnCreateOptionsMenuMenuParam() {
if (onCreateOptionsMenuMenuParam == null) {
setOnCreateOptionsMenu();
}
return onCreateOptionsMenuMenuParam;
}
@Override
public JVar getOnOptionsItemSelectedItem() {
if (onOptionsItemSelectedItem == null) {
setOnOptionsItemSelected();
}
return onOptionsItemSelectedItem;
}
@Override
public JVar getOnOptionsItemSelectedItemId() {
if (onOptionsItemSelectedItemId == null) {
setOnOptionsItemSelected();
}
return onOptionsItemSelectedItemId;
}
@Override
public JBlock getOnOptionsItemSelectedIfElseBlock() {
if (onOptionsItemSelectedIfElseBlock == null) {
setOnOptionsItemSelected();
}
return onOptionsItemSelectedIfElseBlock;
}
public NonConfigurationHolder getNonConfigurationHolder() throws JClassAlreadyExistsException {
if (nonConfigurationHolder == null) {
setNonConfigurationHolder();
}
return nonConfigurationHolder;
}
private void setNonConfigurationHolder() throws JClassAlreadyExistsException {
nonConfigurationHolder = new NonConfigurationHolder(this);
}
public JBlock getInitIfNonConfigurationNotNullBlock() throws JClassAlreadyExistsException {
if (initIfNonConfigurationNotNullBlock == null) {
setInitNonConfigurationInstance();
}
return initIfNonConfigurationNotNullBlock;
}
public JVar getInitNonConfigurationInstance() throws JClassAlreadyExistsException {
if (initNonConfigurationInstance == null) {
setInitNonConfigurationInstance();
}
return initNonConfigurationInstance;
}
private void setInitNonConfigurationInstance() throws JClassAlreadyExistsException {
JBlock initBody = getInitBody();
JDefinedClass ncHolderClass = getNonConfigurationHolder().getGeneratedClass();
initNonConfigurationInstance = initBody.decl(ncHolderClass, "nonConfigurationInstance", cast(ncHolderClass, _super().invoke(getGetLastNonConfigurationInstance())));
initIfNonConfigurationNotNullBlock = initBody._if(initNonConfigurationInstance.ne(_null()))._then();
}
public JMethod getGetLastNonConfigurationInstance() throws JClassAlreadyExistsException {
if (getLastNonConfigurationInstance == null) {
setGetLastNonConfigurationInstance();
}
return getLastNonConfigurationInstance;
}
private void setGetLastNonConfigurationInstance() throws JClassAlreadyExistsException {
AnnotationHelper annotationHelper = new AnnotationHelper(processingEnvironment());
TypeElement fragmentActivityTypeElement = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.FRAGMENT_ACTIVITY);
TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(generatedClass._extends().fullName());
String getLastNonConfigurationInstanceName = "getLastNonConfigurationInstance";
if (fragmentActivityTypeElement != null && annotationHelper.isSubtype(typeElement.asType(), fragmentActivityTypeElement.asType())) {
getLastNonConfigurationInstanceName = "getLastCustomNonConfigurationInstance";
}
NonConfigurationHolder ncHolder = getNonConfigurationHolder();
JDefinedClass ncHolderClass = ncHolder.getGeneratedClass();
JFieldVar superNonConfigurationInstanceField = ncHolder.getSuperNonConfigurationInstanceField();
getLastNonConfigurationInstance = generatedClass.method(PUBLIC, Object.class, getLastNonConfigurationInstanceName);
getLastNonConfigurationInstance.annotate(Override.class);
JBlock body = getLastNonConfigurationInstance.body();
JVar nonConfigurationInstance = body.decl(ncHolderClass, "nonConfigurationInstance", cast(ncHolderClass, _super().invoke(getLastNonConfigurationInstance)));
body._if(nonConfigurationInstance.eq(_null()))._then()._return(_null());
body._return(nonConfigurationInstance.ref(superNonConfigurationInstanceField));
}
public JBlock getOnRetainNonConfigurationInstanceBindBlock() throws JClassAlreadyExistsException {
if (onRetainNonConfigurationInstanceBindBlock == null) {
setOnRetainNonConfigurationInstance();
}
return onRetainNonConfigurationInstanceBindBlock;
}
public JVar getOnRetainNonConfigurationInstance() throws JClassAlreadyExistsException {
if (onRetainNonConfigurationInstance == null) {
setOnRetainNonConfigurationInstance();
}
return onRetainNonConfigurationInstance;
}
private void setOnRetainNonConfigurationInstance() throws JClassAlreadyExistsException {
AnnotationHelper annotationHelper = new AnnotationHelper(processingEnvironment());
TypeElement fragmentActivityTypeElement = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.FRAGMENT_ACTIVITY);
TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(generatedClass._extends().fullName());
String onRetainNonConfigurationInstanceName = "onRetainNonConfigurationInstance";
if (fragmentActivityTypeElement != null && annotationHelper.isSubtype(typeElement.asType(), fragmentActivityTypeElement.asType())) {
onRetainNonConfigurationInstanceName = "onRetainCustomNonConfigurationInstance";
}
NonConfigurationHolder ncHolder = getNonConfigurationHolder();
JDefinedClass ncHolderClass = ncHolder.getGeneratedClass();
JMethod onRetainNonConfigurationInstanceMethod = generatedClass.method(PUBLIC, ncHolderClass, onRetainNonConfigurationInstanceName);
onRetainNonConfigurationInstanceMethod.annotate(Override.class);
JBlock methodBody = onRetainNonConfigurationInstanceMethod.body();
onRetainNonConfigurationInstance = methodBody.decl(ncHolderClass, "nonConfigurationInstanceState_", _new(ncHolderClass));
JExpression superCall = _super().invoke(onRetainNonConfigurationInstanceMethod);
methodBody.assign(onRetainNonConfigurationInstance.ref(ncHolder.getSuperNonConfigurationInstanceField()), superCall);
onRetainNonConfigurationInstanceBindBlock = methodBody.block();
methodBody._return(onRetainNonConfigurationInstance);
}
@Override
public JBlock getOnActivityResultCaseBlock(int requestCode) {
return onActivityResultHolder.getCaseBlock(requestCode);
}
@Override
public JVar getOnActivityResultDataParam() {
return onActivityResultHolder.getDataParam();
}
@Override
public JVar getOnActivityResultResultCodeParam() {
return onActivityResultHolder.getResultCodeParam();
}
public JBlock getOnActivityResultAfterSuperBlock() {
return onActivityResultHolder.getAfterSuperBlock();
}
public JVar getOnActivityResultRequestCodeParam() {
return onActivityResultHolder.getRequestCodeParam();
}
@Override
public JMethod getOnActivityResultMethod() {
return onActivityResultHolder.getMethod();
}
public JBlock getOnDestroyAfterSuperBlock() {
if (onDestroyAfterSuperBlock == null) {
setOnDestroy();
}
return onDestroyAfterSuperBlock;
}
@Override
public JBlock getOnResumeAfterSuperBlock() {
if (onResumeAfterSuperBlock == null) {
setOnResume();
}
return onResumeAfterSuperBlock;
}
@Override
public JBlock getOnCreateAfterSuperBlock() {
return getInitBody();
}
@Override
public JBlock getOnDestroyBeforeSuperBlock() {
if (onDestroyBeforeSuperBlock == null) {
setOnDestroy();
}
return onDestroyBeforeSuperBlock;
}
@Override
public JBlock getOnStartAfterSuperBlock() {
if (onStartAfterSuperBlock == null) {
setOnStart();
}
return onStartAfterSuperBlock;
}
@Override
public JBlock getOnStopBeforeSuperBlock() {
if (onStopBeforeSuperBlock == null) {
setOnStop();
}
return onStopBeforeSuperBlock;
}
@Override
public JBlock getOnPauseBeforeSuperBlock() {
if (onPauseBeforeSuperBlock == null) {
setOnPause();
}
return onPauseBeforeSuperBlock;
}
@Override
public JBlock getOnAttachAfterSuperBlock() {
return receiverRegistrationHolder.getOnAttachAfterSuperBlock();
}
@Override
public JBlock getOnDetachBeforeSuperBlock() {
return receiverRegistrationHolder.getOnDetachBeforeSuperBlock();
}
@Override
public JFieldVar getIntentFilterField(IntentFilterData intentFilterData) {
return receiverRegistrationHolder.getIntentFilterField(intentFilterData);
}
@Override
public JBlock getIntentFilterInitializationBlock(IntentFilterData intentFilterData) {
return getInitBody();
}
@Override
protected JFieldVar setDatabaseHelperRef(TypeMirror databaseHelperTypeMirror) {
JFieldVar databaseHelperRef = super.setDatabaseHelperRef(databaseHelperTypeMirror);
OrmLiteHelper.injectReleaseInDestroy(databaseHelperRef, this, classes());
return databaseHelperRef;
}
@Override
public JMethod getGetParcelableArrayMethod() {
if (getParcelableArray == null) {
getParcelableArray = instanceStateHolder.getGetParcelableArrayMethod();
}
return getParcelableArray;
}
}