Skip to content

Commit cc78b4d

Browse files
committed
Handle new annotation WindowFeature. See issue androidannotations#614
1 parent 11b3e7c commit cc78b4d

4 files changed

Lines changed: 132 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Copyright (C) 2010-2013 eBusiness Information, Excilys Group
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 org.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+
/**
24+
* Should be used on Activity classes that must have no title.
25+
*
26+
* The activity must be annotated with {@link EActivity}.
27+
*
28+
*/
29+
@Retention(RetentionPolicy.CLASS)
30+
@Target(ElementType.TYPE)
31+
public @interface WindowFeature {
32+
33+
int[] value();
34+
35+
}

‎AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/AndroidAnnotationProcessor.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
import org.androidannotations.annotations.Transactional;
9090
import org.androidannotations.annotations.UiThread;
9191
import org.androidannotations.annotations.ViewById;
92+
import org.androidannotations.annotations.WindowFeature;
9293
import org.androidannotations.annotations.res.AnimationRes;
9394
import org.androidannotations.annotations.res.BooleanRes;
9495
import org.androidannotations.annotations.res.ColorRes;
@@ -187,6 +188,7 @@
187188
import org.androidannotations.processing.TransactionalProcessor;
188189
import org.androidannotations.processing.UiThreadProcessor;
189190
import org.androidannotations.processing.ViewByIdProcessor;
191+
import org.androidannotations.processing.WindowFeatureProcessor;
190192
import org.androidannotations.processing.rest.DeleteProcessor;
191193
import org.androidannotations.processing.rest.GetProcessor;
192194
import org.androidannotations.processing.rest.HeadProcessor;
@@ -257,6 +259,7 @@
257259
import org.androidannotations.validation.TraceValidator;
258260
import org.androidannotations.validation.TransactionalValidator;
259261
import org.androidannotations.validation.ViewByIdValidator;
262+
import org.androidannotations.validation.WindowFeatureValidator;
260263
import org.androidannotations.validation.rest.AcceptValidator;
261264
import org.androidannotations.validation.rest.DeleteValidator;
262265
import org.androidannotations.validation.rest.GetValidator;
@@ -426,6 +429,7 @@ private ModelValidator buildModelValidator(IRClass rClass, AndroidSystemServices
426429
modelValidator.register(new OptionsMenuItemValidator(processingEnv, rClass));
427430
modelValidator.register(new OptionsItemValidator(processingEnv, rClass));
428431
modelValidator.register(new NoTitleValidator(processingEnv));
432+
modelValidator.register(new WindowFeatureValidator(processingEnv));
429433
modelValidator.register(new CustomTitleValidator(processingEnv, rClass));
430434
modelValidator.register(new FullscreenValidator(processingEnv));
431435
modelValidator.register(new RestServiceValidator(processingEnv));
@@ -522,6 +526,7 @@ private ModelProcessor buildModelProcessor(IRClass rClass, AndroidSystemServices
522526
modelProcessor.register(new OptionsMenuItemProcessor(processingEnv, rClass));
523527
modelProcessor.register(new OptionsItemProcessor(processingEnv, rClass));
524528
modelProcessor.register(new NoTitleProcessor());
529+
modelProcessor.register(new WindowFeatureProcessor());
525530
modelProcessor.register(new CustomTitleProcessor(processingEnv, rClass));
526531
modelProcessor.register(new FullscreenProcessor());
527532
modelProcessor.register(new RestServiceProcessor());
@@ -642,6 +647,7 @@ public Set<String> getSupportedAnnotationTypes() {
642647
OptionsItem.class, //
643648
HtmlRes.class, //
644649
NoTitle.class, //
650+
WindowFeature.class, //
645651
CustomTitle.class, //
646652
Fullscreen.class, //
647653
RestService.class, //
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Copyright (C) 2010-2013 eBusiness Information, Excilys Group
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 org.androidannotations.processing;
17+
18+
import javax.lang.model.element.Element;
19+
20+
import org.androidannotations.annotations.WindowFeature;
21+
22+
import com.sun.codemodel.JCodeModel;
23+
import com.sun.codemodel.JExpr;
24+
25+
public class WindowFeatureProcessor implements DecoratingElementProcessor {
26+
27+
@Override
28+
public String getTarget() {
29+
return WindowFeature.class.getName();
30+
}
31+
32+
@Override
33+
public void process(Element element, JCodeModel codeModel, EBeanHolder holder) {
34+
WindowFeature annotation = element.getAnnotation(WindowFeature.class);
35+
int[] features = annotation.value();
36+
37+
for (int feature : features) {
38+
holder.initBody.invoke("requestWindowFeature").arg(JExpr.lit(feature));
39+
}
40+
}
41+
42+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
* Copyright (C) 2010-2013 eBusiness Information, Excilys Group
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 org.androidannotations.validation;
17+
18+
import javax.annotation.processing.ProcessingEnvironment;
19+
import javax.lang.model.element.Element;
20+
21+
import org.androidannotations.annotations.WindowFeature;
22+
import org.androidannotations.helper.TargetAnnotationHelper;
23+
import org.androidannotations.helper.ValidatorHelper;
24+
import org.androidannotations.model.AnnotationElements;
25+
26+
public class WindowFeatureValidator implements ElementValidator {
27+
28+
private ValidatorHelper validatorHelper;
29+
30+
public WindowFeatureValidator(ProcessingEnvironment processingEnv) {
31+
TargetAnnotationHelper annotationHelper = new TargetAnnotationHelper(processingEnv, getTarget());
32+
validatorHelper = new ValidatorHelper(annotationHelper);
33+
}
34+
35+
@Override
36+
public String getTarget() {
37+
return WindowFeature.class.getName();
38+
}
39+
40+
@Override
41+
public boolean validate(Element element, AnnotationElements validatedElements) {
42+
IsValid valid = new IsValid();
43+
44+
validatorHelper.hasEActivity(element, validatedElements, valid);
45+
46+
return valid.isValid();
47+
}
48+
49+
}

0 commit comments

Comments
 (0)