Home | History | Annotate | Download | only in annotation
      1 /*
      2  * Copyright (C) 2014 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 element of integer type, represents
     26  * a logical type and that its value should be one of the explicitly
     27  * named constants. If the IntDef#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;IntDef({NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS})
     34  *  public @interface NavigationMode {}
     35  *  public static final int NAVIGATION_MODE_STANDARD = 0;
     36  *  public static final int NAVIGATION_MODE_LIST = 1;
     37  *  public static final int NAVIGATION_MODE_TABS = 2;
     38  *  ...
     39  *  public abstract void setNavigationMode(@NavigationMode int mode);
     40  *  &#64;NavigationMode
     41  *  public abstract int getNavigationMode();
     42  * </code></pre>
     43  * For a flag, set the flag attribute:
     44  * <pre><code>
     45  *  &#64;IntDef(
     46  *      flag = true,
     47  *      value = {NAVIGATION_MODE_STANDARD, NAVIGATION_MODE_LIST, NAVIGATION_MODE_TABS})
     48  * </code></pre>
     49  *
     50  * @see LongDef
     51  */
     52 @Retention(SOURCE)
     53 @Target({ANNOTATION_TYPE})
     54 public @interface IntDef {
     55     /** Defines the allowed constants for this element */
     56     int[] value() default {};
     57 
     58     /** Defines whether the constants can be used as a flag, or just as an enum (the default) */
     59     boolean flag() default false;
     60 }
     61