diff --git a/AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/annotations/CustomTitle.java b/AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/annotations/CustomTitle.java new file mode 100644 index 0000000000..6b436ced50 --- /dev/null +++ b/AndroidAnnotations/androidannotations-api/src/main/java/org/androidannotations/annotations/CustomTitle.java @@ -0,0 +1,34 @@ +/** + * Copyright (C) 2010-2012 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.annotations; + + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Use it on activities to set a custom title layout. + * + * The activity must be annotated with {@link EActivity}. + * + */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.TYPE) +public @interface CustomTitle { + int value(); +} diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/AndroidAnnotationProcessor.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/AndroidAnnotationProcessor.java index 8019d074f3..cc0342435e 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/AndroidAnnotationProcessor.java +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/AndroidAnnotationProcessor.java @@ -62,6 +62,7 @@ import org.androidannotations.annotations.ItemSelect; import org.androidannotations.annotations.LongClick; import org.androidannotations.annotations.NoTitle; +import org.androidannotations.annotations.CustomTitle; import org.androidannotations.annotations.NonConfigurationInstance; import org.androidannotations.annotations.OnActivityResult; import org.androidannotations.annotations.OptionsItem; @@ -148,6 +149,7 @@ import org.androidannotations.processing.ModelProcessor; import org.androidannotations.processing.ModelProcessor.ProcessResult; import org.androidannotations.processing.NoTitleProcessor; +import org.androidannotations.processing.CustomTitleProcessor; import org.androidannotations.processing.NonConfigurationInstanceProcessor; import org.androidannotations.processing.OnActivityResultProcessor; import org.androidannotations.processing.OptionsItemProcessor; @@ -211,6 +213,7 @@ import org.androidannotations.validation.LongClickValidator; import org.androidannotations.validation.ModelValidator; import org.androidannotations.validation.NoTitleValidator; +import org.androidannotations.validation.CustomTitleValidator; import org.androidannotations.validation.NonConfigurationInstanceValidator; import org.androidannotations.validation.OnActivityResultValidator; import org.androidannotations.validation.OptionsItemValidator; @@ -290,6 +293,7 @@ OptionsItem.class, // HtmlRes.class, // NoTitle.class, // + CustomTitle.class, // Fullscreen.class, // RestService.class, // EBean.class, // @@ -462,6 +466,7 @@ private ModelValidator buildModelValidator(IRClass rClass, AndroidSystemServices modelValidator.register(new OptionsMenuValidator(processingEnv, rClass)); modelValidator.register(new OptionsItemValidator(processingEnv, rClass)); modelValidator.register(new NoTitleValidator(processingEnv)); + modelValidator.register(new CustomTitleValidator(processingEnv, rClass)); modelValidator.register(new FullscreenValidator(processingEnv)); modelValidator.register(new RestServiceValidator(processingEnv)); modelValidator.register(new RootContextValidator(processingEnv)); @@ -550,6 +555,7 @@ private ModelProcessor buildModelProcessor(IRClass rClass, AndroidSystemServices modelProcessor.register(new OptionsMenuProcessor(processingEnv, rClass)); modelProcessor.register(new OptionsItemProcessor(processingEnv, rClass)); modelProcessor.register(new NoTitleProcessor()); + modelProcessor.register(new CustomTitleProcessor(processingEnv, rClass)); modelProcessor.register(new FullscreenProcessor()); modelProcessor.register(new RestServiceProcessor()); modelProcessor.register(new OrmLiteDaoProcessor(processingEnv)); diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/CustomTitleProcessor.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/CustomTitleProcessor.java new file mode 100644 index 0000000000..88d621a363 --- /dev/null +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/CustomTitleProcessor.java @@ -0,0 +1,51 @@ +/** + * Copyright (C) 2010-2012 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.processing; + +import org.androidannotations.annotations.CustomTitle; +import com.sun.codemodel.JCodeModel; +import com.sun.codemodel.JFieldRef; +import org.androidannotations.helper.AnnotationHelper; +import org.androidannotations.rclass.IRClass; +import org.androidannotations.rclass.IRClass.Res; + +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.Element; +import java.lang.annotation.Annotation; + +public class CustomTitleProcessor implements DecoratingElementProcessor { + private final AnnotationHelper annotationHelper; + private final IRClass rClass; + + public CustomTitleProcessor(ProcessingEnvironment processingEnv, IRClass rClass) { + annotationHelper = new AnnotationHelper(processingEnv); + this.rClass = rClass; + } + + @Override + public Class getTarget() { + return CustomTitle.class; + } + + @Override + public void process(Element element, JCodeModel codeModel, EBeanHolder holder) { + JFieldRef customTitleFeature = holder.classes().WINDOW.staticRef("FEATURE_CUSTOM_TITLE"); + + holder.init.body().invoke("requestWindowFeature").arg(customTitleFeature); + JFieldRef contentViewId = annotationHelper.extractAnnotationFieldRefs(holder, element, CustomTitle.class, rClass.get(Res.LAYOUT), false).get(0); + holder.afterSetContentView.body().add(holder.contextRef.invoke("getWindow").invoke("setFeatureInt").arg(customTitleFeature).arg(contentViewId)); + } +} \ No newline at end of file diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/validation/CustomTitleValidator.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/validation/CustomTitleValidator.java new file mode 100644 index 0000000000..bda05c191c --- /dev/null +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/validation/CustomTitleValidator.java @@ -0,0 +1,52 @@ +/** + * Copyright (C) 2010-2012 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.validation; + +import org.androidannotations.annotations.CustomTitle; +import org.androidannotations.helper.IdAnnotationHelper; +import org.androidannotations.helper.IdValidatorHelper; +import org.androidannotations.model.AnnotationElements; +import org.androidannotations.rclass.IRClass; + +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.Element; +import java.lang.annotation.Annotation; + +public class CustomTitleValidator implements ElementValidator { + + private IdValidatorHelper validatorHelper; + + public CustomTitleValidator(ProcessingEnvironment processingEnv, IRClass rClass) { + IdAnnotationHelper annotationHelper = new IdAnnotationHelper(processingEnv, getTarget(), rClass); + validatorHelper = new IdValidatorHelper(annotationHelper); + } + + @Override + public Class getTarget() { + return CustomTitle.class; + } + + @Override + public boolean validate(Element element, AnnotationElements validatedElements) { + IsValid valid = new IsValid(); + + validatorHelper.hasEActivity(element, validatedElements, valid); + + validatorHelper.resIdsExist(element, IRClass.Res.LAYOUT, IdValidatorHelper.FallbackStrategy.NEED_RES_ID, valid); + + return valid.isValid(); + } +} diff --git a/AndroidAnnotations/functional-test-1-5/src/main/java/org/androidannotations/test15/CustomTitleActivity.java b/AndroidAnnotations/functional-test-1-5/src/main/java/org/androidannotations/test15/CustomTitleActivity.java new file mode 100644 index 0000000000..6abca565a7 --- /dev/null +++ b/AndroidAnnotations/functional-test-1-5/src/main/java/org/androidannotations/test15/CustomTitleActivity.java @@ -0,0 +1,26 @@ +/** + * Copyright (C) 2010-2012 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.test15; + +import android.app.Activity; + +import org.androidannotations.annotations.EActivity; +import org.androidannotations.annotations.CustomTitle; + +@EActivity +@CustomTitle(R.layout.component) +public class CustomTitleActivity extends Activity { +}