blob: 97ede862bfaa7a4ea86ecf4fabc231680c09efcd [file] [log] [blame]
Ashley Rose041d90b2018-11-07 17:35:19 -05001/*
2 * Copyright 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.view.inspector;
18
Ashley Rose89d6bce2019-03-01 19:24:50 -050019import static java.lang.annotation.ElementType.FIELD;
Ashley Rose041d90b2018-11-07 17:35:19 -050020import static java.lang.annotation.ElementType.METHOD;
Ashley Rosed2c5f452018-11-29 15:40:10 -050021import static java.lang.annotation.ElementType.TYPE;
Ashley Rose041d90b2018-11-07 17:35:19 -050022import static java.lang.annotation.RetentionPolicy.SOURCE;
23
Ashley Rosec1a4dec2018-12-13 18:06:30 -050024import android.annotation.TestApi;
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080025import android.content.res.Resources;
Ashley Rosed2c5f452018-11-29 15:40:10 -050026
Ashley Rose041d90b2018-11-07 17:35:19 -050027import java.lang.annotation.Retention;
28import java.lang.annotation.Target;
29
30/**
31 * Marks a getter of a property on an inspectable node.
32 *
33 * This annotation is inherited by default. If a child class doesn't add it to a getter, but a
34 * parent class does, the property will be inspected, even if the child overrides the definition
35 * of the getter. If a child class defines a property of the same name of a property on the parent
36 * but on a different getter, the inspector will use the child's getter when inspecting instances
37 * of the child, and the parent's otherwise.
38 *
Ashley Rosed2c5f452018-11-29 15:40:10 -050039 * @see InspectionCompanion#mapProperties(PropertyMapper)
40 * @see InspectionCompanion#readProperties(Object, PropertyReader)
Ashley Rose041d90b2018-11-07 17:35:19 -050041 * @hide
42 */
Ashley Rose89d6bce2019-03-01 19:24:50 -050043@Target({METHOD, FIELD})
Ashley Rose041d90b2018-11-07 17:35:19 -050044@Retention(SOURCE)
Ashley Rosec1a4dec2018-12-13 18:06:30 -050045@TestApi
Ashley Rose041d90b2018-11-07 17:35:19 -050046public @interface InspectableProperty {
47 /**
48 * The name of the property.
49 *
50 * If left empty (the default), the property name will be inferred from the name of the getter
51 * method.
52 *
53 * @return The name of the property.
54 */
Ashley Rosed2c5f452018-11-29 15:40:10 -050055 String name() default "";
56
57 /**
58 * If the property is inflated from XML, the resource ID of its XML attribute.
59 *
60 * If left as {ID_NULL}, and {@link #hasAttributeId()} is true, the attribute ID will be
61 * inferred from {@link #name()}.
62 *
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080063 * @return The attribute ID of the property or {@link Resources#ID_NULL}
Ashley Rosed2c5f452018-11-29 15:40:10 -050064 */
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080065 int attributeId() default Resources.ID_NULL;
Ashley Rosed2c5f452018-11-29 15:40:10 -050066
67 /**
68 * If this property has an attribute ID.
69 *
70 * Set to false if the annotated property does not have an attribute ID, that is, it is not
71 * inflated from an XML attribute. This will prevent the automatic inference of the attribute
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080072 * ID if {@link #attributeId()} is set to {@link Resources#ID_NULL}.
Ashley Rosed2c5f452018-11-29 15:40:10 -050073 *
74 * @return Whether to infer an attribute ID if not supplied
75 */
76 boolean hasAttributeId() default true;
77
78 /**
79 * Specify how to interpret a value type packed into a primitive integer.
80 *
81 * @return A {@link ValueType}
82 */
83 ValueType valueType() default ValueType.INFERRED;
84
85 /**
86 * For enumerations packed into primitive {int} properties, map the values to string names.
87 *
88 * Note that {@link #enumMapping()} cannot be used simultaneously with {@link #flagMapping()}.
89 *
90 * @return An array of {@link EnumMap}, empty if not applicable
91 * @see android.annotation.IntDef
Ashley Rosed2c5f452018-11-29 15:40:10 -050092 */
93 EnumMap[] enumMapping() default {};
94
95 /**
96 * For flags packed into primitive {int} properties, model the string names of the flags.
97 *
98 * Note that {@link #flagMapping()} cannot be used simultaneously with {@link #enumMapping()}.
99 *
100 * @return An array of {@link FlagMap}, empty if not applicable
101 * @see android.annotation.IntDef
102 * @see IntFlagMapping
103 */
104 FlagMap[] flagMapping() default {};
105
106
107 /**
108 * One entry in an enumeration packed into a primitive {int}.
109 *
Ashley Rosea61e7cd2019-01-23 14:37:42 -0500110 * @see IntEnumMapping
Ashley Rosed2c5f452018-11-29 15:40:10 -0500111 * @hide
112 */
113 @Target({TYPE})
114 @Retention(SOURCE)
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500115 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500116 @interface EnumMap {
117 /**
118 * The string name of this enumeration value.
119 *
120 * @return A string name
121 */
122 String name();
123
124 /**
125 * The integer value of this enumeration value.
126 *
127 * @return An integer value
128 */
129 int value();
130 }
131
132 /**
133 * One flag value of many that may be packed into a primitive {int}.
134 *
135 * @see IntFlagMapping
136 * @hide
137 */
138 @Target({TYPE})
139 @Retention(SOURCE)
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500140 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500141 @interface FlagMap {
142 /**
143 * The string name of this flag.
144 *
145 * @return A string name
146 */
147 String name();
148
149 /**
150 * A target value that the property's value must equal after masking.
151 *
152 * If a mask is not supplied (i.e., {@link #mask()} is 0), the target will be reused as the
153 * mask. This handles the common case where no flags mutually exclude each other.
154 *
155 * @return The target value to compare against
156 */
157 int target();
158
159 /**
160 * A mask that the property will be bitwise anded with before comparing to the target.
161 *
162 * If set to 0 (the default), the value of {@link #target()} will be used as a mask. Zero
163 * was chosen as the default since bitwise and with zero is always zero.
164 *
165 * @return A mask, or 0 to use the target as a mask
166 */
167 int mask() default 0;
168 }
169
170 /**
171 * The type of value packed into a primitive {int}.
172 *
173 * @hide
174 */
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500175 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500176 enum ValueType {
177 /**
178 * No special handling, property is considered to be a numeric value.
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500179 *
180 * @hide
Ashley Rosed2c5f452018-11-29 15:40:10 -0500181 */
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500182 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500183 NONE,
184
185 /**
186 * The default the annotation processor infers the value type from context.
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500187 *
188 * @hide
Ashley Rosed2c5f452018-11-29 15:40:10 -0500189 */
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500190 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500191 INFERRED,
192
193 /**
194 * Value packs an enumeration.
195 *
196 * This is inferred if {@link #enumMapping()} is specified.
197 *
198 * @see EnumMap
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500199 * @hide
Ashley Rosed2c5f452018-11-29 15:40:10 -0500200 */
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500201 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500202 INT_ENUM,
203
204 /**
205 * Value packs flags, of which many may be enabled at once.
206 *
207 * This is inferred if {@link #flagMapping()} is specified.
208 *
209 * @see FlagMap
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500210 * @hide
Ashley Rosed2c5f452018-11-29 15:40:10 -0500211 */
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500212 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500213 INT_FLAG,
214
215 /**
216 * Value packs color information.
217 *
218 * This is inferred from {@link android.annotation.ColorInt}, or
219 * {@link android.annotation.ColorLong} on the getter method.
220 *
221 * @see android.graphics.Color
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500222 * @hide
Ashley Rosed2c5f452018-11-29 15:40:10 -0500223 */
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500224 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500225 COLOR,
226
227 /**
228 * Value packs gravity information.
229 *
230 * This type is not inferred, and is non-trivial to represent using {@link FlagMap}.
231 *
232 * @see android.view.Gravity
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500233 * @hide
Ashley Rosed2c5f452018-11-29 15:40:10 -0500234 */
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500235 @TestApi
Ashley Rosee8914812019-03-05 17:12:00 -0500236 GRAVITY,
237
238 /**
239 * Value is a resource ID
240 *
241 * This type is inferred from the presence of a resource ID annotation such as
242 * {@link android.annotation.AnyRes}.
243 *
244 * @hide
245 */
246 @TestApi
247 RESOURCE_ID
Ashley Rosed2c5f452018-11-29 15:40:10 -0500248 }
Ashley Rose041d90b2018-11-07 17:35:19 -0500249}