Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public File toGeneratedFile(Class<?> compiledClass) {
return output;
}

public File toGeneratedFile(Class<?> classOfPackagingContainingFile, String compiledClassSimpleName) {
return new File(OUTPUT_DIRECTORY, toPath(classOfPackagingContainingFile.getPackage()) + "/" + compiledClassSimpleName + getAndroidAnnotationsClassSuffix() + SOURCE_FILE_SUFFIX);
}

public String toPath(Class<?> classOfPackagingContainingFile, String filename) {
return classOfPackagingContainingFile.getResource(filename).getPath();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ public final class CanonicalNameConstants {
public static final String PREFERENCE_CLICK_LISTENER = "android.preference.Preference.OnPreferenceClickListener";
public static final String PREFERENCE_ACTIVITY_HEADER = "android.preference.PreferenceActivity.Header";
public static final String APP_WIDGET_MANAGER = "android.appwidget.AppWidgetManager";
public static final String ACTIONBAR_ACTIVITY = "android.support.v7.app.ActionBarActivity";
public static final String APPCOMPAT_ACTIVITY = "android.support.v7.app.AppCompatActivity";

/*
* Android permission
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
package org.androidannotations.internal.core.handler;

import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;

import org.androidannotations.AndroidAnnotationsEnvironment;
import org.androidannotations.ElementValidation;
import org.androidannotations.annotations.WindowFeature;
import org.androidannotations.handler.BaseAnnotationHandler;
import org.androidannotations.helper.CanonicalNameConstants;
import org.androidannotations.holder.EActivityHolder;

import com.sun.codemodel.JExpr;
Expand All @@ -41,8 +43,18 @@ public void process(Element element, EActivityHolder holder) throws Exception {
WindowFeature annotation = element.getAnnotation(WindowFeature.class);
int[] features = annotation.value();

TypeElement appCompatActivity = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.APPCOMPAT_ACTIVITY);
TypeElement actionBarActivity = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.ACTIONBAR_ACTIVITY);
TypeElement type = (TypeElement) element;

String methodName;
if ((appCompatActivity != null && annotationHelper.isSubtype(type, appCompatActivity)) || (actionBarActivity != null && annotationHelper.isSubtype(type, actionBarActivity))) {
methodName = "supportRequestWindowFeature";
} else {
methodName = "requestWindowFeature";
}
for (int feature : features) {
holder.getInitBody().invoke("requestWindowFeature").arg(JExpr.lit(feature));
holder.getInitBody().invoke(methodName).arg(JExpr.lit(feature));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* 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.generation;

import java.io.File;

import org.androidannotations.internal.AndroidAnnotationProcessor;
import org.androidannotations.testutils.AAProcessorTestHelper;
import org.androidannotations.testutils.ProcessorTestHelper;
import org.junit.Before;
import org.junit.Test;

public class WindowFeatureAppCompatActivityTest extends AAProcessorTestHelper {

@Before
public void setUp() {
addProcessor(AndroidAnnotationProcessor.class);
}

@Test
public void activityWithWindowFeatureUsesSupportWhenExtendingAppCompat() throws ClassNotFoundException {
addManifestProcessorParameter(WindowFeatureAppCompatActivityTest.class, "AndroidManifest.xml");
ProcessorTestHelper.CompileResult result = compileFiles(toPath(WindowFeatureAppCompatActivityTest.class, "support/AppCompatActivity.java"), //
toPath(WindowFeatureAppCompatActivityTest.class, "WindowFeatureAppCompatActivity.java"));

File generatedFile = toGeneratedFile(WindowFeatureAppCompatActivityTest.class, "WindowFeatureAppCompatActivity");

assertCompilationSuccessful(result);
assertGeneratedClassMatches(generatedFile, " supportRequestWindowFeature\\(1\\);");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<application>
<activity android:name="org.androidannotations.generation.ActivityWithOnBackPressedMethod_" />
<activity android:name="org.androidannotations.generation.ActivityWithBackgroundMethod_" />
<activity android:name="org.androidannotations.generation.WindowFeatureAppCompatActivity_" />
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* 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.generation;

import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.WindowFeature;

import android.view.Window;

@EActivity
@WindowFeature(Window.FEATURE_NO_TITLE)
public class WindowFeatureAppCompatActivity extends android.support.v7.app.AppCompatActivity {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* 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 android.support.v7.app;

import android.app.Activity;

public class AppCompatActivity extends Activity {

public boolean supportRequestWindowFeature(int featureId) {
return false;
}

}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.