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