Skip to content

Commit

Permalink
Back is now handled only if onBackPressed() exists, not taking into a…
Browse files Browse the repository at this point in the history
…ccount the Activity method. androidannotations#244
  • Loading branch information
pyricau committed Jun 28, 2012
1 parent ca76d5c commit 3c08aad
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import com.googlecode.androidannotations.annotations.EActivity;
import com.googlecode.androidannotations.api.SdkVersionHelper;
import com.googlecode.androidannotations.helper.AnnotationHelper;
import com.googlecode.androidannotations.helper.CanonicalNameConstants;
import com.googlecode.androidannotations.helper.ModelConstants;
import com.googlecode.androidannotations.rclass.IRClass;
import com.googlecode.androidannotations.rclass.IRClass.Res;
Expand Down Expand Up @@ -302,7 +303,7 @@ private boolean isOnCreateMethod(ExecutableElement method) {
List<? extends VariableElement> parameters = method.getParameters();
return method.getSimpleName().toString().equals("onCreate") //
&& parameters.size() == 1 //
&& parameters.get(0).asType().toString().equals("android.os.Bundle") //
&& parameters.get(0).asType().toString().equals(CanonicalNameConstants.BUNDLE) //
;
}

Expand All @@ -313,15 +314,18 @@ private boolean hasOnBackPressedMethod(TypeElement activityElement) {
List<ExecutableElement> activityInheritedMethods = ElementFilter.methodsIn(allMembers);

for (ExecutableElement activityInheritedMethod : activityInheritedMethods) {
if (isOnBackPressedMethod(activityInheritedMethod)) {
if (isCustomOnBackPressedMethod(activityInheritedMethod)) {
return true;
}
}
return false;
}

private boolean isOnBackPressedMethod(ExecutableElement method) {
return method.getSimpleName().toString().equals("onBackPressed") //
private boolean isCustomOnBackPressedMethod(ExecutableElement method) {
TypeElement methodClass = (TypeElement) method.getEnclosingElement();
boolean methodBelongsToActivityClass = methodClass.getQualifiedName().toString().equals(CanonicalNameConstants.ACTIVITY);
return !methodBelongsToActivityClass //
&& method.getSimpleName().toString().equals("onBackPressed") //
&& method.getThrownTypes().size() == 0 //
&& method.getModifiers().contains(Modifier.PUBLIC) //
&& method.getReturnType().getKind().equals(TypeKind.VOID) //
Expand Down

0 comments on commit 3c08aad

Please sign in to comment.