This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
@FocusChange and @CheckedChange #459
Closed
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9193f63
Extract base listener processor to use with View.setOn***Listener
naixx 381fb5b
Add @FocusChange
naixx 1196bc2
Move parameter checkers form ValidatorHelper to separate class.
naixx 85a5434
Add @CheckedChange #389
naixx 07468b2
Add headers, rename some methods
naixx b8bf822
Merge remote-tracking branch 'remotes/upstream/develop' into common_l…
naixx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...ndroidannotations-api/src/main/java/org/androidannotations/annotations/CheckedChange.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package org.androidannotations.annotations; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
|
|
||
| /** | ||
| * | ||
| * @author Rostislav Chekan | ||
| */ | ||
| @Retention(RetentionPolicy.CLASS) | ||
| @Target(ElementType.METHOD) | ||
| public @interface CheckedChange { | ||
| int[] value() default ResId.DEFAULT_VALUE; | ||
|
|
||
| String[] resName() default ""; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...idannotations/src/main/java/org/androidannotations/processing/CheckedChangeProcessor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| package org.androidannotations.processing; | ||
|
|
||
| import java.lang.annotation.Annotation; | ||
| import java.util.List; | ||
|
|
||
| import javax.annotation.processing.ProcessingEnvironment; | ||
| import javax.lang.model.element.VariableElement; | ||
| import javax.lang.model.type.TypeMirror; | ||
|
|
||
| import org.androidannotations.annotations.CheckedChange; | ||
| import org.androidannotations.rclass.IRClass; | ||
|
|
||
| import com.sun.codemodel.JBlock; | ||
| import com.sun.codemodel.JClass; | ||
| import com.sun.codemodel.JDefinedClass; | ||
| import com.sun.codemodel.JExpr; | ||
| import com.sun.codemodel.JExpression; | ||
| import com.sun.codemodel.JInvocation; | ||
| import com.sun.codemodel.JMethod; | ||
| import com.sun.codemodel.JMod; | ||
| import com.sun.codemodel.JVar; | ||
|
|
||
| /** | ||
| * | ||
| * @author Rostislav Chekan | ||
| * | ||
| */ | ||
| public class CheckedChangeProcessor extends AbstractListenerProcessor { | ||
|
|
||
| public CheckedChangeProcessor(ProcessingEnvironment processingEnv, IRClass rClass) { | ||
| super(processingEnv, rClass); | ||
| } | ||
|
|
||
| @Override | ||
| public Class<? extends Annotation> getTarget() { | ||
| return CheckedChange.class; | ||
| } | ||
|
|
||
| @Override | ||
| protected void makeCall(JBlock listenerMethodBody, JInvocation call, TypeMirror returnType) { | ||
| listenerMethodBody.add(call); | ||
| } | ||
|
|
||
| @Override | ||
| protected void processParameters(JMethod listenerMethod, JInvocation call, List<? extends VariableElement> parameters) { | ||
| JVar btnParam = listenerMethod.param(classes.COMPOUND_BUTTON, "buttonView"); | ||
| JVar isCheckedParam = listenerMethod.param(codeModel.BOOLEAN, "isChecked"); | ||
| boolean isCheckedParamExists = parameters.size() == 2; | ||
| boolean btnParamExists = parameters.size() >= 1; | ||
|
|
||
| if (btnParamExists) { | ||
| call.arg(btnParam); | ||
| } | ||
| if (isCheckedParamExists) { | ||
| call.arg(isCheckedParam); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected JMethod createListenerMethod(JDefinedClass listenerAnonymousClass) { | ||
| return listenerAnonymousClass.method(JMod.PUBLIC, codeModel.VOID, "onCheckedChanged"); | ||
| } | ||
|
|
||
| @Override | ||
| protected String getSetterName() { | ||
| return "setOnCheckedChangeListener"; | ||
| } | ||
|
|
||
| @Override | ||
| protected JClass getListenerClass() { | ||
| return holder.refClass("android.widget.CompoundButton.OnCheckedChangeListener"); | ||
| } | ||
|
|
||
| @Override | ||
| protected JExpression castWidget(JVar view) { | ||
| return JExpr.cast(classes.COMPOUND_BUTTON, view); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...idannotations/src/main/java/org/androidannotations/validation/CheckedChangeValidator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /** | ||
| * 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.validation; | ||
|
|
||
| import java.lang.annotation.Annotation; | ||
|
|
||
| import javax.annotation.processing.ProcessingEnvironment; | ||
| import javax.lang.model.element.Element; | ||
| import javax.lang.model.element.ExecutableElement; | ||
|
|
||
| import org.androidannotations.annotations.CheckedChange; | ||
| import org.androidannotations.helper.IdAnnotationHelper; | ||
| import org.androidannotations.helper.IdValidatorHelper; | ||
| import org.androidannotations.helper.IdValidatorHelper.FallbackStrategy; | ||
| import org.androidannotations.model.AnnotationElements; | ||
| import org.androidannotations.rclass.IRClass; | ||
| import org.androidannotations.rclass.IRClass.Res; | ||
|
|
||
| public class CheckedChangeValidator implements ElementValidator { | ||
|
|
||
| private IdValidatorHelper validatorHelper; | ||
|
|
||
| public CheckedChangeValidator(ProcessingEnvironment processingEnv, IRClass rClass) { | ||
| IdAnnotationHelper annotationHelper = new IdAnnotationHelper(processingEnv, getTarget(), rClass); | ||
| validatorHelper = new IdValidatorHelper(annotationHelper); | ||
| } | ||
|
|
||
| @Override | ||
| public Class<? extends Annotation> getTarget() { | ||
| return CheckedChange.class; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean validate(Element element, AnnotationElements validatedElements) { | ||
|
|
||
| IsValid valid = new IsValid(); | ||
|
|
||
| validatorHelper.enclosingElementHasEnhancedViewSupportAnnotation(element, validatedElements, valid); | ||
|
|
||
| validatorHelper.resIdsExist(element, Res.ID, FallbackStrategy.USE_ELEMENT_NAME, valid); | ||
|
|
||
| validatorHelper.isNotPrivate(element, valid); | ||
|
|
||
| validatorHelper.doesntThrowException(element, valid); | ||
|
|
||
| validatorHelper.uniqueId(element, validatedElements, valid); | ||
|
|
||
| ExecutableElement executableElement = (ExecutableElement) element; | ||
| validatorHelper.returnTypeIsVoid(executableElement, valid); | ||
|
|
||
| validatorHelper.param.hasZeroOrOneCompoundButtonOrTwoCompoundButtonBooleanParameters(executableElement, valid); | ||
|
|
||
| return valid.isValid(); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...al-test-1-5/src/main/java/org/androidannotations/test15/CheckedChangeHandledActivity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /** | ||
| * 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; | ||
|
|
||
| import org.androidannotations.annotations.CheckedChange; | ||
| import org.androidannotations.annotations.EActivity; | ||
| import org.androidannotations.annotations.FocusChange; | ||
|
|
||
| import android.view.View; | ||
| import android.widget.CompoundButton; | ||
|
|
||
| @EActivity(R.layout.clickable_widgets) | ||
| public class CheckedChangeHandledActivity extends EventsHandledAbstractActivity { | ||
|
|
||
| @CheckedChange | ||
| public void conventionButton(CompoundButton evt, boolean hasFocus) { | ||
|
|
||
| } | ||
|
|
||
| @CheckedChange | ||
| public void snakeCaseButton() { | ||
|
|
||
| } | ||
|
|
||
| @CheckedChange | ||
| public void extendedConventionButton(CompoundButton evt) { | ||
|
|
||
| } | ||
|
|
||
| @CheckedChange(R.id.configurationOverConventionButton) | ||
| public void overridenConventionButton() { | ||
|
|
||
| } | ||
|
|
||
| @CheckedChange | ||
| public void buttonWithViewArgument() { | ||
|
|
||
| } | ||
|
|
||
| @CheckedChange({ R.id.button1, R.id.button2 }) | ||
| public void multipleButtonWithViewArgument(CompoundButton v, boolean hasFocus) { | ||
|
|
||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you test that this method is called when the checked state is changed (
CompundButton.setChecked(boolean)) ?You could checkout
ClicksHandledActivityfrom the functional-test-1-5 module andClicksHandledActivityTestfrom the functional-test-1-5-tests module as example.