1 /*
2  * Copyright (C) 2013 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 package android.annotation;
17 
18 import java.lang.annotation.Retention;
19 import java.lang.annotation.Target;
20 
21 import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
22 import static java.lang.annotation.RetentionPolicy.SOURCE;
23 
24 /**
25  * Denotes that the annotated element of integer type, represents
26  * a logical type and that its value should be one of the explicitly
27  * named constants. If the {@link #flag()} attribute is set to true,
28  * multiple constants can be combined.
29  * <p>
30  * <pre><code>
31  *  &#64;Retention(SOURCE)
32  *  &#64;IntDef({NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS})
33  *  public @interface NavigationMode {}
34  *  public static final int NAVIGATION_MODE_STANDARD = 0;
35  *  public static final int NAVIGATION_MODE_LIST = 1;
36  *  public static final int NAVIGATION_MODE_TABS = 2;
37  *  ...
38  *  public abstract void setNavigationMode(@NavigationMode int mode);
39  *  &#64;NavigationMode
40  *  public abstract int getNavigationMode();
41  * </code></pre>
42  * For a flag, set the flag attribute:
43  * <pre><code>
44  *  &#64;IntDef(
45  *      flag = true,
46  *      value = {NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS})
47  * </code></pre>
48  *
49  * @hide
50  */
51 @Retention(SOURCE)
52 @Target({ANNOTATION_TYPE})
53 public @interface IntDef {
54     /** Defines the constant prefix for this element */
prefix()55     String[] prefix() default {};
56     /** Defines the constant suffix for this element */
suffix()57     String[] suffix() default {};
58 
59     /** Defines the allowed constants for this element */
value()60     int[] value() default {};
61 
62     /** Defines whether the constants can be used as a flag, or just as an enum (the default) */
flag()63     boolean flag() default false;
64 }
65