From 189b9d98363d89b21b0ad7b7ec8e43b882a7bfa2 Mon Sep 17 00:00:00 2001 From: Michael Greifeneder Date: Mon, 10 Dec 2012 13:11:52 +0100 Subject: [PATCH] Integration with HoloEverywhere --- .../helper/CanonicalNameConstants.java | 5 ++ .../helper/HoloEverywhereHelper.java | 53 +++++++++++++++++++ .../helper/SherlockHelper.java | 6 ++- .../processing/EBeansHolder.java | 5 ++ .../processing/EFragmentProcessor.java | 15 +++++- 5 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/HoloEverywhereHelper.java diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/CanonicalNameConstants.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/CanonicalNameConstants.java index df038444fb..d9add30141 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/CanonicalNameConstants.java +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/CanonicalNameConstants.java @@ -90,6 +90,11 @@ public final class CanonicalNameConstants { public static final String SHERLOCK_MENU_ITEM = "com.actionbarsherlock.view.MenuItem"; public static final String SHERLOCK_MENU_INFLATER = "com.actionbarsherlock.view.MenuInflater"; + /* + * HoloEverywhere + */ + public static final String HOLO_EVERYWHERE_LAYOUT_INFLATER = "org.holoeverywhere.LayoutInflater"; + /* * SpringFramework */ diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/HoloEverywhereHelper.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/HoloEverywhereHelper.java new file mode 100644 index 0000000000..073a24af56 --- /dev/null +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/HoloEverywhereHelper.java @@ -0,0 +1,53 @@ +/** + * 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.helper; + +import javax.lang.model.element.TypeElement; +import javax.lang.model.type.DeclaredType; +import javax.lang.model.type.NoType; +import javax.lang.model.type.TypeMirror; + +import org.androidannotations.processing.EBeanHolder; + +/** + * @author Eric Kok + */ +public class HoloEverywhereHelper { + + private final AnnotationHelper annotationHelper; + + public HoloEverywhereHelper(AnnotationHelper annotationHelper) { + this.annotationHelper = annotationHelper; + } + + /** + * Checks whether the Activity extends one of the ActionBarSherlock Activity + * types + */ + public boolean usesHoloEverywhere(EBeanHolder holder) { + TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(holder.generatedClass._extends().fullName()); + + TypeMirror superType; + while (!((superType = typeElement.getSuperclass()) instanceof NoType)) { + typeElement = (TypeElement) ((DeclaredType) superType).asElement(); + String qName = typeElement.getQualifiedName().toString(); + if (qName.startsWith("org.holoeverywhere")) { + return true; + } + } + return false; + } +} diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/SherlockHelper.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/SherlockHelper.java index 01e153fe85..3abeec14a7 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/SherlockHelper.java +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/helper/SherlockHelper.java @@ -43,7 +43,11 @@ public boolean usesSherlock(EBeanHolder holder) { TypeMirror superType; while (!((superType = typeElement.getSuperclass()) instanceof NoType)) { typeElement = (TypeElement) ((DeclaredType) superType).asElement(); - if (typeElement.getQualifiedName().toString().startsWith("com.actionbarsherlock.app")) { + String qName = typeElement.getQualifiedName().toString(); + if (qName.startsWith("com.actionbarsherlock.app")) { + return true; + } + if (qName.startsWith("org.holoeverywhere")) { return true; } } diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/EBeansHolder.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/EBeansHolder.java index 090d001e82..7b58d2073d 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/EBeansHolder.java +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/EBeansHolder.java @@ -99,6 +99,11 @@ public class Classes { public final JClass SHERLOCK_MENU_ITEM = refClass(CanonicalNameConstants.SHERLOCK_MENU_ITEM); public final JClass SHERLOCK_MENU_INFLATER = refClass(CanonicalNameConstants.SHERLOCK_MENU_INFLATER); + /* + * HoloEverywhre + */ + public final JClass HOLO_EVERYWHERE_LAYOUT_INFLATER = refClass(CanonicalNameConstants.HOLO_EVERYWHERE_LAYOUT_INFLATER); + /* * RoboGuice */ diff --git a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/EFragmentProcessor.java b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/EFragmentProcessor.java index 6eaf9f3b2d..f05295b6c3 100644 --- a/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/EFragmentProcessor.java +++ b/AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/processing/EFragmentProcessor.java @@ -15,7 +15,6 @@ */ package org.androidannotations.processing; -import static org.androidannotations.helper.ModelConstants.GENERATION_SUFFIX; import static com.sun.codemodel.JExpr.FALSE; import static com.sun.codemodel.JExpr._new; import static com.sun.codemodel.JExpr._null; @@ -25,6 +24,7 @@ import static com.sun.codemodel.JMod.PRIVATE; import static com.sun.codemodel.JMod.PUBLIC; import static com.sun.codemodel.JMod.STATIC; +import static org.androidannotations.helper.ModelConstants.GENERATION_SUFFIX; import java.lang.annotation.Annotation; @@ -33,10 +33,12 @@ import javax.lang.model.element.TypeElement; import org.androidannotations.annotations.EFragment; +import org.androidannotations.helper.HoloEverywhereHelper; import org.androidannotations.helper.IdAnnotationHelper; import org.androidannotations.processing.EBeansHolder.Classes; import org.androidannotations.rclass.IRClass; import org.androidannotations.rclass.IRClass.Res; + import com.sun.codemodel.ClassType; import com.sun.codemodel.JBlock; import com.sun.codemodel.JClass; @@ -51,9 +53,12 @@ public class EFragmentProcessor implements GeneratingElementProcessor { private final IdAnnotationHelper helper; + private HoloEverywhereHelper holoEverywhereHelper; public EFragmentProcessor(ProcessingEnvironment processingEnv, IRClass rClass) { helper = new IdAnnotationHelper(processingEnv, getTarget(), rClass); + holoEverywhereHelper = new HoloEverywhereHelper(helper); + } @Override @@ -113,7 +118,13 @@ public void process(Element element, JCodeModel codeModel, EBeansHolder eBeansHo // onCreateView() JMethod onCreateView = holder.generatedClass.method(PUBLIC, classes.VIEW, "onCreateView"); onCreateView.annotate(Override.class); - JVar inflater = onCreateView.param(classes.LAYOUT_INFLATER, "inflater"); + JClass inflaterClass = classes.LAYOUT_INFLATER; + + if (holoEverywhereHelper.usesHoloEverywhere(holder)) { + inflaterClass = classes.HOLO_EVERYWHERE_LAYOUT_INFLATER; + } + JVar inflater = onCreateView.param(inflaterClass, "inflater"); + JVar container = onCreateView.param(classes.VIEW_GROUP, "container"); JVar savedInstanceState = onCreateView.param(classes.BUNDLE, "savedInstanceState");