Permalink
Browse files

Merge branch 'hotfix/2.7'

  • Loading branch information...
2 parents 4c15998 + 42d8585 commit c05c8b7d44f34b389224f60ef721414ab41b34cb @mathieuboniface mathieuboniface committed Feb 25, 2013
@@ -5,7 +5,7 @@
<parent>
<artifactId>androidannotations-parent</artifactId>
<groupId>com.googlecode.androidannotations</groupId>
- <version>3.0-SNAPSHOT</version>
+ <version>2.7.1-SNAPSHOT</version>
</parent>
<artifactId>androidannotations-api</artifactId>
@@ -5,7 +5,7 @@
<parent>
<artifactId>androidannotations-parent</artifactId>
<groupId>com.googlecode.androidannotations</groupId>
- <version>3.0-SNAPSHOT</version>
+ <version>2.7.1-SNAPSHOT</version>
</parent>
<artifactId>androidannotations-bundle</artifactId>
@@ -5,7 +5,7 @@
<parent>
<artifactId>androidannotations-parent</artifactId>
<groupId>com.googlecode.androidannotations</groupId>
- <version>3.0-SNAPSHOT</version>
+ <version>2.7.1-SNAPSHOT</version>
</parent>
<artifactId>androidannotations-with-codemodel</artifactId>
@@ -5,7 +5,7 @@
<parent>
<groupId>com.googlecode.androidannotations</groupId>
<artifactId>androidannotations-parent</artifactId>
- <version>3.0-SNAPSHOT</version>
+ <version>2.7.1-SNAPSHOT</version>
</parent>
<artifactId>androidannotations</artifactId>
@@ -22,7 +22,6 @@
import com.googlecode.androidannotations.annotations.EViewGroup;
import com.googlecode.androidannotations.processing.EBeansHolder.Classes;
import com.sun.codemodel.JBlock;
-import com.sun.codemodel.JCase;
import com.sun.codemodel.JClass;
import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JDefinedClass;
@@ -91,7 +90,7 @@
/**
* OnActivityResult byResultCode
*/
- public final HashMap<Integer, JCase> onActivityResultCases = new HashMap<Integer, JCase>();
+ public final HashMap<Integer, JBlock> onActivityResultCases = new HashMap<Integer, JBlock>();
public JSwitch onActivityResultSwitch;
public JMethod onActivityResultMethod;
@@ -128,12 +128,26 @@ public void process(Element element, JCodeModel codeModel, EBeansHolder eBeansHo
.assign(contentView, inflater.invoke("inflate").arg(contentViewId).arg(container).arg(FALSE));
}
- body.invoke(holder.afterSetContentView);
-
body._return(contentView);
}
{
+ // onViewCreated
+
+ JMethod onViewCreated = holder.generatedClass.method(PUBLIC, codeModel.VOID, "onViewCreated");
+ onViewCreated.annotate(Override.class);
+ JVar view = onViewCreated.param(classes.VIEW, "view");
+ JVar savedInstanceState = onViewCreated.param(classes.BUNDLE, "savedInstanceState");
+
+ JBlock onViewCreatedBody = onViewCreated.body();
+
+ onViewCreatedBody.invoke(_super(), onViewCreated).arg(view).arg(savedInstanceState);
+
+ onViewCreatedBody.invoke(holder.afterSetContentView);
+ }
+
+
+ {
// findViewById
JMethod findViewById = holder.generatedClass.method(PUBLIC, classes.VIEW, "findViewById");
@@ -29,6 +29,7 @@
import com.googlecode.androidannotations.helper.APTCodeModelHelper;
import com.googlecode.androidannotations.helper.CanonicalNameConstants;
import com.googlecode.androidannotations.rclass.IRClass;
+
import com.sun.codemodel.JBlock;
import com.sun.codemodel.JCase;
import com.sun.codemodel.JClass;
@@ -83,10 +84,10 @@ public void process(Element element, JCodeModel codeModel, EBeanHolder holder) {
int requestCode = executableElement.getAnnotation(OnActivityResult.class).value();
- JCase onActivityResultCase = getOrCreateOnActivityResultMethodBody(codeModel, holder, requestCode);
+ JBlock onActivityResultCase = getOrCreateOnActivityResultMethodBody(codeModel, holder, requestCode);
JExpression activityRef = holder.generatedClass.staticRef("this");
- JInvocation onResultInvocation = onActivityResultCase.body().invoke(activityRef, methodName);
+ JInvocation onResultInvocation = onActivityResultCase.invoke(activityRef, methodName);
for (int i = 0; i < parameters.size(); i++) {
if (i == intentParameterPosition) {
@@ -100,7 +101,7 @@ public void process(Element element, JCodeModel codeModel, EBeanHolder holder) {
}
- public JCase getOrCreateOnActivityResultMethodBody(JCodeModel codeModel, EBeanHolder holder, int requestCode) {
+ public JBlock getOrCreateOnActivityResultMethodBody(JCodeModel codeModel, EBeanHolder holder, int requestCode) {
JClass intentClass = holder.classes().INTENT;
if (holder.onActivityResultSwitch == null) {
@@ -120,16 +121,20 @@ public JCase getOrCreateOnActivityResultMethodBody(JCodeModel codeModel, EBeanHo
JSwitch onActivityResultSwitch = holder.onActivityResultSwitch;
- JCase onActivityResultCase = holder.onActivityResultCases.get(requestCode);
+ JBlock onActivityResultCaseBlock = holder.onActivityResultCases.get(requestCode);
+
+ if (onActivityResultCaseBlock == null) {
+
+ JCase onActivityResultCase = onActivityResultSwitch._case(JExpr.lit(requestCode));
- if (onActivityResultCase == null) {
+ onActivityResultCaseBlock = onActivityResultCase.body().block();
- onActivityResultCase = onActivityResultSwitch._case(JExpr.lit(requestCode));
+ onActivityResultCase.body()._break();
- holder.onActivityResultCases.put(requestCode, onActivityResultCase);
+ holder.onActivityResultCases.put(requestCode, onActivityResultCaseBlock);
}
- return onActivityResultCase;
+ return onActivityResultCaseBlock;
}
}
@@ -5,7 +5,7 @@
<parent>
<artifactId>androidannotations-parent</artifactId>
<groupId>com.googlecode.androidannotations</groupId>
- <version>3.0-SNAPSHOT</version>
+ <version>2.7.1-SNAPSHOT</version>
</parent>
<artifactId>functional-test-1-5-tests</artifactId>
@@ -0,0 +1,70 @@
+/**
+ * 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 com.googlecode.androidannotations.test15;
+
+import static org.fest.assertions.Assertions.assertThat;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith(AndroidAnnotationsTestRunner.class)
+public class AwaitingResultActivityTest {
+
+ @Test
+ public void onlyFirstRequestAnnotatedMethodAreCalled() {
+ AwaitingResultActivity_ activity = new AwaitingResultActivity_();
+
+ activity.onActivityResult(AwaitingResultActivity.FIRST_REQUEST, 0, null);
+
+ assertThat(activity.onResultCalled).isTrue();
+ assertThat(activity.onResultWithDataCalled).isFalse();
+ assertThat(activity.onActivityResultWithResultCodeAndDataCalled).isFalse();
+ assertThat(activity.onActivityResultWithDataAndResultCodeCalled).isFalse();
+ assertThat(activity.onResultWithIntResultCodeCalled).isFalse();
+ assertThat(activity.onResultWithIntegerResultCodeCalled).isFalse();
+ }
+
+
+ @Test
+ public void onlySecondRequestAnnotatedMethodAreCalled() {
+ AwaitingResultActivity_ activity = new AwaitingResultActivity_();
+
+ activity.onActivityResult(AwaitingResultActivity.SECOND_REQUEST, 0, null);
+
+ assertThat(activity.onResultCalled).isFalse();
+ assertThat(activity.onResultWithDataCalled).isTrue();
+ assertThat(activity.onActivityResultWithResultCodeAndDataCalled).isTrue();
+ assertThat(activity.onActivityResultWithDataAndResultCodeCalled).isTrue();
+ assertThat(activity.onResultWithIntResultCodeCalled).isFalse();
+ assertThat(activity.onResultWithIntegerResultCodeCalled).isFalse();
+ }
+
+
+ @Test
+ public void onlyThirdRequestAnnotatedMethodAreCalled() {
+ AwaitingResultActivity_ activity = new AwaitingResultActivity_();
+
+ activity.onActivityResult(AwaitingResultActivity.THIRD_REQUEST, 0, null);
+
+ assertThat(activity.onResultCalled).isFalse();
+ assertThat(activity.onResultWithDataCalled).isFalse();
+ assertThat(activity.onActivityResultWithResultCodeAndDataCalled).isFalse();
+ assertThat(activity.onActivityResultWithDataAndResultCodeCalled).isFalse();
+ assertThat(activity.onResultWithIntResultCodeCalled).isTrue();
+ assertThat(activity.onResultWithIntegerResultCodeCalled).isTrue();
+ }
+
+}
@@ -5,7 +5,7 @@
<parent>
<artifactId>androidannotations-parent</artifactId>
<groupId>com.googlecode.androidannotations</groupId>
- <version>3.0-SNAPSHOT</version>
+ <version>2.7.1-SNAPSHOT</version>
</parent>
<artifactId>functional-test-1-5</artifactId>
@@ -24,32 +24,45 @@
@EActivity(R.layout.views_injected)
public class AwaitingResultActivity extends Activity {
- private static final int FIRST_REQUEST = 11;
- private static final int SECOND_REQUEST = 22;
- private static final int THIRD_REQUEST = 33;
+ static final int FIRST_REQUEST = 11;
+ static final int SECOND_REQUEST = 22;
+ static final int THIRD_REQUEST = 33;
+
+ boolean onResultCalled = false;
+ boolean onResultWithDataCalled = false;
+ boolean onActivityResultWithResultCodeAndDataCalled = false;
+ boolean onActivityResultWithDataAndResultCodeCalled = false;
+ boolean onResultWithIntResultCodeCalled = false;
+ boolean onResultWithIntegerResultCodeCalled = false;
@OnActivityResult(FIRST_REQUEST)
void onResult() {
+ onResultCalled = true;
}
@OnActivityResult(SECOND_REQUEST)
void onResultWithData(Intent intentData) {
+ onResultWithDataCalled = true;
}
@OnActivityResult(SECOND_REQUEST)
void onActivityResultWithResultCodeAndData(int result, Intent intentData) {
+ onActivityResultWithResultCodeAndDataCalled = true;
}
@OnActivityResult(SECOND_REQUEST)
void onActivityResultWithDataAndResultCode(Intent intentData, int result) {
+ onActivityResultWithDataAndResultCodeCalled = true;
}
@OnActivityResult(THIRD_REQUEST)
void onResultWithIntResultCode(int resultCode) {
+ onResultWithIntResultCodeCalled = true;
}
@OnActivityResult(THIRD_REQUEST)
void onResultWithIntegerResultCode(Integer resultCodeInteger) {
+ onResultWithIntegerResultCodeCalled = true;
}
}
@@ -10,7 +10,7 @@
<groupId>com.googlecode.androidannotations</groupId>
<artifactId>androidannotations-parent</artifactId>
- <version>3.0-SNAPSHOT</version>
+ <version>2.7.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>AndroidAnnotations Parent</name>

0 comments on commit c05c8b7

Please sign in to comment.