Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Commit 335181e

Browse files
committed
Allow android.support{v7,v14} for @PreferenceXXX
1 parent 966520b commit 335181e

34 files changed

Lines changed: 320 additions & 61 deletions

‎AndroidAnnotations/androidannotations-core/androidannotations-api/src/main/java/org/androidannotations/annotations/AfterPreferences.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
* an {@link AfterPreferences} annotated method.
3232
* </p>
3333
* <p>
34+
* This annotation only can be used inside
35+
* {@link org.androidannotations.annotations.EActivity EActivity} or
36+
* {@link org.androidannotations.annotations.EFragment EFragment} annotated
37+
* class, which is a subclass of {@link android.preference.PreferenceActivity
38+
* PreferenceActivity} or <code>PreferenceFragment(Compat)</code>, respectively.
39+
* </p>
40+
* <p>
3441
* The method MUST have zero parameters.
3542
* </p>
3643
* <p>

‎AndroidAnnotations/androidannotations-core/androidannotations-api/src/main/java/org/androidannotations/annotations/PreferenceByKey.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323
/**
2424
* <p>
2525
* Use it on a {@link android.preference.Preference Preference} or
26-
* {@link android.preference.Preference Preference} subtype fields in a
26+
* {@link android.preference.Preference Preference} subtype or
27+
* <code>android.support.v7.preference.Preference</code> or
28+
* <code>android.support.v7.preference.Preference</code> subtype fields in a
2729
* {@link org.androidannotations.annotations.EActivity EActivity} or
2830
* {@link org.androidannotations.annotations.EFragment EFragment} annotated
2931
* class, which is a subclass of {@link android.preference.PreferenceActivity
30-
* PreferenceActivity} or <code>PreferenceFragment</code>, respectively.
32+
* PreferenceActivity} or <code>PreferenceFragment(Compat)</code>, respectively.
3133
* </p>
3234
* <p>
3335
* The annotation value should be an array of R.string.* fields.

‎AndroidAnnotations/androidannotations-core/androidannotations-api/src/main/java/org/androidannotations/annotations/PreferenceChange.java‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,37 @@
2424
* <p>
2525
* This annotation is intended to be used on methods to receive events defined
2626
* by
27-
* {@link android.preference.Preference.OnPreferenceChangeListener#onPreferenceChange(android.preference.Preference, Object)
28-
* OnPreferenceChangeListener#onPreferenceChange} when the value of a
29-
* {@link android.preference.Preference Preference} has been changed by the user
30-
* and is about to be set and/or persisted.
27+
* <code>OnPreferenceChangeListener#onPreferenceChange(Preference, Object)</code>
28+
* when the value of a <code>Preference</code> has been changed by the user and
29+
* is about to be set and/or persisted.
3130
* </p>
3231
* <p>
3332
* The annotation value should be one or several R.string.* fields that refers
3433
* to {@link android.preference.Preference Preference} or subclasses of
35-
* {@link android.preference.Preference Preference}. If not set, the method name
36-
* will be used as the R.string.* field name.
34+
* {@link android.preference.Preference Preference} or
35+
* <code>android.support.v7.preference.Preference</code> or subclasses of
36+
* <code>android.support.v7.preference.Preference</code>. If not set, the method
37+
* name will be used as the R.string.* field name. This annotation only can be
38+
* used inside {@link org.androidannotations.annotations.EActivity EActivity} or
39+
* {@link org.androidannotations.annotations.EFragment EFragment} annotated
40+
* class, which is a subclass of {@link android.preference.PreferenceActivity
41+
* PreferenceActivity} or <code>PreferenceFragment(Compat)</code>, respectively.
3742
* </p>
3843
* <p>
3944
* The method MAY have multiple parameter:
4045
* </p>
4146
* <ul>
42-
* <li>A {@link android.preference.Preference Preference} (or a sublcass)
47+
* <li>A {@link android.preference.Preference Preference} (or a subclass) or
48+
* <code>android.support.v7.preference.Preference</code> (or a subclass)
4349
* parameter to know which preference was targeted by this event</li>
4450
* <li>An {@link Object}, {@link String}, {@link java.util.Set Set of strings}
4551
* and also a {@link Boolean}, {@link Float}, {@link Integer}, {@link Long} or
4652
* their corresponding primitive types to obtain the new value of the
47-
* {@link android.preference.Preference Preference}. Please note with number
48-
* types, we assume that the <code>newValue</code> parameter coming from the
49-
* {@link android.preference.Preference Preference} is a {@link String}, so we
50-
* parse it to a number object (Android {@link android.preference.Preference
51-
* Preference} classes use {@link String}s instead of number objects).</li>
53+
* <code>Preference</code>. Please note with number types, we assume that the
54+
* <code>newValue</code> parameter coming from the <code>Preference</code> is a
55+
* {@link String}, so we parse it to a number object (Android
56+
* <code>Preference</code> classes use {@link String}s instead of number
57+
* objects).</li>
5258
* </ul>
5359
* <blockquote>
5460
*

‎AndroidAnnotations/androidannotations-core/androidannotations-api/src/main/java/org/androidannotations/annotations/PreferenceClick.java‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@
2323
/**
2424
* <p>
2525
* This annotation is intended to be used on methods to receive events defined
26-
* by
27-
* {@link android.preference.Preference.OnPreferenceClickListener#onPreferenceClick(android.preference.Preference)
28-
* OnPreferenceClickListener#onPreferenceClick} when the
29-
* {@link android.preference.Preference Preference} has been clicked by the
30-
* user.
26+
* by <code>OnPreferenceClickListener#onPreferenceClick(Preference)</code> when
27+
* the <code>Preference</code> has been clicked by the user.
28+
* </p>
29+
* <p>
30+
* This annotation only can be used inside
31+
* {@link org.androidannotations.annotations.EActivity EActivity} or
32+
* {@link org.androidannotations.annotations.EFragment EFragment} annotated
33+
* class, which is a subclass of {@link android.preference.PreferenceActivity
34+
* PreferenceActivity} or <code>PreferenceFragment(Compat)</code>, respectively.
3135
* </p>
3236
* <p>
3337
* The annotation value should be one or several of R.string.* fields. If not
@@ -37,7 +41,8 @@
3741
* The method MAY have one parameter:
3842
* </p>
3943
* <ul>
40-
* <li>A {@link android.preference.Preference Preference} (or a subclass)
44+
* <li>A {@link android.preference.Preference Preference} (or a subclass) or
45+
* <code>android.support.v7.preference.Preference</code> (or a subclass)
4146
* parameter to know which preference has been clicked</li>
4247
* </ul>
4348
* <blockquote>

‎AndroidAnnotations/androidannotations-core/androidannotations-api/src/main/java/org/androidannotations/annotations/PreferenceScreen.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
* Should be used on {@link org.androidannotations.annotations.EActivity
2626
* EActivity} or {@link org.androidannotations.annotations.EFragment EFragment}
2727
* classes which are subclass of {@link android.preference.PreferenceActivity
28-
* PreferenceActivity} or <code>PreferenceFragment</code>, to inject the
29-
* preference screen from resource.
28+
* PreferenceActivity} or <code>PreferenceFragment</code> or
29+
* <code>android.support.v7.preference.PreferenceFragmentCompat</code> or
30+
* <code>android.support.v14.PreferenceFragment</code>, to inject the preference
31+
* screen from resource.
3032
* </p>
3133
* <p>
3234
* The annotation value should be one of R.xml.* fields.

‎AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/helper/CanonicalNameConstants.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,17 @@ public final class CanonicalNameConstants {
114114
public static final String PREFERENCE_ACTIVITY = "android.preference.PreferenceActivity";
115115
public static final String PREFERENCE_FRAGMENT = "android.preference.PreferenceFragment";
116116
public static final String SUPPORT_V4_PREFERENCE_FRAGMENT = "android.support.v4.preference.PreferenceFragment";
117+
public static final String SUPPORT_V7_PREFERENCE_FRAGMENTCOMPAT = "android.support.v7.preference.PreferenceFragmentCompat";
118+
public static final String SUPPORT_V14_PREFERENCE_FRAGMENT = "android.support.v14.preference.PreferenceFragment";
117119
public static final String MACHINARIUS_V4_PREFERENCE_FRAGMENT = "com.github.machinarius.preferencefragment.PreferenceFragment";
118120
public static final String ACTIVITY_COMPAT = "android.support.v4.app.ActivityCompat";
119121
public static final String CONTEXT_COMPAT = "android.support.v4.content.ContextCompat";
120122
public static final String PREFERENCE = "android.preference.Preference";
123+
public static final String SUPPORT_V7_PREFERENCE = "android.support.v7.preference.Preference";
121124
public static final String PREFERENCE_CHANGE_LISTENER = "android.preference.Preference.OnPreferenceChangeListener";
125+
public static final String SUPPORT_V7_PREFERENCE_CHANGE_LISTENER = "android.support.v7.preference.Preference.OnPreferenceChangeListener";
122126
public static final String PREFERENCE_CLICK_LISTENER = "android.preference.Preference.OnPreferenceClickListener";
127+
public static final String SUPPORT_V7_PREFERENCE_CLICK_LISTENER = "android.support.v7.preference.Preference.OnPreferenceClickListener";
123128
public static final String PREFERENCE_ACTIVITY_HEADER = "android.preference.PreferenceActivity.Header";
124129
public static final String APP_WIDGET_MANAGER = "android.appwidget.AppWidgetManager";
125130

‎AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/helper/ValidatorHelper.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public class ValidatorHelper {
6969
private static final Collection<Integer> VALID_LOG_LEVELS = Arrays.asList(LOG_VERBOSE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR);
7070

7171
private static final List<String> VALID_PREFERENCE_CLASSES = asList(CanonicalNameConstants.PREFERENCE_ACTIVITY, CanonicalNameConstants.PREFERENCE_FRAGMENT,
72-
CanonicalNameConstants.SUPPORT_V4_PREFERENCE_FRAGMENT, CanonicalNameConstants.MACHINARIUS_V4_PREFERENCE_FRAGMENT);
72+
CanonicalNameConstants.SUPPORT_V4_PREFERENCE_FRAGMENT, CanonicalNameConstants.MACHINARIUS_V4_PREFERENCE_FRAGMENT, CanonicalNameConstants.SUPPORT_V7_PREFERENCE_FRAGMENTCOMPAT,
73+
CanonicalNameConstants.SUPPORT_V14_PREFERENCE_FRAGMENT);
7374

7475
protected final TargetAnnotationHelper annotationHelper;
7576

@@ -407,7 +408,7 @@ public void extendsListOfView(Element element, ElementValidation valid) {
407408
}
408409

409410
public void extendsPreference(Element element, ElementValidation validation) {
410-
extendsType(element, CanonicalNameConstants.PREFERENCE, validation);
411+
extendsOneOfTypes(element, asList(CanonicalNameConstants.PREFERENCE, CanonicalNameConstants.SUPPORT_V7_PREFERENCE), validation);
411412
}
412413

413414
public void extendsOneOfTypes(Element element, List<String> typeQualifiedNames, ElementValidation valid) {

‎AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/helper/ValidatorParameterHelper.java‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ public V extendsType(String qualifiedName) {
119119
return param(new ExtendsTypeParameterRequirement(qualifiedName));
120120
}
121121

122+
public V extendsAnyOfTypes(String... types) {
123+
return param(new ExtendsAnyOfTypesParameterRequirement(types));
124+
}
125+
122126
public V anyType() {
123127
return extendsType(CanonicalNameConstants.OBJECT);
124128
}
@@ -361,6 +365,44 @@ protected String description() {
361365
}
362366
}
363367

368+
public class ExtendsAnyOfTypesParameterRequirement extends BaseParameterRequirement {
369+
370+
private List<String> types;
371+
372+
public ExtendsAnyOfTypesParameterRequirement(String... types) {
373+
this.types = Arrays.asList(types);
374+
}
375+
376+
@Override
377+
public boolean isSatisfied(VariableElement parameter) {
378+
TypeMirror elementType = parameter.asType();
379+
380+
for (String type : types) {
381+
TypeElement typeElement = annotationHelper.typeElementFromQualifiedName(type);
382+
if (typeElement != null) {
383+
TypeMirror expectedType = typeElement.asType();
384+
if (annotationHelper.isSubtype(elementType, expectedType)) {
385+
return true;
386+
}
387+
}
388+
}
389+
390+
return false;
391+
}
392+
393+
@Override
394+
protected String description() {
395+
StringBuilder builder = new StringBuilder();
396+
builder.append("extending one of the following: [");
397+
for (int i = 0; i < types.size() - 1; ++i) {
398+
builder.append(types.get(i)).append(", ");
399+
}
400+
builder.append(types.get(types.size() - 1)).append(" ]");
401+
402+
return builder.toString();
403+
}
404+
}
405+
364406
public class AnnotatedWithParameterRequirement extends BaseParameterRequirement {
365407

366408
private Class<? extends Annotation> annotationClass;
@@ -460,6 +502,10 @@ public OneParamValidator extendsType(String qualifiedName) {
460502
return param(new ExtendsTypeParameterRequirement(qualifiedName));
461503
}
462504

505+
public OneParamValidator extendsAnyOfTypes(String... types) {
506+
return param(new ExtendsAnyOfTypesParameterRequirement(types));
507+
}
508+
463509
public OneParamValidator anyType() {
464510
return param(new AnyTypeParameterRequirement());
465511
}

‎AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/holder/EActivityHolder.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,11 @@ public FoundPreferenceHolder getFoundPreferenceHolder(JFieldRef idRef, JClass pr
753753
return preferencesHolder.getFoundPreferenceHolder(idRef, preferenceClass);
754754
}
755755

756+
@Override
757+
public boolean usingSupportV7Preference() {
758+
return preferencesHolder.usingSupportV7Preference();
759+
}
760+
756761
@Override
757762
public JBlock getOnBuildHeadersBlock() {
758763
return preferencesHolder.getOnBuildHeadersBlock();

‎AndroidAnnotations/androidannotations-core/androidannotations/src/main/java/org/androidannotations/holder/EFragmentHolder.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,4 +565,9 @@ public void assignFindPreferenceByKey(JFieldRef idRef, JClass preferenceClass, J
565565
public FoundPreferenceHolder getFoundPreferenceHolder(JFieldRef idRef, JClass preferenceClass) {
566566
return preferencesDelegate.getFoundPreferenceHolder(idRef, preferenceClass);
567567
}
568+
569+
@Override
570+
public boolean usingSupportV7Preference() {
571+
return preferencesDelegate.usingSupportV7Preference();
572+
}
568573
}

0 commit comments

Comments
 (0)