blob: f85952108f0783d5583900588ed7df4d9d30d0ff [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
19import static java.lang.annotation.ElementType.METHOD;
Ashley Rosed2c5f452018-11-29 15:40:10 -050020import static java.lang.annotation.ElementType.TYPE;
Ashley Rose041d90b2018-11-07 17:35:19 -050021import static java.lang.annotation.RetentionPolicy.SOURCE;
22
Ashley Rosec1a4dec2018-12-13 18:06:30 -050023import android.annotation.TestApi;
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080024import android.content.res.Resources;
Ashley Rosed2c5f452018-11-29 15:40:10 -050025
Ashley Rose041d90b2018-11-07 17:35:19 -050026import java.lang.annotation.Retention;
27import java.lang.annotation.Target;
28
29/**
30 * Marks a getter of a property on an inspectable node.
31 *
32 * This annotation is inherited by default. If a child class doesn't add it to a getter, but a
33 * parent class does, the property will be inspected, even if the child overrides the definition
34 * of the getter. If a child class defines a property of the same name of a property on the parent
35 * but on a different getter, the inspector will use the child's getter when inspecting instances
36 * of the child, and the parent's otherwise.
37 *
Ashley Rosed2c5f452018-11-29 15:40:10 -050038 * @see InspectionCompanion#mapProperties(PropertyMapper)
39 * @see InspectionCompanion#readProperties(Object, PropertyReader)
Ashley Rose041d90b2018-11-07 17:35:19 -050040 * @hide
41 */
42@Target({METHOD})
43@Retention(SOURCE)
Ashley Rosec1a4dec2018-12-13 18:06:30 -050044@TestApi
Ashley Rose041d90b2018-11-07 17:35:19 -050045public @interface InspectableProperty {
46 /**
47 * The name of the property.
48 *
49 * If left empty (the default), the property name will be inferred from the name of the getter
50 * method.
51 *
52 * @return The name of the property.
53 */
Ashley Rosed2c5f452018-11-29 15:40:10 -050054 String name() default "";
55
56 /**
57 * If the property is inflated from XML, the resource ID of its XML attribute.
58 *
59 * If left as {ID_NULL}, and {@link #hasAttributeId()} is true, the attribute ID will be
60 * inferred from {@link #name()}.
61 *
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080062 * @return The attribute ID of the property or {@link Resources#ID_NULL}
Ashley Rosed2c5f452018-11-29 15:40:10 -050063 */
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080064 int attributeId() default Resources.ID_NULL;
Ashley Rosed2c5f452018-11-29 15:40:10 -050065
66 /**
67 * If this property has an attribute ID.
68 *
69 * Set to false if the annotated property does not have an attribute ID, that is, it is not
70 * inflated from an XML attribute. This will prevent the automatic inference of the attribute
Aurimas Liutikasd8ebfef2019-01-16 12:46:42 -080071 * ID if {@link #attributeId()} is set to {@link Resources#ID_NULL}.
Ashley Rosed2c5f452018-11-29 15:40:10 -050072 *
73 * @return Whether to infer an attribute ID if not supplied
74 */
75 boolean hasAttributeId() default true;
76
77 /**
78 * Specify how to interpret a value type packed into a primitive integer.
79 *
80 * @return A {@link ValueType}
81 */
82 ValueType valueType() default ValueType.INFERRED;
83
84 /**
85 * For enumerations packed into primitive {int} properties, map the values to string names.
86 *
87 * Note that {@link #enumMapping()} cannot be used simultaneously with {@link #flagMapping()}.
88 *
89 * @return An array of {@link EnumMap}, empty if not applicable
90 * @see android.annotation.IntDef
Ashley Rosed2c5f452018-11-29 15:40:10 -050091 */
92 EnumMap[] enumMapping() default {};
93
94 /**
95 * For flags packed into primitive {int} properties, model the string names of the flags.
96 *
97 * Note that {@link #flagMapping()} cannot be used simultaneously with {@link #enumMapping()}.
98 *
99 * @return An array of {@link FlagMap}, empty if not applicable
100 * @see android.annotation.IntDef
101 * @see IntFlagMapping
102 */
103 FlagMap[] flagMapping() default {};
104
105
106 /**
107 * One entry in an enumeration packed into a primitive {int}.
108 *
Ashley Rosea61e7cd2019-01-23 14:37:42 -0500109 * @see IntEnumMapping
Ashley Rosed2c5f452018-11-29 15:40:10 -0500110 * @hide
111 */
112 @Target({TYPE})
113 @Retention(SOURCE)
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500114 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500115 @interface EnumMap {
116 /**
117 * The string name of this enumeration value.
118 *
119 * @return A string name
120 */
121 String name();
122
123 /**
124 * The integer value of this enumeration value.
125 *
126 * @return An integer value
127 */
128 int value();
129 }
130
131 /**
132 * One flag value of many that may be packed into a primitive {int}.
133 *
134 * @see IntFlagMapping
135 * @hide
136 */
137 @Target({TYPE})
138 @Retention(SOURCE)
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500139 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500140 @interface FlagMap {
141 /**
142 * The string name of this flag.
143 *
144 * @return A string name
145 */
146 String name();
147
148 /**
149 * A target value that the property's value must equal after masking.
150 *
151 * If a mask is not supplied (i.e., {@link #mask()} is 0), the target will be reused as the
152 * mask. This handles the common case where no flags mutually exclude each other.
153 *
154 * @return The target value to compare against
155 */
156 int target();
157
158 /**
159 * A mask that the property will be bitwise anded with before comparing to the target.
160 *
161 * If set to 0 (the default), the value of {@link #target()} will be used as a mask. Zero
162 * was chosen as the default since bitwise and with zero is always zero.
163 *
164 * @return A mask, or 0 to use the target as a mask
165 */
166 int mask() default 0;
167 }
168
169 /**
170 * The type of value packed into a primitive {int}.
171 *
172 * @hide
173 */
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500174 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500175 enum ValueType {
176 /**
177 * No special handling, property is considered to be a numeric value.
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500178 *
179 * @hide
Ashley Rosed2c5f452018-11-29 15:40:10 -0500180 */
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500181 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500182 NONE,
183
184 /**
185 * The default the annotation processor infers the value type from context.
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500186 *
187 * @hide
Ashley Rosed2c5f452018-11-29 15:40:10 -0500188 */
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500189 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500190 INFERRED,
191
192 /**
193 * Value packs an enumeration.
194 *
195 * This is inferred if {@link #enumMapping()} is specified.
196 *
197 * @see EnumMap
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500198 * @hide
Ashley Rosed2c5f452018-11-29 15:40:10 -0500199 */
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500200 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500201 INT_ENUM,
202
203 /**
204 * Value packs flags, of which many may be enabled at once.
205 *
206 * This is inferred if {@link #flagMapping()} is specified.
207 *
208 * @see FlagMap
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500209 * @hide
Ashley Rosed2c5f452018-11-29 15:40:10 -0500210 */
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500211 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500212 INT_FLAG,
213
214 /**
215 * Value packs color information.
216 *
217 * This is inferred from {@link android.annotation.ColorInt}, or
218 * {@link android.annotation.ColorLong} on the getter method.
219 *
220 * @see android.graphics.Color
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500221 * @hide
Ashley Rosed2c5f452018-11-29 15:40:10 -0500222 */
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500223 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500224 COLOR,
225
226 /**
227 * Value packs gravity information.
228 *
229 * This type is not inferred, and is non-trivial to represent using {@link FlagMap}.
230 *
231 * @see android.view.Gravity
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500232 * @hide
Ashley Rosed2c5f452018-11-29 15:40:10 -0500233 */
Ashley Rosec1a4dec2018-12-13 18:06:30 -0500234 @TestApi
Ashley Rosed2c5f452018-11-29 15:40:10 -0500235 GRAVITY
236 }
Ashley Rose041d90b2018-11-07 17:35:19 -0500237}