This repository was archived by the owner on Feb 26, 2023. It is now read-only.
Repository navigation
Annotation helpers for PreferenceActivity and PreferenceFragment #1162
Merged
yDelouis
merged 16 commits into
androidannotations:develop
from
WonderCsabo:7_preferenceScreen
Apr 25, 2015
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
1919b96
Add @PreferenceScreen
WonderCsabo 8b0ff95
Implement PreferenceScreenHandler
WonderCsabo dde2477
Add @PreferenceByKey
WonderCsabo bfefdc7
Implement PreferenceByKeyHandler
WonderCsabo 54dbcbe
Add @PreferenceChange
WonderCsabo 9e73bc6
Refactor AbstractListenerHandler
WonderCsabo fc08a40
Implement PreferenceChangeHandler
WonderCsabo 38eb04f
Add @PreferenceClick
WonderCsabo 81cef78
Implement PreferenceClickHandler
WonderCsabo b9b9b70
Add @AfterPreferences
WonderCsabo cc84769
Implement AfterPreferencesHandler
WonderCsabo f692e93
Add @PreferenceHeaders
WonderCsabo 8ac3e84
Implement PreferenceHeadersHandler
WonderCsabo 2f2e544
Allow more then 100 methods in ValitorHelper with Checkstyle
WonderCsabo 502a555
Add JavaDoc for new @PreferenceXXX annotations
WonderCsabo 2064edf
Add tests for @PreferenceXXX annotations
WonderCsabo 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
64 changes: 64 additions & 0 deletions
64
...oidannotations-api/src/main/java/org/androidannotations/annotations/AfterPreferences.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,64 @@ | ||
| /** | ||
| * 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.annotations; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * <p> | ||
| * Methods annotated with {@link AfterPreferences} will be called after | ||
| * <code>addPreferenceFromResource</code> is called by the generated classs. | ||
| * </p> | ||
| * <p> | ||
| * This occurs AFTER <code>addPreferencesFromResource</code> which is called at | ||
| * the end of super.onCreate(). Any preference depending code should be done in | ||
| * an {@link AfterPreferences} annotated method. | ||
| * </p> | ||
| * <p> | ||
| * The method MUST have zero parameters. | ||
| * </p> | ||
| * <p> | ||
| * There MAY be several methods annotated with {@link AfterPreferences} in the | ||
| * same class. | ||
| * </p> | ||
| * <blockquote> | ||
| * | ||
| * Example : | ||
| * | ||
| * <pre> | ||
| * @EActivity | ||
| * public class SettingsActivity extends PreferenceActivity { | ||
| * | ||
| * @PreferenceByKey(R.string.checkBoxPref) | ||
| * CheckBoxPreference checkBoxPref; | ||
| * | ||
| * @AfterPreferences | ||
| * void initPrefs() { | ||
| * checkBoxPref.setChecked(false); | ||
| * } | ||
| * } | ||
| * </pre> | ||
| * | ||
| * </blockquote> | ||
| * | ||
| */ | ||
| @Retention(RetentionPolicy.CLASS) | ||
| @Target(ElementType.METHOD) | ||
| public @interface AfterPreferences { | ||
| } |
72 changes: 72 additions & 0 deletions
72
...roidannotations-api/src/main/java/org/androidannotations/annotations/PreferenceByKey.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,72 @@ | ||
| /** | ||
| * 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.annotations; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * <p> | ||
| * Use it on a {@link android.preference.Preference Preference} or | ||
| * {@link android.preference.Preference Preference} subtype fields in a | ||
| * {@link org.androidannotations.annotations.EActivity EActivity} or | ||
| * {@link org.androidannotations.annotations.EFragment EFragment} annotated | ||
| * class, which is a subclass of {@link android.preference.PreferenceActivity | ||
| * PreferenceActivity} or <code>PreferenceFragment</code>, respectively. | ||
| * </p> | ||
| * <p> | ||
| * The annotation value should be an array of R.string.* fields. | ||
| * </p> | ||
| * <p> | ||
| * Your code related to injected views should go in an | ||
| * {@link org.androidannotations.annotations.AfterPreferences AfterPreferences} | ||
| * annotated method. | ||
| * </p> | ||
| * <blockquote> | ||
| * | ||
| * Example : | ||
| * | ||
| * <pre> | ||
| * @EActivity | ||
| * public class SettingsActivity extends PreferenceActivity { | ||
| * | ||
| * @PreferenceByKey(R.string.myPref1) | ||
| * Preference myPreference1; | ||
| * | ||
| * @PreferenceByKey(R.string.checkBoxPref) | ||
| * CheckBoxPreference checkBoxPref; | ||
| * | ||
| * @AfterPreferences | ||
| * void initPrefs() { | ||
| * checkBoxPref.setChecked(false); | ||
| * } | ||
| * } | ||
| * </pre> | ||
| * | ||
| * </blockquote> | ||
| * | ||
| * @see org.androidannotations.annotations.AfterPreferences AfterPreferences | ||
| */ | ||
| @Retention(RetentionPolicy.CLASS) | ||
| @Target(ElementType.FIELD) | ||
| public @interface PreferenceByKey { | ||
|
|
||
| int value() default ResId.DEFAULT_VALUE; | ||
|
|
||
| String resName() default ""; | ||
| } | ||
85 changes: 85 additions & 0 deletions
85
...oidannotations-api/src/main/java/org/androidannotations/annotations/PreferenceChange.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,85 @@ | ||
| /** | ||
| * 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.annotations; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * <p> | ||
| * This annotation is intended to be used on methods to receive events defined | ||
| * by | ||
| * {@link android.preference.Preference.OnPreferenceChangeListener#onPreferenceChange(android.preference.Preference, Object) | ||
| * OnPreferenceChangeListener#onPreferenceChange} when the value of a | ||
| * {@link android.preference.Preference Preference} has been changed by the user | ||
| * and is about to be set and/or persisted. | ||
| * </p> | ||
| * <p> | ||
| * The annotation value should be one or several R.string.* fields that refers | ||
| * to {@link android.preference.Preference Preference} or subclasses of | ||
| * {@link android.preference.Preference Preference}. If not set, the method name | ||
| * will be used as the R.string.* field name. | ||
| * </p> | ||
| * <p> | ||
| * The method MAY have multiple parameter: | ||
| * </p> | ||
| * <ul> | ||
| * <li>A {@link android.preference.Preference Preference} parameter to know | ||
| * which preference was targeted by this event</li> | ||
| * <li>An {@link Object} or {@link java.util.Set Set of strings} or | ||
| * {@link Boolean} or {@link String} to obtain the new value of the | ||
| * {@link android.preference.Preference Preference}</li> | ||
| * </ul> | ||
| * <blockquote> | ||
| * | ||
| * Example : | ||
| * | ||
| * <pre> | ||
| * @PreferenceChange(<b>R.string.myPref</b>) | ||
| * void checkedChangedOnMyButton(boolean newValue, Preference preference) { | ||
| * // Something Here | ||
| * } | ||
| * | ||
| * @PreferenceChange | ||
| * void <b>myPref</b>PreferenceChanged(Preference preference) { | ||
| * // Something Here | ||
| * } | ||
| * | ||
| * @PreferenceChange(<b>{R.string.myPref1, R.string.myPref2}</b>) | ||
| * void preferenceChangeOnMultiplePrefs(Preference preference, String newValue) { | ||
| * // Something Here | ||
| * } | ||
| * | ||
| * @PreferenceChange(<b>R.string.myPref</b>) | ||
| * void preferenceChangeOnMyPref() { | ||
| * // Something Here | ||
| * } | ||
| * </pre> | ||
| * | ||
| * </blockquote> | ||
| * | ||
| * @see PreferenceClick | ||
| */ | ||
| @Retention(RetentionPolicy.CLASS) | ||
| @Target(ElementType.METHOD) | ||
| public @interface PreferenceChange { | ||
|
|
||
| int[] value() default ResId.DEFAULT_VALUE; | ||
|
|
||
| String[] resName() default ""; | ||
| } |
70 changes: 70 additions & 0 deletions
70
...roidannotations-api/src/main/java/org/androidannotations/annotations/PreferenceClick.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,70 @@ | ||
| /** | ||
| * 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.annotations; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * <p> | ||
| * This annotation is intended to be used on methods to receive events defined | ||
| * by | ||
| * {@link android.preference.Preference.OnPreferenceClickListener#onPreferenceClick(android.preference.Preference) | ||
| * OnPreferenceClickListener#onPreferenceClick} when the | ||
| * {@link android.preference.Preference Preference} has been clicked by the | ||
| * user. | ||
| * </p> | ||
| * <p> | ||
| * The annotation value should be one or several of R.string.* fields. If not | ||
| * set, the method name will be used as the R.string.* field name. | ||
| * </p> | ||
| * <p> | ||
| * The method MAY have one parameter: | ||
| * </p> | ||
| * <ul> | ||
| * <li>A {@link android.preference.Preference Preference} parameter to know | ||
| * which preference has been clicked</li> | ||
| * </ul> | ||
| * <blockquote> | ||
| * | ||
| * Example : | ||
| * | ||
| * <pre> | ||
| * @PreferenceClick(<b>R.string.myPref</b>) | ||
| * void clickOnMyPref() { | ||
| * // Something Here | ||
| * } | ||
| * | ||
| * @PreferenceClick | ||
| * void <b>myPref</b>PreferenceClicked(Preference preference) { | ||
| * // Something Here | ||
| * } | ||
| * </pre> | ||
| * | ||
| * </blockquote> | ||
| * | ||
| * @see PreferenceChange | ||
| */ | ||
| @Retention(RetentionPolicy.CLASS) | ||
| @Target(ElementType.METHOD) | ||
| public @interface PreferenceClick { | ||
|
|
||
| int[] value() default ResId.DEFAULT_VALUE; | ||
|
|
||
| String[] resName() default ""; | ||
| } |
67 changes: 67 additions & 0 deletions
67
...idannotations-api/src/main/java/org/androidannotations/annotations/PreferenceHeaders.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,67 @@ | ||
| /** | ||
| * 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.annotations; | ||
|
|
||
| import java.lang.annotation.ElementType; | ||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.RetentionPolicy; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| /** | ||
| * <p> | ||
| * Should be used on a {@link org.androidannotations.annotations.EActivity | ||
| * EActivity} class which is a subclass of | ||
| * {@link android.preference.PreferenceActivity PreferenceActivity}, to inject | ||
| * the preference headers from resource. | ||
| * </p> | ||
| * <p> | ||
| * The annotation value should be one of R.xml.* fields. | ||
| * </p> | ||
| * | ||
| * <blockquote> | ||
| * | ||
| * Example : | ||
| * | ||
| * <pre> | ||
| * @PreferenceHeaders(R.xml.preference_headers) | ||
| * @EActivity | ||
| * public class SettingsActivity extends PreferenceActivity { | ||
| * | ||
| * @PreferenceByKey(R.string.myPref1) | ||
| * Preference myPreference1; | ||
| * | ||
| * @PreferenceByKey(R.string.checkBoxPref) | ||
| * CheckBoxPreference checkBoxPref; | ||
| * | ||
| * @AfterPreferences | ||
| * void initPrefs() { | ||
| * checkBoxPref.setChecked(false); | ||
| * } | ||
| * } | ||
| * </pre> | ||
| * | ||
| * </blockquote> | ||
| * | ||
| * @see PreferenceScreen | ||
| */ | ||
| @Retention(RetentionPolicy.CLASS) | ||
| @Target(ElementType.TYPE) | ||
| public @interface PreferenceHeaders { | ||
|
|
||
| int value() default ResId.DEFAULT_VALUE; | ||
|
|
||
| String resName() default ""; | ||
| } |
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.
@Targetand@RetentionThere 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.
Yeah, i do not know how could i forget that.
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.
i think you'd see that by yourself when writing the javadocs ;)