Skip to content

Commit e6fdea7

Browse files
committed
@BeforeCreate has be renamed @BeforeViews, and the javadoc has been updated to explain the behavior. Also updated the samples. Fixes issue 45.
1 parent b781186 commit e6fdea7

7 files changed

Lines changed: 63 additions & 50 deletions

File tree

‎AndroidAnnotations/src/main/java/com/googlecode/androidannotations/AndroidAnnotationProcessor.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import javax.tools.Diagnostic;
3131

3232
import com.googlecode.androidannotations.annotations.Background;
33-
import com.googlecode.androidannotations.annotations.BeforeCreate;
33+
import com.googlecode.androidannotations.annotations.BeforeViews;
3434
import com.googlecode.androidannotations.annotations.Click;
3535
import com.googlecode.androidannotations.annotations.EActivity;
3636
import com.googlecode.androidannotations.annotations.Extra;
@@ -113,7 +113,7 @@
113113
import com.sun.codemodel.JCodeModel;
114114

115115
@SupportedAnnotationClasses({ EActivity.class, //
116-
BeforeCreate.class, //
116+
BeforeViews.class, //
117117
RoboGuice.class, //
118118
ViewById.class, //
119119
Click.class, //

‎AndroidAnnotations/src/main/java/com/googlecode/androidannotations/annotations/BeforeCreate.java‎

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2010-2011 Pierre-Yves Ricau (py.ricau at gmail.com)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package com.googlecode.androidannotations.annotations;
17+
18+
import java.lang.annotation.ElementType;
19+
import java.lang.annotation.Retention;
20+
import java.lang.annotation.RetentionPolicy;
21+
import java.lang.annotation.Target;
22+
23+
import android.app.Activity;
24+
import android.os.Bundle;
25+
26+
import com.googlecode.androidannotations.annotations.res.StringRes;
27+
28+
/**
29+
* Methods annotated with @{@link BeforeViews} will be called before
30+
* {@link Activity#setContentView(int)} is called by the generated activity.
31+
*
32+
* When the onCreate() method of your activity is called,
33+
* {@link Activity#setContentView(int)} has already been called, the views have
34+
* been injected and the listeners are bound. Sometimes, you might want to
35+
* execute code before {@link Activity#setContentView(int)} is called. For
36+
* instance, if you need to call {@link Activity#requestWindowFeature(int)}.
37+
*
38+
* When methods annotated with @{@link BeforeViews} are called,
39+
* {@link SystemService}s, Resources (e.g. {@link StringRes}) and {@link Extra}s
40+
* are already injected. However views are not injected yet, so beware of
41+
* {@link NullPointerException}s.
42+
*
43+
* The method may have zero or one parameter, that must be a {@link Bundle}.
44+
*
45+
* There may be several methods annotated with @{@link BeforeViews} in the same
46+
* activity.
47+
*
48+
*/
49+
@Retention(RetentionPolicy.SOURCE)
50+
@Target(ElementType.METHOD)
51+
public @interface BeforeViews {
52+
}

‎AndroidAnnotations/src/main/java/com/googlecode/androidannotations/processing/BeforeCreateProcessor.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
import javax.lang.model.element.ExecutableElement;
2323
import javax.lang.model.element.VariableElement;
2424

25-
import com.googlecode.androidannotations.annotations.BeforeCreate;
25+
import com.googlecode.androidannotations.annotations.BeforeViews;
2626
import com.sun.codemodel.JCodeModel;
2727
import com.sun.codemodel.JInvocation;
2828

2929
public class BeforeCreateProcessor implements ElementProcessor {
3030

3131
@Override
3232
public Class<? extends Annotation> getTarget() {
33-
return BeforeCreate.class;
33+
return BeforeViews.class;
3434
}
3535

3636
@Override

‎AndroidAnnotations/src/main/java/com/googlecode/androidannotations/validation/BeforeCreateValidator.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import javax.lang.model.element.Element;
2222
import javax.lang.model.element.ExecutableElement;
2323

24-
import com.googlecode.androidannotations.annotations.BeforeCreate;
24+
import com.googlecode.androidannotations.annotations.BeforeViews;
2525
import com.googlecode.androidannotations.helper.TargetAnnotationHelper;
2626
import com.googlecode.androidannotations.helper.ValidatorHelper;
2727
import com.googlecode.androidannotations.model.AnnotationElements;
@@ -37,7 +37,7 @@ public BeforeCreateValidator(ProcessingEnvironment processingEnv) {
3737

3838
@Override
3939
public Class<? extends Annotation> getTarget() {
40-
return BeforeCreate.class;
40+
return BeforeViews.class;
4141
}
4242

4343
@Override

‎HelloWorldEclipse/src/com/googlecode/androidannotations/helloworldeclipse/MyActivity.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import android.widget.TextView;
1919

2020
import com.googlecode.androidannotations.annotations.Background;
21-
import com.googlecode.androidannotations.annotations.BeforeCreate;
21+
import com.googlecode.androidannotations.annotations.BeforeViews;
2222
import com.googlecode.androidannotations.annotations.Click;
2323
import com.googlecode.androidannotations.annotations.EActivity;
2424
import com.googlecode.androidannotations.annotations.LongClick;
@@ -56,13 +56,13 @@ public class MyActivity extends Activity {
5656
@SystemService
5757
WindowManager windowManager;
5858

59-
@BeforeCreate
59+
@BeforeViews
6060
void doStuffWithDisplay() {
6161
// windowManager should not be null
6262
windowManager.getDefaultDisplay();
6363
}
6464

65-
@BeforeCreate
65+
@BeforeViews
6666
void requestIndeterminateProgress() {
6767
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
6868
}

‎HelloWorldEclipse/src/com/googlecode/androidannotations/helloworldeclipse/MyListActivity.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import android.widget.ListAdapter;
77
import android.widget.Toast;
88

9-
import com.googlecode.androidannotations.annotations.BeforeCreate;
9+
import com.googlecode.androidannotations.annotations.BeforeViews;
1010
import com.googlecode.androidannotations.annotations.EActivity;
1111
import com.googlecode.androidannotations.annotations.ItemClick;
1212
import com.googlecode.androidannotations.annotations.ItemLongClick;
@@ -22,7 +22,7 @@ public class MyListActivity extends ListActivity {
2222

2323
private ListAdapter adapter;
2424

25-
@BeforeCreate
25+
@BeforeViews
2626
void initListActivity(Bundle savedInstanceState) {
2727
// Ensure that ListActivity sets its content view before AndroidAnnotation injection
2828
getListView();

0 commit comments

Comments
 (0)