Skip to content

Instantly share code, notes, and snippets.

@emedinaa
Last active November 12, 2017 13:55
Show Gist options
  • Save emedinaa/701203a9f768d980c772934bf396f8c6 to your computer and use it in GitHub Desktop.
Save emedinaa/701203a9f768d980c772934bf396f8c6 to your computer and use it in GitHub Desktop.
Android-Annotations
Reference : https://developer.android.com/studio/write/annotations.html#enum-annotations
public class FilterColorDescriptor {
public static final String FILTER_BLUE = "blue";
public static final String FILTER_RED = "red";
public static final String FILTER_GRAY = "gray";
public final String filterColor;
public FilterColorDescriptor(String filterColor) {
this.filterColor = filterColor;
}
}
public class FilterColorDescriptor {
// ... type definitions
// Describes when the annotation will be discarded
@Retention(RetentionPolicy.SOURCE)
// Enumerate valid values for this interface
@StringDef({ FILTER_BLUE, FILTER_RED, FILTER_GRAY })
// Create an interface for validating String types
public @interface FilterColorDef { }
// Mark the argument as restricted to these enumerated types
public FilterColorDescriptor(@FilterColorDef String filterColor) {
this.filterColor = filterColor;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment