X Tutup
Skip to content
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 @@ -114,6 +114,10 @@ public class EBeanHolder {
public JMethod findNativeFragmentByTag;
public JMethod findSupportFragmentByTag;

public JBlock onCreateOptionMenuMethodBody;
public JVar onCreateOptionMenuMenuInflaterVariable;
public JVar onCreateOptionMenuMenuParam;

private final EBeansHolder eBeansHolder;
public final Class<? extends Annotation> eBeanAnnotation;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.androidannotations.processing;

import static com.sun.codemodel.JExpr.TRUE;
import static com.sun.codemodel.JExpr._super;
import static com.sun.codemodel.JExpr.invoke;
import static com.sun.codemodel.JMod.PUBLIC;

Expand All @@ -33,9 +31,11 @@
import org.androidannotations.processing.EBeansHolder.Classes;
import org.androidannotations.rclass.IRClass;
import org.androidannotations.rclass.IRClass.Res;

import com.sun.codemodel.JBlock;
import com.sun.codemodel.JClass;
import com.sun.codemodel.JCodeModel;
import com.sun.codemodel.JExpr;
import com.sun.codemodel.JFieldRef;
import com.sun.codemodel.JInvocation;
import com.sun.codemodel.JMethod;
Expand Down Expand Up @@ -86,33 +86,48 @@ public void process(Element element, JCodeModel codeModel, EBeanHolder holder) {
returnType = codeModel.BOOLEAN;
}

JMethod method = holder.generatedClass.method(PUBLIC, returnType, "onCreateOptionsMenu");
method.annotate(Override.class);
JVar menuParam = method.param(menuClass, "menu");
JBlock body = holder.onCreateOptionMenuMethodBody;
JVar menuInflater = holder.onCreateOptionMenuMenuInflaterVariable;
JVar menuParam = holder.onCreateOptionMenuMenuParam;

JBlock body = method.body();
if (body == null) {
JMethod method = holder.generatedClass.method(PUBLIC, returnType, "onCreateOptionsMenu");
method.annotate(Override.class);

JVar menuInflater;
if (isFragment) {
menuInflater = method.param(menuInflaterClass, "inflater");
} else {
menuInflater = body.decl(menuInflaterClass, "menuInflater", invoke(getMenuInflaterMethodName));
menuParam = method.param(menuClass, "menu");

JBlock methodBody = method.body();

if (isFragment) {
menuInflater = method.param(menuInflaterClass, "inflater");
} else {
menuInflater = methodBody.decl(menuInflaterClass, "menuInflater", invoke(getMenuInflaterMethodName));
}

body = methodBody.block();

JInvocation superCall = invoke(JExpr._super(), method);
superCall.arg(menuParam);

if (isFragment) {
superCall.arg(menuInflater);
methodBody.add(superCall);
} else {
methodBody._return(superCall);
}

if (isFragment) {
holder.init.body().invoke("setHasOptionsMenu").arg(JExpr.TRUE);
}

holder.onCreateOptionMenuMethodBody = body;
holder.onCreateOptionMenuMenuInflaterVariable = menuInflater;
holder.onCreateOptionMenuMenuParam = menuParam;
}

for (JFieldRef optionsMenuRefId : fieldRefs) {
body.invoke(menuInflater, "inflate").arg(optionsMenuRefId).arg(menuParam);
}

JInvocation superCall = invoke(_super(), method).arg(menuParam);
if (isFragment) {
superCall.arg(menuInflater);
body.add(superCall);
} else {
body._return(superCall);
}

if (isFragment) {
holder.init.body().invoke("setHasOptionsMenu").arg(TRUE);
}
}
}
1 change: 1 addition & 0 deletions AndroidAnnotations/functional-test-1-5/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
<activity android:name=".TextWatchedActivity_" />
<activity android:name=".ormlite.OrmLiteActivity_" />
<activity android:name="org.androidannotations.test15.menu.OptionsMenuActivity_" />
<activity android:name="org.androidannotations.test15.menu.OptionsMenuSubActivity_" />
<activity android:name="org.androidannotations.test15.NoTitleFullscreenActivity_" />
<activity android:name="org.androidannotations.test15.ExtendingActivity_" />
<activity android:name="org.androidannotations.test15.ebean.BeanInjectedActivity_" />
Expand Down
25 changes: 25 additions & 0 deletions AndroidAnnotations/functional-test-1-5/res/menu/my_menu3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--

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.

-->
<menu xmlns:android="http://schemas.android.com/apk/res/android" >

<item
android:id="@+id/menu_settings"
android:title="Settings"/>

</menu>
Original file line number Diff line number Diff line change
@@ -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.menu;

import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.OptionsMenu;
import org.androidannotations.test15.R;

@EActivity
@OptionsMenu(R.menu.my_menu3)
public class OptionsMenuSubActivity extends OptionsMenuActivity {

}
X Tutup