Annotation Interface GlideOption


@Target(METHOD) @Retention(CLASS) public @interface GlideOption
Identifies methods in GlideExtension annotated classes that extend com.bumptech.glide.request.RequestOptions.

All annotated methods will be added to a single com.bumptech.glide.request.RequestOptions implementation generated per application. Overlapping method names in different extensions may cause errors at compile time.

Static equivalents of annotated methods will also be generated.

Methods with this annotation will only be found if they belong to classes annotated with GlideExtension.

The preferred way of writing extension methods returns the provided com.bumptech.glide.request.RequestOptions object with one or more methods called on it. You must not return a newly instantiated com.bumptech.glide.request.RequestOptions object as doing so my cause a ClassCastException at runtime. Calling either com.bumptech.glide.request.RequestOptions#autoClone() or com.bumptech.glide.request.RequestOptions#lock() is safe, but unnecessary and should typically be avoided. The preferred style looks like:


 {@link @}GlideExtension
 public class MyExtension {
   private MyExtension() {}

   {@literal @}GlideOption
   public static RequestOptions myOption(RequestOptions options) {
     return options
         .optionOne()
         .optionTwo();
   }
 }
 

The deprecated way of writing extension methods is simply a static void method. The com.bumptech.glide.request.RequestOptions object is cloned before it is passed to this method to avoid an option method returning a new instance, but using methods like com.bumptech.glide.request.RequestOptions#clone() or com.bumptech.glide.request.RequestOptions#autoClone() can result in options applied in the method being silently ignored. Prefer the new style whenever possible.


 {@literal @}GlideExtension
 public class MyExtension {
   private MyExtension() {}

   // Deprecated! Use the new style of GlideOption extensions instead.
   {@literal @}GlideOption
   public static void myOption(RequestOptions options) {
     options
         .optionOne()
         .optionTwo();
   }
 }
 
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    true to indicate that it's safe to statically memoize the result of this method using com.bumptech.glide.request.RequestOptions#autoClone().
    int
    Determines how and whether a generated method should extend a method from it's parent.
    boolean
    true to prevent a static builder method from being generated.
    Sets the name for the generated static version of this method.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Expects to call super and then add additional functionality to an overridden method.
    static final int
    Does not intend to override a method in a super class.
    static final int
    Expects to not call super and replace an overridden method.
  • Field Details

    • OVERRIDE_NONE

      static final int OVERRIDE_NONE
      Does not intend to override a method in a super class.
      See Also:
    • OVERRIDE_EXTEND

      static final int OVERRIDE_EXTEND
      Expects to call super and then add additional functionality to an overridden method.
      See Also:
    • OVERRIDE_REPLACE

      static final int OVERRIDE_REPLACE
      Expects to not call super and replace an overridden method.
      See Also:
  • Element Details

    • override

      int override
      Determines how and whether a generated method should extend a method from it's parent.

      Must be one of OVERRIDE_NONE, OVERRIDE_EXTEND, OVERRIDE_REPLACE.

      The extended method is determined by String and argument matching against methods in the extended class. If OVERRIDE_NONE is used and the method and arguments match a method in the extended class, a compile time error will result. Similarly if any other override type is used and no method/arguments in the extended class match, a compile time error will result.

      Default:
      0
    • staticMethodName

      String staticMethodName
      Sets the name for the generated static version of this method.

      If this value is not set, the static method name is just the original method name with "Of" appended.

      Default:
      ""
    • memoizeStaticMethod

      boolean memoizeStaticMethod
      true to indicate that it's safe to statically memoize the result of this method using com.bumptech.glide.request.RequestOptions#autoClone().

      This method should only be used for no-arg methods where there's only a single possible value.

      Memoization can save object allocations for frequently used options.

      Default:
      false
    • skipStaticMethod

      boolean skipStaticMethod
      true to prevent a static builder method from being generated.

      By default static methods are generated for all methods annotated with GlideOption. These static factory methods allow for a cleaner API when used with com.bumptech.glide.RequestBuilder#apply. The static factory method by default simply creates a new com.bumptech.glide.request.RequestOptions object, calls the instance version of the method on it and returns it. For example:

       
       public static GlideOptions noAnimation() {
         return new GlideOptions().dontAnimate();
       }
       
       
      See Also:
      Default:
      false