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