From ed20643fb94d4e17f4cdb3699a6d83621408dd34 Mon Sep 17 00:00:00 2001 From: judds Date: Wed, 5 Sep 2018 08:53:33 -0700 Subject: [PATCH] Directly include RequestOptions in ReqestBuilder using CRGP https://www.artima.com/weblogs/viewpost.jsp?thread=133275 This means that you can write: Glide.with(context) .load(url) .placeholder(R.drawable.placeholder) .into(imageView); Instead of: Glide.with(contex) .apply(placeholderOf(R.drawable.placeholder) .into(imageView); Without using the generated API. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=211640993 --- .../compiler/AppModuleProcessor.java | 2 +- .../compiler/FieldUniqueIdGenerator.java | 16 + .../compiler/GlideExtensionValidator.java | 35 +- .../compiler/RequestBuilderGenerator.java | 185 +-- .../RequestOptionsExtensionGenerator.java | 208 +++ .../compiler/RequestOptionsGenerator.java | 336 +--- .../RequestOptionsOverrideGenerator.java | 105 ++ .../EmptyAppGlideModuleTest/GlideOptions.java | 15 +- .../EmptyAppGlideModuleTest/GlideRequest.java | 551 ++----- .../MemoizeStaticMethod/GlideOptions.java | 15 +- .../MemoizeStaticMethod/GlideRequest.java | 565 ++----- .../OverrideExtend/GlideOptions.java | 15 +- .../OverrideExtend/GlideRequest.java | 553 ++----- .../GlideOptions.java | 15 +- .../GlideRequest.java | 553 ++----- .../OverrideReplace/GlideOptions.java | 15 +- .../OverrideReplace/GlideRequest.java | 553 ++----- .../SkipStaticMethod/GlideOptions.java | 15 +- .../SkipStaticMethod/GlideRequest.java | 565 ++----- .../StaticMethodName/GlideOptions.java | 15 +- .../StaticMethodName/GlideRequest.java | 565 ++----- .../GlideOptions.java | 15 +- .../GlideRequest.java | 565 ++----- .../GlideOptions.java | 15 +- .../MemoizeStaticMethod/GlideOptions.java | 15 +- .../MemoizeStaticMethod/GlideRequest.java | 565 ++----- .../OverrideExtend/GlideOptions.java | 15 +- .../OverrideExtend/GlideRequest.java | 553 ++----- .../OverrideReplace/GlideOptions.java | 15 +- .../OverrideReplace/GlideRequest.java | 553 ++----- .../SkipStaticMethod/GlideOptions.java | 15 +- .../SkipStaticMethod/GlideRequest.java | 565 ++----- .../StaticMethodName/GlideOptions.java | 15 +- .../StaticMethodName/GlideRequest.java | 565 ++----- .../GlideOptions.java | 15 +- .../GlideRequest.java | 565 ++----- .../GlideOptions.java | 15 +- .../com/bumptech/glide/RequestBuilder.java | 97 +- .../glide/request/BaseRequestOptions.java | 1430 +++++++++++++++++ .../glide/request/RequestOptions.java | 1398 +--------------- .../bumptech/glide/request/SingleRequest.java | 6 +- .../samples/flickr/FlickrGlideExtension.java | 6 +- 42 files changed, 3890 insertions(+), 8010 deletions(-) create mode 100644 annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/FieldUniqueIdGenerator.java create mode 100644 annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsExtensionGenerator.java create mode 100644 annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsOverrideGenerator.java create mode 100644 library/src/main/java/com/bumptech/glide/request/BaseRequestOptions.java diff --git a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/AppModuleProcessor.java b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/AppModuleProcessor.java index 5e10a334bb..23124a547b 100644 --- a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/AppModuleProcessor.java +++ b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/AppModuleProcessor.java @@ -88,7 +88,7 @@ boolean maybeWriteAppModule() { writeRequestOptions(generatedCodePackageName, generatedRequestOptions); TypeSpec generatedRequestBuilder = - requestBuilderGenerator.generate(generatedCodePackageName, generatedRequestOptions); + requestBuilderGenerator.generate(generatedCodePackageName, indexedClassNames.extensions); writeRequestBuilder(generatedCodePackageName, generatedRequestBuilder); TypeSpec requestManager = diff --git a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/FieldUniqueIdGenerator.java b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/FieldUniqueIdGenerator.java new file mode 100644 index 0000000000..617fd636eb --- /dev/null +++ b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/FieldUniqueIdGenerator.java @@ -0,0 +1,16 @@ +package com.bumptech.glide.annotation.compiler; + +/** + * Generates unique field ids for classes generated by Glide's annotation processor. + */ +final class FieldUniqueIdGenerator { + private static int nextStaticFieldUniqueId; + + private FieldUniqueIdGenerator() { + // Utility class. + } + + static int next() { + return nextStaticFieldUniqueId++; + } +} diff --git a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideExtensionValidator.java b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideExtensionValidator.java index b69b2ac37a..f515f4378f 100644 --- a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideExtensionValidator.java +++ b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideExtensionValidator.java @@ -100,11 +100,12 @@ private void validateNewGlideOption(ExecutableElement executableElement) { validateNewGlideOptionAnnotations(executableElement); validateGlideOptionParameters(executableElement); TypeMirror returnType = executableElement.getReturnType(); - if (!isRequestOptions(returnType)) { - throw new IllegalArgumentException("@GlideOption methods should return a RequestOptions" - + " object, but " + getQualifiedMethodName(executableElement) + " returns " + returnType - + ". If you're using old style @GlideOption methods, your method may have a void return" - + " type, but doing so is deprecated and support will be removed in a future version"); + if (!isBaseRequestOptions(returnType)) { + throw new IllegalArgumentException("@GlideOption methods should return a" + + " BaseRequestOptions object, but " + getQualifiedMethodName(executableElement) + + " returns " + returnType + ". If you're using old style @GlideOption methods, your" + + " method may have a void return type, but doing so is deprecated and support will be" + + " removed in a future version"); } validateGlideOptionOverride(executableElement); } @@ -122,45 +123,45 @@ private void validateDeprecatedGlideOption(ExecutableElement executableElement) private static void validateGlideOptionParameters(ExecutableElement executableElement) { if (executableElement.getParameters().isEmpty()) { throw new IllegalArgumentException("@GlideOption methods must take a " - + "RequestOptions object as their first parameter, but " + + "BaseRequestOptions object as their first parameter, but " + getQualifiedMethodName(executableElement) + " has none"); } VariableElement first = executableElement.getParameters().get(0); TypeMirror expected = first.asType(); - if (!isRequestOptions(expected)) { + if (!isBaseRequestOptions(expected)) { throw new IllegalArgumentException("@GlideOption methods must take a" - + " RequestOptions object as their first parameter, but the first parameter in " + + " BaseRequestOptions object as their first parameter, but the first parameter in " + getQualifiedMethodName(executableElement) + " is " + expected); } } - private static boolean isRequestOptions(TypeMirror typeMirror) { - return typeMirror.toString().equals("com.bumptech.glide.request.RequestOptions"); + private static boolean isBaseRequestOptions(TypeMirror typeMirror) { + return typeMirror.toString().equals("com.bumptech.glide.request.BaseRequestOptions"); } private void validateGlideOptionOverride(ExecutableElement element) { int overrideType = processorUtil.getOverrideType(element); - boolean isOverridingRequestOptionsMethod = isMethodInRequestOptions(element); - if (isOverridingRequestOptionsMethod && overrideType == GlideOption.OVERRIDE_NONE) { + boolean isOverridingBaseRequestOptionsMethod = isMethodInBaseRequestOptions(element); + if (isOverridingBaseRequestOptionsMethod && overrideType == GlideOption.OVERRIDE_NONE) { throw new IllegalArgumentException("Accidentally attempting to override a method in" - + " RequestOptions. Add an 'override' value in the @GlideOption annotation" + + " BaseRequestOptions. Add an 'override' value in the @GlideOption annotation" + " if this is intentional. Offending method: " + getQualifiedMethodName(element)); - } else if (!isOverridingRequestOptionsMethod && overrideType != GlideOption.OVERRIDE_NONE) { + } else if (!isOverridingBaseRequestOptionsMethod && overrideType != GlideOption.OVERRIDE_NONE) { throw new IllegalArgumentException("Requested to override an existing method in" - + " RequestOptions, but no such method was found. Offending method: " + + " BaseRequestOptions, but no such method was found. Offending method: " + getQualifiedMethodName(element)); } } - private boolean isMethodInRequestOptions(ExecutableElement toFind) { + private boolean isMethodInBaseRequestOptions(ExecutableElement toFind) { // toFind is a method in a GlideExtension whose first argument is a BaseRequestOptions type. // Since we're comparing against methods in BaseRequestOptions itself, we need to drop that // first type. TypeElement requestOptionsType = processingEnvironment .getElementUtils() - .getTypeElement(RequestOptionsGenerator.REQUEST_OPTIONS_QUALIFIED_NAME); + .getTypeElement(RequestOptionsGenerator.BASE_REQUEST_OPTIONS_QUALIFIED_NAME); List toFindParameterNames = getComparableParameterNames(toFind, true /*skipFirst*/); String toFindSimpleName = toFind.getSimpleName().toString(); for (Element element : requestOptionsType.getEnclosedElements()) { diff --git a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestBuilderGenerator.java b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestBuilderGenerator.java index c110aa429b..05d958fbb8 100644 --- a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestBuilderGenerator.java +++ b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestBuilderGenerator.java @@ -7,7 +7,6 @@ import com.bumptech.glide.annotation.GlideOption; import com.google.common.base.Function; import com.google.common.base.Joiner; -import com.google.common.base.Predicate; import com.google.common.collect.FluentIterable; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; @@ -23,12 +22,8 @@ import com.squareup.javapoet.TypeVariableName; import com.squareup.javapoet.WildcardTypeName; import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; import java.util.List; import java.util.Set; -import javax.annotation.Nullable; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; @@ -113,12 +108,11 @@ final class RequestBuilderGenerator { private final ProcessingEnvironment processingEnv; private final ProcessorUtil processorUtil; - private ClassName generatedRequestBuilderClassName; + private final RequestOptionsOverrideGenerator requestOptionsOverrideGenerator; private final TypeVariableName transcodeTypeName; - private ParameterizedTypeName generatedRequestBuilderOfTranscodeType; private final TypeElement requestOptionsType; private final TypeElement requestBuilderType; - private ClassName requestOptionsClassName; + private ClassName generatedRequestBuilderClassName; RequestBuilderGenerator(ProcessingEnvironment processingEnv, ProcessorUtil processorUtil) { this.processingEnv = processingEnv; @@ -131,29 +125,28 @@ final class RequestBuilderGenerator { requestOptionsType = processingEnv.getElementUtils().getTypeElement( REQUEST_OPTIONS_QUALIFIED_NAME); + + requestOptionsOverrideGenerator = + new RequestOptionsOverrideGenerator(processingEnv, processorUtil); } - TypeSpec generate(String generatedCodePackageName, @Nullable TypeSpec generatedOptions) { + TypeSpec generate(String generatedCodePackageName, Set glideExtensionClassNames) { generatedRequestBuilderClassName = ClassName.get(generatedCodePackageName, GENERATED_REQUEST_BUILDER_SIMPLE_NAME); - generatedRequestBuilderOfTranscodeType = + ParameterizedTypeName generatedRequestBuilderOfTranscodeType = ParameterizedTypeName.get(generatedRequestBuilderClassName, transcodeTypeName); - - if (generatedOptions != null) { - requestOptionsClassName = - ClassName.get(generatedCodePackageName, generatedOptions.name); - } else { - requestOptionsClassName = - ClassName.get( - RequestOptionsGenerator.REQUEST_OPTIONS_PACKAGE_NAME, - RequestBuilderGenerator.REQUEST_OPTIONS_SIMPLE_NAME); - } + RequestOptionsExtensionGenerator requestOptionsExtensionGenerator = + new RequestOptionsExtensionGenerator(generatedRequestBuilderOfTranscodeType, processorUtil); ParameterizedTypeName requestBuilderOfTranscodeType = ParameterizedTypeName.get( ClassName.get(REQUEST_BUILDER_PACKAGE_NAME, REQUEST_BUILDER_SIMPLE_NAME), transcodeTypeName); + List requestOptionsExtensionMethods = + requestOptionsExtensionGenerator.generateInstanceMethodsForExtensions( + glideExtensionClassNames); + return TypeSpec.classBuilder(GENERATED_REQUEST_BUILDER_SIMPLE_NAME) .addJavadoc("Contains all public methods from {@link $T}, all options from\n", requestBuilderType) @@ -176,8 +169,11 @@ TypeSpec generate(String generatedCodePackageName, @Nullable TypeSpec generatedO .addSuperinterface(Cloneable.class) .addMethods(generateConstructors()) .addMethod(generateDownloadOnlyRequestMethod()) - .addMethods(generateGeneratedRequestOptionsEquivalents(generatedOptions)) + .addMethods( + requestOptionsOverrideGenerator.generateInstanceMethodOverridesForRequestOptions( + generatedRequestBuilderOfTranscodeType, EXCLUDED_METHODS_FROM_BASE_REQUEST_OPTIONS)) .addMethods(generateRequestBuilderOverrides()) + .addMethods(requestOptionsExtensionMethods) .build(); } @@ -198,6 +194,7 @@ public MethodSpec apply(ExecutableElement input) { }); } + /** * Generates an override of a particular method in {@code com.bumptech.glide.RequestBuilder} that * returns {@code com.bumptech.glide.RequestBuilder} so that it returns our generated subclass @@ -245,152 +242,6 @@ public String apply(ParameterSpec input) { return builder.build(); } - /** - * Generates methods with equivalent names and arguments to methods annotated with - * {@link GlideOption} in - * {@link com.bumptech.glide.annotation.GlideExtension}s that return our generated - * {@code com.bumptech.glide.RequestBuilder} subclass. - */ - private List generateGeneratedRequestOptionsEquivalents( - @Nullable final TypeSpec generatedOptions) { - if (generatedOptions == null) { - return Collections.emptyList(); - } - return FluentIterable - .from(generatedOptions.methodSpecs) - .filter(new Predicate() { - @Override - public boolean apply(MethodSpec input) { - return isUsefulGeneratedRequestOption(input); - } - }) - .transform(new Function() { - @Override - public MethodSpec apply(MethodSpec input) { - return generateGeneratedRequestOptionEquivalent(input); - } - }) - .toList(); - } - - /** - * Returns {@code true} if the given {@link MethodSpec} is a useful method to have in our - * {@code com.bumptech.glide.RequestBuilder} subclass. - * - *

Only newly generated methods will be included in the generated - * {@code com.bumptech.glide.request.BaseRequestBuilder} subclass, so we only have to filter out - * methods that override other methods to avoid duplicates. - */ - private boolean isUsefulGeneratedRequestOption(MethodSpec requestOptionMethod) { - return - !EXCLUDED_METHODS_FROM_BASE_REQUEST_OPTIONS.contains(requestOptionMethod.name) - && requestOptionMethod.hasModifier(Modifier.PUBLIC) - && !requestOptionMethod.hasModifier(Modifier.STATIC) - && requestOptionMethod.returnType.toString() - .equals(requestOptionsClassName.toString()); - } - - /** - * Generates a particular method with an equivalent name and arguments to the given method - * from the generated {@code com.bumptech.glide.request.BaseRequestBuilder} subclass. - */ - private MethodSpec generateGeneratedRequestOptionEquivalent(MethodSpec requestOptionMethod) { - CodeBlock callRequestOptionsMethod = CodeBlock.builder() - .add(".$N(", requestOptionMethod.name) - .add(FluentIterable.from(requestOptionMethod.parameters) - .transform(new Function() { - @Override - public String apply(ParameterSpec input) { - return input.name; - } - }) - .join(Joiner.on(", "))) - .add(");\n") - .build(); - - MethodSpec.Builder result = MethodSpec.methodBuilder(requestOptionMethod.name) - .addJavadoc( - processorUtil.generateSeeMethodJavadoc(requestOptionsClassName, requestOptionMethod)) - .addModifiers(Modifier.PUBLIC) - .varargs(requestOptionMethod.varargs) - .addAnnotations( - FluentIterable.from(requestOptionMethod.annotations) - .filter(new Predicate() { - @Override - public boolean apply(AnnotationSpec input) { - return !input.type.equals(TypeName.get(Override.class)) - // SafeVarargs can only be applied to final methods. GlideRequest is - // non-final to allow for mocking. - && !input.type.equals(TypeName.get(SafeVarargs.class)) - // We need to combine warnings below. - && !input.type.equals(TypeName.get(SuppressWarnings.class)); - } - }) - .toList() - ) - .addTypeVariables(requestOptionMethod.typeVariables) - .addParameters(requestOptionMethod.parameters) - .returns(generatedRequestBuilderOfTranscodeType) - .beginControlFlow( - "if (getMutableOptions() instanceof $T)", requestOptionsClassName) - .addCode("this.requestOptions = (($T) getMutableOptions())", - requestOptionsClassName) - .addCode(callRequestOptionsMethod) - .nextControlFlow("else") - .addCode(CodeBlock.of("this.requestOptions = new $T().apply(this.requestOptions)", - requestOptionsClassName)) - .addCode(callRequestOptionsMethod) - .endControlFlow() - .addStatement("return this"); - - AnnotationSpec suppressWarnings = buildSuppressWarnings(requestOptionMethod); - if (suppressWarnings != null) { - result.addAnnotation(suppressWarnings); - } - return result.build(); - } - - @Nullable - private AnnotationSpec buildSuppressWarnings(MethodSpec requestOptionMethod) { - Set suppressions = new HashSet<>(); - if (requestOptionMethod.annotations.contains( - AnnotationSpec.builder(SuppressWarnings.class).build())) { - for (AnnotationSpec annotation : requestOptionMethod.annotations) { - if (annotation.type.equals(TypeName.get(SuppressWarnings.class))) { - List codeBlocks = annotation.members.get("value"); - suppressions.addAll(FluentIterable.from(codeBlocks).transform( - new Function() { - @Override - public String apply(CodeBlock input) { - return input.toString(); - } - }).toSet()); - } - } - } - - if (requestOptionMethod.annotations.contains( - AnnotationSpec.builder(SafeVarargs.class).build())) { - suppressions.add("unchecked"); - suppressions.add("varargs"); - } - - if (suppressions.isEmpty()) { - return null; - } - // Enforce ordering across compilers (Internal and External compilers end up disagreeing on the - // order produced by the Set additions above.) - ArrayList suppressionsList = new ArrayList<>(suppressions); - Collections.sort(suppressionsList); - - AnnotationSpec.Builder builder = AnnotationSpec.builder(SuppressWarnings.class); - for (String suppression : suppressionsList) { - builder.addMember("value", "$S", suppression); - } - - return builder.build(); - } - private List generateConstructors() { ParameterizedTypeName classOfTranscodeType = ParameterizedTypeName.get(ClassName.get(Class.class), transcodeTypeName); diff --git a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsExtensionGenerator.java b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsExtensionGenerator.java new file mode 100644 index 0000000000..e2e1ba8b93 --- /dev/null +++ b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsExtensionGenerator.java @@ -0,0 +1,208 @@ +package com.bumptech.glide.annotation.compiler; + +import static com.bumptech.glide.annotation.GlideOption.OVERRIDE_EXTEND; +import static com.bumptech.glide.annotation.compiler.ProcessorUtil.checkResult; +import static com.bumptech.glide.annotation.compiler.ProcessorUtil.nonNull; + +import com.bumptech.glide.annotation.GlideOption; +import com.squareup.javapoet.ClassName; +import com.squareup.javapoet.CodeBlock; +import com.squareup.javapoet.MethodSpec; +import com.squareup.javapoet.ParameterSpec; +import com.squareup.javapoet.TypeName; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.VariableElement; +import javax.lang.model.type.TypeKind; + +/** + * Generates method overrides for classes that want to mix in {@link GlideOption} annotated methods + * in Glide extensions. + */ +final class RequestOptionsExtensionGenerator { + private TypeName containingClassName; + private ProcessorUtil processorUtil; + + RequestOptionsExtensionGenerator(TypeName containingClassName, ProcessorUtil processorUtil) { + this.containingClassName = containingClassName; + this.processorUtil = processorUtil; + } + + /** + * Returns the set of {@link GlideOption} annotated methods in the classes that correspond to the + * given extension class names. + */ + List getRequestOptionExtensionMethods(Set glideExtensionClassNames) { + return processorUtil.findAnnotatedElementsInClasses(glideExtensionClassNames, GlideOption.class); + } + + /** + * Returns a list containing an override {@link MethodSpec} for all {@link GlideOption} annotated + * methods in the classes that correspond to the given extension class names. + */ + List generateInstanceMethodsForExtensions(Set glideExtensionClassNames) { + List requestOptionExtensionMethods = + getRequestOptionExtensionMethods(glideExtensionClassNames); + + List result = new ArrayList<>(requestOptionExtensionMethods.size()); + for (ExecutableElement requestOptionsExtensionMethod : requestOptionExtensionMethods) { + result.add(generateMethodsForRequestOptionsExtension(requestOptionsExtensionMethod)); + } + + return result; + } + + private MethodSpec generateMethodsForRequestOptionsExtension( + ExecutableElement element) { + if (element.getReturnType().getKind() == TypeKind.VOID) { + processorUtil.warnLog( + "The " + element.getSimpleName() + " method annotated with @GlideOption in the " + + element.getEnclosingElement().getSimpleName() + " @GlideExtension is using a legacy" + + " format. Support will be removed in a future version. Please change your method" + + " definition so that your @GlideModule annotated methods return RequestOptions" + + " objects instead of null."); + return generateMethodsForRequestOptionsExtensionDeprecated(element); + } else { + return generateMethodsForRequestOptionsExtensionNew(element); + } + } + + private MethodSpec generateMethodsForRequestOptionsExtensionNew( + ExecutableElement element) { + int overrideType = processorUtil.getOverrideType(element); + + String methodName = element.getSimpleName().toString(); + MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName) + .addModifiers(Modifier.PUBLIC) + .addJavadoc(processorUtil.generateSeeMethodJavadoc(element)) + .varargs(element.isVarArgs()) + .returns(containingClassName); + + // The 0th element is expected to be a RequestOptions object. + List paramElements = + element.getParameters().subList(1, element.getParameters().size()); + List parameters = ProcessorUtil.getParameters(paramElements); + builder.addParameters(parameters); + + String extensionRequestOptionsArgument; + if (overrideType == OVERRIDE_EXTEND) { + builder + .addJavadoc( + processorUtil.generateSeeMethodJavadoc( + containingClassName, methodName, paramElements)) + .addAnnotation(Override.class); + + List methodArgs = new ArrayList<>(); + methodArgs.add(element.getSimpleName().toString()); + StringBuilder methodLiterals = new StringBuilder(); + if (!parameters.isEmpty()) { + for (ParameterSpec parameter : parameters) { + methodLiterals.append("$L, "); + methodArgs.add(parameter.name); + } + methodLiterals = new StringBuilder( + methodLiterals.substring(0, methodLiterals.length() - 2)); + } + extensionRequestOptionsArgument = CodeBlock.builder() + .add("super.$N(" + methodLiterals + ")", methodArgs.toArray(new Object[0])) + .build() + .toString(); + } else { + extensionRequestOptionsArgument = "this"; + } + + List args = new ArrayList<>(); + StringBuilder code = new StringBuilder("return ($T) $T.$L($L, "); + args.add(containingClassName); + args.add(ClassName.get(element.getEnclosingElement().asType())); + args.add(element.getSimpleName().toString()); + args.add(extensionRequestOptionsArgument); + if (!parameters.isEmpty()) { + for (ParameterSpec parameter : parameters) { + code.append("$L, "); + args.add(parameter.name); + } + } + code = new StringBuilder(code.substring(0, code.length() - 2)); + code.append(")"); + builder.addStatement(code.toString(), args.toArray(new Object[0])); + + builder + .addAnnotation(checkResult()) + .addAnnotation(nonNull()); + + return builder.build(); + } + + private MethodSpec generateMethodsForRequestOptionsExtensionDeprecated( + ExecutableElement element) { + int overrideType = processorUtil.getOverrideType(element); + + String methodName = element.getSimpleName().toString(); + MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName) + .addModifiers(Modifier.PUBLIC) + .addJavadoc(processorUtil.generateSeeMethodJavadoc(element)) + .varargs(element.isVarArgs()) + .returns(containingClassName); + + // The 0th element is expected to be a RequestOptions object. + List paramElements = + element.getParameters().subList(1, element.getParameters().size()); + List parameters = ProcessorUtil.getParameters(paramElements); + builder.addParameters(parameters); + + // Generates the String and list of arguments to pass in when calling this method or super. + // IE centerCrop(context) creates methodLiterals="%L" and methodArgs=[centerCrop, context]. + List methodArgs = new ArrayList<>(); + methodArgs.add(element.getSimpleName().toString()); + StringBuilder methodLiterals = new StringBuilder(); + if (!parameters.isEmpty()) { + for (ParameterSpec parameter : parameters) { + methodLiterals.append("$L, "); + methodArgs.add(parameter.name); + } + methodLiterals = new StringBuilder(methodLiterals.substring(0, methodLiterals.length() - 2)); + } + + builder.beginControlFlow("if (isAutoCloneEnabled())") + .addStatement( + "return clone().$N(" + methodLiterals + ")", methodArgs.toArray(new Object[0])) + .endControlFlow(); + + // Add the correct super() call. + if (overrideType == OVERRIDE_EXTEND) { + String callSuper = "super.$L(" + methodLiterals + ")"; + builder.addStatement(callSuper, methodArgs.toArray(new Object[0])) + .addJavadoc( + processorUtil.generateSeeMethodJavadoc( + containingClassName, methodName, paramElements)) + .addAnnotation(Override.class); + } + + // Adds: .(RequestOptions, , , ); + List args = new ArrayList<>(); + StringBuilder code = new StringBuilder("$T.$L($L, "); + args.add(ClassName.get(element.getEnclosingElement().asType())); + args.add(element.getSimpleName().toString()); + args.add("this"); + if (!parameters.isEmpty()) { + for (ParameterSpec parameter : parameters) { + code.append("$L, "); + args.add(parameter.name); + } + } + code = new StringBuilder(code.substring(0, code.length() - 2)); + code.append(")"); + builder.addStatement(code.toString(), args.toArray(new Object[0])); + + builder.addStatement("return this") + .addAnnotation(checkResult()) + .addAnnotation(nonNull()); + + return builder.build(); + } + +} diff --git a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsGenerator.java b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsGenerator.java index 3697aeaeed..33caa07841 100644 --- a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsGenerator.java +++ b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsGenerator.java @@ -1,13 +1,11 @@ package com.bumptech.glide.annotation.compiler; -import static com.bumptech.glide.annotation.GlideOption.OVERRIDE_EXTEND; import static com.bumptech.glide.annotation.compiler.ProcessorUtil.checkResult; import static com.bumptech.glide.annotation.compiler.ProcessorUtil.nonNull; import com.bumptech.glide.annotation.GlideExtension; import com.bumptech.glide.annotation.GlideOption; import com.google.common.base.Function; -import com.google.common.base.Joiner; import com.google.common.base.Objects; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -30,13 +28,11 @@ import java.util.Set; import javax.annotation.Nullable; import javax.annotation.processing.ProcessingEnvironment; -import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.Modifier; import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeParameterElement; import javax.lang.model.element.VariableElement; -import javax.lang.model.type.TypeKind; /** * Generates a new implementation of {@code com.bumptech.glide.request.RequestOptions} @@ -73,21 +69,24 @@ */ final class RequestOptionsGenerator { private static final String GENERATED_REQUEST_OPTIONS_SIMPLE_NAME = "GlideOptions"; - static final String REQUEST_OPTIONS_PACKAGE_NAME = "com.bumptech.glide.request"; + private static final String REQUEST_OPTIONS_PACKAGE_NAME = "com.bumptech.glide.request"; private static final String REQUEST_OPTIONS_SIMPLE_NAME = "RequestOptions"; static final String REQUEST_OPTIONS_QUALIFIED_NAME = REQUEST_OPTIONS_PACKAGE_NAME + "." + REQUEST_OPTIONS_SIMPLE_NAME; - private final ProcessingEnvironment processingEnvironment; + private static final String BASE_REQUEST_OPTIONS_SIMPLE_NAME = "BaseRequestOptions"; + static final String BASE_REQUEST_OPTIONS_QUALIFIED_NAME = + REQUEST_OPTIONS_PACKAGE_NAME + "." + BASE_REQUEST_OPTIONS_SIMPLE_NAME; + private final ClassName requestOptionsName; private final TypeElement requestOptionsType; private final ProcessorUtil processorUtil; + private final RequestOptionsOverrideGenerator requestOptionsOverrideGenerator; + private ClassName glideOptionsName; - private int nextStaticFieldUniqueId; RequestOptionsGenerator( ProcessingEnvironment processingEnvironment, ProcessorUtil processorUtil) { - this.processingEnvironment = processingEnvironment; this.processorUtil = processorUtil; requestOptionsName = ClassName.get(REQUEST_OPTIONS_PACKAGE_NAME, @@ -95,19 +94,48 @@ final class RequestOptionsGenerator { requestOptionsType = processingEnvironment.getElementUtils().getTypeElement( REQUEST_OPTIONS_QUALIFIED_NAME); + + requestOptionsOverrideGenerator = + new RequestOptionsOverrideGenerator(processingEnvironment, processorUtil); } TypeSpec generate(String generatedCodePackageName, Set glideExtensionClassNames) { glideOptionsName = ClassName.get(generatedCodePackageName, GENERATED_REQUEST_OPTIONS_SIMPLE_NAME); - List methodsForExtensions = - generateMethodsForExtensions(glideExtensionClassNames); + RequestOptionsExtensionGenerator requestOptionsExtensionGenerator = + new RequestOptionsExtensionGenerator(glideOptionsName, processorUtil); + List instanceMethodsForExtensions = + FluentIterable.from( + requestOptionsExtensionGenerator + .generateInstanceMethodsForExtensions(glideExtensionClassNames)) + .transform(new Function() { + @Override + public MethodAndStaticVar apply(MethodSpec input) { + return new MethodAndStaticVar(input); + } + }) + .toList(); + List staticMethodsForExtensions = + FluentIterable.from( + requestOptionsExtensionGenerator.getRequestOptionExtensionMethods( + glideExtensionClassNames)) + .transform(new Function() { + @Override + public MethodAndStaticVar apply(ExecutableElement input) { + return generateStaticMethodEquivalentForExtensionMethod(input); + } + }) + .toList(); + + List methodsForExtensions = new ArrayList<>(); + methodsForExtensions.addAll(instanceMethodsForExtensions); + methodsForExtensions.addAll(staticMethodsForExtensions); - Set extensionMethodSignatures = ImmutableSet.copyOf( - Iterables.transform(methodsForExtensions, - new Function() { - @Nullable + Set extensionMethodSignatures = + ImmutableSet.copyOf( + Iterables.transform(methodsForExtensions, + new Function() { @Override public MethodSignature apply(MethodAndStaticVar f) { return new MethodSignature(f.method); @@ -115,7 +143,9 @@ public MethodSignature apply(MethodAndStaticVar f) { })); List staticOverrides = generateStaticMethodOverridesForRequestOptions(); - List instanceOverrides = generateInstanceMethodOverridesForRequestOptions(); + List instanceOverrides = + requestOptionsOverrideGenerator.generateInstanceMethodOverridesForRequestOptions( + glideOptionsName); List allMethodsAndStaticVars = new ArrayList<>(); for (MethodAndStaticVar item : staticOverrides) { @@ -167,226 +197,6 @@ private CodeBlock generateClassJavadoc(Set glideExtensionClassNames) { return builder.build(); } - private List generateMethodsForExtensions( - Set glideExtensionClassNames) { - List requestOptionExtensionMethods = - processorUtil.findAnnotatedElementsInClasses( - glideExtensionClassNames, GlideOption.class); - - List result = new ArrayList<>(requestOptionExtensionMethods.size()); - for (ExecutableElement requestOptionsExtensionMethod : requestOptionExtensionMethods) { - result.addAll(generateMethodsForRequestOptionsExtension(requestOptionsExtensionMethod)); - } - - return result; - } - - private List generateInstanceMethodOverridesForRequestOptions() { - return Lists.transform( - processorUtil.findInstanceMethodsReturning(requestOptionsType, requestOptionsType), - new Function() { - @Override - public MethodSpec apply(ExecutableElement input) { - return generateRequestOptionOverride(input); - } - }); - } - - private MethodSpec generateRequestOptionOverride(ExecutableElement methodToOverride) { - MethodSpec.Builder result = ProcessorUtil.overriding(methodToOverride) - .returns(glideOptionsName) - .addModifiers(Modifier.FINAL); - result.addCode(CodeBlock.builder() - .add("return ($T) super.$N(", glideOptionsName, methodToOverride.getSimpleName()) - .add(FluentIterable.from(result.build().parameters) - .transform(new Function() { - @Override - public String apply(ParameterSpec input) { - return input.name; - } - }) - .join(Joiner.on(", "))) - .add(");\n") - .build()); - - if (methodToOverride.getSimpleName().toString().equals("transforms")) { - result - .addAnnotation(SafeVarargs.class) - .addAnnotation( - AnnotationSpec.builder(SuppressWarnings.class) - .addMember("value", "$S", "varargs") - .build()); - } - - for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) { - result.addAnnotation(AnnotationSpec.get(mirror)); - } - - return result.build(); - } - - private List generateMethodsForRequestOptionsExtension( - ExecutableElement element) { - if (element.getReturnType().getKind() == TypeKind.VOID) { - processorUtil.warnLog( - "The " + element.getSimpleName() + " method annotated with @GlideOption in the " - + element.getEnclosingElement().getSimpleName() + " @GlideExtension is using a legacy" - + " format. Support will be removed in a future version. Please change your method" - + " definition so that your @GlideModule annotated methods return RequestOptions" - + " objects instead of null."); - return generateMethodsForRequestOptionsExtensionDeprecated(element); - } else { - return generateMethodsForRequestOptionsExtensionNew(element); - } - } - - private List generateMethodsForRequestOptionsExtensionNew( - ExecutableElement element) { - int overrideType = processorUtil.getOverrideType(element); - - String methodName = element.getSimpleName().toString(); - MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName) - .addModifiers(Modifier.PUBLIC) - .addJavadoc(processorUtil.generateSeeMethodJavadoc(element)) - .varargs(element.isVarArgs()) - .returns(glideOptionsName); - - // The 0th element is expected to be a RequestOptions object. - List paramElements = - element.getParameters().subList(1, element.getParameters().size()); - List parameters = ProcessorUtil.getParameters(paramElements); - builder.addParameters(parameters); - - String extensionRequestOptionsArgument; - if (overrideType == OVERRIDE_EXTEND) { - builder - .addJavadoc( - processorUtil.generateSeeMethodJavadoc(requestOptionsName, methodName, paramElements)) - .addAnnotation(Override.class); - - List methodArgs = new ArrayList<>(); - methodArgs.add(element.getSimpleName().toString()); - StringBuilder methodLiterals = new StringBuilder(); - if (!parameters.isEmpty()) { - for (ParameterSpec parameter : parameters) { - methodLiterals.append("$L, "); - methodArgs.add(parameter.name); - } - methodLiterals = new StringBuilder( - methodLiterals.substring(0, methodLiterals.length() - 2)); - } - extensionRequestOptionsArgument = CodeBlock.builder() - .add("super.$N(" + methodLiterals + ")", methodArgs.toArray(new Object[0])) - .build() - .toString(); - } else { - extensionRequestOptionsArgument = "this"; - } - - List args = new ArrayList<>(); - StringBuilder code = new StringBuilder("return ($T) $T.$L($L, "); - args.add(glideOptionsName); - args.add(ClassName.get(element.getEnclosingElement().asType())); - args.add(element.getSimpleName().toString()); - args.add(extensionRequestOptionsArgument); - if (!parameters.isEmpty()) { - for (ParameterSpec parameter : parameters) { - code.append("$L, "); - args.add(parameter.name); - } - } - code = new StringBuilder(code.substring(0, code.length() - 2)); - code.append(")"); - builder.addStatement(code.toString(), args.toArray(new Object[0])); - - builder - .addAnnotation(checkResult()) - .addAnnotation(nonNull()); - - List result = new ArrayList<>(); - result.add(new MethodAndStaticVar(builder.build())); - MethodAndStaticVar methodAndVar = generateStaticMethodEquivalentForExtensionMethod(element); - if (methodAndVar != null) { - result.add(methodAndVar); - } - - return result; - } - - private List generateMethodsForRequestOptionsExtensionDeprecated( - ExecutableElement element) { - int overrideType = processorUtil.getOverrideType(element); - - String methodName = element.getSimpleName().toString(); - MethodSpec.Builder builder = MethodSpec.methodBuilder(methodName) - .addModifiers(Modifier.PUBLIC) - .addJavadoc(processorUtil.generateSeeMethodJavadoc(element)) - .varargs(element.isVarArgs()) - .returns(glideOptionsName); - - // The 0th element is expected to be a RequestOptions object. - List paramElements = - element.getParameters().subList(1, element.getParameters().size()); - List parameters = ProcessorUtil.getParameters(paramElements); - builder.addParameters(parameters); - - // Generates the String and list of arguments to pass in when calling this method or super. - // IE centerCrop(context) creates methodLiterals="%L" and methodArgs=[centerCrop, context]. - List methodArgs = new ArrayList<>(); - methodArgs.add(element.getSimpleName().toString()); - StringBuilder methodLiterals = new StringBuilder(); - if (!parameters.isEmpty()) { - for (ParameterSpec parameter : parameters) { - methodLiterals.append("$L, "); - methodArgs.add(parameter.name); - } - methodLiterals = new StringBuilder(methodLiterals.substring(0, methodLiterals.length() - 2)); - } - - builder.beginControlFlow("if (isAutoCloneEnabled())") - .addStatement( - "return clone().$N(" + methodLiterals + ")", methodArgs.toArray(new Object[0])) - .endControlFlow(); - - // Add the correct super() call. - if (overrideType == OVERRIDE_EXTEND) { - String callSuper = "super.$L(" + methodLiterals + ")"; - builder.addStatement(callSuper, methodArgs.toArray(new Object[0])) - .addJavadoc(processorUtil.generateSeeMethodJavadoc( - requestOptionsName, methodName, paramElements)) - .addAnnotation(Override.class); - } - - // Adds: .(RequestOptions, , , ); - List args = new ArrayList<>(); - StringBuilder code = new StringBuilder("$T.$L($L, "); - args.add(ClassName.get(element.getEnclosingElement().asType())); - args.add(element.getSimpleName().toString()); - args.add("this"); - if (!parameters.isEmpty()) { - for (ParameterSpec parameter : parameters) { - code.append("$L, "); - args.add(parameter.name); - } - } - code = new StringBuilder(code.substring(0, code.length() - 2)); - code.append(")"); - builder.addStatement(code.toString(), args.toArray(new Object[0])); - - builder.addStatement("return this") - .addAnnotation(checkResult()) - .addAnnotation(nonNull()); - - List result = new ArrayList<>(); - result.add(new MethodAndStaticVar(builder.build())); - MethodAndStaticVar methodAndVar = generateStaticMethodEquivalentForExtensionMethod(element); - if (methodAndVar != null) { - result.add(methodAndVar); - } - - return result; - } - private List generateStaticMethodOverridesForRequestOptions() { List staticMethodsThatReturnRequestOptions = processorUtil.findStaticMethodsReturning(requestOptionsType, requestOptionsType); @@ -457,7 +267,7 @@ private MethodAndStaticVar generateStaticMethodEquivalentForRequestOptionsStatic // } // Mix in an incrementing unique id to handle method overloading. - String staticVariableName = staticMethodName + nextStaticFieldUniqueId++; + String staticVariableName = staticMethodName + FieldUniqueIdGenerator.next(); requiredStaticField = FieldSpec.builder(glideOptionsName, staticVariableName) .addModifiers(Modifier.PRIVATE, Modifier.STATIC) .build(); @@ -495,6 +305,32 @@ private static boolean memoizeStaticMethodFromArguments(ExecutableElement static .equals("android.content.Context")); } + private StringBuilder createNewOptionAndCall(boolean memoize, + MethodSpec.Builder methodSpecBuilder, + String start, List specs) { + StringBuilder createNewOptionAndCall = new StringBuilder(start); + if (!specs.isEmpty()) { + methodSpecBuilder.addParameters(specs); + for (ParameterSpec parameter : specs) { + createNewOptionAndCall.append(parameter.name); + // use the Application Context to avoid memory leaks. + if (memoize && isAndroidContext(parameter)) { + createNewOptionAndCall.append(".getApplicationContext()"); + } + createNewOptionAndCall.append(", "); + } + createNewOptionAndCall = new StringBuilder( + createNewOptionAndCall.substring(0, createNewOptionAndCall.length() - 2)); + } + createNewOptionAndCall.append(")"); + return createNewOptionAndCall; + } + + private boolean isAndroidContext(ParameterSpec parameter) { + return parameter.type.toString().equals("android.content.Context"); + } + + @Nullable private MethodAndStaticVar generateStaticMethodEquivalentForExtensionMethod( ExecutableElement instanceMethod) { @@ -544,7 +380,7 @@ private MethodAndStaticVar generateStaticMethodEquivalentForExtensionMethod( // } // Mix in an incrementing unique id to handle method overloading. - String staticVariableName = staticMethodName + nextStaticFieldUniqueId++; + String staticVariableName = staticMethodName + FieldUniqueIdGenerator.next(); requiredStaticField = FieldSpec.builder(glideOptionsName, staticVariableName) .addModifiers(Modifier.PRIVATE, Modifier.STATIC) .build(); @@ -573,31 +409,6 @@ private MethodAndStaticVar generateStaticMethodEquivalentForExtensionMethod( return new MethodAndStaticVar(methodSpecBuilder.build(), requiredStaticField); } - private StringBuilder createNewOptionAndCall(boolean memoize, - MethodSpec.Builder methodSpecBuilder, - String start, List specs) { - StringBuilder createNewOptionAndCall = new StringBuilder(start); - if (!specs.isEmpty()) { - methodSpecBuilder.addParameters(specs); - for (ParameterSpec parameter : specs) { - createNewOptionAndCall.append(parameter.name); - // use the Application Context to avoid memory leaks. - if (memoize && isAndroidContext(parameter)) { - createNewOptionAndCall.append(".getApplicationContext()"); - } - createNewOptionAndCall.append(", "); - } - createNewOptionAndCall = new StringBuilder( - createNewOptionAndCall.substring(0, createNewOptionAndCall.length() - 2)); - } - createNewOptionAndCall.append(")"); - return createNewOptionAndCall; - } - - private boolean isAndroidContext(ParameterSpec parameter) { - return parameter.type.toString().equals("android.content.Context"); - } - @Nullable private static String getStaticMethodName(ExecutableElement element) { GlideOption glideOption = @@ -648,7 +459,6 @@ private static final class MethodSignature { @Override public TypeName apply(ParameterSpec parameterSpec) { return parameterSpec.type; - } }); } diff --git a/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsOverrideGenerator.java b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsOverrideGenerator.java new file mode 100644 index 0000000000..065ac564fe --- /dev/null +++ b/annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsOverrideGenerator.java @@ -0,0 +1,105 @@ +package com.bumptech.glide.annotation.compiler; + +import static com.bumptech.glide.annotation.compiler.RequestOptionsGenerator.BASE_REQUEST_OPTIONS_QUALIFIED_NAME; + +import com.google.common.base.Function; +import com.google.common.base.Joiner; +import com.google.common.base.Predicate; +import com.google.common.collect.FluentIterable; +import com.squareup.javapoet.AnnotationSpec; +import com.squareup.javapoet.CodeBlock; +import com.squareup.javapoet.MethodSpec; +import com.squareup.javapoet.ParameterSpec; +import com.squareup.javapoet.TypeName; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import javax.annotation.processing.ProcessingEnvironment; +import javax.lang.model.element.AnnotationMirror; +import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.Modifier; +import javax.lang.model.element.TypeElement; + +/** + * Generates overrides for BaseRequestOptions methods so that subclasses' methods return the + * subclass type, not just BaseRequestOptions. + */ +final class RequestOptionsOverrideGenerator { + + private final TypeElement baseRequestOptionsType; + private ProcessorUtil processorUtil; + + RequestOptionsOverrideGenerator( + ProcessingEnvironment processingEnv, ProcessorUtil processorUtil) { + + this.processorUtil = processorUtil; + baseRequestOptionsType = processingEnv.getElementUtils().getTypeElement( + BASE_REQUEST_OPTIONS_QUALIFIED_NAME); + } + + List generateInstanceMethodOverridesForRequestOptions(TypeName typeToOverrideIn) { + return generateInstanceMethodOverridesForRequestOptions( + typeToOverrideIn, Collections.emptySet()); + } + + List generateInstanceMethodOverridesForRequestOptions( + final TypeName typeToOverrideIn, final Set excludedMethods) { + return + FluentIterable.from( + processorUtil.findInstanceMethodsReturning( + baseRequestOptionsType, baseRequestOptionsType)) + .filter(new Predicate() { + @Override + public boolean apply(ExecutableElement input) { + return !excludedMethods.contains(input.getSimpleName().toString()); + } + }) + .transform( + new Function() { + @Override + public MethodSpec apply(ExecutableElement input) { + return generateRequestOptionOverride(typeToOverrideIn, input); + } + }) + .toList(); + } + + private MethodSpec generateRequestOptionOverride( + TypeName typeToOverrideIn, ExecutableElement methodToOverride) { + MethodSpec.Builder result = + ProcessorUtil.overriding(methodToOverride) + .returns(typeToOverrideIn); + result.addCode( + CodeBlock.builder() + .add( + "return ($T) super.$N(", + typeToOverrideIn, + methodToOverride.getSimpleName()) + .add(FluentIterable.from(result.build().parameters) + .transform(new Function() { + @Override + public String apply(ParameterSpec input) { + return input.name; + } + }) + .join(Joiner.on(", "))) + .add(");\n") + .build()); + + if (methodToOverride.getSimpleName().toString().equals("transforms")) { + result + .addModifiers(Modifier.FINAL) + .addAnnotation(SafeVarargs.class) + .addAnnotation( + AnnotationSpec.builder(SuppressWarnings.class) + .addMember("value", "$S", "varargs") + .build()); + } + + for (AnnotationMirror mirror : methodToOverride.getAnnotationMirrors()) { + result.addAnnotation(AnnotationSpec.get(mirror)); + } + + return result.build(); + } +} diff --git a/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideOptions.java b/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideOptions.java index 6c2f592f19..b6441aab35 100644 --- a/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -429,8 +430,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -571,16 +572,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -601,7 +602,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideRequest.java b/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideRequest.java index 9536fe2304..46784109cb 100644 --- a/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/EmptyAppGlideModuleTest/GlideRequest.java @@ -23,8 +23,8 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.RequestOptions; import java.io.File; import java.lang.Class; import java.lang.Cloneable; @@ -39,14 +39,14 @@ /** * Contains all public methods from {@link RequestBuilder}, all options from - * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.request.RequestOptions} and all generated options from * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. * *

Generated code, do not modify. * * @see RequestBuilder - * @see RequestOptions + * @see com.bumptech.glide.request.RequestOptions */ @SuppressWarnings({ "unused", @@ -69,590 +69,301 @@ protected GlideRequest getDownloadOnlyRequest() { return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); } - /** - * @see GlideOptions#sizeMultiplier(float) - */ + @Override @NonNull @CheckResult - public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(value); - } - return this; + public final GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { + return (GlideRequest) super.sizeMultiplier(value); } - /** - * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); - } - return this; + public final GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideRequest) super.useUnlimitedSourceGeneratorsPool(flag); } - /** - * @see GlideOptions#useAnimationPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useAnimationPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); - } - return this; + public final GlideRequest useAnimationPool(boolean flag) { + return (GlideRequest) super.useAnimationPool(flag); } - /** - * @see GlideOptions#onlyRetrieveFromCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest onlyRetrieveFromCache(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); - } - return this; + public final GlideRequest onlyRetrieveFromCache(boolean flag) { + return (GlideRequest) super.onlyRetrieveFromCache(flag); } - /** - * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(strategy); - } - return this; + public final GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { + return (GlideRequest) super.diskCacheStrategy(strategy); } - /** - * @see GlideOptions#priority(Priority) - */ + @Override @NonNull @CheckResult - public GlideRequest priority(@NonNull Priority priority) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).priority(priority); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(priority); - } - return this; + public final GlideRequest priority(@NonNull Priority priority) { + return (GlideRequest) super.priority(priority); } - /** - * @see GlideOptions#placeholder(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(drawable); - } - return this; + public final GlideRequest placeholder(@Nullable Drawable drawable) { + return (GlideRequest) super.placeholder(drawable); } - /** - * @see GlideOptions#placeholder(int) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(id); - } - return this; + public final GlideRequest placeholder(@DrawableRes int id) { + return (GlideRequest) super.placeholder(id); } - /** - * @see GlideOptions#fallback(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(drawable); - } - return this; + public final GlideRequest fallback(@Nullable Drawable drawable) { + return (GlideRequest) super.fallback(drawable); } - /** - * @see GlideOptions#fallback(int) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(id); - } - return this; + public final GlideRequest fallback(@DrawableRes int id) { + return (GlideRequest) super.fallback(id); } - /** - * @see GlideOptions#error(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(drawable); - } - return this; + public final GlideRequest error(@Nullable Drawable drawable) { + return (GlideRequest) super.error(drawable); } - /** - * @see GlideOptions#error(int) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(id); - } - return this; + public final GlideRequest error(@DrawableRes int id) { + return (GlideRequest) super.error(id); } - /** - * @see GlideOptions#theme(Resources.Theme) - */ + @Override @NonNull @CheckResult - public GlideRequest theme(@Nullable Resources.Theme theme) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).theme(theme); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(theme); - } - return this; + public final GlideRequest theme(@Nullable Resources.Theme theme) { + return (GlideRequest) super.theme(theme); } - /** - * @see GlideOptions#skipMemoryCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest skipMemoryCache(boolean skip) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); - } - return this; + public final GlideRequest skipMemoryCache(boolean skip) { + return (GlideRequest) super.skipMemoryCache(skip); } - /** - * @see GlideOptions#override(int, int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int width, int height) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); - } - return this; + public final GlideRequest override(int width, int height) { + return (GlideRequest) super.override(width, height); } - /** - * @see GlideOptions#override(int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int size) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); - } - return this; + public final GlideRequest override(int size) { + return (GlideRequest) super.override(size); } - /** - * @see GlideOptions#signature(Key) - */ + @Override @NonNull @CheckResult - public GlideRequest signature(@NonNull Key key) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).signature(key); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(key); - } - return this; + public final GlideRequest signature(@NonNull Key key) { + return (GlideRequest) super.signature(key); } - /** - * @see GlideOptions#set(Option, T) - */ + @Override @NonNull @CheckResult - public GlideRequest set(@NonNull Option option, @NonNull T t) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).set(option, t); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).set(option, t); - } - return this; + public final GlideRequest set(@NonNull Option option, @NonNull Y y) { + return (GlideRequest) super.set(option, y); } - /** - * @see GlideOptions#decode(Class) - */ + @Override @NonNull @CheckResult - public GlideRequest decode(@NonNull Class clazz) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).decode(clazz); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(clazz); - } - return this; + public final GlideRequest decode(@NonNull Class clazz) { + return (GlideRequest) super.decode(clazz); } - /** - * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(format); - } - return this; + public final GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { + return (GlideRequest) super.encodeFormat(format); } - /** - * @see GlideOptions#encodeQuality(int) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(value); - } - return this; + public final GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { + return (GlideRequest) super.encodeQuality(value); } - /** - * @see GlideOptions#frame(long) - */ + @Override @NonNull @CheckResult - public GlideRequest frame(@IntRange(from = 0) long value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).frame(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(value); - } - return this; + public final GlideRequest frame(@IntRange(from = 0) long value) { + return (GlideRequest) super.frame(value); } - /** - * @see GlideOptions#format(DecodeFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest format(@NonNull DecodeFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).format(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).format(format); - } - return this; + public final GlideRequest format(@NonNull DecodeFormat format) { + return (GlideRequest) super.format(format); } - /** - * @see GlideOptions#disallowHardwareConfig() - */ + @Override @NonNull @CheckResult - public GlideRequest disallowHardwareConfig() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); - } - return this; + public final GlideRequest disallowHardwareConfig() { + return (GlideRequest) super.disallowHardwareConfig(); } - /** - * @see GlideOptions#downsample(DownsampleStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest downsample(@NonNull DownsampleStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(strategy); - } - return this; + public final GlideRequest downsample(@NonNull DownsampleStrategy strategy) { + return (GlideRequest) super.downsample(strategy); } - /** - * @see GlideOptions#timeout(int) - */ + @Override @NonNull @CheckResult - public GlideRequest timeout(@IntRange(from = 0) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(value); - } - return this; + public final GlideRequest timeout(@IntRange(from = 0) int value) { + return (GlideRequest) super.timeout(value); } - /** - * @see GlideOptions#optionalCenterCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); - } - return this; + public final GlideRequest optionalCenterCrop() { + return (GlideRequest) super.optionalCenterCrop(); } - /** - * @see GlideOptions#centerCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest centerCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); - } - return this; + public final GlideRequest centerCrop() { + return (GlideRequest) super.centerCrop(); } - /** - * @see GlideOptions#optionalFitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalFitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); - } - return this; + public final GlideRequest optionalFitCenter() { + return (GlideRequest) super.optionalFitCenter(); } - /** - * @see GlideOptions#fitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest fitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); - } - return this; + public final GlideRequest fitCenter() { + return (GlideRequest) super.fitCenter(); } - /** - * @see GlideOptions#optionalCenterInside() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); - } - return this; + public final GlideRequest optionalCenterInside() { + return (GlideRequest) super.optionalCenterInside(); } - /** - * @see GlideOptions#centerInside() - */ + @Override @NonNull @CheckResult - public GlideRequest centerInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); - } - return this; + public final GlideRequest centerInside() { + return (GlideRequest) super.centerInside(); } - /** - * @see GlideOptions#optionalCircleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCircleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); - } - return this; + public final GlideRequest optionalCircleCrop() { + return (GlideRequest) super.optionalCircleCrop(); } - /** - * @see GlideOptions#circleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest circleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); - } - return this; + public final GlideRequest circleCrop() { + return (GlideRequest) super.circleCrop(); } - /** - * @see GlideOptions#transform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(transformation); - } - return this; + public final GlideRequest transform(@NonNull Transformation transformation) { + return (GlideRequest) super.transform(transformation); } - /** - * @see GlideOptions#transforms(Transformation[]) - */ + @Override + @SafeVarargs + @SuppressWarnings("varargs") @NonNull @CheckResult - @SuppressWarnings({ - "unchecked", - "varargs" - }) - public GlideRequest transforms(@NonNull Transformation... transformations) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(transformations); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(transformations); - } - return this; + public final GlideRequest transforms(@NonNull Transformation... transformations) { + return (GlideRequest) super.transforms(transformations); } - /** - * @see GlideOptions#optionalTransform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(transformation); } - /** - * @see GlideOptions#optionalTransform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(clazz, transformation); } - /** - * @see GlideOptions#transform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(clazz, transformation); - } - return this; + public final GlideRequest transform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.transform(clazz, transformation); } - /** - * @see GlideOptions#dontTransform() - */ + @Override @NonNull @CheckResult - public GlideRequest dontTransform() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); - } - return this; + public final GlideRequest dontTransform() { + return (GlideRequest) super.dontTransform(); } - /** - * @see GlideOptions#dontAnimate() - */ + @Override @NonNull @CheckResult - public GlideRequest dontAnimate() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); - } - return this; + public final GlideRequest dontAnimate() { + return (GlideRequest) super.dontAnimate(); } @Override @NonNull @CheckResult - public GlideRequest apply(@NonNull RequestOptions options) { + public GlideRequest apply(@NonNull BaseRequestOptions options) { return (GlideRequest) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java index 90fe262f38..845d05e987 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -432,8 +433,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -574,16 +575,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -604,7 +605,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java index f0377a0a7c..46784109cb 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java @@ -23,8 +23,8 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.RequestOptions; import java.io.File; import java.lang.Class; import java.lang.Cloneable; @@ -39,14 +39,14 @@ /** * Contains all public methods from {@link RequestBuilder}, all options from - * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.request.RequestOptions} and all generated options from * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. * *

Generated code, do not modify. * * @see RequestBuilder - * @see RequestOptions + * @see com.bumptech.glide.request.RequestOptions */ @SuppressWarnings({ "unused", @@ -69,604 +69,301 @@ protected GlideRequest getDownloadOnlyRequest() { return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); } - /** - * @see GlideOptions#sizeMultiplier(float) - */ + @Override @NonNull @CheckResult - public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(value); - } - return this; + public final GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { + return (GlideRequest) super.sizeMultiplier(value); } - /** - * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); - } - return this; + public final GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideRequest) super.useUnlimitedSourceGeneratorsPool(flag); } - /** - * @see GlideOptions#useAnimationPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useAnimationPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); - } - return this; + public final GlideRequest useAnimationPool(boolean flag) { + return (GlideRequest) super.useAnimationPool(flag); } - /** - * @see GlideOptions#onlyRetrieveFromCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest onlyRetrieveFromCache(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); - } - return this; + public final GlideRequest onlyRetrieveFromCache(boolean flag) { + return (GlideRequest) super.onlyRetrieveFromCache(flag); } - /** - * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(strategy); - } - return this; + public final GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { + return (GlideRequest) super.diskCacheStrategy(strategy); } - /** - * @see GlideOptions#priority(Priority) - */ + @Override @NonNull @CheckResult - public GlideRequest priority(@NonNull Priority priority) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).priority(priority); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(priority); - } - return this; + public final GlideRequest priority(@NonNull Priority priority) { + return (GlideRequest) super.priority(priority); } - /** - * @see GlideOptions#placeholder(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(drawable); - } - return this; + public final GlideRequest placeholder(@Nullable Drawable drawable) { + return (GlideRequest) super.placeholder(drawable); } - /** - * @see GlideOptions#placeholder(int) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(id); - } - return this; + public final GlideRequest placeholder(@DrawableRes int id) { + return (GlideRequest) super.placeholder(id); } - /** - * @see GlideOptions#fallback(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(drawable); - } - return this; + public final GlideRequest fallback(@Nullable Drawable drawable) { + return (GlideRequest) super.fallback(drawable); } - /** - * @see GlideOptions#fallback(int) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(id); - } - return this; + public final GlideRequest fallback(@DrawableRes int id) { + return (GlideRequest) super.fallback(id); } - /** - * @see GlideOptions#error(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(drawable); - } - return this; + public final GlideRequest error(@Nullable Drawable drawable) { + return (GlideRequest) super.error(drawable); } - /** - * @see GlideOptions#error(int) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(id); - } - return this; + public final GlideRequest error(@DrawableRes int id) { + return (GlideRequest) super.error(id); } - /** - * @see GlideOptions#theme(Resources.Theme) - */ + @Override @NonNull @CheckResult - public GlideRequest theme(@Nullable Resources.Theme theme) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).theme(theme); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(theme); - } - return this; + public final GlideRequest theme(@Nullable Resources.Theme theme) { + return (GlideRequest) super.theme(theme); } - /** - * @see GlideOptions#skipMemoryCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest skipMemoryCache(boolean skip) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); - } - return this; + public final GlideRequest skipMemoryCache(boolean skip) { + return (GlideRequest) super.skipMemoryCache(skip); } - /** - * @see GlideOptions#override(int, int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int width, int height) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); - } - return this; + public final GlideRequest override(int width, int height) { + return (GlideRequest) super.override(width, height); } - /** - * @see GlideOptions#override(int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int size) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); - } - return this; + public final GlideRequest override(int size) { + return (GlideRequest) super.override(size); } - /** - * @see GlideOptions#signature(Key) - */ + @Override @NonNull @CheckResult - public GlideRequest signature(@NonNull Key key) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).signature(key); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(key); - } - return this; + public final GlideRequest signature(@NonNull Key key) { + return (GlideRequest) super.signature(key); } - /** - * @see GlideOptions#set(Option, T) - */ + @Override @NonNull @CheckResult - public GlideRequest set(@NonNull Option option, @NonNull T t) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).set(option, t); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).set(option, t); - } - return this; + public final GlideRequest set(@NonNull Option option, @NonNull Y y) { + return (GlideRequest) super.set(option, y); } - /** - * @see GlideOptions#decode(Class) - */ + @Override @NonNull @CheckResult - public GlideRequest decode(@NonNull Class clazz) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).decode(clazz); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(clazz); - } - return this; + public final GlideRequest decode(@NonNull Class clazz) { + return (GlideRequest) super.decode(clazz); } - /** - * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(format); - } - return this; + public final GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { + return (GlideRequest) super.encodeFormat(format); } - /** - * @see GlideOptions#encodeQuality(int) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(value); - } - return this; + public final GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { + return (GlideRequest) super.encodeQuality(value); } - /** - * @see GlideOptions#frame(long) - */ + @Override @NonNull @CheckResult - public GlideRequest frame(@IntRange(from = 0) long value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).frame(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(value); - } - return this; + public final GlideRequest frame(@IntRange(from = 0) long value) { + return (GlideRequest) super.frame(value); } - /** - * @see GlideOptions#format(DecodeFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest format(@NonNull DecodeFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).format(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).format(format); - } - return this; + public final GlideRequest format(@NonNull DecodeFormat format) { + return (GlideRequest) super.format(format); } - /** - * @see GlideOptions#disallowHardwareConfig() - */ + @Override @NonNull @CheckResult - public GlideRequest disallowHardwareConfig() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); - } - return this; + public final GlideRequest disallowHardwareConfig() { + return (GlideRequest) super.disallowHardwareConfig(); } - /** - * @see GlideOptions#downsample(DownsampleStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest downsample(@NonNull DownsampleStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(strategy); - } - return this; + public final GlideRequest downsample(@NonNull DownsampleStrategy strategy) { + return (GlideRequest) super.downsample(strategy); } - /** - * @see GlideOptions#timeout(int) - */ + @Override @NonNull @CheckResult - public GlideRequest timeout(@IntRange(from = 0) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(value); - } - return this; + public final GlideRequest timeout(@IntRange(from = 0) int value) { + return (GlideRequest) super.timeout(value); } - /** - * @see GlideOptions#optionalCenterCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); - } - return this; + public final GlideRequest optionalCenterCrop() { + return (GlideRequest) super.optionalCenterCrop(); } - /** - * @see GlideOptions#centerCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest centerCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); - } - return this; + public final GlideRequest centerCrop() { + return (GlideRequest) super.centerCrop(); } - /** - * @see GlideOptions#optionalFitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalFitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); - } - return this; + public final GlideRequest optionalFitCenter() { + return (GlideRequest) super.optionalFitCenter(); } - /** - * @see GlideOptions#fitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest fitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); - } - return this; + public final GlideRequest fitCenter() { + return (GlideRequest) super.fitCenter(); } - /** - * @see GlideOptions#optionalCenterInside() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); - } - return this; + public final GlideRequest optionalCenterInside() { + return (GlideRequest) super.optionalCenterInside(); } - /** - * @see GlideOptions#centerInside() - */ + @Override @NonNull @CheckResult - public GlideRequest centerInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); - } - return this; + public final GlideRequest centerInside() { + return (GlideRequest) super.centerInside(); } - /** - * @see GlideOptions#optionalCircleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCircleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); - } - return this; + public final GlideRequest optionalCircleCrop() { + return (GlideRequest) super.optionalCircleCrop(); } - /** - * @see GlideOptions#circleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest circleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); - } - return this; + public final GlideRequest circleCrop() { + return (GlideRequest) super.circleCrop(); } - /** - * @see GlideOptions#transform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(transformation); - } - return this; + public final GlideRequest transform(@NonNull Transformation transformation) { + return (GlideRequest) super.transform(transformation); } - /** - * @see GlideOptions#transforms(Transformation[]) - */ + @Override + @SafeVarargs + @SuppressWarnings("varargs") @NonNull @CheckResult - @SuppressWarnings({ - "unchecked", - "varargs" - }) - public GlideRequest transforms(@NonNull Transformation... transformations) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(transformations); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(transformations); - } - return this; + public final GlideRequest transforms(@NonNull Transformation... transformations) { + return (GlideRequest) super.transforms(transformations); } - /** - * @see GlideOptions#optionalTransform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(transformation); } - /** - * @see GlideOptions#optionalTransform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(clazz, transformation); } - /** - * @see GlideOptions#transform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(clazz, transformation); - } - return this; + public final GlideRequest transform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.transform(clazz, transformation); } - /** - * @see GlideOptions#dontTransform() - */ + @Override @NonNull @CheckResult - public GlideRequest dontTransform() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); - } - return this; + public final GlideRequest dontTransform() { + return (GlideRequest) super.dontTransform(); } - /** - * @see GlideOptions#dontAnimate() - */ + @Override @NonNull @CheckResult - public GlideRequest dontAnimate() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); - } - return this; - } - - /** - * @see GlideOptions#test() - */ - @CheckResult - @NonNull - public GlideRequest test() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).test(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).test(); - } - return this; + public final GlideRequest dontAnimate() { + return (GlideRequest) super.dontAnimate(); } @Override @NonNull @CheckResult - public GlideRequest apply(@NonNull RequestOptions options) { + public GlideRequest apply(@NonNull BaseRequestOptions options) { return (GlideRequest) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideOptions.java index dc6c873f89..a2ecb5e2f8 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -430,8 +431,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -565,16 +566,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -595,7 +596,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java index ee391f551e..46784109cb 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtend/GlideRequest.java @@ -23,8 +23,8 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.RequestOptions; import java.io.File; import java.lang.Class; import java.lang.Cloneable; @@ -39,14 +39,14 @@ /** * Contains all public methods from {@link RequestBuilder}, all options from - * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.request.RequestOptions} and all generated options from * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. * *

Generated code, do not modify. * * @see RequestBuilder - * @see RequestOptions + * @see com.bumptech.glide.request.RequestOptions */ @SuppressWarnings({ "unused", @@ -69,590 +69,301 @@ protected GlideRequest getDownloadOnlyRequest() { return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); } - /** - * @see GlideOptions#sizeMultiplier(float) - */ + @Override @NonNull @CheckResult - public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(value); - } - return this; + public final GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { + return (GlideRequest) super.sizeMultiplier(value); } - /** - * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); - } - return this; + public final GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideRequest) super.useUnlimitedSourceGeneratorsPool(flag); } - /** - * @see GlideOptions#useAnimationPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useAnimationPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); - } - return this; + public final GlideRequest useAnimationPool(boolean flag) { + return (GlideRequest) super.useAnimationPool(flag); } - /** - * @see GlideOptions#onlyRetrieveFromCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest onlyRetrieveFromCache(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); - } - return this; + public final GlideRequest onlyRetrieveFromCache(boolean flag) { + return (GlideRequest) super.onlyRetrieveFromCache(flag); } - /** - * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(strategy); - } - return this; + public final GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { + return (GlideRequest) super.diskCacheStrategy(strategy); } - /** - * @see GlideOptions#priority(Priority) - */ + @Override @NonNull @CheckResult - public GlideRequest priority(@NonNull Priority priority) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).priority(priority); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(priority); - } - return this; + public final GlideRequest priority(@NonNull Priority priority) { + return (GlideRequest) super.priority(priority); } - /** - * @see GlideOptions#placeholder(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(drawable); - } - return this; + public final GlideRequest placeholder(@Nullable Drawable drawable) { + return (GlideRequest) super.placeholder(drawable); } - /** - * @see GlideOptions#placeholder(int) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(id); - } - return this; + public final GlideRequest placeholder(@DrawableRes int id) { + return (GlideRequest) super.placeholder(id); } - /** - * @see GlideOptions#fallback(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(drawable); - } - return this; + public final GlideRequest fallback(@Nullable Drawable drawable) { + return (GlideRequest) super.fallback(drawable); } - /** - * @see GlideOptions#fallback(int) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(id); - } - return this; + public final GlideRequest fallback(@DrawableRes int id) { + return (GlideRequest) super.fallback(id); } - /** - * @see GlideOptions#error(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(drawable); - } - return this; + public final GlideRequest error(@Nullable Drawable drawable) { + return (GlideRequest) super.error(drawable); } - /** - * @see GlideOptions#error(int) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(id); - } - return this; + public final GlideRequest error(@DrawableRes int id) { + return (GlideRequest) super.error(id); } - /** - * @see GlideOptions#theme(Resources.Theme) - */ + @Override @NonNull @CheckResult - public GlideRequest theme(@Nullable Resources.Theme theme) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).theme(theme); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(theme); - } - return this; + public final GlideRequest theme(@Nullable Resources.Theme theme) { + return (GlideRequest) super.theme(theme); } - /** - * @see GlideOptions#skipMemoryCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest skipMemoryCache(boolean skip) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); - } - return this; + public final GlideRequest skipMemoryCache(boolean skip) { + return (GlideRequest) super.skipMemoryCache(skip); } - /** - * @see GlideOptions#override(int, int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int width, int height) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); - } - return this; + public final GlideRequest override(int width, int height) { + return (GlideRequest) super.override(width, height); } - /** - * @see GlideOptions#override(int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int size) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); - } - return this; + public final GlideRequest override(int size) { + return (GlideRequest) super.override(size); } - /** - * @see GlideOptions#signature(Key) - */ + @Override @NonNull @CheckResult - public GlideRequest signature(@NonNull Key key) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).signature(key); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(key); - } - return this; + public final GlideRequest signature(@NonNull Key key) { + return (GlideRequest) super.signature(key); } - /** - * @see GlideOptions#set(Option, T) - */ + @Override @NonNull @CheckResult - public GlideRequest set(@NonNull Option option, @NonNull T t) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).set(option, t); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).set(option, t); - } - return this; + public final GlideRequest set(@NonNull Option option, @NonNull Y y) { + return (GlideRequest) super.set(option, y); } - /** - * @see GlideOptions#decode(Class) - */ + @Override @NonNull @CheckResult - public GlideRequest decode(@NonNull Class clazz) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).decode(clazz); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(clazz); - } - return this; + public final GlideRequest decode(@NonNull Class clazz) { + return (GlideRequest) super.decode(clazz); } - /** - * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(format); - } - return this; + public final GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { + return (GlideRequest) super.encodeFormat(format); } - /** - * @see GlideOptions#encodeQuality(int) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(value); - } - return this; + public final GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { + return (GlideRequest) super.encodeQuality(value); } - /** - * @see GlideOptions#frame(long) - */ + @Override @NonNull @CheckResult - public GlideRequest frame(@IntRange(from = 0) long value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).frame(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(value); - } - return this; + public final GlideRequest frame(@IntRange(from = 0) long value) { + return (GlideRequest) super.frame(value); } - /** - * @see GlideOptions#format(DecodeFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest format(@NonNull DecodeFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).format(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).format(format); - } - return this; + public final GlideRequest format(@NonNull DecodeFormat format) { + return (GlideRequest) super.format(format); } - /** - * @see GlideOptions#disallowHardwareConfig() - */ + @Override @NonNull @CheckResult - public GlideRequest disallowHardwareConfig() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); - } - return this; + public final GlideRequest disallowHardwareConfig() { + return (GlideRequest) super.disallowHardwareConfig(); } - /** - * @see GlideOptions#downsample(DownsampleStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest downsample(@NonNull DownsampleStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(strategy); - } - return this; + public final GlideRequest downsample(@NonNull DownsampleStrategy strategy) { + return (GlideRequest) super.downsample(strategy); } - /** - * @see GlideOptions#timeout(int) - */ + @Override @NonNull @CheckResult - public GlideRequest timeout(@IntRange(from = 0) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(value); - } - return this; + public final GlideRequest timeout(@IntRange(from = 0) int value) { + return (GlideRequest) super.timeout(value); } - /** - * @see GlideOptions#optionalCenterCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); - } - return this; + public final GlideRequest optionalCenterCrop() { + return (GlideRequest) super.optionalCenterCrop(); } - /** - * @see GlideOptions#optionalFitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalFitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); - } - return this; + public final GlideRequest centerCrop() { + return (GlideRequest) super.centerCrop(); } - /** - * @see GlideOptions#fitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest fitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); - } - return this; + public final GlideRequest optionalFitCenter() { + return (GlideRequest) super.optionalFitCenter(); } - /** - * @see GlideOptions#optionalCenterInside() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); - } - return this; + public final GlideRequest fitCenter() { + return (GlideRequest) super.fitCenter(); } - /** - * @see GlideOptions#centerInside() - */ + @Override @NonNull @CheckResult - public GlideRequest centerInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); - } - return this; + public final GlideRequest optionalCenterInside() { + return (GlideRequest) super.optionalCenterInside(); } - /** - * @see GlideOptions#optionalCircleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCircleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); - } - return this; + public final GlideRequest centerInside() { + return (GlideRequest) super.centerInside(); } - /** - * @see GlideOptions#circleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest circleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); - } - return this; + public final GlideRequest optionalCircleCrop() { + return (GlideRequest) super.optionalCircleCrop(); } - /** - * @see GlideOptions#transform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(transformation); - } - return this; + public final GlideRequest circleCrop() { + return (GlideRequest) super.circleCrop(); } - /** - * @see GlideOptions#transforms(Transformation[]) - */ + @Override @NonNull @CheckResult - @SuppressWarnings({ - "unchecked", - "varargs" - }) - public GlideRequest transforms(@NonNull Transformation... transformations) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(transformations); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(transformations); - } - return this; + public final GlideRequest transform(@NonNull Transformation transformation) { + return (GlideRequest) super.transform(transformation); } - /** - * @see GlideOptions#optionalTransform(Transformation) - */ + @Override + @SafeVarargs + @SuppressWarnings("varargs") @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(transformation); - } - return this; + public final GlideRequest transforms(@NonNull Transformation... transformations) { + return (GlideRequest) super.transforms(transformations); } - /** - * @see GlideOptions#optionalTransform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(transformation); } - /** - * @see GlideOptions#transform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(clazz, transformation); } - /** - * @see GlideOptions#dontTransform() - */ + @Override @NonNull @CheckResult - public GlideRequest dontTransform() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); - } - return this; + public final GlideRequest transform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.transform(clazz, transformation); } - /** - * @see GlideOptions#dontAnimate() - */ + @Override @NonNull @CheckResult - public GlideRequest dontAnimate() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); - } - return this; + public final GlideRequest dontTransform() { + return (GlideRequest) super.dontTransform(); } - /** - * @see GlideOptions#centerCrop() - */ - @CheckResult + @Override @NonNull - public GlideRequest centerCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); - } - return this; + @CheckResult + public final GlideRequest dontAnimate() { + return (GlideRequest) super.dontAnimate(); } @Override @NonNull @CheckResult - public GlideRequest apply(@NonNull RequestOptions options) { + public GlideRequest apply(@NonNull BaseRequestOptions options) { return (GlideRequest) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideOptions.java index 9fca6bfb56..d77337e2ac 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -413,8 +414,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -555,16 +556,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -585,7 +586,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java index e6e2e53801..46784109cb 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideExtendMultipleArguments/GlideRequest.java @@ -23,8 +23,8 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.RequestOptions; import java.io.File; import java.lang.Class; import java.lang.Cloneable; @@ -39,14 +39,14 @@ /** * Contains all public methods from {@link RequestBuilder}, all options from - * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.request.RequestOptions} and all generated options from * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. * *

Generated code, do not modify. * * @see RequestBuilder - * @see RequestOptions + * @see com.bumptech.glide.request.RequestOptions */ @SuppressWarnings({ "unused", @@ -69,590 +69,301 @@ protected GlideRequest getDownloadOnlyRequest() { return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); } - /** - * @see GlideOptions#sizeMultiplier(float) - */ + @Override @NonNull @CheckResult - public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(value); - } - return this; + public final GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { + return (GlideRequest) super.sizeMultiplier(value); } - /** - * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); - } - return this; + public final GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideRequest) super.useUnlimitedSourceGeneratorsPool(flag); } - /** - * @see GlideOptions#useAnimationPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useAnimationPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); - } - return this; + public final GlideRequest useAnimationPool(boolean flag) { + return (GlideRequest) super.useAnimationPool(flag); } - /** - * @see GlideOptions#onlyRetrieveFromCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest onlyRetrieveFromCache(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); - } - return this; + public final GlideRequest onlyRetrieveFromCache(boolean flag) { + return (GlideRequest) super.onlyRetrieveFromCache(flag); } - /** - * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(strategy); - } - return this; + public final GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { + return (GlideRequest) super.diskCacheStrategy(strategy); } - /** - * @see GlideOptions#priority(Priority) - */ + @Override @NonNull @CheckResult - public GlideRequest priority(@NonNull Priority priority) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).priority(priority); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(priority); - } - return this; + public final GlideRequest priority(@NonNull Priority priority) { + return (GlideRequest) super.priority(priority); } - /** - * @see GlideOptions#placeholder(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(drawable); - } - return this; + public final GlideRequest placeholder(@Nullable Drawable drawable) { + return (GlideRequest) super.placeholder(drawable); } - /** - * @see GlideOptions#placeholder(int) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(id); - } - return this; + public final GlideRequest placeholder(@DrawableRes int id) { + return (GlideRequest) super.placeholder(id); } - /** - * @see GlideOptions#fallback(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(drawable); - } - return this; + public final GlideRequest fallback(@Nullable Drawable drawable) { + return (GlideRequest) super.fallback(drawable); } - /** - * @see GlideOptions#fallback(int) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(id); - } - return this; + public final GlideRequest fallback(@DrawableRes int id) { + return (GlideRequest) super.fallback(id); } - /** - * @see GlideOptions#error(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(drawable); - } - return this; + public final GlideRequest error(@Nullable Drawable drawable) { + return (GlideRequest) super.error(drawable); } - /** - * @see GlideOptions#error(int) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(id); - } - return this; + public final GlideRequest error(@DrawableRes int id) { + return (GlideRequest) super.error(id); } - /** - * @see GlideOptions#theme(Resources.Theme) - */ + @Override @NonNull @CheckResult - public GlideRequest theme(@Nullable Resources.Theme theme) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).theme(theme); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(theme); - } - return this; + public final GlideRequest theme(@Nullable Resources.Theme theme) { + return (GlideRequest) super.theme(theme); } - /** - * @see GlideOptions#skipMemoryCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest skipMemoryCache(boolean skip) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); - } - return this; + public final GlideRequest skipMemoryCache(boolean skip) { + return (GlideRequest) super.skipMemoryCache(skip); } - /** - * @see GlideOptions#override(int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int size) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); - } - return this; + public final GlideRequest override(int width, int height) { + return (GlideRequest) super.override(width, height); } - /** - * @see GlideOptions#signature(Key) - */ + @Override @NonNull @CheckResult - public GlideRequest signature(@NonNull Key key) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).signature(key); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(key); - } - return this; + public final GlideRequest override(int size) { + return (GlideRequest) super.override(size); } - /** - * @see GlideOptions#set(Option, T) - */ + @Override @NonNull @CheckResult - public GlideRequest set(@NonNull Option option, @NonNull T t) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).set(option, t); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).set(option, t); - } - return this; + public final GlideRequest signature(@NonNull Key key) { + return (GlideRequest) super.signature(key); } - /** - * @see GlideOptions#decode(Class) - */ + @Override @NonNull @CheckResult - public GlideRequest decode(@NonNull Class clazz) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).decode(clazz); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(clazz); - } - return this; + public final GlideRequest set(@NonNull Option option, @NonNull Y y) { + return (GlideRequest) super.set(option, y); } - /** - * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(format); - } - return this; + public final GlideRequest decode(@NonNull Class clazz) { + return (GlideRequest) super.decode(clazz); } - /** - * @see GlideOptions#encodeQuality(int) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(value); - } - return this; + public final GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { + return (GlideRequest) super.encodeFormat(format); } - /** - * @see GlideOptions#frame(long) - */ + @Override @NonNull @CheckResult - public GlideRequest frame(@IntRange(from = 0) long value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).frame(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(value); - } - return this; + public final GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { + return (GlideRequest) super.encodeQuality(value); } - /** - * @see GlideOptions#format(DecodeFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest format(@NonNull DecodeFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).format(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).format(format); - } - return this; + public final GlideRequest frame(@IntRange(from = 0) long value) { + return (GlideRequest) super.frame(value); } - /** - * @see GlideOptions#disallowHardwareConfig() - */ + @Override @NonNull @CheckResult - public GlideRequest disallowHardwareConfig() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); - } - return this; + public final GlideRequest format(@NonNull DecodeFormat format) { + return (GlideRequest) super.format(format); } - /** - * @see GlideOptions#downsample(DownsampleStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest downsample(@NonNull DownsampleStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(strategy); - } - return this; + public final GlideRequest disallowHardwareConfig() { + return (GlideRequest) super.disallowHardwareConfig(); } - /** - * @see GlideOptions#timeout(int) - */ + @Override @NonNull @CheckResult - public GlideRequest timeout(@IntRange(from = 0) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(value); - } - return this; + public final GlideRequest downsample(@NonNull DownsampleStrategy strategy) { + return (GlideRequest) super.downsample(strategy); } - /** - * @see GlideOptions#optionalCenterCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); - } - return this; + public final GlideRequest timeout(@IntRange(from = 0) int value) { + return (GlideRequest) super.timeout(value); } - /** - * @see GlideOptions#centerCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest centerCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); - } - return this; + public final GlideRequest optionalCenterCrop() { + return (GlideRequest) super.optionalCenterCrop(); } - /** - * @see GlideOptions#optionalFitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalFitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); - } - return this; + public final GlideRequest centerCrop() { + return (GlideRequest) super.centerCrop(); } - /** - * @see GlideOptions#fitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest fitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); - } - return this; + public final GlideRequest optionalFitCenter() { + return (GlideRequest) super.optionalFitCenter(); } - /** - * @see GlideOptions#optionalCenterInside() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); - } - return this; + public final GlideRequest fitCenter() { + return (GlideRequest) super.fitCenter(); } - /** - * @see GlideOptions#centerInside() - */ + @Override @NonNull @CheckResult - public GlideRequest centerInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); - } - return this; + public final GlideRequest optionalCenterInside() { + return (GlideRequest) super.optionalCenterInside(); } - /** - * @see GlideOptions#optionalCircleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCircleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); - } - return this; + public final GlideRequest centerInside() { + return (GlideRequest) super.centerInside(); } - /** - * @see GlideOptions#circleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest circleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); - } - return this; + public final GlideRequest optionalCircleCrop() { + return (GlideRequest) super.optionalCircleCrop(); } - /** - * @see GlideOptions#transform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(transformation); - } - return this; + public final GlideRequest circleCrop() { + return (GlideRequest) super.circleCrop(); } - /** - * @see GlideOptions#transforms(Transformation[]) - */ + @Override @NonNull @CheckResult - @SuppressWarnings({ - "unchecked", - "varargs" - }) - public GlideRequest transforms(@NonNull Transformation... transformations) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(transformations); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(transformations); - } - return this; + public final GlideRequest transform(@NonNull Transformation transformation) { + return (GlideRequest) super.transform(transformation); } - /** - * @see GlideOptions#optionalTransform(Transformation) - */ + @Override + @SafeVarargs + @SuppressWarnings("varargs") @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(transformation); - } - return this; + public final GlideRequest transforms(@NonNull Transformation... transformations) { + return (GlideRequest) super.transforms(transformations); } - /** - * @see GlideOptions#optionalTransform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(transformation); } - /** - * @see GlideOptions#transform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(clazz, transformation); } - /** - * @see GlideOptions#dontTransform() - */ + @Override @NonNull @CheckResult - public GlideRequest dontTransform() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); - } - return this; + public final GlideRequest transform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.transform(clazz, transformation); } - /** - * @see GlideOptions#dontAnimate() - */ + @Override @NonNull @CheckResult - public GlideRequest dontAnimate() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); - } - return this; + public final GlideRequest dontTransform() { + return (GlideRequest) super.dontTransform(); } - /** - * @see GlideOptions#override(int, int) - */ - @CheckResult + @Override @NonNull - public GlideRequest override(int width, int height) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); - } - return this; + @CheckResult + public final GlideRequest dontAnimate() { + return (GlideRequest) super.dontAnimate(); } @Override @NonNull @CheckResult - public GlideRequest apply(@NonNull RequestOptions options) { + public GlideRequest apply(@NonNull BaseRequestOptions options) { return (GlideRequest) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideOptions.java index 39689658e3..12698f7beb 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -430,8 +431,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -565,16 +566,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -595,7 +596,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java index ee391f551e..46784109cb 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/OverrideReplace/GlideRequest.java @@ -23,8 +23,8 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.RequestOptions; import java.io.File; import java.lang.Class; import java.lang.Cloneable; @@ -39,14 +39,14 @@ /** * Contains all public methods from {@link RequestBuilder}, all options from - * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.request.RequestOptions} and all generated options from * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. * *

Generated code, do not modify. * * @see RequestBuilder - * @see RequestOptions + * @see com.bumptech.glide.request.RequestOptions */ @SuppressWarnings({ "unused", @@ -69,590 +69,301 @@ protected GlideRequest getDownloadOnlyRequest() { return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); } - /** - * @see GlideOptions#sizeMultiplier(float) - */ + @Override @NonNull @CheckResult - public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(value); - } - return this; + public final GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { + return (GlideRequest) super.sizeMultiplier(value); } - /** - * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); - } - return this; + public final GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideRequest) super.useUnlimitedSourceGeneratorsPool(flag); } - /** - * @see GlideOptions#useAnimationPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useAnimationPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); - } - return this; + public final GlideRequest useAnimationPool(boolean flag) { + return (GlideRequest) super.useAnimationPool(flag); } - /** - * @see GlideOptions#onlyRetrieveFromCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest onlyRetrieveFromCache(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); - } - return this; + public final GlideRequest onlyRetrieveFromCache(boolean flag) { + return (GlideRequest) super.onlyRetrieveFromCache(flag); } - /** - * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(strategy); - } - return this; + public final GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { + return (GlideRequest) super.diskCacheStrategy(strategy); } - /** - * @see GlideOptions#priority(Priority) - */ + @Override @NonNull @CheckResult - public GlideRequest priority(@NonNull Priority priority) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).priority(priority); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(priority); - } - return this; + public final GlideRequest priority(@NonNull Priority priority) { + return (GlideRequest) super.priority(priority); } - /** - * @see GlideOptions#placeholder(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(drawable); - } - return this; + public final GlideRequest placeholder(@Nullable Drawable drawable) { + return (GlideRequest) super.placeholder(drawable); } - /** - * @see GlideOptions#placeholder(int) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(id); - } - return this; + public final GlideRequest placeholder(@DrawableRes int id) { + return (GlideRequest) super.placeholder(id); } - /** - * @see GlideOptions#fallback(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(drawable); - } - return this; + public final GlideRequest fallback(@Nullable Drawable drawable) { + return (GlideRequest) super.fallback(drawable); } - /** - * @see GlideOptions#fallback(int) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(id); - } - return this; + public final GlideRequest fallback(@DrawableRes int id) { + return (GlideRequest) super.fallback(id); } - /** - * @see GlideOptions#error(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(drawable); - } - return this; + public final GlideRequest error(@Nullable Drawable drawable) { + return (GlideRequest) super.error(drawable); } - /** - * @see GlideOptions#error(int) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(id); - } - return this; + public final GlideRequest error(@DrawableRes int id) { + return (GlideRequest) super.error(id); } - /** - * @see GlideOptions#theme(Resources.Theme) - */ + @Override @NonNull @CheckResult - public GlideRequest theme(@Nullable Resources.Theme theme) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).theme(theme); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(theme); - } - return this; + public final GlideRequest theme(@Nullable Resources.Theme theme) { + return (GlideRequest) super.theme(theme); } - /** - * @see GlideOptions#skipMemoryCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest skipMemoryCache(boolean skip) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); - } - return this; + public final GlideRequest skipMemoryCache(boolean skip) { + return (GlideRequest) super.skipMemoryCache(skip); } - /** - * @see GlideOptions#override(int, int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int width, int height) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); - } - return this; + public final GlideRequest override(int width, int height) { + return (GlideRequest) super.override(width, height); } - /** - * @see GlideOptions#override(int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int size) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); - } - return this; + public final GlideRequest override(int size) { + return (GlideRequest) super.override(size); } - /** - * @see GlideOptions#signature(Key) - */ + @Override @NonNull @CheckResult - public GlideRequest signature(@NonNull Key key) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).signature(key); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(key); - } - return this; + public final GlideRequest signature(@NonNull Key key) { + return (GlideRequest) super.signature(key); } - /** - * @see GlideOptions#set(Option, T) - */ + @Override @NonNull @CheckResult - public GlideRequest set(@NonNull Option option, @NonNull T t) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).set(option, t); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).set(option, t); - } - return this; + public final GlideRequest set(@NonNull Option option, @NonNull Y y) { + return (GlideRequest) super.set(option, y); } - /** - * @see GlideOptions#decode(Class) - */ + @Override @NonNull @CheckResult - public GlideRequest decode(@NonNull Class clazz) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).decode(clazz); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(clazz); - } - return this; + public final GlideRequest decode(@NonNull Class clazz) { + return (GlideRequest) super.decode(clazz); } - /** - * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(format); - } - return this; + public final GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { + return (GlideRequest) super.encodeFormat(format); } - /** - * @see GlideOptions#encodeQuality(int) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(value); - } - return this; + public final GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { + return (GlideRequest) super.encodeQuality(value); } - /** - * @see GlideOptions#frame(long) - */ + @Override @NonNull @CheckResult - public GlideRequest frame(@IntRange(from = 0) long value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).frame(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(value); - } - return this; + public final GlideRequest frame(@IntRange(from = 0) long value) { + return (GlideRequest) super.frame(value); } - /** - * @see GlideOptions#format(DecodeFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest format(@NonNull DecodeFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).format(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).format(format); - } - return this; + public final GlideRequest format(@NonNull DecodeFormat format) { + return (GlideRequest) super.format(format); } - /** - * @see GlideOptions#disallowHardwareConfig() - */ + @Override @NonNull @CheckResult - public GlideRequest disallowHardwareConfig() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); - } - return this; + public final GlideRequest disallowHardwareConfig() { + return (GlideRequest) super.disallowHardwareConfig(); } - /** - * @see GlideOptions#downsample(DownsampleStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest downsample(@NonNull DownsampleStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(strategy); - } - return this; + public final GlideRequest downsample(@NonNull DownsampleStrategy strategy) { + return (GlideRequest) super.downsample(strategy); } - /** - * @see GlideOptions#timeout(int) - */ + @Override @NonNull @CheckResult - public GlideRequest timeout(@IntRange(from = 0) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(value); - } - return this; + public final GlideRequest timeout(@IntRange(from = 0) int value) { + return (GlideRequest) super.timeout(value); } - /** - * @see GlideOptions#optionalCenterCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); - } - return this; + public final GlideRequest optionalCenterCrop() { + return (GlideRequest) super.optionalCenterCrop(); } - /** - * @see GlideOptions#optionalFitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalFitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); - } - return this; + public final GlideRequest centerCrop() { + return (GlideRequest) super.centerCrop(); } - /** - * @see GlideOptions#fitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest fitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); - } - return this; + public final GlideRequest optionalFitCenter() { + return (GlideRequest) super.optionalFitCenter(); } - /** - * @see GlideOptions#optionalCenterInside() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); - } - return this; + public final GlideRequest fitCenter() { + return (GlideRequest) super.fitCenter(); } - /** - * @see GlideOptions#centerInside() - */ + @Override @NonNull @CheckResult - public GlideRequest centerInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); - } - return this; + public final GlideRequest optionalCenterInside() { + return (GlideRequest) super.optionalCenterInside(); } - /** - * @see GlideOptions#optionalCircleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCircleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); - } - return this; + public final GlideRequest centerInside() { + return (GlideRequest) super.centerInside(); } - /** - * @see GlideOptions#circleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest circleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); - } - return this; + public final GlideRequest optionalCircleCrop() { + return (GlideRequest) super.optionalCircleCrop(); } - /** - * @see GlideOptions#transform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(transformation); - } - return this; + public final GlideRequest circleCrop() { + return (GlideRequest) super.circleCrop(); } - /** - * @see GlideOptions#transforms(Transformation[]) - */ + @Override @NonNull @CheckResult - @SuppressWarnings({ - "unchecked", - "varargs" - }) - public GlideRequest transforms(@NonNull Transformation... transformations) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(transformations); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(transformations); - } - return this; + public final GlideRequest transform(@NonNull Transformation transformation) { + return (GlideRequest) super.transform(transformation); } - /** - * @see GlideOptions#optionalTransform(Transformation) - */ + @Override + @SafeVarargs + @SuppressWarnings("varargs") @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(transformation); - } - return this; + public final GlideRequest transforms(@NonNull Transformation... transformations) { + return (GlideRequest) super.transforms(transformations); } - /** - * @see GlideOptions#optionalTransform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(transformation); } - /** - * @see GlideOptions#transform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(clazz, transformation); } - /** - * @see GlideOptions#dontTransform() - */ + @Override @NonNull @CheckResult - public GlideRequest dontTransform() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); - } - return this; + public final GlideRequest transform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.transform(clazz, transformation); } - /** - * @see GlideOptions#dontAnimate() - */ + @Override @NonNull @CheckResult - public GlideRequest dontAnimate() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); - } - return this; + public final GlideRequest dontTransform() { + return (GlideRequest) super.dontTransform(); } - /** - * @see GlideOptions#centerCrop() - */ - @CheckResult + @Override @NonNull - public GlideRequest centerCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); - } - return this; + @CheckResult + public final GlideRequest dontAnimate() { + return (GlideRequest) super.dontAnimate(); } @Override @NonNull @CheckResult - public GlideRequest apply(@NonNull RequestOptions options) { + public GlideRequest apply(@NonNull BaseRequestOptions options) { return (GlideRequest) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java index f89ddbc67f..3caeb0e5e7 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -430,8 +431,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -572,16 +573,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -602,7 +603,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java index f0377a0a7c..46784109cb 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java @@ -23,8 +23,8 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.RequestOptions; import java.io.File; import java.lang.Class; import java.lang.Cloneable; @@ -39,14 +39,14 @@ /** * Contains all public methods from {@link RequestBuilder}, all options from - * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.request.RequestOptions} and all generated options from * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. * *

Generated code, do not modify. * * @see RequestBuilder - * @see RequestOptions + * @see com.bumptech.glide.request.RequestOptions */ @SuppressWarnings({ "unused", @@ -69,604 +69,301 @@ protected GlideRequest getDownloadOnlyRequest() { return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); } - /** - * @see GlideOptions#sizeMultiplier(float) - */ + @Override @NonNull @CheckResult - public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(value); - } - return this; + public final GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { + return (GlideRequest) super.sizeMultiplier(value); } - /** - * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); - } - return this; + public final GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideRequest) super.useUnlimitedSourceGeneratorsPool(flag); } - /** - * @see GlideOptions#useAnimationPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useAnimationPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); - } - return this; + public final GlideRequest useAnimationPool(boolean flag) { + return (GlideRequest) super.useAnimationPool(flag); } - /** - * @see GlideOptions#onlyRetrieveFromCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest onlyRetrieveFromCache(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); - } - return this; + public final GlideRequest onlyRetrieveFromCache(boolean flag) { + return (GlideRequest) super.onlyRetrieveFromCache(flag); } - /** - * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(strategy); - } - return this; + public final GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { + return (GlideRequest) super.diskCacheStrategy(strategy); } - /** - * @see GlideOptions#priority(Priority) - */ + @Override @NonNull @CheckResult - public GlideRequest priority(@NonNull Priority priority) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).priority(priority); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(priority); - } - return this; + public final GlideRequest priority(@NonNull Priority priority) { + return (GlideRequest) super.priority(priority); } - /** - * @see GlideOptions#placeholder(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(drawable); - } - return this; + public final GlideRequest placeholder(@Nullable Drawable drawable) { + return (GlideRequest) super.placeholder(drawable); } - /** - * @see GlideOptions#placeholder(int) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(id); - } - return this; + public final GlideRequest placeholder(@DrawableRes int id) { + return (GlideRequest) super.placeholder(id); } - /** - * @see GlideOptions#fallback(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(drawable); - } - return this; + public final GlideRequest fallback(@Nullable Drawable drawable) { + return (GlideRequest) super.fallback(drawable); } - /** - * @see GlideOptions#fallback(int) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(id); - } - return this; + public final GlideRequest fallback(@DrawableRes int id) { + return (GlideRequest) super.fallback(id); } - /** - * @see GlideOptions#error(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(drawable); - } - return this; + public final GlideRequest error(@Nullable Drawable drawable) { + return (GlideRequest) super.error(drawable); } - /** - * @see GlideOptions#error(int) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(id); - } - return this; + public final GlideRequest error(@DrawableRes int id) { + return (GlideRequest) super.error(id); } - /** - * @see GlideOptions#theme(Resources.Theme) - */ + @Override @NonNull @CheckResult - public GlideRequest theme(@Nullable Resources.Theme theme) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).theme(theme); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(theme); - } - return this; + public final GlideRequest theme(@Nullable Resources.Theme theme) { + return (GlideRequest) super.theme(theme); } - /** - * @see GlideOptions#skipMemoryCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest skipMemoryCache(boolean skip) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); - } - return this; + public final GlideRequest skipMemoryCache(boolean skip) { + return (GlideRequest) super.skipMemoryCache(skip); } - /** - * @see GlideOptions#override(int, int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int width, int height) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); - } - return this; + public final GlideRequest override(int width, int height) { + return (GlideRequest) super.override(width, height); } - /** - * @see GlideOptions#override(int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int size) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); - } - return this; + public final GlideRequest override(int size) { + return (GlideRequest) super.override(size); } - /** - * @see GlideOptions#signature(Key) - */ + @Override @NonNull @CheckResult - public GlideRequest signature(@NonNull Key key) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).signature(key); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(key); - } - return this; + public final GlideRequest signature(@NonNull Key key) { + return (GlideRequest) super.signature(key); } - /** - * @see GlideOptions#set(Option, T) - */ + @Override @NonNull @CheckResult - public GlideRequest set(@NonNull Option option, @NonNull T t) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).set(option, t); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).set(option, t); - } - return this; + public final GlideRequest set(@NonNull Option option, @NonNull Y y) { + return (GlideRequest) super.set(option, y); } - /** - * @see GlideOptions#decode(Class) - */ + @Override @NonNull @CheckResult - public GlideRequest decode(@NonNull Class clazz) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).decode(clazz); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(clazz); - } - return this; + public final GlideRequest decode(@NonNull Class clazz) { + return (GlideRequest) super.decode(clazz); } - /** - * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(format); - } - return this; + public final GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { + return (GlideRequest) super.encodeFormat(format); } - /** - * @see GlideOptions#encodeQuality(int) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(value); - } - return this; + public final GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { + return (GlideRequest) super.encodeQuality(value); } - /** - * @see GlideOptions#frame(long) - */ + @Override @NonNull @CheckResult - public GlideRequest frame(@IntRange(from = 0) long value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).frame(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(value); - } - return this; + public final GlideRequest frame(@IntRange(from = 0) long value) { + return (GlideRequest) super.frame(value); } - /** - * @see GlideOptions#format(DecodeFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest format(@NonNull DecodeFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).format(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).format(format); - } - return this; + public final GlideRequest format(@NonNull DecodeFormat format) { + return (GlideRequest) super.format(format); } - /** - * @see GlideOptions#disallowHardwareConfig() - */ + @Override @NonNull @CheckResult - public GlideRequest disallowHardwareConfig() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); - } - return this; + public final GlideRequest disallowHardwareConfig() { + return (GlideRequest) super.disallowHardwareConfig(); } - /** - * @see GlideOptions#downsample(DownsampleStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest downsample(@NonNull DownsampleStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(strategy); - } - return this; + public final GlideRequest downsample(@NonNull DownsampleStrategy strategy) { + return (GlideRequest) super.downsample(strategy); } - /** - * @see GlideOptions#timeout(int) - */ + @Override @NonNull @CheckResult - public GlideRequest timeout(@IntRange(from = 0) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(value); - } - return this; + public final GlideRequest timeout(@IntRange(from = 0) int value) { + return (GlideRequest) super.timeout(value); } - /** - * @see GlideOptions#optionalCenterCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); - } - return this; + public final GlideRequest optionalCenterCrop() { + return (GlideRequest) super.optionalCenterCrop(); } - /** - * @see GlideOptions#centerCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest centerCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); - } - return this; + public final GlideRequest centerCrop() { + return (GlideRequest) super.centerCrop(); } - /** - * @see GlideOptions#optionalFitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalFitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); - } - return this; + public final GlideRequest optionalFitCenter() { + return (GlideRequest) super.optionalFitCenter(); } - /** - * @see GlideOptions#fitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest fitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); - } - return this; + public final GlideRequest fitCenter() { + return (GlideRequest) super.fitCenter(); } - /** - * @see GlideOptions#optionalCenterInside() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); - } - return this; + public final GlideRequest optionalCenterInside() { + return (GlideRequest) super.optionalCenterInside(); } - /** - * @see GlideOptions#centerInside() - */ + @Override @NonNull @CheckResult - public GlideRequest centerInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); - } - return this; + public final GlideRequest centerInside() { + return (GlideRequest) super.centerInside(); } - /** - * @see GlideOptions#optionalCircleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCircleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); - } - return this; + public final GlideRequest optionalCircleCrop() { + return (GlideRequest) super.optionalCircleCrop(); } - /** - * @see GlideOptions#circleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest circleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); - } - return this; + public final GlideRequest circleCrop() { + return (GlideRequest) super.circleCrop(); } - /** - * @see GlideOptions#transform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(transformation); - } - return this; + public final GlideRequest transform(@NonNull Transformation transformation) { + return (GlideRequest) super.transform(transformation); } - /** - * @see GlideOptions#transforms(Transformation[]) - */ + @Override + @SafeVarargs + @SuppressWarnings("varargs") @NonNull @CheckResult - @SuppressWarnings({ - "unchecked", - "varargs" - }) - public GlideRequest transforms(@NonNull Transformation... transformations) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(transformations); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(transformations); - } - return this; + public final GlideRequest transforms(@NonNull Transformation... transformations) { + return (GlideRequest) super.transforms(transformations); } - /** - * @see GlideOptions#optionalTransform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(transformation); } - /** - * @see GlideOptions#optionalTransform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(clazz, transformation); } - /** - * @see GlideOptions#transform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(clazz, transformation); - } - return this; + public final GlideRequest transform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.transform(clazz, transformation); } - /** - * @see GlideOptions#dontTransform() - */ + @Override @NonNull @CheckResult - public GlideRequest dontTransform() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); - } - return this; + public final GlideRequest dontTransform() { + return (GlideRequest) super.dontTransform(); } - /** - * @see GlideOptions#dontAnimate() - */ + @Override @NonNull @CheckResult - public GlideRequest dontAnimate() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); - } - return this; - } - - /** - * @see GlideOptions#test() - */ - @CheckResult - @NonNull - public GlideRequest test() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).test(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).test(); - } - return this; + public final GlideRequest dontAnimate() { + return (GlideRequest) super.dontAnimate(); } @Override @NonNull @CheckResult - public GlideRequest apply(@NonNull RequestOptions options) { + public GlideRequest apply(@NonNull BaseRequestOptions options) { return (GlideRequest) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideOptions.java index 3484cb1886..2f1e8a0349 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -430,8 +431,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -572,16 +573,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -602,7 +603,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java index f0377a0a7c..46784109cb 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionOptionsTest/StaticMethodName/GlideRequest.java @@ -23,8 +23,8 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.RequestOptions; import java.io.File; import java.lang.Class; import java.lang.Cloneable; @@ -39,14 +39,14 @@ /** * Contains all public methods from {@link RequestBuilder}, all options from - * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.request.RequestOptions} and all generated options from * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. * *

Generated code, do not modify. * * @see RequestBuilder - * @see RequestOptions + * @see com.bumptech.glide.request.RequestOptions */ @SuppressWarnings({ "unused", @@ -69,604 +69,301 @@ protected GlideRequest getDownloadOnlyRequest() { return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); } - /** - * @see GlideOptions#sizeMultiplier(float) - */ + @Override @NonNull @CheckResult - public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(value); - } - return this; + public final GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { + return (GlideRequest) super.sizeMultiplier(value); } - /** - * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); - } - return this; + public final GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideRequest) super.useUnlimitedSourceGeneratorsPool(flag); } - /** - * @see GlideOptions#useAnimationPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useAnimationPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); - } - return this; + public final GlideRequest useAnimationPool(boolean flag) { + return (GlideRequest) super.useAnimationPool(flag); } - /** - * @see GlideOptions#onlyRetrieveFromCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest onlyRetrieveFromCache(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); - } - return this; + public final GlideRequest onlyRetrieveFromCache(boolean flag) { + return (GlideRequest) super.onlyRetrieveFromCache(flag); } - /** - * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(strategy); - } - return this; + public final GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { + return (GlideRequest) super.diskCacheStrategy(strategy); } - /** - * @see GlideOptions#priority(Priority) - */ + @Override @NonNull @CheckResult - public GlideRequest priority(@NonNull Priority priority) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).priority(priority); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(priority); - } - return this; + public final GlideRequest priority(@NonNull Priority priority) { + return (GlideRequest) super.priority(priority); } - /** - * @see GlideOptions#placeholder(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(drawable); - } - return this; + public final GlideRequest placeholder(@Nullable Drawable drawable) { + return (GlideRequest) super.placeholder(drawable); } - /** - * @see GlideOptions#placeholder(int) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(id); - } - return this; + public final GlideRequest placeholder(@DrawableRes int id) { + return (GlideRequest) super.placeholder(id); } - /** - * @see GlideOptions#fallback(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(drawable); - } - return this; + public final GlideRequest fallback(@Nullable Drawable drawable) { + return (GlideRequest) super.fallback(drawable); } - /** - * @see GlideOptions#fallback(int) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(id); - } - return this; + public final GlideRequest fallback(@DrawableRes int id) { + return (GlideRequest) super.fallback(id); } - /** - * @see GlideOptions#error(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(drawable); - } - return this; + public final GlideRequest error(@Nullable Drawable drawable) { + return (GlideRequest) super.error(drawable); } - /** - * @see GlideOptions#error(int) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(id); - } - return this; + public final GlideRequest error(@DrawableRes int id) { + return (GlideRequest) super.error(id); } - /** - * @see GlideOptions#theme(Resources.Theme) - */ + @Override @NonNull @CheckResult - public GlideRequest theme(@Nullable Resources.Theme theme) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).theme(theme); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(theme); - } - return this; + public final GlideRequest theme(@Nullable Resources.Theme theme) { + return (GlideRequest) super.theme(theme); } - /** - * @see GlideOptions#skipMemoryCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest skipMemoryCache(boolean skip) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); - } - return this; + public final GlideRequest skipMemoryCache(boolean skip) { + return (GlideRequest) super.skipMemoryCache(skip); } - /** - * @see GlideOptions#override(int, int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int width, int height) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); - } - return this; + public final GlideRequest override(int width, int height) { + return (GlideRequest) super.override(width, height); } - /** - * @see GlideOptions#override(int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int size) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); - } - return this; + public final GlideRequest override(int size) { + return (GlideRequest) super.override(size); } - /** - * @see GlideOptions#signature(Key) - */ + @Override @NonNull @CheckResult - public GlideRequest signature(@NonNull Key key) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).signature(key); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(key); - } - return this; + public final GlideRequest signature(@NonNull Key key) { + return (GlideRequest) super.signature(key); } - /** - * @see GlideOptions#set(Option, T) - */ + @Override @NonNull @CheckResult - public GlideRequest set(@NonNull Option option, @NonNull T t) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).set(option, t); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).set(option, t); - } - return this; + public final GlideRequest set(@NonNull Option option, @NonNull Y y) { + return (GlideRequest) super.set(option, y); } - /** - * @see GlideOptions#decode(Class) - */ + @Override @NonNull @CheckResult - public GlideRequest decode(@NonNull Class clazz) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).decode(clazz); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(clazz); - } - return this; + public final GlideRequest decode(@NonNull Class clazz) { + return (GlideRequest) super.decode(clazz); } - /** - * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(format); - } - return this; + public final GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { + return (GlideRequest) super.encodeFormat(format); } - /** - * @see GlideOptions#encodeQuality(int) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(value); - } - return this; + public final GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { + return (GlideRequest) super.encodeQuality(value); } - /** - * @see GlideOptions#frame(long) - */ + @Override @NonNull @CheckResult - public GlideRequest frame(@IntRange(from = 0) long value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).frame(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(value); - } - return this; + public final GlideRequest frame(@IntRange(from = 0) long value) { + return (GlideRequest) super.frame(value); } - /** - * @see GlideOptions#format(DecodeFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest format(@NonNull DecodeFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).format(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).format(format); - } - return this; + public final GlideRequest format(@NonNull DecodeFormat format) { + return (GlideRequest) super.format(format); } - /** - * @see GlideOptions#disallowHardwareConfig() - */ + @Override @NonNull @CheckResult - public GlideRequest disallowHardwareConfig() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); - } - return this; + public final GlideRequest disallowHardwareConfig() { + return (GlideRequest) super.disallowHardwareConfig(); } - /** - * @see GlideOptions#downsample(DownsampleStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest downsample(@NonNull DownsampleStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(strategy); - } - return this; + public final GlideRequest downsample(@NonNull DownsampleStrategy strategy) { + return (GlideRequest) super.downsample(strategy); } - /** - * @see GlideOptions#timeout(int) - */ + @Override @NonNull @CheckResult - public GlideRequest timeout(@IntRange(from = 0) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(value); - } - return this; + public final GlideRequest timeout(@IntRange(from = 0) int value) { + return (GlideRequest) super.timeout(value); } - /** - * @see GlideOptions#optionalCenterCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); - } - return this; + public final GlideRequest optionalCenterCrop() { + return (GlideRequest) super.optionalCenterCrop(); } - /** - * @see GlideOptions#centerCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest centerCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); - } - return this; + public final GlideRequest centerCrop() { + return (GlideRequest) super.centerCrop(); } - /** - * @see GlideOptions#optionalFitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalFitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); - } - return this; + public final GlideRequest optionalFitCenter() { + return (GlideRequest) super.optionalFitCenter(); } - /** - * @see GlideOptions#fitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest fitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); - } - return this; + public final GlideRequest fitCenter() { + return (GlideRequest) super.fitCenter(); } - /** - * @see GlideOptions#optionalCenterInside() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); - } - return this; + public final GlideRequest optionalCenterInside() { + return (GlideRequest) super.optionalCenterInside(); } - /** - * @see GlideOptions#centerInside() - */ + @Override @NonNull @CheckResult - public GlideRequest centerInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); - } - return this; + public final GlideRequest centerInside() { + return (GlideRequest) super.centerInside(); } - /** - * @see GlideOptions#optionalCircleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCircleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); - } - return this; + public final GlideRequest optionalCircleCrop() { + return (GlideRequest) super.optionalCircleCrop(); } - /** - * @see GlideOptions#circleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest circleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); - } - return this; + public final GlideRequest circleCrop() { + return (GlideRequest) super.circleCrop(); } - /** - * @see GlideOptions#transform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(transformation); - } - return this; + public final GlideRequest transform(@NonNull Transformation transformation) { + return (GlideRequest) super.transform(transformation); } - /** - * @see GlideOptions#transforms(Transformation[]) - */ + @Override + @SafeVarargs + @SuppressWarnings("varargs") @NonNull @CheckResult - @SuppressWarnings({ - "unchecked", - "varargs" - }) - public GlideRequest transforms(@NonNull Transformation... transformations) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(transformations); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(transformations); - } - return this; + public final GlideRequest transforms(@NonNull Transformation... transformations) { + return (GlideRequest) super.transforms(transformations); } - /** - * @see GlideOptions#optionalTransform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(transformation); } - /** - * @see GlideOptions#optionalTransform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(clazz, transformation); } - /** - * @see GlideOptions#transform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(clazz, transformation); - } - return this; + public final GlideRequest transform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.transform(clazz, transformation); } - /** - * @see GlideOptions#dontTransform() - */ + @Override @NonNull @CheckResult - public GlideRequest dontTransform() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); - } - return this; + public final GlideRequest dontTransform() { + return (GlideRequest) super.dontTransform(); } - /** - * @see GlideOptions#dontAnimate() - */ + @Override @NonNull @CheckResult - public GlideRequest dontAnimate() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); - } - return this; - } - - /** - * @see GlideOptions#test() - */ - @CheckResult - @NonNull - public GlideRequest test() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).test(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).test(); - } - return this; + public final GlideRequest dontAnimate() { + return (GlideRequest) super.dontAnimate(); } @Override @NonNull @CheckResult - public GlideRequest apply(@NonNull RequestOptions options) { + public GlideRequest apply(@NonNull BaseRequestOptions options) { return (GlideRequest) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideOptions.java index ea3991d196..06c166ec5e 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -430,8 +431,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -572,16 +573,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -602,7 +603,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java index 05b6b7d5c0..46784109cb 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionWithOptionTest/GlideRequest.java @@ -23,8 +23,8 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.RequestOptions; import java.io.File; import java.lang.Class; import java.lang.Cloneable; @@ -39,14 +39,14 @@ /** * Contains all public methods from {@link RequestBuilder}, all options from - * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.request.RequestOptions} and all generated options from * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. * *

Generated code, do not modify. * * @see RequestBuilder - * @see RequestOptions + * @see com.bumptech.glide.request.RequestOptions */ @SuppressWarnings({ "unused", @@ -69,604 +69,301 @@ protected GlideRequest getDownloadOnlyRequest() { return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); } - /** - * @see GlideOptions#sizeMultiplier(float) - */ + @Override @NonNull @CheckResult - public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(value); - } - return this; + public final GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { + return (GlideRequest) super.sizeMultiplier(value); } - /** - * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); - } - return this; + public final GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideRequest) super.useUnlimitedSourceGeneratorsPool(flag); } - /** - * @see GlideOptions#useAnimationPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useAnimationPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); - } - return this; + public final GlideRequest useAnimationPool(boolean flag) { + return (GlideRequest) super.useAnimationPool(flag); } - /** - * @see GlideOptions#onlyRetrieveFromCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest onlyRetrieveFromCache(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); - } - return this; + public final GlideRequest onlyRetrieveFromCache(boolean flag) { + return (GlideRequest) super.onlyRetrieveFromCache(flag); } - /** - * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(strategy); - } - return this; + public final GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { + return (GlideRequest) super.diskCacheStrategy(strategy); } - /** - * @see GlideOptions#priority(Priority) - */ + @Override @NonNull @CheckResult - public GlideRequest priority(@NonNull Priority priority) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).priority(priority); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(priority); - } - return this; + public final GlideRequest priority(@NonNull Priority priority) { + return (GlideRequest) super.priority(priority); } - /** - * @see GlideOptions#placeholder(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(drawable); - } - return this; + public final GlideRequest placeholder(@Nullable Drawable drawable) { + return (GlideRequest) super.placeholder(drawable); } - /** - * @see GlideOptions#placeholder(int) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(id); - } - return this; + public final GlideRequest placeholder(@DrawableRes int id) { + return (GlideRequest) super.placeholder(id); } - /** - * @see GlideOptions#fallback(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(drawable); - } - return this; + public final GlideRequest fallback(@Nullable Drawable drawable) { + return (GlideRequest) super.fallback(drawable); } - /** - * @see GlideOptions#fallback(int) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(id); - } - return this; + public final GlideRequest fallback(@DrawableRes int id) { + return (GlideRequest) super.fallback(id); } - /** - * @see GlideOptions#error(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(drawable); - } - return this; + public final GlideRequest error(@Nullable Drawable drawable) { + return (GlideRequest) super.error(drawable); } - /** - * @see GlideOptions#error(int) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(id); - } - return this; + public final GlideRequest error(@DrawableRes int id) { + return (GlideRequest) super.error(id); } - /** - * @see GlideOptions#theme(Resources.Theme) - */ + @Override @NonNull @CheckResult - public GlideRequest theme(@Nullable Resources.Theme theme) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).theme(theme); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(theme); - } - return this; + public final GlideRequest theme(@Nullable Resources.Theme theme) { + return (GlideRequest) super.theme(theme); } - /** - * @see GlideOptions#skipMemoryCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest skipMemoryCache(boolean skip) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); - } - return this; + public final GlideRequest skipMemoryCache(boolean skip) { + return (GlideRequest) super.skipMemoryCache(skip); } - /** - * @see GlideOptions#override(int, int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int width, int height) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); - } - return this; + public final GlideRequest override(int width, int height) { + return (GlideRequest) super.override(width, height); } - /** - * @see GlideOptions#override(int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int size) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); - } - return this; + public final GlideRequest override(int size) { + return (GlideRequest) super.override(size); } - /** - * @see GlideOptions#signature(Key) - */ + @Override @NonNull @CheckResult - public GlideRequest signature(@NonNull Key key) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).signature(key); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(key); - } - return this; + public final GlideRequest signature(@NonNull Key key) { + return (GlideRequest) super.signature(key); } - /** - * @see GlideOptions#set(Option, T) - */ + @Override @NonNull @CheckResult - public GlideRequest set(@NonNull Option option, @NonNull T t) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).set(option, t); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).set(option, t); - } - return this; + public final GlideRequest set(@NonNull Option option, @NonNull Y y) { + return (GlideRequest) super.set(option, y); } - /** - * @see GlideOptions#decode(Class) - */ + @Override @NonNull @CheckResult - public GlideRequest decode(@NonNull Class clazz) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).decode(clazz); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(clazz); - } - return this; + public final GlideRequest decode(@NonNull Class clazz) { + return (GlideRequest) super.decode(clazz); } - /** - * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(format); - } - return this; + public final GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { + return (GlideRequest) super.encodeFormat(format); } - /** - * @see GlideOptions#encodeQuality(int) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(value); - } - return this; + public final GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { + return (GlideRequest) super.encodeQuality(value); } - /** - * @see GlideOptions#frame(long) - */ + @Override @NonNull @CheckResult - public GlideRequest frame(@IntRange(from = 0) long value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).frame(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(value); - } - return this; + public final GlideRequest frame(@IntRange(from = 0) long value) { + return (GlideRequest) super.frame(value); } - /** - * @see GlideOptions#format(DecodeFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest format(@NonNull DecodeFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).format(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).format(format); - } - return this; + public final GlideRequest format(@NonNull DecodeFormat format) { + return (GlideRequest) super.format(format); } - /** - * @see GlideOptions#disallowHardwareConfig() - */ + @Override @NonNull @CheckResult - public GlideRequest disallowHardwareConfig() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); - } - return this; + public final GlideRequest disallowHardwareConfig() { + return (GlideRequest) super.disallowHardwareConfig(); } - /** - * @see GlideOptions#downsample(DownsampleStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest downsample(@NonNull DownsampleStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(strategy); - } - return this; + public final GlideRequest downsample(@NonNull DownsampleStrategy strategy) { + return (GlideRequest) super.downsample(strategy); } - /** - * @see GlideOptions#timeout(int) - */ + @Override @NonNull @CheckResult - public GlideRequest timeout(@IntRange(from = 0) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(value); - } - return this; + public final GlideRequest timeout(@IntRange(from = 0) int value) { + return (GlideRequest) super.timeout(value); } - /** - * @see GlideOptions#optionalCenterCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); - } - return this; + public final GlideRequest optionalCenterCrop() { + return (GlideRequest) super.optionalCenterCrop(); } - /** - * @see GlideOptions#centerCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest centerCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); - } - return this; + public final GlideRequest centerCrop() { + return (GlideRequest) super.centerCrop(); } - /** - * @see GlideOptions#optionalFitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalFitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); - } - return this; + public final GlideRequest optionalFitCenter() { + return (GlideRequest) super.optionalFitCenter(); } - /** - * @see GlideOptions#fitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest fitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); - } - return this; + public final GlideRequest fitCenter() { + return (GlideRequest) super.fitCenter(); } - /** - * @see GlideOptions#optionalCenterInside() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); - } - return this; + public final GlideRequest optionalCenterInside() { + return (GlideRequest) super.optionalCenterInside(); } - /** - * @see GlideOptions#centerInside() - */ + @Override @NonNull @CheckResult - public GlideRequest centerInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); - } - return this; + public final GlideRequest centerInside() { + return (GlideRequest) super.centerInside(); } - /** - * @see GlideOptions#optionalCircleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCircleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); - } - return this; + public final GlideRequest optionalCircleCrop() { + return (GlideRequest) super.optionalCircleCrop(); } - /** - * @see GlideOptions#circleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest circleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); - } - return this; + public final GlideRequest circleCrop() { + return (GlideRequest) super.circleCrop(); } - /** - * @see GlideOptions#transform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(transformation); - } - return this; + public final GlideRequest transform(@NonNull Transformation transformation) { + return (GlideRequest) super.transform(transformation); } - /** - * @see GlideOptions#transforms(Transformation[]) - */ + @Override + @SafeVarargs + @SuppressWarnings("varargs") @NonNull @CheckResult - @SuppressWarnings({ - "unchecked", - "varargs" - }) - public GlideRequest transforms(@NonNull Transformation... transformations) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(transformations); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(transformations); - } - return this; + public final GlideRequest transforms(@NonNull Transformation... transformations) { + return (GlideRequest) super.transforms(transformations); } - /** - * @see GlideOptions#optionalTransform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(transformation); } - /** - * @see GlideOptions#optionalTransform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(clazz, transformation); } - /** - * @see GlideOptions#transform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(clazz, transformation); - } - return this; + public final GlideRequest transform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.transform(clazz, transformation); } - /** - * @see GlideOptions#dontTransform() - */ + @Override @NonNull @CheckResult - public GlideRequest dontTransform() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); - } - return this; + public final GlideRequest dontTransform() { + return (GlideRequest) super.dontTransform(); } - /** - * @see GlideOptions#dontAnimate() - */ + @Override @NonNull @CheckResult - public GlideRequest dontAnimate() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); - } - return this; - } - - /** - * @see GlideOptions#squareThumb() - */ - @CheckResult - @NonNull - public GlideRequest squareThumb() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).squareThumb(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).squareThumb(); - } - return this; + public final GlideRequest dontAnimate() { + return (GlideRequest) super.dontAnimate(); } @Override @NonNull @CheckResult - public GlideRequest apply(@NonNull RequestOptions options) { + public GlideRequest apply(@NonNull BaseRequestOptions options) { return (GlideRequest) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/GlideExtensionWithTypeTest/GlideOptions.java b/annotation/compiler/test/src/test/resources/GlideExtensionWithTypeTest/GlideOptions.java index 558dc9f8cb..ad1030d178 100644 --- a/annotation/compiler/test/src/test/resources/GlideExtensionWithTypeTest/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/GlideExtensionWithTypeTest/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -430,8 +431,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -572,16 +573,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -602,7 +603,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java index 76a59cadd8..a910dab15c 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -432,8 +433,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -574,16 +575,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -604,7 +605,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java index f0377a0a7c..46784109cb 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/MemoizeStaticMethod/GlideRequest.java @@ -23,8 +23,8 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.RequestOptions; import java.io.File; import java.lang.Class; import java.lang.Cloneable; @@ -39,14 +39,14 @@ /** * Contains all public methods from {@link RequestBuilder}, all options from - * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.request.RequestOptions} and all generated options from * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. * *

Generated code, do not modify. * * @see RequestBuilder - * @see RequestOptions + * @see com.bumptech.glide.request.RequestOptions */ @SuppressWarnings({ "unused", @@ -69,604 +69,301 @@ protected GlideRequest getDownloadOnlyRequest() { return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); } - /** - * @see GlideOptions#sizeMultiplier(float) - */ + @Override @NonNull @CheckResult - public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(value); - } - return this; + public final GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { + return (GlideRequest) super.sizeMultiplier(value); } - /** - * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); - } - return this; + public final GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideRequest) super.useUnlimitedSourceGeneratorsPool(flag); } - /** - * @see GlideOptions#useAnimationPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useAnimationPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); - } - return this; + public final GlideRequest useAnimationPool(boolean flag) { + return (GlideRequest) super.useAnimationPool(flag); } - /** - * @see GlideOptions#onlyRetrieveFromCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest onlyRetrieveFromCache(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); - } - return this; + public final GlideRequest onlyRetrieveFromCache(boolean flag) { + return (GlideRequest) super.onlyRetrieveFromCache(flag); } - /** - * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(strategy); - } - return this; + public final GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { + return (GlideRequest) super.diskCacheStrategy(strategy); } - /** - * @see GlideOptions#priority(Priority) - */ + @Override @NonNull @CheckResult - public GlideRequest priority(@NonNull Priority priority) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).priority(priority); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(priority); - } - return this; + public final GlideRequest priority(@NonNull Priority priority) { + return (GlideRequest) super.priority(priority); } - /** - * @see GlideOptions#placeholder(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(drawable); - } - return this; + public final GlideRequest placeholder(@Nullable Drawable drawable) { + return (GlideRequest) super.placeholder(drawable); } - /** - * @see GlideOptions#placeholder(int) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(id); - } - return this; + public final GlideRequest placeholder(@DrawableRes int id) { + return (GlideRequest) super.placeholder(id); } - /** - * @see GlideOptions#fallback(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(drawable); - } - return this; + public final GlideRequest fallback(@Nullable Drawable drawable) { + return (GlideRequest) super.fallback(drawable); } - /** - * @see GlideOptions#fallback(int) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(id); - } - return this; + public final GlideRequest fallback(@DrawableRes int id) { + return (GlideRequest) super.fallback(id); } - /** - * @see GlideOptions#error(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(drawable); - } - return this; + public final GlideRequest error(@Nullable Drawable drawable) { + return (GlideRequest) super.error(drawable); } - /** - * @see GlideOptions#error(int) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(id); - } - return this; + public final GlideRequest error(@DrawableRes int id) { + return (GlideRequest) super.error(id); } - /** - * @see GlideOptions#theme(Resources.Theme) - */ + @Override @NonNull @CheckResult - public GlideRequest theme(@Nullable Resources.Theme theme) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).theme(theme); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(theme); - } - return this; + public final GlideRequest theme(@Nullable Resources.Theme theme) { + return (GlideRequest) super.theme(theme); } - /** - * @see GlideOptions#skipMemoryCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest skipMemoryCache(boolean skip) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); - } - return this; + public final GlideRequest skipMemoryCache(boolean skip) { + return (GlideRequest) super.skipMemoryCache(skip); } - /** - * @see GlideOptions#override(int, int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int width, int height) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); - } - return this; + public final GlideRequest override(int width, int height) { + return (GlideRequest) super.override(width, height); } - /** - * @see GlideOptions#override(int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int size) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); - } - return this; + public final GlideRequest override(int size) { + return (GlideRequest) super.override(size); } - /** - * @see GlideOptions#signature(Key) - */ + @Override @NonNull @CheckResult - public GlideRequest signature(@NonNull Key key) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).signature(key); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(key); - } - return this; + public final GlideRequest signature(@NonNull Key key) { + return (GlideRequest) super.signature(key); } - /** - * @see GlideOptions#set(Option, T) - */ + @Override @NonNull @CheckResult - public GlideRequest set(@NonNull Option option, @NonNull T t) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).set(option, t); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).set(option, t); - } - return this; + public final GlideRequest set(@NonNull Option option, @NonNull Y y) { + return (GlideRequest) super.set(option, y); } - /** - * @see GlideOptions#decode(Class) - */ + @Override @NonNull @CheckResult - public GlideRequest decode(@NonNull Class clazz) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).decode(clazz); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(clazz); - } - return this; + public final GlideRequest decode(@NonNull Class clazz) { + return (GlideRequest) super.decode(clazz); } - /** - * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(format); - } - return this; + public final GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { + return (GlideRequest) super.encodeFormat(format); } - /** - * @see GlideOptions#encodeQuality(int) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(value); - } - return this; + public final GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { + return (GlideRequest) super.encodeQuality(value); } - /** - * @see GlideOptions#frame(long) - */ + @Override @NonNull @CheckResult - public GlideRequest frame(@IntRange(from = 0) long value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).frame(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(value); - } - return this; + public final GlideRequest frame(@IntRange(from = 0) long value) { + return (GlideRequest) super.frame(value); } - /** - * @see GlideOptions#format(DecodeFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest format(@NonNull DecodeFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).format(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).format(format); - } - return this; + public final GlideRequest format(@NonNull DecodeFormat format) { + return (GlideRequest) super.format(format); } - /** - * @see GlideOptions#disallowHardwareConfig() - */ + @Override @NonNull @CheckResult - public GlideRequest disallowHardwareConfig() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); - } - return this; + public final GlideRequest disallowHardwareConfig() { + return (GlideRequest) super.disallowHardwareConfig(); } - /** - * @see GlideOptions#downsample(DownsampleStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest downsample(@NonNull DownsampleStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(strategy); - } - return this; + public final GlideRequest downsample(@NonNull DownsampleStrategy strategy) { + return (GlideRequest) super.downsample(strategy); } - /** - * @see GlideOptions#timeout(int) - */ + @Override @NonNull @CheckResult - public GlideRequest timeout(@IntRange(from = 0) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(value); - } - return this; + public final GlideRequest timeout(@IntRange(from = 0) int value) { + return (GlideRequest) super.timeout(value); } - /** - * @see GlideOptions#optionalCenterCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); - } - return this; + public final GlideRequest optionalCenterCrop() { + return (GlideRequest) super.optionalCenterCrop(); } - /** - * @see GlideOptions#centerCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest centerCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); - } - return this; + public final GlideRequest centerCrop() { + return (GlideRequest) super.centerCrop(); } - /** - * @see GlideOptions#optionalFitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalFitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); - } - return this; + public final GlideRequest optionalFitCenter() { + return (GlideRequest) super.optionalFitCenter(); } - /** - * @see GlideOptions#fitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest fitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); - } - return this; + public final GlideRequest fitCenter() { + return (GlideRequest) super.fitCenter(); } - /** - * @see GlideOptions#optionalCenterInside() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); - } - return this; + public final GlideRequest optionalCenterInside() { + return (GlideRequest) super.optionalCenterInside(); } - /** - * @see GlideOptions#centerInside() - */ + @Override @NonNull @CheckResult - public GlideRequest centerInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); - } - return this; + public final GlideRequest centerInside() { + return (GlideRequest) super.centerInside(); } - /** - * @see GlideOptions#optionalCircleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCircleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); - } - return this; + public final GlideRequest optionalCircleCrop() { + return (GlideRequest) super.optionalCircleCrop(); } - /** - * @see GlideOptions#circleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest circleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); - } - return this; + public final GlideRequest circleCrop() { + return (GlideRequest) super.circleCrop(); } - /** - * @see GlideOptions#transform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(transformation); - } - return this; + public final GlideRequest transform(@NonNull Transformation transformation) { + return (GlideRequest) super.transform(transformation); } - /** - * @see GlideOptions#transforms(Transformation[]) - */ + @Override + @SafeVarargs + @SuppressWarnings("varargs") @NonNull @CheckResult - @SuppressWarnings({ - "unchecked", - "varargs" - }) - public GlideRequest transforms(@NonNull Transformation... transformations) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(transformations); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(transformations); - } - return this; + public final GlideRequest transforms(@NonNull Transformation... transformations) { + return (GlideRequest) super.transforms(transformations); } - /** - * @see GlideOptions#optionalTransform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(transformation); } - /** - * @see GlideOptions#optionalTransform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(clazz, transformation); } - /** - * @see GlideOptions#transform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(clazz, transformation); - } - return this; + public final GlideRequest transform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.transform(clazz, transformation); } - /** - * @see GlideOptions#dontTransform() - */ + @Override @NonNull @CheckResult - public GlideRequest dontTransform() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); - } - return this; + public final GlideRequest dontTransform() { + return (GlideRequest) super.dontTransform(); } - /** - * @see GlideOptions#dontAnimate() - */ + @Override @NonNull @CheckResult - public GlideRequest dontAnimate() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); - } - return this; - } - - /** - * @see GlideOptions#test() - */ - @CheckResult - @NonNull - public GlideRequest test() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).test(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).test(); - } - return this; + public final GlideRequest dontAnimate() { + return (GlideRequest) super.dontAnimate(); } @Override @NonNull @CheckResult - public GlideRequest apply(@NonNull RequestOptions options) { + public GlideRequest apply(@NonNull BaseRequestOptions options) { return (GlideRequest) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideOptions.java index e7bfc9733b..ab5a9750af 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -430,8 +431,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -565,16 +566,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -595,7 +596,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideRequest.java index ee391f551e..46784109cb 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideExtend/GlideRequest.java @@ -23,8 +23,8 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.RequestOptions; import java.io.File; import java.lang.Class; import java.lang.Cloneable; @@ -39,14 +39,14 @@ /** * Contains all public methods from {@link RequestBuilder}, all options from - * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.request.RequestOptions} and all generated options from * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. * *

Generated code, do not modify. * * @see RequestBuilder - * @see RequestOptions + * @see com.bumptech.glide.request.RequestOptions */ @SuppressWarnings({ "unused", @@ -69,590 +69,301 @@ protected GlideRequest getDownloadOnlyRequest() { return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); } - /** - * @see GlideOptions#sizeMultiplier(float) - */ + @Override @NonNull @CheckResult - public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(value); - } - return this; + public final GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { + return (GlideRequest) super.sizeMultiplier(value); } - /** - * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); - } - return this; + public final GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideRequest) super.useUnlimitedSourceGeneratorsPool(flag); } - /** - * @see GlideOptions#useAnimationPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useAnimationPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); - } - return this; + public final GlideRequest useAnimationPool(boolean flag) { + return (GlideRequest) super.useAnimationPool(flag); } - /** - * @see GlideOptions#onlyRetrieveFromCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest onlyRetrieveFromCache(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); - } - return this; + public final GlideRequest onlyRetrieveFromCache(boolean flag) { + return (GlideRequest) super.onlyRetrieveFromCache(flag); } - /** - * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(strategy); - } - return this; + public final GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { + return (GlideRequest) super.diskCacheStrategy(strategy); } - /** - * @see GlideOptions#priority(Priority) - */ + @Override @NonNull @CheckResult - public GlideRequest priority(@NonNull Priority priority) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).priority(priority); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(priority); - } - return this; + public final GlideRequest priority(@NonNull Priority priority) { + return (GlideRequest) super.priority(priority); } - /** - * @see GlideOptions#placeholder(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(drawable); - } - return this; + public final GlideRequest placeholder(@Nullable Drawable drawable) { + return (GlideRequest) super.placeholder(drawable); } - /** - * @see GlideOptions#placeholder(int) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(id); - } - return this; + public final GlideRequest placeholder(@DrawableRes int id) { + return (GlideRequest) super.placeholder(id); } - /** - * @see GlideOptions#fallback(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(drawable); - } - return this; + public final GlideRequest fallback(@Nullable Drawable drawable) { + return (GlideRequest) super.fallback(drawable); } - /** - * @see GlideOptions#fallback(int) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(id); - } - return this; + public final GlideRequest fallback(@DrawableRes int id) { + return (GlideRequest) super.fallback(id); } - /** - * @see GlideOptions#error(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(drawable); - } - return this; + public final GlideRequest error(@Nullable Drawable drawable) { + return (GlideRequest) super.error(drawable); } - /** - * @see GlideOptions#error(int) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(id); - } - return this; + public final GlideRequest error(@DrawableRes int id) { + return (GlideRequest) super.error(id); } - /** - * @see GlideOptions#theme(Resources.Theme) - */ + @Override @NonNull @CheckResult - public GlideRequest theme(@Nullable Resources.Theme theme) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).theme(theme); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(theme); - } - return this; + public final GlideRequest theme(@Nullable Resources.Theme theme) { + return (GlideRequest) super.theme(theme); } - /** - * @see GlideOptions#skipMemoryCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest skipMemoryCache(boolean skip) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); - } - return this; + public final GlideRequest skipMemoryCache(boolean skip) { + return (GlideRequest) super.skipMemoryCache(skip); } - /** - * @see GlideOptions#override(int, int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int width, int height) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); - } - return this; + public final GlideRequest override(int width, int height) { + return (GlideRequest) super.override(width, height); } - /** - * @see GlideOptions#override(int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int size) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); - } - return this; + public final GlideRequest override(int size) { + return (GlideRequest) super.override(size); } - /** - * @see GlideOptions#signature(Key) - */ + @Override @NonNull @CheckResult - public GlideRequest signature(@NonNull Key key) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).signature(key); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(key); - } - return this; + public final GlideRequest signature(@NonNull Key key) { + return (GlideRequest) super.signature(key); } - /** - * @see GlideOptions#set(Option, T) - */ + @Override @NonNull @CheckResult - public GlideRequest set(@NonNull Option option, @NonNull T t) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).set(option, t); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).set(option, t); - } - return this; + public final GlideRequest set(@NonNull Option option, @NonNull Y y) { + return (GlideRequest) super.set(option, y); } - /** - * @see GlideOptions#decode(Class) - */ + @Override @NonNull @CheckResult - public GlideRequest decode(@NonNull Class clazz) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).decode(clazz); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(clazz); - } - return this; + public final GlideRequest decode(@NonNull Class clazz) { + return (GlideRequest) super.decode(clazz); } - /** - * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(format); - } - return this; + public final GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { + return (GlideRequest) super.encodeFormat(format); } - /** - * @see GlideOptions#encodeQuality(int) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(value); - } - return this; + public final GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { + return (GlideRequest) super.encodeQuality(value); } - /** - * @see GlideOptions#frame(long) - */ + @Override @NonNull @CheckResult - public GlideRequest frame(@IntRange(from = 0) long value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).frame(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(value); - } - return this; + public final GlideRequest frame(@IntRange(from = 0) long value) { + return (GlideRequest) super.frame(value); } - /** - * @see GlideOptions#format(DecodeFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest format(@NonNull DecodeFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).format(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).format(format); - } - return this; + public final GlideRequest format(@NonNull DecodeFormat format) { + return (GlideRequest) super.format(format); } - /** - * @see GlideOptions#disallowHardwareConfig() - */ + @Override @NonNull @CheckResult - public GlideRequest disallowHardwareConfig() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); - } - return this; + public final GlideRequest disallowHardwareConfig() { + return (GlideRequest) super.disallowHardwareConfig(); } - /** - * @see GlideOptions#downsample(DownsampleStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest downsample(@NonNull DownsampleStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(strategy); - } - return this; + public final GlideRequest downsample(@NonNull DownsampleStrategy strategy) { + return (GlideRequest) super.downsample(strategy); } - /** - * @see GlideOptions#timeout(int) - */ + @Override @NonNull @CheckResult - public GlideRequest timeout(@IntRange(from = 0) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(value); - } - return this; + public final GlideRequest timeout(@IntRange(from = 0) int value) { + return (GlideRequest) super.timeout(value); } - /** - * @see GlideOptions#optionalCenterCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); - } - return this; + public final GlideRequest optionalCenterCrop() { + return (GlideRequest) super.optionalCenterCrop(); } - /** - * @see GlideOptions#optionalFitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalFitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); - } - return this; + public final GlideRequest centerCrop() { + return (GlideRequest) super.centerCrop(); } - /** - * @see GlideOptions#fitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest fitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); - } - return this; + public final GlideRequest optionalFitCenter() { + return (GlideRequest) super.optionalFitCenter(); } - /** - * @see GlideOptions#optionalCenterInside() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); - } - return this; + public final GlideRequest fitCenter() { + return (GlideRequest) super.fitCenter(); } - /** - * @see GlideOptions#centerInside() - */ + @Override @NonNull @CheckResult - public GlideRequest centerInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); - } - return this; + public final GlideRequest optionalCenterInside() { + return (GlideRequest) super.optionalCenterInside(); } - /** - * @see GlideOptions#optionalCircleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCircleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); - } - return this; + public final GlideRequest centerInside() { + return (GlideRequest) super.centerInside(); } - /** - * @see GlideOptions#circleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest circleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); - } - return this; + public final GlideRequest optionalCircleCrop() { + return (GlideRequest) super.optionalCircleCrop(); } - /** - * @see GlideOptions#transform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(transformation); - } - return this; + public final GlideRequest circleCrop() { + return (GlideRequest) super.circleCrop(); } - /** - * @see GlideOptions#transforms(Transformation[]) - */ + @Override @NonNull @CheckResult - @SuppressWarnings({ - "unchecked", - "varargs" - }) - public GlideRequest transforms(@NonNull Transformation... transformations) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(transformations); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(transformations); - } - return this; + public final GlideRequest transform(@NonNull Transformation transformation) { + return (GlideRequest) super.transform(transformation); } - /** - * @see GlideOptions#optionalTransform(Transformation) - */ + @Override + @SafeVarargs + @SuppressWarnings("varargs") @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(transformation); - } - return this; + public final GlideRequest transforms(@NonNull Transformation... transformations) { + return (GlideRequest) super.transforms(transformations); } - /** - * @see GlideOptions#optionalTransform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(transformation); } - /** - * @see GlideOptions#transform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(clazz, transformation); } - /** - * @see GlideOptions#dontTransform() - */ + @Override @NonNull @CheckResult - public GlideRequest dontTransform() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); - } - return this; + public final GlideRequest transform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.transform(clazz, transformation); } - /** - * @see GlideOptions#dontAnimate() - */ + @Override @NonNull @CheckResult - public GlideRequest dontAnimate() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); - } - return this; + public final GlideRequest dontTransform() { + return (GlideRequest) super.dontTransform(); } - /** - * @see GlideOptions#centerCrop() - */ - @CheckResult + @Override @NonNull - public GlideRequest centerCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); - } - return this; + @CheckResult + public final GlideRequest dontAnimate() { + return (GlideRequest) super.dontAnimate(); } @Override @NonNull @CheckResult - public GlideRequest apply(@NonNull RequestOptions options) { + public GlideRequest apply(@NonNull BaseRequestOptions options) { return (GlideRequest) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideOptions.java index 5474f2008a..de051a0477 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -430,8 +431,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -565,16 +566,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -595,7 +596,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideRequest.java index ee391f551e..46784109cb 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/OverrideReplace/GlideRequest.java @@ -23,8 +23,8 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.RequestOptions; import java.io.File; import java.lang.Class; import java.lang.Cloneable; @@ -39,14 +39,14 @@ /** * Contains all public methods from {@link RequestBuilder}, all options from - * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.request.RequestOptions} and all generated options from * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. * *

Generated code, do not modify. * * @see RequestBuilder - * @see RequestOptions + * @see com.bumptech.glide.request.RequestOptions */ @SuppressWarnings({ "unused", @@ -69,590 +69,301 @@ protected GlideRequest getDownloadOnlyRequest() { return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); } - /** - * @see GlideOptions#sizeMultiplier(float) - */ + @Override @NonNull @CheckResult - public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(value); - } - return this; + public final GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { + return (GlideRequest) super.sizeMultiplier(value); } - /** - * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); - } - return this; + public final GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideRequest) super.useUnlimitedSourceGeneratorsPool(flag); } - /** - * @see GlideOptions#useAnimationPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useAnimationPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); - } - return this; + public final GlideRequest useAnimationPool(boolean flag) { + return (GlideRequest) super.useAnimationPool(flag); } - /** - * @see GlideOptions#onlyRetrieveFromCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest onlyRetrieveFromCache(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); - } - return this; + public final GlideRequest onlyRetrieveFromCache(boolean flag) { + return (GlideRequest) super.onlyRetrieveFromCache(flag); } - /** - * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(strategy); - } - return this; + public final GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { + return (GlideRequest) super.diskCacheStrategy(strategy); } - /** - * @see GlideOptions#priority(Priority) - */ + @Override @NonNull @CheckResult - public GlideRequest priority(@NonNull Priority priority) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).priority(priority); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(priority); - } - return this; + public final GlideRequest priority(@NonNull Priority priority) { + return (GlideRequest) super.priority(priority); } - /** - * @see GlideOptions#placeholder(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(drawable); - } - return this; + public final GlideRequest placeholder(@Nullable Drawable drawable) { + return (GlideRequest) super.placeholder(drawable); } - /** - * @see GlideOptions#placeholder(int) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(id); - } - return this; + public final GlideRequest placeholder(@DrawableRes int id) { + return (GlideRequest) super.placeholder(id); } - /** - * @see GlideOptions#fallback(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(drawable); - } - return this; + public final GlideRequest fallback(@Nullable Drawable drawable) { + return (GlideRequest) super.fallback(drawable); } - /** - * @see GlideOptions#fallback(int) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(id); - } - return this; + public final GlideRequest fallback(@DrawableRes int id) { + return (GlideRequest) super.fallback(id); } - /** - * @see GlideOptions#error(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(drawable); - } - return this; + public final GlideRequest error(@Nullable Drawable drawable) { + return (GlideRequest) super.error(drawable); } - /** - * @see GlideOptions#error(int) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(id); - } - return this; + public final GlideRequest error(@DrawableRes int id) { + return (GlideRequest) super.error(id); } - /** - * @see GlideOptions#theme(Resources.Theme) - */ + @Override @NonNull @CheckResult - public GlideRequest theme(@Nullable Resources.Theme theme) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).theme(theme); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(theme); - } - return this; + public final GlideRequest theme(@Nullable Resources.Theme theme) { + return (GlideRequest) super.theme(theme); } - /** - * @see GlideOptions#skipMemoryCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest skipMemoryCache(boolean skip) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); - } - return this; + public final GlideRequest skipMemoryCache(boolean skip) { + return (GlideRequest) super.skipMemoryCache(skip); } - /** - * @see GlideOptions#override(int, int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int width, int height) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); - } - return this; + public final GlideRequest override(int width, int height) { + return (GlideRequest) super.override(width, height); } - /** - * @see GlideOptions#override(int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int size) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); - } - return this; + public final GlideRequest override(int size) { + return (GlideRequest) super.override(size); } - /** - * @see GlideOptions#signature(Key) - */ + @Override @NonNull @CheckResult - public GlideRequest signature(@NonNull Key key) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).signature(key); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(key); - } - return this; + public final GlideRequest signature(@NonNull Key key) { + return (GlideRequest) super.signature(key); } - /** - * @see GlideOptions#set(Option, T) - */ + @Override @NonNull @CheckResult - public GlideRequest set(@NonNull Option option, @NonNull T t) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).set(option, t); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).set(option, t); - } - return this; + public final GlideRequest set(@NonNull Option option, @NonNull Y y) { + return (GlideRequest) super.set(option, y); } - /** - * @see GlideOptions#decode(Class) - */ + @Override @NonNull @CheckResult - public GlideRequest decode(@NonNull Class clazz) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).decode(clazz); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(clazz); - } - return this; + public final GlideRequest decode(@NonNull Class clazz) { + return (GlideRequest) super.decode(clazz); } - /** - * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(format); - } - return this; + public final GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { + return (GlideRequest) super.encodeFormat(format); } - /** - * @see GlideOptions#encodeQuality(int) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(value); - } - return this; + public final GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { + return (GlideRequest) super.encodeQuality(value); } - /** - * @see GlideOptions#frame(long) - */ + @Override @NonNull @CheckResult - public GlideRequest frame(@IntRange(from = 0) long value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).frame(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(value); - } - return this; + public final GlideRequest frame(@IntRange(from = 0) long value) { + return (GlideRequest) super.frame(value); } - /** - * @see GlideOptions#format(DecodeFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest format(@NonNull DecodeFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).format(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).format(format); - } - return this; + public final GlideRequest format(@NonNull DecodeFormat format) { + return (GlideRequest) super.format(format); } - /** - * @see GlideOptions#disallowHardwareConfig() - */ + @Override @NonNull @CheckResult - public GlideRequest disallowHardwareConfig() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); - } - return this; + public final GlideRequest disallowHardwareConfig() { + return (GlideRequest) super.disallowHardwareConfig(); } - /** - * @see GlideOptions#downsample(DownsampleStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest downsample(@NonNull DownsampleStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(strategy); - } - return this; + public final GlideRequest downsample(@NonNull DownsampleStrategy strategy) { + return (GlideRequest) super.downsample(strategy); } - /** - * @see GlideOptions#timeout(int) - */ + @Override @NonNull @CheckResult - public GlideRequest timeout(@IntRange(from = 0) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(value); - } - return this; + public final GlideRequest timeout(@IntRange(from = 0) int value) { + return (GlideRequest) super.timeout(value); } - /** - * @see GlideOptions#optionalCenterCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); - } - return this; + public final GlideRequest optionalCenterCrop() { + return (GlideRequest) super.optionalCenterCrop(); } - /** - * @see GlideOptions#optionalFitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalFitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); - } - return this; + public final GlideRequest centerCrop() { + return (GlideRequest) super.centerCrop(); } - /** - * @see GlideOptions#fitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest fitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); - } - return this; + public final GlideRequest optionalFitCenter() { + return (GlideRequest) super.optionalFitCenter(); } - /** - * @see GlideOptions#optionalCenterInside() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); - } - return this; + public final GlideRequest fitCenter() { + return (GlideRequest) super.fitCenter(); } - /** - * @see GlideOptions#centerInside() - */ + @Override @NonNull @CheckResult - public GlideRequest centerInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); - } - return this; + public final GlideRequest optionalCenterInside() { + return (GlideRequest) super.optionalCenterInside(); } - /** - * @see GlideOptions#optionalCircleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCircleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); - } - return this; + public final GlideRequest centerInside() { + return (GlideRequest) super.centerInside(); } - /** - * @see GlideOptions#circleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest circleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); - } - return this; + public final GlideRequest optionalCircleCrop() { + return (GlideRequest) super.optionalCircleCrop(); } - /** - * @see GlideOptions#transform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(transformation); - } - return this; + public final GlideRequest circleCrop() { + return (GlideRequest) super.circleCrop(); } - /** - * @see GlideOptions#transforms(Transformation[]) - */ + @Override @NonNull @CheckResult - @SuppressWarnings({ - "unchecked", - "varargs" - }) - public GlideRequest transforms(@NonNull Transformation... transformations) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(transformations); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(transformations); - } - return this; + public final GlideRequest transform(@NonNull Transformation transformation) { + return (GlideRequest) super.transform(transformation); } - /** - * @see GlideOptions#optionalTransform(Transformation) - */ + @Override + @SafeVarargs + @SuppressWarnings("varargs") @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(transformation); - } - return this; + public final GlideRequest transforms(@NonNull Transformation... transformations) { + return (GlideRequest) super.transforms(transformations); } - /** - * @see GlideOptions#optionalTransform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(transformation); } - /** - * @see GlideOptions#transform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(clazz, transformation); } - /** - * @see GlideOptions#dontTransform() - */ + @Override @NonNull @CheckResult - public GlideRequest dontTransform() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); - } - return this; + public final GlideRequest transform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.transform(clazz, transformation); } - /** - * @see GlideOptions#dontAnimate() - */ + @Override @NonNull @CheckResult - public GlideRequest dontAnimate() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); - } - return this; + public final GlideRequest dontTransform() { + return (GlideRequest) super.dontTransform(); } - /** - * @see GlideOptions#centerCrop() - */ - @CheckResult + @Override @NonNull - public GlideRequest centerCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); - } - return this; + @CheckResult + public final GlideRequest dontAnimate() { + return (GlideRequest) super.dontAnimate(); } @Override @NonNull @CheckResult - public GlideRequest apply(@NonNull RequestOptions options) { + public GlideRequest apply(@NonNull BaseRequestOptions options) { return (GlideRequest) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java index 3e78d0ad4c..8f7ce94388 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -430,8 +431,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -572,16 +573,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -602,7 +603,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java index f0377a0a7c..46784109cb 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/SkipStaticMethod/GlideRequest.java @@ -23,8 +23,8 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.RequestOptions; import java.io.File; import java.lang.Class; import java.lang.Cloneable; @@ -39,14 +39,14 @@ /** * Contains all public methods from {@link RequestBuilder}, all options from - * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.request.RequestOptions} and all generated options from * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. * *

Generated code, do not modify. * * @see RequestBuilder - * @see RequestOptions + * @see com.bumptech.glide.request.RequestOptions */ @SuppressWarnings({ "unused", @@ -69,604 +69,301 @@ protected GlideRequest getDownloadOnlyRequest() { return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); } - /** - * @see GlideOptions#sizeMultiplier(float) - */ + @Override @NonNull @CheckResult - public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(value); - } - return this; + public final GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { + return (GlideRequest) super.sizeMultiplier(value); } - /** - * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); - } - return this; + public final GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideRequest) super.useUnlimitedSourceGeneratorsPool(flag); } - /** - * @see GlideOptions#useAnimationPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useAnimationPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); - } - return this; + public final GlideRequest useAnimationPool(boolean flag) { + return (GlideRequest) super.useAnimationPool(flag); } - /** - * @see GlideOptions#onlyRetrieveFromCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest onlyRetrieveFromCache(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); - } - return this; + public final GlideRequest onlyRetrieveFromCache(boolean flag) { + return (GlideRequest) super.onlyRetrieveFromCache(flag); } - /** - * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(strategy); - } - return this; + public final GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { + return (GlideRequest) super.diskCacheStrategy(strategy); } - /** - * @see GlideOptions#priority(Priority) - */ + @Override @NonNull @CheckResult - public GlideRequest priority(@NonNull Priority priority) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).priority(priority); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(priority); - } - return this; + public final GlideRequest priority(@NonNull Priority priority) { + return (GlideRequest) super.priority(priority); } - /** - * @see GlideOptions#placeholder(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(drawable); - } - return this; + public final GlideRequest placeholder(@Nullable Drawable drawable) { + return (GlideRequest) super.placeholder(drawable); } - /** - * @see GlideOptions#placeholder(int) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(id); - } - return this; + public final GlideRequest placeholder(@DrawableRes int id) { + return (GlideRequest) super.placeholder(id); } - /** - * @see GlideOptions#fallback(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(drawable); - } - return this; + public final GlideRequest fallback(@Nullable Drawable drawable) { + return (GlideRequest) super.fallback(drawable); } - /** - * @see GlideOptions#fallback(int) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(id); - } - return this; + public final GlideRequest fallback(@DrawableRes int id) { + return (GlideRequest) super.fallback(id); } - /** - * @see GlideOptions#error(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(drawable); - } - return this; + public final GlideRequest error(@Nullable Drawable drawable) { + return (GlideRequest) super.error(drawable); } - /** - * @see GlideOptions#error(int) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(id); - } - return this; + public final GlideRequest error(@DrawableRes int id) { + return (GlideRequest) super.error(id); } - /** - * @see GlideOptions#theme(Resources.Theme) - */ + @Override @NonNull @CheckResult - public GlideRequest theme(@Nullable Resources.Theme theme) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).theme(theme); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(theme); - } - return this; + public final GlideRequest theme(@Nullable Resources.Theme theme) { + return (GlideRequest) super.theme(theme); } - /** - * @see GlideOptions#skipMemoryCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest skipMemoryCache(boolean skip) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); - } - return this; + public final GlideRequest skipMemoryCache(boolean skip) { + return (GlideRequest) super.skipMemoryCache(skip); } - /** - * @see GlideOptions#override(int, int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int width, int height) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); - } - return this; + public final GlideRequest override(int width, int height) { + return (GlideRequest) super.override(width, height); } - /** - * @see GlideOptions#override(int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int size) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); - } - return this; + public final GlideRequest override(int size) { + return (GlideRequest) super.override(size); } - /** - * @see GlideOptions#signature(Key) - */ + @Override @NonNull @CheckResult - public GlideRequest signature(@NonNull Key key) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).signature(key); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(key); - } - return this; + public final GlideRequest signature(@NonNull Key key) { + return (GlideRequest) super.signature(key); } - /** - * @see GlideOptions#set(Option, T) - */ + @Override @NonNull @CheckResult - public GlideRequest set(@NonNull Option option, @NonNull T t) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).set(option, t); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).set(option, t); - } - return this; + public final GlideRequest set(@NonNull Option option, @NonNull Y y) { + return (GlideRequest) super.set(option, y); } - /** - * @see GlideOptions#decode(Class) - */ + @Override @NonNull @CheckResult - public GlideRequest decode(@NonNull Class clazz) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).decode(clazz); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(clazz); - } - return this; + public final GlideRequest decode(@NonNull Class clazz) { + return (GlideRequest) super.decode(clazz); } - /** - * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(format); - } - return this; + public final GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { + return (GlideRequest) super.encodeFormat(format); } - /** - * @see GlideOptions#encodeQuality(int) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(value); - } - return this; + public final GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { + return (GlideRequest) super.encodeQuality(value); } - /** - * @see GlideOptions#frame(long) - */ + @Override @NonNull @CheckResult - public GlideRequest frame(@IntRange(from = 0) long value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).frame(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(value); - } - return this; + public final GlideRequest frame(@IntRange(from = 0) long value) { + return (GlideRequest) super.frame(value); } - /** - * @see GlideOptions#format(DecodeFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest format(@NonNull DecodeFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).format(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).format(format); - } - return this; + public final GlideRequest format(@NonNull DecodeFormat format) { + return (GlideRequest) super.format(format); } - /** - * @see GlideOptions#disallowHardwareConfig() - */ + @Override @NonNull @CheckResult - public GlideRequest disallowHardwareConfig() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); - } - return this; + public final GlideRequest disallowHardwareConfig() { + return (GlideRequest) super.disallowHardwareConfig(); } - /** - * @see GlideOptions#downsample(DownsampleStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest downsample(@NonNull DownsampleStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(strategy); - } - return this; + public final GlideRequest downsample(@NonNull DownsampleStrategy strategy) { + return (GlideRequest) super.downsample(strategy); } - /** - * @see GlideOptions#timeout(int) - */ + @Override @NonNull @CheckResult - public GlideRequest timeout(@IntRange(from = 0) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(value); - } - return this; + public final GlideRequest timeout(@IntRange(from = 0) int value) { + return (GlideRequest) super.timeout(value); } - /** - * @see GlideOptions#optionalCenterCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); - } - return this; + public final GlideRequest optionalCenterCrop() { + return (GlideRequest) super.optionalCenterCrop(); } - /** - * @see GlideOptions#centerCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest centerCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); - } - return this; + public final GlideRequest centerCrop() { + return (GlideRequest) super.centerCrop(); } - /** - * @see GlideOptions#optionalFitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalFitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); - } - return this; + public final GlideRequest optionalFitCenter() { + return (GlideRequest) super.optionalFitCenter(); } - /** - * @see GlideOptions#fitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest fitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); - } - return this; + public final GlideRequest fitCenter() { + return (GlideRequest) super.fitCenter(); } - /** - * @see GlideOptions#optionalCenterInside() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); - } - return this; + public final GlideRequest optionalCenterInside() { + return (GlideRequest) super.optionalCenterInside(); } - /** - * @see GlideOptions#centerInside() - */ + @Override @NonNull @CheckResult - public GlideRequest centerInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); - } - return this; + public final GlideRequest centerInside() { + return (GlideRequest) super.centerInside(); } - /** - * @see GlideOptions#optionalCircleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCircleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); - } - return this; + public final GlideRequest optionalCircleCrop() { + return (GlideRequest) super.optionalCircleCrop(); } - /** - * @see GlideOptions#circleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest circleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); - } - return this; + public final GlideRequest circleCrop() { + return (GlideRequest) super.circleCrop(); } - /** - * @see GlideOptions#transform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(transformation); - } - return this; + public final GlideRequest transform(@NonNull Transformation transformation) { + return (GlideRequest) super.transform(transformation); } - /** - * @see GlideOptions#transforms(Transformation[]) - */ + @Override + @SafeVarargs + @SuppressWarnings("varargs") @NonNull @CheckResult - @SuppressWarnings({ - "unchecked", - "varargs" - }) - public GlideRequest transforms(@NonNull Transformation... transformations) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(transformations); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(transformations); - } - return this; + public final GlideRequest transforms(@NonNull Transformation... transformations) { + return (GlideRequest) super.transforms(transformations); } - /** - * @see GlideOptions#optionalTransform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(transformation); } - /** - * @see GlideOptions#optionalTransform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(clazz, transformation); } - /** - * @see GlideOptions#transform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(clazz, transformation); - } - return this; + public final GlideRequest transform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.transform(clazz, transformation); } - /** - * @see GlideOptions#dontTransform() - */ + @Override @NonNull @CheckResult - public GlideRequest dontTransform() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); - } - return this; + public final GlideRequest dontTransform() { + return (GlideRequest) super.dontTransform(); } - /** - * @see GlideOptions#dontAnimate() - */ + @Override @NonNull @CheckResult - public GlideRequest dontAnimate() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); - } - return this; - } - - /** - * @see GlideOptions#test() - */ - @CheckResult - @NonNull - public GlideRequest test() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).test(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).test(); - } - return this; + public final GlideRequest dontAnimate() { + return (GlideRequest) super.dontAnimate(); } @Override @NonNull @CheckResult - public GlideRequest apply(@NonNull RequestOptions options) { + public GlideRequest apply(@NonNull BaseRequestOptions options) { return (GlideRequest) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideOptions.java index 27dae5637f..77aae1cd84 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -430,8 +431,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -572,16 +573,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -602,7 +603,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideRequest.java index f0377a0a7c..46784109cb 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionOptionsTest/StaticMethodName/GlideRequest.java @@ -23,8 +23,8 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.RequestOptions; import java.io.File; import java.lang.Class; import java.lang.Cloneable; @@ -39,14 +39,14 @@ /** * Contains all public methods from {@link RequestBuilder}, all options from - * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.request.RequestOptions} and all generated options from * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. * *

Generated code, do not modify. * * @see RequestBuilder - * @see RequestOptions + * @see com.bumptech.glide.request.RequestOptions */ @SuppressWarnings({ "unused", @@ -69,604 +69,301 @@ protected GlideRequest getDownloadOnlyRequest() { return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); } - /** - * @see GlideOptions#sizeMultiplier(float) - */ + @Override @NonNull @CheckResult - public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(value); - } - return this; + public final GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { + return (GlideRequest) super.sizeMultiplier(value); } - /** - * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); - } - return this; + public final GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideRequest) super.useUnlimitedSourceGeneratorsPool(flag); } - /** - * @see GlideOptions#useAnimationPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useAnimationPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); - } - return this; + public final GlideRequest useAnimationPool(boolean flag) { + return (GlideRequest) super.useAnimationPool(flag); } - /** - * @see GlideOptions#onlyRetrieveFromCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest onlyRetrieveFromCache(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); - } - return this; + public final GlideRequest onlyRetrieveFromCache(boolean flag) { + return (GlideRequest) super.onlyRetrieveFromCache(flag); } - /** - * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(strategy); - } - return this; + public final GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { + return (GlideRequest) super.diskCacheStrategy(strategy); } - /** - * @see GlideOptions#priority(Priority) - */ + @Override @NonNull @CheckResult - public GlideRequest priority(@NonNull Priority priority) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).priority(priority); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(priority); - } - return this; + public final GlideRequest priority(@NonNull Priority priority) { + return (GlideRequest) super.priority(priority); } - /** - * @see GlideOptions#placeholder(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(drawable); - } - return this; + public final GlideRequest placeholder(@Nullable Drawable drawable) { + return (GlideRequest) super.placeholder(drawable); } - /** - * @see GlideOptions#placeholder(int) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(id); - } - return this; + public final GlideRequest placeholder(@DrawableRes int id) { + return (GlideRequest) super.placeholder(id); } - /** - * @see GlideOptions#fallback(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(drawable); - } - return this; + public final GlideRequest fallback(@Nullable Drawable drawable) { + return (GlideRequest) super.fallback(drawable); } - /** - * @see GlideOptions#fallback(int) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(id); - } - return this; + public final GlideRequest fallback(@DrawableRes int id) { + return (GlideRequest) super.fallback(id); } - /** - * @see GlideOptions#error(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(drawable); - } - return this; + public final GlideRequest error(@Nullable Drawable drawable) { + return (GlideRequest) super.error(drawable); } - /** - * @see GlideOptions#error(int) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(id); - } - return this; + public final GlideRequest error(@DrawableRes int id) { + return (GlideRequest) super.error(id); } - /** - * @see GlideOptions#theme(Resources.Theme) - */ + @Override @NonNull @CheckResult - public GlideRequest theme(@Nullable Resources.Theme theme) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).theme(theme); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(theme); - } - return this; + public final GlideRequest theme(@Nullable Resources.Theme theme) { + return (GlideRequest) super.theme(theme); } - /** - * @see GlideOptions#skipMemoryCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest skipMemoryCache(boolean skip) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); - } - return this; + public final GlideRequest skipMemoryCache(boolean skip) { + return (GlideRequest) super.skipMemoryCache(skip); } - /** - * @see GlideOptions#override(int, int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int width, int height) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); - } - return this; + public final GlideRequest override(int width, int height) { + return (GlideRequest) super.override(width, height); } - /** - * @see GlideOptions#override(int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int size) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); - } - return this; + public final GlideRequest override(int size) { + return (GlideRequest) super.override(size); } - /** - * @see GlideOptions#signature(Key) - */ + @Override @NonNull @CheckResult - public GlideRequest signature(@NonNull Key key) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).signature(key); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(key); - } - return this; + public final GlideRequest signature(@NonNull Key key) { + return (GlideRequest) super.signature(key); } - /** - * @see GlideOptions#set(Option, T) - */ + @Override @NonNull @CheckResult - public GlideRequest set(@NonNull Option option, @NonNull T t) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).set(option, t); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).set(option, t); - } - return this; + public final GlideRequest set(@NonNull Option option, @NonNull Y y) { + return (GlideRequest) super.set(option, y); } - /** - * @see GlideOptions#decode(Class) - */ + @Override @NonNull @CheckResult - public GlideRequest decode(@NonNull Class clazz) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).decode(clazz); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(clazz); - } - return this; + public final GlideRequest decode(@NonNull Class clazz) { + return (GlideRequest) super.decode(clazz); } - /** - * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(format); - } - return this; + public final GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { + return (GlideRequest) super.encodeFormat(format); } - /** - * @see GlideOptions#encodeQuality(int) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(value); - } - return this; + public final GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { + return (GlideRequest) super.encodeQuality(value); } - /** - * @see GlideOptions#frame(long) - */ + @Override @NonNull @CheckResult - public GlideRequest frame(@IntRange(from = 0) long value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).frame(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(value); - } - return this; + public final GlideRequest frame(@IntRange(from = 0) long value) { + return (GlideRequest) super.frame(value); } - /** - * @see GlideOptions#format(DecodeFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest format(@NonNull DecodeFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).format(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).format(format); - } - return this; + public final GlideRequest format(@NonNull DecodeFormat format) { + return (GlideRequest) super.format(format); } - /** - * @see GlideOptions#disallowHardwareConfig() - */ + @Override @NonNull @CheckResult - public GlideRequest disallowHardwareConfig() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); - } - return this; + public final GlideRequest disallowHardwareConfig() { + return (GlideRequest) super.disallowHardwareConfig(); } - /** - * @see GlideOptions#downsample(DownsampleStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest downsample(@NonNull DownsampleStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(strategy); - } - return this; + public final GlideRequest downsample(@NonNull DownsampleStrategy strategy) { + return (GlideRequest) super.downsample(strategy); } - /** - * @see GlideOptions#timeout(int) - */ + @Override @NonNull @CheckResult - public GlideRequest timeout(@IntRange(from = 0) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(value); - } - return this; + public final GlideRequest timeout(@IntRange(from = 0) int value) { + return (GlideRequest) super.timeout(value); } - /** - * @see GlideOptions#optionalCenterCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); - } - return this; + public final GlideRequest optionalCenterCrop() { + return (GlideRequest) super.optionalCenterCrop(); } - /** - * @see GlideOptions#centerCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest centerCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); - } - return this; + public final GlideRequest centerCrop() { + return (GlideRequest) super.centerCrop(); } - /** - * @see GlideOptions#optionalFitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalFitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); - } - return this; + public final GlideRequest optionalFitCenter() { + return (GlideRequest) super.optionalFitCenter(); } - /** - * @see GlideOptions#fitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest fitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); - } - return this; + public final GlideRequest fitCenter() { + return (GlideRequest) super.fitCenter(); } - /** - * @see GlideOptions#optionalCenterInside() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); - } - return this; + public final GlideRequest optionalCenterInside() { + return (GlideRequest) super.optionalCenterInside(); } - /** - * @see GlideOptions#centerInside() - */ + @Override @NonNull @CheckResult - public GlideRequest centerInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); - } - return this; + public final GlideRequest centerInside() { + return (GlideRequest) super.centerInside(); } - /** - * @see GlideOptions#optionalCircleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCircleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); - } - return this; + public final GlideRequest optionalCircleCrop() { + return (GlideRequest) super.optionalCircleCrop(); } - /** - * @see GlideOptions#circleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest circleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); - } - return this; + public final GlideRequest circleCrop() { + return (GlideRequest) super.circleCrop(); } - /** - * @see GlideOptions#transform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(transformation); - } - return this; + public final GlideRequest transform(@NonNull Transformation transformation) { + return (GlideRequest) super.transform(transformation); } - /** - * @see GlideOptions#transforms(Transformation[]) - */ + @Override + @SafeVarargs + @SuppressWarnings("varargs") @NonNull @CheckResult - @SuppressWarnings({ - "unchecked", - "varargs" - }) - public GlideRequest transforms(@NonNull Transformation... transformations) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(transformations); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(transformations); - } - return this; + public final GlideRequest transforms(@NonNull Transformation... transformations) { + return (GlideRequest) super.transforms(transformations); } - /** - * @see GlideOptions#optionalTransform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(transformation); } - /** - * @see GlideOptions#optionalTransform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(clazz, transformation); } - /** - * @see GlideOptions#transform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(clazz, transformation); - } - return this; + public final GlideRequest transform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.transform(clazz, transformation); } - /** - * @see GlideOptions#dontTransform() - */ + @Override @NonNull @CheckResult - public GlideRequest dontTransform() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); - } - return this; + public final GlideRequest dontTransform() { + return (GlideRequest) super.dontTransform(); } - /** - * @see GlideOptions#dontAnimate() - */ + @Override @NonNull @CheckResult - public GlideRequest dontAnimate() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); - } - return this; - } - - /** - * @see GlideOptions#test() - */ - @CheckResult - @NonNull - public GlideRequest test() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).test(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).test(); - } - return this; + public final GlideRequest dontAnimate() { + return (GlideRequest) super.dontAnimate(); } @Override @NonNull @CheckResult - public GlideRequest apply(@NonNull RequestOptions options) { + public GlideRequest apply(@NonNull BaseRequestOptions options) { return (GlideRequest) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideOptions.java index c4cef3aa9b..f54218130b 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -430,8 +431,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -572,16 +573,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -602,7 +603,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideRequest.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideRequest.java index 05b6b7d5c0..46784109cb 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideRequest.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithOptionTest/GlideRequest.java @@ -23,8 +23,8 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestListener; -import com.bumptech.glide.request.RequestOptions; import java.io.File; import java.lang.Class; import java.lang.Cloneable; @@ -39,14 +39,14 @@ /** * Contains all public methods from {@link RequestBuilder}, all options from - * {@link RequestOptions} and all generated options from + * {@link com.bumptech.glide.request.RequestOptions} and all generated options from * {@link com.bumptech.glide.annotation.GlideOption} in annotated methods in * {@link com.bumptech.glide.annotation.GlideExtension} annotated classes. * *

Generated code, do not modify. * * @see RequestBuilder - * @see RequestOptions + * @see com.bumptech.glide.request.RequestOptions */ @SuppressWarnings({ "unused", @@ -69,604 +69,301 @@ protected GlideRequest getDownloadOnlyRequest() { return new GlideRequest<>(File.class, this).apply(DOWNLOAD_ONLY_OPTIONS); } - /** - * @see GlideOptions#sizeMultiplier(float) - */ + @Override @NonNull @CheckResult - public GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).sizeMultiplier(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).sizeMultiplier(value); - } - return this; + public final GlideRequest sizeMultiplier(@FloatRange(from = 0.0, to = 1.0) float value) { + return (GlideRequest) super.sizeMultiplier(value); } - /** - * @see GlideOptions#useUnlimitedSourceGeneratorsPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useUnlimitedSourceGeneratorsPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useUnlimitedSourceGeneratorsPool(flag); - } - return this; + public final GlideRequest useUnlimitedSourceGeneratorsPool(boolean flag) { + return (GlideRequest) super.useUnlimitedSourceGeneratorsPool(flag); } - /** - * @see GlideOptions#useAnimationPool(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest useAnimationPool(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).useAnimationPool(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).useAnimationPool(flag); - } - return this; + public final GlideRequest useAnimationPool(boolean flag) { + return (GlideRequest) super.useAnimationPool(flag); } - /** - * @see GlideOptions#onlyRetrieveFromCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest onlyRetrieveFromCache(boolean flag) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).onlyRetrieveFromCache(flag); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).onlyRetrieveFromCache(flag); - } - return this; + public final GlideRequest onlyRetrieveFromCache(boolean flag) { + return (GlideRequest) super.onlyRetrieveFromCache(flag); } - /** - * @see GlideOptions#diskCacheStrategy(DiskCacheStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).diskCacheStrategy(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).diskCacheStrategy(strategy); - } - return this; + public final GlideRequest diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { + return (GlideRequest) super.diskCacheStrategy(strategy); } - /** - * @see GlideOptions#priority(Priority) - */ + @Override @NonNull @CheckResult - public GlideRequest priority(@NonNull Priority priority) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).priority(priority); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).priority(priority); - } - return this; + public final GlideRequest priority(@NonNull Priority priority) { + return (GlideRequest) super.priority(priority); } - /** - * @see GlideOptions#placeholder(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(drawable); - } - return this; + public final GlideRequest placeholder(@Nullable Drawable drawable) { + return (GlideRequest) super.placeholder(drawable); } - /** - * @see GlideOptions#placeholder(int) - */ + @Override @NonNull @CheckResult - public GlideRequest placeholder(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).placeholder(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).placeholder(id); - } - return this; + public final GlideRequest placeholder(@DrawableRes int id) { + return (GlideRequest) super.placeholder(id); } - /** - * @see GlideOptions#fallback(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(drawable); - } - return this; + public final GlideRequest fallback(@Nullable Drawable drawable) { + return (GlideRequest) super.fallback(drawable); } - /** - * @see GlideOptions#fallback(int) - */ + @Override @NonNull @CheckResult - public GlideRequest fallback(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fallback(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fallback(id); - } - return this; + public final GlideRequest fallback(@DrawableRes int id) { + return (GlideRequest) super.fallback(id); } - /** - * @see GlideOptions#error(Drawable) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@Nullable Drawable drawable) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(drawable); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(drawable); - } - return this; + public final GlideRequest error(@Nullable Drawable drawable) { + return (GlideRequest) super.error(drawable); } - /** - * @see GlideOptions#error(int) - */ + @Override @NonNull @CheckResult - public GlideRequest error(@DrawableRes int id) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).error(id); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).error(id); - } - return this; + public final GlideRequest error(@DrawableRes int id) { + return (GlideRequest) super.error(id); } - /** - * @see GlideOptions#theme(Resources.Theme) - */ + @Override @NonNull @CheckResult - public GlideRequest theme(@Nullable Resources.Theme theme) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).theme(theme); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).theme(theme); - } - return this; + public final GlideRequest theme(@Nullable Resources.Theme theme) { + return (GlideRequest) super.theme(theme); } - /** - * @see GlideOptions#skipMemoryCache(boolean) - */ + @Override @NonNull @CheckResult - public GlideRequest skipMemoryCache(boolean skip) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).skipMemoryCache(skip); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).skipMemoryCache(skip); - } - return this; + public final GlideRequest skipMemoryCache(boolean skip) { + return (GlideRequest) super.skipMemoryCache(skip); } - /** - * @see GlideOptions#override(int, int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int width, int height) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(width, height); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(width, height); - } - return this; + public final GlideRequest override(int width, int height) { + return (GlideRequest) super.override(width, height); } - /** - * @see GlideOptions#override(int) - */ + @Override @NonNull @CheckResult - public GlideRequest override(int size) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).override(size); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).override(size); - } - return this; + public final GlideRequest override(int size) { + return (GlideRequest) super.override(size); } - /** - * @see GlideOptions#signature(Key) - */ + @Override @NonNull @CheckResult - public GlideRequest signature(@NonNull Key key) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).signature(key); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).signature(key); - } - return this; + public final GlideRequest signature(@NonNull Key key) { + return (GlideRequest) super.signature(key); } - /** - * @see GlideOptions#set(Option, T) - */ + @Override @NonNull @CheckResult - public GlideRequest set(@NonNull Option option, @NonNull T t) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).set(option, t); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).set(option, t); - } - return this; + public final GlideRequest set(@NonNull Option option, @NonNull Y y) { + return (GlideRequest) super.set(option, y); } - /** - * @see GlideOptions#decode(Class) - */ + @Override @NonNull @CheckResult - public GlideRequest decode(@NonNull Class clazz) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).decode(clazz); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).decode(clazz); - } - return this; + public final GlideRequest decode(@NonNull Class clazz) { + return (GlideRequest) super.decode(clazz); } - /** - * @see GlideOptions#encodeFormat(Bitmap.CompressFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeFormat(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeFormat(format); - } - return this; + public final GlideRequest encodeFormat(@NonNull Bitmap.CompressFormat format) { + return (GlideRequest) super.encodeFormat(format); } - /** - * @see GlideOptions#encodeQuality(int) - */ + @Override @NonNull @CheckResult - public GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).encodeQuality(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).encodeQuality(value); - } - return this; + public final GlideRequest encodeQuality(@IntRange(from = 0, to = 100) int value) { + return (GlideRequest) super.encodeQuality(value); } - /** - * @see GlideOptions#frame(long) - */ + @Override @NonNull @CheckResult - public GlideRequest frame(@IntRange(from = 0) long value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).frame(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).frame(value); - } - return this; + public final GlideRequest frame(@IntRange(from = 0) long value) { + return (GlideRequest) super.frame(value); } - /** - * @see GlideOptions#format(DecodeFormat) - */ + @Override @NonNull @CheckResult - public GlideRequest format(@NonNull DecodeFormat format) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).format(format); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).format(format); - } - return this; + public final GlideRequest format(@NonNull DecodeFormat format) { + return (GlideRequest) super.format(format); } - /** - * @see GlideOptions#disallowHardwareConfig() - */ + @Override @NonNull @CheckResult - public GlideRequest disallowHardwareConfig() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).disallowHardwareConfig(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).disallowHardwareConfig(); - } - return this; + public final GlideRequest disallowHardwareConfig() { + return (GlideRequest) super.disallowHardwareConfig(); } - /** - * @see GlideOptions#downsample(DownsampleStrategy) - */ + @Override @NonNull @CheckResult - public GlideRequest downsample(@NonNull DownsampleStrategy strategy) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).downsample(strategy); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).downsample(strategy); - } - return this; + public final GlideRequest downsample(@NonNull DownsampleStrategy strategy) { + return (GlideRequest) super.downsample(strategy); } - /** - * @see GlideOptions#timeout(int) - */ + @Override @NonNull @CheckResult - public GlideRequest timeout(@IntRange(from = 0) int value) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).timeout(value); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).timeout(value); - } - return this; + public final GlideRequest timeout(@IntRange(from = 0) int value) { + return (GlideRequest) super.timeout(value); } - /** - * @see GlideOptions#optionalCenterCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterCrop(); - } - return this; + public final GlideRequest optionalCenterCrop() { + return (GlideRequest) super.optionalCenterCrop(); } - /** - * @see GlideOptions#centerCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest centerCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerCrop(); - } - return this; + public final GlideRequest centerCrop() { + return (GlideRequest) super.centerCrop(); } - /** - * @see GlideOptions#optionalFitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalFitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalFitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalFitCenter(); - } - return this; + public final GlideRequest optionalFitCenter() { + return (GlideRequest) super.optionalFitCenter(); } - /** - * @see GlideOptions#fitCenter() - */ + @Override @NonNull @CheckResult - public GlideRequest fitCenter() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).fitCenter(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).fitCenter(); - } - return this; + public final GlideRequest fitCenter() { + return (GlideRequest) super.fitCenter(); } - /** - * @see GlideOptions#optionalCenterInside() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCenterInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCenterInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCenterInside(); - } - return this; + public final GlideRequest optionalCenterInside() { + return (GlideRequest) super.optionalCenterInside(); } - /** - * @see GlideOptions#centerInside() - */ + @Override @NonNull @CheckResult - public GlideRequest centerInside() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).centerInside(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).centerInside(); - } - return this; + public final GlideRequest centerInside() { + return (GlideRequest) super.centerInside(); } - /** - * @see GlideOptions#optionalCircleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest optionalCircleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalCircleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalCircleCrop(); - } - return this; + public final GlideRequest optionalCircleCrop() { + return (GlideRequest) super.optionalCircleCrop(); } - /** - * @see GlideOptions#circleCrop() - */ + @Override @NonNull @CheckResult - public GlideRequest circleCrop() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).circleCrop(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).circleCrop(); - } - return this; + public final GlideRequest circleCrop() { + return (GlideRequest) super.circleCrop(); } - /** - * @see GlideOptions#transform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(transformation); - } - return this; + public final GlideRequest transform(@NonNull Transformation transformation) { + return (GlideRequest) super.transform(transformation); } - /** - * @see GlideOptions#transforms(Transformation[]) - */ + @Override + @SafeVarargs + @SuppressWarnings("varargs") @NonNull @CheckResult - @SuppressWarnings({ - "unchecked", - "varargs" - }) - public GlideRequest transforms(@NonNull Transformation... transformations) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transforms(transformations); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transforms(transformations); - } - return this; + public final GlideRequest transforms(@NonNull Transformation... transformations) { + return (GlideRequest) super.transforms(transformations); } - /** - * @see GlideOptions#optionalTransform(Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(transformation); } - /** - * @see GlideOptions#optionalTransform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).optionalTransform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).optionalTransform(clazz, transformation); - } - return this; + public final GlideRequest optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.optionalTransform(clazz, transformation); } - /** - * @see GlideOptions#transform(Class, Transformation) - */ + @Override @NonNull @CheckResult - public GlideRequest transform(@NonNull Class clazz, - @NonNull Transformation transformation) { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).transform(clazz, transformation); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).transform(clazz, transformation); - } - return this; + public final GlideRequest transform(@NonNull Class clazz, + @NonNull Transformation transformation) { + return (GlideRequest) super.transform(clazz, transformation); } - /** - * @see GlideOptions#dontTransform() - */ + @Override @NonNull @CheckResult - public GlideRequest dontTransform() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontTransform(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontTransform(); - } - return this; + public final GlideRequest dontTransform() { + return (GlideRequest) super.dontTransform(); } - /** - * @see GlideOptions#dontAnimate() - */ + @Override @NonNull @CheckResult - public GlideRequest dontAnimate() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).dontAnimate(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).dontAnimate(); - } - return this; - } - - /** - * @see GlideOptions#squareThumb() - */ - @CheckResult - @NonNull - public GlideRequest squareThumb() { - if (getMutableOptions() instanceof GlideOptions) { - this.requestOptions = ((GlideOptions) getMutableOptions()).squareThumb(); - } else { - this.requestOptions = new GlideOptions().apply(this.requestOptions).squareThumb(); - } - return this; + public final GlideRequest dontAnimate() { + return (GlideRequest) super.dontAnimate(); } @Override @NonNull @CheckResult - public GlideRequest apply(@NonNull RequestOptions options) { + public GlideRequest apply(@NonNull BaseRequestOptions options) { return (GlideRequest) super.apply(options); } diff --git a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithTypeTest/GlideOptions.java b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithTypeTest/GlideOptions.java index 558dc9f8cb..ad1030d178 100644 --- a/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithTypeTest/GlideOptions.java +++ b/annotation/compiler/test/src/test/resources/LegacyGlideExtensionWithTypeTest/GlideOptions.java @@ -16,6 +16,7 @@ import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.RequestOptions; import java.lang.Class; import java.lang.Cloneable; @@ -430,8 +431,8 @@ public final GlideOptions clone() { @Override @NonNull @CheckResult - public final GlideOptions set(@NonNull Option option, @NonNull T t) { - return (GlideOptions) super.set(option, t); + public final GlideOptions set(@NonNull Option option, @NonNull Y y) { + return (GlideOptions) super.set(option, y); } @Override @@ -572,16 +573,16 @@ public final GlideOptions optionalTransform(@NonNull Transformation tran @Override @NonNull @CheckResult - public final GlideOptions optionalTransform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions optionalTransform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.optionalTransform(clazz, transformation); } @Override @NonNull @CheckResult - public final GlideOptions transform(@NonNull Class clazz, - @NonNull Transformation transformation) { + public final GlideOptions transform(@NonNull Class clazz, + @NonNull Transformation transformation) { return (GlideOptions) super.transform(clazz, transformation); } @@ -602,7 +603,7 @@ public final GlideOptions dontAnimate() { @Override @NonNull @CheckResult - public final GlideOptions apply(@NonNull RequestOptions options) { + public final GlideOptions apply(@NonNull BaseRequestOptions options) { return (GlideOptions) super.apply(options); } diff --git a/library/src/main/java/com/bumptech/glide/RequestBuilder.java b/library/src/main/java/com/bumptech/glide/RequestBuilder.java index 2f0bd6e406..a01d45500e 100644 --- a/library/src/main/java/com/bumptech/glide/RequestBuilder.java +++ b/library/src/main/java/com/bumptech/glide/RequestBuilder.java @@ -17,6 +17,7 @@ import android.widget.ImageView; import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.request.ErrorRequestCoordinator; import com.bumptech.glide.request.FutureTarget; import com.bumptech.glide.request.Request; @@ -46,7 +47,8 @@ */ // Public API. @SuppressWarnings({"unused", "WeakerAccess"}) -public class RequestBuilder implements Cloneable, +public class RequestBuilder extends BaseRequestOptions> + implements Cloneable, ModelTypes> { // Used in generated subclasses protected static final RequestOptions DOWNLOAD_ONLY_OPTIONS = @@ -56,12 +58,9 @@ public class RequestBuilder implements Cloneable, private final Context context; private final RequestManager requestManager; private final Class transcodeClass; - private final RequestOptions defaultRequestOptions; private final Glide glide; private final GlideContext glideContext; - @NonNull protected RequestOptions requestOptions; - @NonNull @SuppressWarnings("unchecked") private TransitionOptions transitionOptions; @@ -88,20 +87,21 @@ protected RequestBuilder( this.glide = glide; this.requestManager = requestManager; this.transcodeClass = transcodeClass; - this.defaultRequestOptions = requestManager.getDefaultRequestOptions(); this.context = context; this.transitionOptions = requestManager.getDefaultTransitionOptions(transcodeClass); - this.requestOptions = defaultRequestOptions; this.glideContext = glide.getGlideContext(); initRequestListeners(requestManager.getDefaultRequestListeners()); + apply(requestManager.getDefaultRequestOptions()); } + @SuppressWarnings("PMD.ConstructorCallsOverridableMethod") protected RequestBuilder(Class transcodeClass, RequestBuilder other) { this(other.glide, other.requestManager, transcodeClass, other.context); model = other.model; isModelSet = other.isModelSet; - requestOptions = other.requestOptions; + + apply(other); } // Casting from Object to a specific type is always safe. @@ -117,29 +117,20 @@ private void initRequestListeners(List> requestListeners /** * Applies the given options to the request. * - *

As with {@link RequestOptions#apply(RequestOptions)}, {@code #apply} only replaces those + *

As with {@link RequestOptions#apply(BaseRequestOptions)}, {@code #apply} only replaces those * values that are explicitly set in the given {@link RequestOptions} object. If you need to * completely reset all previously set options, create a new {@code RequestBuilder} instead of * using this method. * - * @see RequestOptions#apply(RequestOptions) + * @see RequestOptions#apply(BaseRequestOptions) * @return This request builder. */ @NonNull @CheckResult - public RequestBuilder apply(@NonNull RequestOptions requestOptions) { + @Override + public RequestBuilder apply(@NonNull BaseRequestOptions requestOptions) { Preconditions.checkNotNull(requestOptions); - this.requestOptions = getMutableOptions().apply(requestOptions); - return this; - } - - // We're checking to see if we need to clone our options object because we want to make sure the - // original is never modified, so we need reference equality. - @SuppressWarnings("ReferenceEquality") - @NonNull - protected RequestOptions getMutableOptions() { - return defaultRequestOptions == this.requestOptions - ? this.requestOptions.clone() : this.requestOptions; + return super.apply(requestOptions); } /** @@ -389,7 +380,7 @@ private RequestBuilder loadGeneric(@Nullable Object model) { * {@link com.bumptech.glide.load.ResourceDecoder} instead of using this method. * *

The {@link DiskCacheStrategy} is set to {@link DiskCacheStrategy#NONE}. Previous calls to - * {@link #apply(RequestOptions)} or previously applied {@link DiskCacheStrategy}s will be + * {@link #apply(BaseRequestOptions)} or previously applied {@link DiskCacheStrategy}s will be * overridden by this method. Applying an {@link DiskCacheStrategy} other than * {@link DiskCacheStrategy#NONE} after calling this method may result in undefined behavior. * @@ -416,7 +407,7 @@ public RequestBuilder load(@Nullable Bitmap bitmap) { * {@link com.bumptech.glide.load.ResourceDecoder} instead of using this method. * *

The {@link DiskCacheStrategy} is set to {@link DiskCacheStrategy#NONE}. Previous calls to - * {@link #apply(RequestOptions)} or previously applied {@link DiskCacheStrategy}s will be + * {@link #apply(BaseRequestOptions)} or previously applied {@link DiskCacheStrategy}s will be * overridden by this method. Applying an {@link DiskCacheStrategy} other than * {@link DiskCacheStrategy#NONE} after calling this method may result in undefined behavior. * @@ -576,10 +567,10 @@ public RequestBuilder load(@Nullable URL url) { @Override public RequestBuilder load(@Nullable byte[] model) { RequestBuilder result = loadGeneric(model); - if (!result.requestOptions.isDiskCacheStrategySet()) { + if (!result.isDiskCacheStrategySet()) { result = result.apply(diskCacheStrategyOf(DiskCacheStrategy.NONE)); } - if (!result.requestOptions.isSkipMemoryCacheSet()) { + if (!result.isSkipMemoryCacheSet()) { result = result.apply(skipMemoryCacheOf(true /*skipMemoryCache*/)); } return result; @@ -601,14 +592,9 @@ public RequestBuilder load(@Nullable byte[] model) { @CheckResult @Override public RequestBuilder clone() { - try { - RequestBuilder result = (RequestBuilder) super.clone(); - result.requestOptions = result.requestOptions.clone(); - result.transitionOptions = result.transitionOptions.clone(); - return result; - } catch (CloneNotSupportedException e) { - throw new RuntimeException(e); - } + RequestBuilder result = super.clone(); + result.transitionOptions = result.transitionOptions.clone(); + return result; } /** @@ -627,20 +613,19 @@ public > Y into(@NonNull Y target) { @Synthetic > Y into( @NonNull Y target, @Nullable RequestListener targetListener) { - return into(target, targetListener, getMutableOptions()); + return into(target, targetListener, /*options=*/ this); } private > Y into( @NonNull Y target, @Nullable RequestListener targetListener, - @NonNull RequestOptions options) { + BaseRequestOptions options) { Util.assertMainThread(); Preconditions.checkNotNull(target); if (!isModelSet) { throw new IllegalArgumentException("You must call #load() before calling #into()"); } - options = options.autoClone(); Request request = buildRequest(target, targetListener, options); Request previous = target.getRequest(); @@ -673,7 +658,7 @@ private > Y into( // because the previous request must also be using skipMemoryCache for the requests to be // equivalent. See #2663 for additional context. private boolean isSkipMemoryCacheWithCompletePreviousRequest( - RequestOptions options, Request previous) { + BaseRequestOptions options, Request previous) { return !options.isMemoryCacheable() && previous.isComplete(); } @@ -693,7 +678,7 @@ public ViewTarget into(@NonNull ImageView view) { Util.assertMainThread(); Preconditions.checkNotNull(view); - RequestOptions requestOptions = this.requestOptions; + BaseRequestOptions requestOptions = this; if (!requestOptions.isTransformationSet() && requestOptions.isTransformationAllowed() && view.getScaleType() != null) { @@ -887,14 +872,14 @@ private Priority getThumbnailPriority(@NonNull Priority current) { case IMMEDIATE: return Priority.IMMEDIATE; default: - throw new IllegalArgumentException("unknown priority: " + requestOptions.getPriority()); + throw new IllegalArgumentException("unknown priority: " + getPriority()); } } private Request buildRequest( Target target, @Nullable RequestListener targetListener, - RequestOptions requestOptions) { + BaseRequestOptions requestOptions) { return buildRequestRecursive( target, targetListener, @@ -914,7 +899,7 @@ private Request buildRequestRecursive( Priority priority, int overrideWidth, int overrideHeight, - RequestOptions requestOptions) { + BaseRequestOptions requestOptions) { // Build the ErrorRequestCoordinator first if necessary so we can update parentCoordinator. ErrorRequestCoordinator errorRequestCoordinator = null; @@ -938,10 +923,10 @@ private Request buildRequestRecursive( return mainRequest; } - int errorOverrideWidth = errorBuilder.requestOptions.getOverrideWidth(); - int errorOverrideHeight = errorBuilder.requestOptions.getOverrideHeight(); + int errorOverrideWidth = errorBuilder.getOverrideWidth(); + int errorOverrideHeight = errorBuilder.getOverrideHeight(); if (Util.isValidDimensions(overrideWidth, overrideHeight) - && !errorBuilder.requestOptions.isValidOverride()) { + && !errorBuilder.isValidOverride()) { errorOverrideWidth = requestOptions.getOverrideWidth(); errorOverrideHeight = requestOptions.getOverrideHeight(); } @@ -951,10 +936,10 @@ private Request buildRequestRecursive( targetListener, errorRequestCoordinator, errorBuilder.transitionOptions, - errorBuilder.requestOptions.getPriority(), + errorBuilder.getPriority(), errorOverrideWidth, errorOverrideHeight, - errorBuilder.requestOptions); + errorBuilder); errorRequestCoordinator.setRequests(mainRequest, errorRequest); return errorRequestCoordinator; } @@ -967,7 +952,7 @@ private Request buildThumbnailRequestRecursive( Priority priority, int overrideWidth, int overrideHeight, - RequestOptions requestOptions) { + BaseRequestOptions requestOptions) { if (thumbnailBuilder != null) { // Recursive case: contains a potentially recursive thumbnail request builder. if (isThumbnailBuilt) { @@ -984,13 +969,13 @@ private Request buildThumbnailRequestRecursive( thumbTransitionOptions = transitionOptions; } - Priority thumbPriority = thumbnailBuilder.requestOptions.isPrioritySet() - ? thumbnailBuilder.requestOptions.getPriority() : getThumbnailPriority(priority); + Priority thumbPriority = thumbnailBuilder.isPrioritySet() + ? thumbnailBuilder.getPriority() : getThumbnailPriority(priority); - int thumbOverrideWidth = thumbnailBuilder.requestOptions.getOverrideWidth(); - int thumbOverrideHeight = thumbnailBuilder.requestOptions.getOverrideHeight(); + int thumbOverrideWidth = thumbnailBuilder.getOverrideWidth(); + int thumbOverrideHeight = thumbnailBuilder.getOverrideHeight(); if (Util.isValidDimensions(overrideWidth, overrideHeight) - && !thumbnailBuilder.requestOptions.isValidOverride()) { + && !thumbnailBuilder.isValidOverride()) { thumbOverrideWidth = requestOptions.getOverrideWidth(); thumbOverrideHeight = requestOptions.getOverrideHeight(); } @@ -1017,7 +1002,7 @@ private Request buildThumbnailRequestRecursive( thumbPriority, thumbOverrideWidth, thumbOverrideHeight, - thumbnailBuilder.requestOptions); + thumbnailBuilder); isThumbnailBuilt = false; coordinator.setRequests(fullRequest, thumbRequest); return coordinator; @@ -1034,8 +1019,8 @@ private Request buildThumbnailRequestRecursive( priority, overrideWidth, overrideHeight); - RequestOptions thumbnailOptions = requestOptions.clone() - .sizeMultiplier(thumbSizeMultiplier); + BaseRequestOptions thumbnailOptions = + requestOptions.clone().sizeMultiplier(thumbSizeMultiplier); Request thumbnailRequest = obtainRequest( @@ -1067,7 +1052,7 @@ private Request buildThumbnailRequestRecursive( private Request obtainRequest( Target target, RequestListener targetListener, - RequestOptions requestOptions, + BaseRequestOptions requestOptions, RequestCoordinator requestCoordinator, TransitionOptions transitionOptions, Priority priority, diff --git a/library/src/main/java/com/bumptech/glide/request/BaseRequestOptions.java b/library/src/main/java/com/bumptech/glide/request/BaseRequestOptions.java new file mode 100644 index 0000000000..08136a3270 --- /dev/null +++ b/library/src/main/java/com/bumptech/glide/request/BaseRequestOptions.java @@ -0,0 +1,1430 @@ +package com.bumptech.glide.request; + +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; +import android.support.annotation.CheckResult; +import android.support.annotation.DrawableRes; +import android.support.annotation.FloatRange; +import android.support.annotation.IntRange; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import com.bumptech.glide.Priority; +import com.bumptech.glide.load.DecodeFormat; +import com.bumptech.glide.load.Key; +import com.bumptech.glide.load.MultiTransformation; +import com.bumptech.glide.load.Option; +import com.bumptech.glide.load.Options; +import com.bumptech.glide.load.Transformation; +import com.bumptech.glide.load.engine.DiskCacheStrategy; +import com.bumptech.glide.load.model.stream.HttpGlideUrlLoader; +import com.bumptech.glide.load.resource.bitmap.BitmapEncoder; +import com.bumptech.glide.load.resource.bitmap.CenterCrop; +import com.bumptech.glide.load.resource.bitmap.CenterInside; +import com.bumptech.glide.load.resource.bitmap.CircleCrop; +import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; +import com.bumptech.glide.load.resource.bitmap.Downsampler; +import com.bumptech.glide.load.resource.bitmap.DrawableTransformation; +import com.bumptech.glide.load.resource.bitmap.FitCenter; +import com.bumptech.glide.load.resource.bitmap.VideoDecoder; +import com.bumptech.glide.load.resource.gif.GifDrawable; +import com.bumptech.glide.load.resource.gif.GifDrawableTransformation; +import com.bumptech.glide.load.resource.gif.GifOptions; +import com.bumptech.glide.signature.EmptySignature; +import com.bumptech.glide.util.CachedHashCodeArrayMap; +import com.bumptech.glide.util.Preconditions; +import com.bumptech.glide.util.Util; +import java.util.Map; + +/** + * A base object to allow method sharing between {@link RequestOptions} and + * {@link com.bumptech.glide.RequestBuilder}. + * + *

This class is not meant for general use and may change at any time. + * + * @param The particular child implementation + */ +@SuppressWarnings({"PMD.UseUtilityClass", "unused"}) +public abstract class BaseRequestOptions> implements Cloneable { + private static final int UNSET = -1; + private static final int SIZE_MULTIPLIER = 1 << 1; + private static final int DISK_CACHE_STRATEGY = 1 << 2; + private static final int PRIORITY = 1 << 3; + private static final int ERROR_PLACEHOLDER = 1 << 4; + private static final int ERROR_ID = 1 << 5; + private static final int PLACEHOLDER = 1 << 6; + private static final int PLACEHOLDER_ID = 1 << 7; + private static final int IS_CACHEABLE = 1 << 8; + private static final int OVERRIDE = 1 << 9; + private static final int SIGNATURE = 1 << 10; + private static final int TRANSFORMATION = 1 << 11; + private static final int RESOURCE_CLASS = 1 << 12; + private static final int FALLBACK = 1 << 13; + private static final int FALLBACK_ID = 1 << 14; + private static final int THEME = 1 << 15; + private static final int TRANSFORMATION_ALLOWED = 1 << 16; + private static final int TRANSFORMATION_REQUIRED = 1 << 17; + private static final int USE_UNLIMITED_SOURCE_GENERATORS_POOL = 1 << 18; + private static final int ONLY_RETRIEVE_FROM_CACHE = 1 << 19; + private static final int USE_ANIMATION_POOL = 1 << 20; + + private int fields; + private float sizeMultiplier = 1f; + @NonNull + private DiskCacheStrategy diskCacheStrategy = DiskCacheStrategy.AUTOMATIC; + @NonNull + private Priority priority = Priority.NORMAL; + @Nullable + private Drawable errorPlaceholder; + private int errorId; + @Nullable + private Drawable placeholderDrawable; + private int placeholderId; + private boolean isCacheable = true; + private int overrideHeight = UNSET; + private int overrideWidth = UNSET; + @NonNull + private Key signature = EmptySignature.obtain(); + private boolean isTransformationRequired; + private boolean isTransformationAllowed = true; + @Nullable + private Drawable fallbackDrawable; + private int fallbackId; + @NonNull + private Options options = new Options(); + @NonNull + private Map, Transformation> transformations = new CachedHashCodeArrayMap<>(); + @NonNull + private Class resourceClass = Object.class; + private boolean isLocked; + @Nullable + private Resources.Theme theme; + private boolean isAutoCloneEnabled; + private boolean useUnlimitedSourceGeneratorsPool; + private boolean onlyRetrieveFromCache; + private boolean isScaleOnlyOrNoTransform = true; + private boolean useAnimationPool; + + + private static boolean isSet(int fields, int flag) { + return (fields & flag) != 0; + } + + /** + * Applies a multiplier to the {@link com.bumptech.glide.request.target.Target}'s size before + * loading the resource. Useful for loading thumbnails or trying to avoid loading huge resources + * (particularly {@link Bitmap}s on devices with overly dense screens. + * + * @param sizeMultiplier The multiplier to apply to the + * {@link com.bumptech.glide.request.target.Target}'s dimensions when + * loading the resource. + * @return This request builder. + */ + @NonNull + @CheckResult + public T sizeMultiplier(@FloatRange(from = 0, to = 1) float sizeMultiplier) { + if (isAutoCloneEnabled) { + return clone().sizeMultiplier(sizeMultiplier); + } + + if (sizeMultiplier < 0f || sizeMultiplier > 1f) { + throw new IllegalArgumentException("sizeMultiplier must be between 0 and 1"); + } + this.sizeMultiplier = sizeMultiplier; + fields |= SIZE_MULTIPLIER; + + return selfOrThrowIfLocked(); + } + + /** + * If set to {@code true}, uses a cached unlimited {@link java.util.concurrent.Executor} to run + * the request. + * + *

This method should ONLY be used when a Glide load is started recursively on one + * of Glide's threads as part of another request. Using this method in other scenarios can lead + * to excessive memory usage and OOMs and/or a significant decrease in performance across an + * application. + * + *

If both this method and {@link #useAnimationPool(boolean)} are set, this method will be + * preferred and {@link #useAnimationPool(boolean)} will be ignored. + */ + @NonNull + @CheckResult + public T useUnlimitedSourceGeneratorsPool(boolean flag) { + if (isAutoCloneEnabled) { + return clone().useUnlimitedSourceGeneratorsPool(flag); + } + + this.useUnlimitedSourceGeneratorsPool = flag; + fields |= USE_UNLIMITED_SOURCE_GENERATORS_POOL; + + return selfOrThrowIfLocked(); + } + + /** + * If set to {@code true}, uses a special {@link java.util.concurrent.Executor} that is used + * exclusively for decoding frames of animated resources, like GIFs. + * + *

The animation executor disallows network operations and must not be used for loads that + * may load remote data. The animation executor has fewer threads available to it than Glide's + * normal executors and is only useful as a way of avoiding blocking on longer and more expensive + * reads for critical requests like those in an animating GIF. + * + *

If both {@link #useUnlimitedSourceGeneratorsPool(boolean)} and this method are set, + * {@link #useUnlimitedSourceGeneratorsPool(boolean)} will be preferred and this method will be + * ignored. + */ + @NonNull + @CheckResult + public T useAnimationPool(boolean flag) { + if (isAutoCloneEnabled) { + return clone().useAnimationPool(flag); + } + + useAnimationPool = flag; + fields |= USE_ANIMATION_POOL; + + return selfOrThrowIfLocked(); + } + + /** + * + * If set to true, will only load an item if found in the cache, and will not fetch from source. + */ + @NonNull + @CheckResult + public T onlyRetrieveFromCache(boolean flag) { + if (isAutoCloneEnabled) { + return clone().onlyRetrieveFromCache(flag); + } + + this.onlyRetrieveFromCache = flag; + fields |= ONLY_RETRIEVE_FROM_CACHE; + + return selfOrThrowIfLocked(); + } + + /** + * Sets the {@link DiskCacheStrategy} to use for this load. + * + *

Defaults to {@link DiskCacheStrategy#AUTOMATIC}.

+ * + *

For most applications {@link DiskCacheStrategy#RESOURCE} is + * ideal. Applications that use the same resource multiple times in multiple sizes and are willing + * to trade off some speed and disk space in return for lower bandwidth usage may want to consider + * using {@link DiskCacheStrategy#DATA} or + * {@link DiskCacheStrategy#ALL}.

+ * + * @param strategy The strategy to use. + * @return This request builder. + */ + @NonNull + @CheckResult + public T diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { + if (isAutoCloneEnabled) { + return clone().diskCacheStrategy(strategy); + } + this.diskCacheStrategy = Preconditions.checkNotNull(strategy); + fields |= DISK_CACHE_STRATEGY; + + return selfOrThrowIfLocked(); + } + + /** + * Sets the priority for this load. + * + * @param priority A priority. + * @return This request builder. + */ + @NonNull + @CheckResult + public T priority(@NonNull Priority priority) { + if (isAutoCloneEnabled) { + return clone().priority(priority); + } + + this.priority = Preconditions.checkNotNull(priority); + fields |= PRIORITY; + + return selfOrThrowIfLocked(); + } + + /** + * Sets an {@link Drawable} to display while a resource is loading. + * + *

Replaces any previous calls to this method or {@link #placeholder(int)}. + * + * @param drawable The drawable to display as a placeholder. + * @return This request builder. + */ + @NonNull + @CheckResult + public T placeholder(@Nullable Drawable drawable) { + if (isAutoCloneEnabled) { + return clone().placeholder(drawable); + } + + this.placeholderDrawable = drawable; + fields |= PLACEHOLDER; + + placeholderId = 0; + fields &= ~PLACEHOLDER_ID; + + return selfOrThrowIfLocked(); + } + + /** + * Sets an Android resource id for a {@link Drawable} resource to + * display while a resource is loading. + * + *

Replaces any previous calls to this method or {@link #placeholder(Drawable)} + * + * @param resourceId The id of the resource to use as a placeholder + * @return This request builder. + */ + @NonNull + @CheckResult + public T placeholder(@DrawableRes int resourceId) { + if (isAutoCloneEnabled) { + return clone().placeholder(resourceId); + } + + this.placeholderId = resourceId; + fields |= PLACEHOLDER_ID; + + placeholderDrawable = null; + fields &= ~PLACEHOLDER; + + return selfOrThrowIfLocked(); + } + + /** + * Sets an {@link Drawable} to display if the model provided to + * {@link com.bumptech.glide.RequestBuilder#load(Object)} is {@code null}. + * + *

If a fallback is not set, null models will cause the error drawable to be displayed. If the + * error drawable is not set, the placeholder will be displayed. + * + *

Replaces any previous calls to this method or {@link #fallback(int)}. + * + * @see #placeholder(Drawable) + * @see #placeholder(int) + * + * @param drawable The drawable to display as a placeholder. + * @return This request builder. + */ + @NonNull + @CheckResult + public T fallback(@Nullable Drawable drawable) { + if (isAutoCloneEnabled) { + return clone().fallback(drawable); + } + + this.fallbackDrawable = drawable; + fields |= FALLBACK; + + fallbackId = 0; + fields &= ~FALLBACK_ID; + + return selfOrThrowIfLocked(); + } + + /** + * Sets a resource to display if the model provided to + * {@link com.bumptech.glide.RequestBuilder#load(Object)} is {@code null}. + * + *

If a fallback is not set, null models will cause the error drawable to be displayed. If + * the error drawable is not set, the placeholder will be displayed. + * + *

Replaces any previous calls to this method or {@link #fallback(Drawable)}. + * + * @see #placeholder(Drawable) + * @see #placeholder(int) + * + * @param resourceId The id of the resource to use as a fallback. + * @return This request builder. + */ + @NonNull + @CheckResult + public T fallback(@DrawableRes int resourceId) { + if (isAutoCloneEnabled) { + return clone().fallback(resourceId); + } + + this.fallbackId = resourceId; + fields |= FALLBACK_ID; + + fallbackDrawable = null; + fields &= ~FALLBACK; + + return selfOrThrowIfLocked(); + } + + /** + * Sets a {@link Drawable} to display if a load fails. + * + *

Replaces any previous calls to this method or {@link #error(int)} + * + * @param drawable The drawable to display. + * @return This request builder. + */ + @NonNull + @CheckResult + public T error(@Nullable Drawable drawable) { + if (isAutoCloneEnabled) { + return clone().error(drawable); + } + + this.errorPlaceholder = drawable; + fields |= ERROR_PLACEHOLDER; + + this.errorId = 0; + fields &= ~ERROR_ID; + + return selfOrThrowIfLocked(); + } + + /** + * Sets a resource to display if a load fails. + * + *

Replaces any previous calls to this method or {@link #error(Drawable)} + * + * @param resourceId The id of the resource to use as a placeholder. + * @return This request builder. + */ + @NonNull + @CheckResult + public T error(@DrawableRes int resourceId) { + if (isAutoCloneEnabled) { + return clone().error(resourceId); + } + this.errorId = resourceId; + fields |= ERROR_ID; + + this.errorPlaceholder = null; + fields &= ~ERROR_PLACEHOLDER; + + return selfOrThrowIfLocked(); + } + + /** + * Sets the {@link android.content.res.Resources.Theme} to apply when loading {@link Drawable}s + * for resource ids provided via {@link #error(int)}, {@link #placeholder(int)}, and + * {@link #fallback(Drawable)}. + * + *

The theme is NOT applied in the decoder that will attempt to decode a given + * resource id model on Glide's background threads. The theme is used exclusively on the main + * thread to obtain placeholder/error/fallback drawables to avoid leaking Activities. + * + *

If the {@link android.content.Context} of the {@link android.app.Fragment} or + * {@link android.app.Activity} used to start this load has a different + * {@link android.content.res.Resources.Theme}, the {@link android.content.res.Resources.Theme} + * provided here will override the {@link android.content.res.Resources.Theme} of the + * {@link android.content.Context}. + * + * @param theme The theme to use when loading Drawables. + * @return this request builder. + */ + @NonNull + @CheckResult + public T theme(@Nullable Resources.Theme theme) { + if (isAutoCloneEnabled) { + return clone().theme(theme); + } + + this.theme = theme; + fields |= THEME; + + return selfOrThrowIfLocked(); + } + + /** + * Allows the loaded resource to skip the memory cache. + * + *

Note - this is not a guarantee. If a request is already pending for this resource and that + * request is not also skipping the memory cache, the resource will be cached in memory.

+ * + * @param skip True to allow the resource to skip the memory cache. + * @return This request builder. + */ + @NonNull + @CheckResult + public T skipMemoryCache(boolean skip) { + if (isAutoCloneEnabled) { + return clone().skipMemoryCache(true); + } + + this.isCacheable = !skip; + fields |= IS_CACHEABLE; + + return selfOrThrowIfLocked(); + } + + /** + * Overrides the {@link com.bumptech.glide.request.target.Target}'s width and height with the + * given values. This is useful for thumbnails, and should only be used for other cases when you + * need a very specific image size. + * + * @param width The width in pixels to use to load the resource. + * @param height The height in pixels to use to load the resource. + * @return This request builder. + */ + @NonNull + @CheckResult + public T override(int width, int height) { + if (isAutoCloneEnabled) { + return clone().override(width, height); + } + + this.overrideWidth = width; + this.overrideHeight = height; + fields |= OVERRIDE; + + return selfOrThrowIfLocked(); + } + + /** + * Overrides the {@link com.bumptech.glide.request.target.Target}'s width and height with the + * given size. + * + * @see #override(int, int) + * @param size The width and height to use. + * @return This request builder. + */ + @NonNull + @CheckResult + public T override(int size) { + return override(size, size); + } + + /** + * Sets some additional data to be mixed in to the memory and disk cache keys allowing the caller + * more control over when cached data is invalidated. + * + *

Note - The signature does not replace the cache key, it is purely additive.

+ * + * @param signature A unique non-null {@link Key} representing the current + * state of the model that will be mixed in to the cache key. + * @return This request builder. + * @see com.bumptech.glide.signature.ObjectKey + */ + @NonNull + @CheckResult + public T signature(@NonNull Key signature) { + if (isAutoCloneEnabled) { + return clone().signature(signature); + } + + this.signature = Preconditions.checkNotNull(signature); + fields |= SIGNATURE; + return selfOrThrowIfLocked(); + } + + /** + * Returns a copy of this request builder with all of the options put so far on this builder. + * + *

This method returns a "deep" copy in that all non-immutable arguments are copied such that + * changes to one builder will not affect the other builder. However, in addition to immutable + * arguments, the current model is not copied copied so changes to the model will affect both + * builders.

+ * + *

Even if this object was locked, the cloned object returned from this method will not be + * locked.

+ */ + @SuppressWarnings({ + "unchecked", + // we don't want to throw to be user friendly + "PMD.CloneThrowsCloneNotSupportedException", + // The types we're using here do this automatically. + "PMD.CloneMethodReturnTypeMustMatchClassName" + }) + @CheckResult + @Override + public T clone() { + try { + BaseRequestOptions result = (BaseRequestOptions) super.clone(); + result.options = new Options(); + result.options.putAll(options); + result.transformations = new CachedHashCodeArrayMap<>(); + result.transformations.putAll(transformations); + result.isLocked = false; + result.isAutoCloneEnabled = false; + return (T) result; + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + } + + @NonNull + @CheckResult + public T set(@NonNull Option option, @NonNull Y value) { + if (isAutoCloneEnabled) { + return clone().set(option, value); + } + + Preconditions.checkNotNull(option); + Preconditions.checkNotNull(value); + options.set(option, value); + return selfOrThrowIfLocked(); + } + + @NonNull + @CheckResult + public T decode(@NonNull Class resourceClass) { + if (isAutoCloneEnabled) { + return clone().decode(resourceClass); + } + + this.resourceClass = Preconditions.checkNotNull(resourceClass); + fields |= RESOURCE_CLASS; + return selfOrThrowIfLocked(); + } + + public final boolean isTransformationAllowed() { + return isTransformationAllowed; + } + + public final boolean isTransformationSet() { + return isSet(TRANSFORMATION); + } + + public final boolean isLocked() { + return isLocked; + } + + /** + * Sets the value for key + * {@link com.bumptech.glide.load.resource.bitmap.BitmapEncoder#COMPRESSION_FORMAT}. + */ + @NonNull + @CheckResult + public T encodeFormat(@NonNull Bitmap.CompressFormat format) { + return set(BitmapEncoder.COMPRESSION_FORMAT, Preconditions.checkNotNull(format)); + } + + /** + * Sets the value for key + * {@link BitmapEncoder#COMPRESSION_QUALITY}. + */ + @NonNull + @CheckResult + public T encodeQuality(@IntRange(from = 0, to = 100) int quality) { + return set(BitmapEncoder.COMPRESSION_QUALITY, quality); + } + + /** + * Sets the time position of the frame to extract from a video. + * + *

This is a component option specific to {@link VideoDecoder}. If the default video + * decoder is replaced or skipped because of your configuration, this option may be ignored. + * + * @see VideoDecoder#TARGET_FRAME + * @param frameTimeMicros The time position in microseconds of the desired frame. If negative, the + * Android framework implementation return a representative frame. + */ + @NonNull + @CheckResult + public T frame(@IntRange(from = 0) long frameTimeMicros) { + return set(VideoDecoder.TARGET_FRAME, frameTimeMicros); + } + + /** + * Sets the {@link DecodeFormat} to use when decoding {@link Bitmap} objects using + * {@link Downsampler} and Glide's default GIF decoders. + * + *

{@link DecodeFormat} is a request, not a requirement. It's possible the resource will be + * decoded using a decoder that cannot control the format + * ({@link android.media.MediaMetadataRetriever} for example), or that the decoder may choose to + * ignore the requested format if it can't display the image (i.e. RGB_565 is requested, but the + * image has alpha). + * + *

This is a component option specific to {@link Downsampler} and Glide's GIF decoders. If the + * default Bitmap decoders are replaced or skipped because of your configuration, this option may + * be ignored. + * + *

To set only the format used when decoding {@link Bitmap}s, use + * {@link #set(Option, Object)}} and {@link Downsampler#DECODE_FORMAT}. To set only the format + * used when decoding GIF frames, use {@link #set(Option, Object)} and + * {@link GifOptions#DECODE_FORMAT}. + * + * @see Downsampler#DECODE_FORMAT + * @see GifOptions#DECODE_FORMAT + */ + @NonNull + @CheckResult + public T format(@NonNull DecodeFormat format) { + Preconditions.checkNotNull(format); + return set(Downsampler.DECODE_FORMAT, format) + .set(GifOptions.DECODE_FORMAT, format); + } + + /** + * Disables the use of {@link android.graphics.Bitmap.Config#HARDWARE} in {@link Downsampler} to + * avoid errors caused by inspecting Bitmap pixels, drawing with hardware support disabled, + * drawing to {@link android.graphics.Canvas}s backed by {@link Bitmap}s etc. + * + *

It's almost never safe to set {@link Downsampler#ALLOW_HARDWARE_CONFIG} to {@code true} so + * we only provide a way to disable hardware configs entirely. If no option is set for + * {@link Downsampler#ALLOW_HARDWARE_CONFIG}, Glide will set the value per request based on + * whether or not a {@link Transformation} is applied and if one is, the type of + * {@link Transformation} applied. Built in transformations like {@link FitCenter} and + * {@link com.bumptech.glide.load.resource.bitmap.DownsampleStrategy.CenterOutside} can safely use + * {@link android.graphics.Bitmap.Config#HARDWARE} because they can be entirely replaced by + * scaling within {@link Downsampler}. {@link Transformation}s like {@link #circleCrop()} that + * can't be replicated by {@link Downsampler} cannot use {@link Bitmap.Config#HARDWARE} because + * {@link android.graphics.Bitmap.Config#HARDWARE} cannot be drawn to + * {@link android.graphics.Canvas}s, which is required by most {@link Transformation}s. + */ + @NonNull + @CheckResult + public T disallowHardwareConfig() { + return set(Downsampler.ALLOW_HARDWARE_CONFIG, false); + } + + /** + * Sets the {@link DownsampleStrategy} to use when decoding {@link Bitmap Bitmaps} using + * {@link Downsampler}. + * + *

This is a component option specific to {@link Downsampler}. If the defautlt Bitmap decoder + * is replaced or skipped because of your configuration, this option may be ignored. + */ + @NonNull + @CheckResult + public T downsample(@NonNull DownsampleStrategy strategy) { + return set(DownsampleStrategy.OPTION, Preconditions.checkNotNull(strategy)); + } + + /** + * Sets the read and write timeout for the http requests used to load the image. + * + *

This is a component option specific to Glide's default networking library and + * {@link com.bumptech.glide.load.model.stream.HttpGlideUrlLoader}. If you use any other + * networking library including Glide's Volley or OkHttp integration libraries, this option will + * be ignored. + * + * @see com.bumptech.glide.load.model.stream.HttpGlideUrlLoader#TIMEOUT + * @param timeoutMs The read and write timeout in milliseconds. + */ + @NonNull + @CheckResult + public T timeout(@IntRange(from = 0) int timeoutMs) { + return set(HttpGlideUrlLoader.TIMEOUT, timeoutMs); + } + + /** + * Applies {@link com.bumptech.glide.load.resource.bitmap.CenterCrop} to all default types, and + * ignores unknown types. + * + *

This will override previous calls to {@link #dontTransform()}. + * + * @see #optionalTransform(Class, Transformation) + * @see #centerCrop() + */ + @NonNull + @CheckResult + public T optionalCenterCrop() { + return optionalTransform(DownsampleStrategy.CENTER_OUTSIDE, new CenterCrop()); + } + + /** + * Applies {@link CenterCrop} to all default types and + * throws an exception if asked to transform an unknown type. + * + *

this will override previous calls to {@link #dontTransform()} ()}. + * + * @see #transform(Class, Transformation) + * @see #optionalCenterCrop() + */ + @NonNull + @CheckResult + public T centerCrop() { + return transform(DownsampleStrategy.CENTER_OUTSIDE, new CenterCrop()); + } + + /** + * + * Applies {@link FitCenter} and to all default types, {@link DownsampleStrategy#FIT_CENTER} to + * image types, and ignores unknown types. + * + *

This will override previous calls to {@link #dontTransform()} and previous calls to + * {@link #downsample(DownsampleStrategy)}. + * + * @see #optionalTransform(Class, Transformation) + * @see #fitCenter() + */ + @NonNull + @CheckResult + public T optionalFitCenter() { + return optionalScaleOnlyTransform(DownsampleStrategy.FIT_CENTER, new FitCenter()); + } + + /** + * Applies {@link FitCenter} and to all default types, {@link DownsampleStrategy#FIT_CENTER} to + * image types, and throws an exception if asked to transform an unknown + * type. + * + *

This will override previous calls to {@link #dontTransform()} and previous calls to + * {@link #downsample(DownsampleStrategy)}. + * + * @see #transform(Class, Transformation) + * @see #optionalFitCenter() + */ + @NonNull + @CheckResult + public T fitCenter() { + return scaleOnlyTransform(DownsampleStrategy.FIT_CENTER, new FitCenter()); + } + + /** + * Applies {@link com.bumptech.glide.load.resource.bitmap.CenterInside} to all default types, + * {@link DownsampleStrategy#CENTER_INSIDE} to image types, and ignores unknown types. + * + *

This will override previous calls to {@link #dontTransform()} and previous calls to + * {@link #downsample(DownsampleStrategy)}. + * + * @see #optionalTransform(Class, Transformation) + * @see #centerInside() + */ + @NonNull + @CheckResult + public T optionalCenterInside() { + return optionalScaleOnlyTransform(DownsampleStrategy.CENTER_INSIDE, new CenterInside()); + } + + /** + * Applies {@link CenterInside} to all default types, {@link DownsampleStrategy#CENTER_INSIDE} to + * image types and throws an exception if asked to transform an unknown type. + * + *

This will override previous calls to {@link #dontTransform()} and previous calls to + * {@link #downsample(DownsampleStrategy)}. + * + * @see #transform(Class, Transformation) + * @see #optionalCenterInside() + */ + @NonNull + @CheckResult + public T centerInside() { + return scaleOnlyTransform(DownsampleStrategy.CENTER_INSIDE, new CenterInside()); + } + + /** + * Applies {@link CircleCrop} to all default types, and ignores unknown types. + * + *

This will override previous calls to {@link #dontTransform()}. + * + * @see #optionalTransform(Transformation) + * @see #circleCrop() + */ + @NonNull + @CheckResult + public T optionalCircleCrop() { + return optionalTransform(DownsampleStrategy.CENTER_OUTSIDE, new CircleCrop()); + } + + /** + * Applies {@link CircleCrop} to all default types and throws an exception if asked to transform + * an unknown type. + * + *

This will override previous calls to {@link #dontTransform()}. + * + * @see #transform(Class, Transformation) + * @see #optionalCenterCrop() + */ + @NonNull + @CheckResult + public T circleCrop() { + return transform(DownsampleStrategy.CENTER_INSIDE, new CircleCrop()); + } + + // calling optionalTransform() on the result of clone() requires greater access. + // calling downsample is guaranteed to modify the current object by the isAutoCloneEnabledCheck. + @SuppressWarnings({"WeakerAccess", "CheckResult"}) + @NonNull + final T optionalTransform(@NonNull DownsampleStrategy downsampleStrategy, + @NonNull Transformation transformation) { + if (isAutoCloneEnabled) { + return clone().optionalTransform(downsampleStrategy, transformation); + } + + downsample(downsampleStrategy); + return transform(transformation, /*isRequired=*/ false); + } + + // calling transform() on the result of clone() requires greater access. + // calling downsample is guaranteed to modify the current object by the isAutoCloneEnabledCheck. + @SuppressWarnings({"WeakerAccess", "CheckResult"}) + @NonNull + @CheckResult + final T transform(@NonNull DownsampleStrategy downsampleStrategy, + @NonNull Transformation transformation) { + if (isAutoCloneEnabled) { + return clone().transform(downsampleStrategy, transformation); + } + + downsample(downsampleStrategy); + return transform(transformation); + } + + @NonNull + private T scaleOnlyTransform( + @NonNull DownsampleStrategy strategy, @NonNull Transformation transformation) { + return scaleOnlyTransform(strategy, transformation, true /*isTransformationRequired*/); + } + + @NonNull + private T optionalScaleOnlyTransform( + @NonNull DownsampleStrategy strategy, @NonNull Transformation transformation) { + return scaleOnlyTransform(strategy, transformation, false /*isTransformationRequired*/); + } + + // We know that result will always be T since we created result. + @SuppressWarnings("unchecked") + @NonNull + private T scaleOnlyTransform( + @NonNull DownsampleStrategy strategy, + @NonNull Transformation transformation, + boolean isTransformationRequired) { + BaseRequestOptions result = isTransformationRequired + ? transform(strategy, transformation) : optionalTransform(strategy, transformation); + result.isScaleOnlyOrNoTransform = true; + return (T) result; + } + + /** + * Applies the given {@link Transformation} for + * {@link Bitmap Bitmaps} to the default types ({@link Bitmap}, + * {@link android.graphics.drawable.BitmapDrawable}, and + * {@link com.bumptech.glide.load.resource.gif.GifDrawable}) + * and throws an exception if asked to transform an unknown type. + * + *

This will override previous calls to {@link #dontTransform()}. + * + * @param transformation Any {@link Transformation} for {@link Bitmap}s. + * @see #optionalTransform(Transformation) + * @see #optionalTransform(Class, Transformation) + */ + // Guaranteed to modify the current object by the isAutoCloneEnabledCheck. + @SuppressWarnings("CheckResult") + @NonNull + @CheckResult + public T transform(@NonNull Transformation transformation) { + return transform(transformation, /*isRequired=*/ true); + } + + /** + * Applies the given {@link Transformation}s in the given order for + * {@link Bitmap Bitmaps} to the default types ({@link Bitmap}, + * {@link android.graphics.drawable.BitmapDrawable}, and + * {@link com.bumptech.glide.load.resource.gif.GifDrawable}) + * and throws an exception if asked to transform an unknown type. + * + *

This will override previous calls to {@link #dontTransform()}. + * + * @param transformations One or more {@link Transformation}s for {@link Bitmap}s. + * @see #optionalTransform(Transformation) + * @see #optionalTransform(Class, Transformation) + */ + // Guaranteed to modify the current object by the isAutoCloneEnabledCheck. + @SuppressWarnings({"unchecked", "varargs", "CheckResult"}) + @NonNull + @CheckResult + public T transforms(@NonNull Transformation... transformations) { + return transform(new MultiTransformation<>(transformations), /*isRequired=*/ true); + } + + /** + * Applies the given {@link Transformation} for + * {@link Bitmap Bitmaps} to the default types ({@link Bitmap}, + * {@link android.graphics.drawable.BitmapDrawable}, and + * {@link com.bumptech.glide.load.resource.gif.GifDrawable}) and ignores unknown types. + * + *

This will override previous calls to {@link #dontTransform()}. + * + * @param transformation Any {@link Transformation} for {@link Bitmap}s. + * @see #transform(Transformation) + * @see #transform(Class, Transformation) + */ + // Guaranteed to modify the current object by the isAutoCloneEnabledCheck. + @SuppressWarnings("CheckResult") + @NonNull + @CheckResult + public T optionalTransform(@NonNull Transformation transformation) { + return transform(transformation, /*isRequired=*/ false); + } + + @NonNull + T transform( + @NonNull Transformation transformation, boolean isRequired) { + if (isAutoCloneEnabled) { + return clone().transform(transformation, isRequired); + } + + DrawableTransformation drawableTransformation = + new DrawableTransformation(transformation, isRequired); + transform(Bitmap.class, transformation, isRequired); + transform(Drawable.class, drawableTransformation, isRequired); + // TODO: remove BitmapDrawable decoder and this transformation. + // Registering as BitmapDrawable is simply an optimization to avoid some iteration and + // isAssignableFrom checks when obtaining the transformation later on. It can be removed without + // affecting the functionality. + transform(BitmapDrawable.class, drawableTransformation.asBitmapDrawable(), isRequired); + transform(GifDrawable.class, new GifDrawableTransformation(transformation), isRequired); + return selfOrThrowIfLocked(); + } + + /** + * Applies the given {@link Transformation} for any decoded resource of + * the given type and allows unknown resource types to be ignored. + * + *

Users can apply different transformations for each resource class. Applying a + * {@link Transformation} for a resource type that already has a + * {@link Transformation} will override the previous call.

+ * + *

If any calls are made to the non-optional transform methods, then attempting to transform + * an unknown resource class will throw an exception. To allow unknown types, users must always + * call the optional version of each method.

+ * + *

This will override previous calls to {@link #dontTransform()}. + * + * @param resourceClass The type of resource to transform. + * @param transformation The {@link Transformation} to apply. + */ + @NonNull + @CheckResult + public T optionalTransform( + @NonNull Class resourceClass, @NonNull Transformation transformation) { + return transform(resourceClass, transformation, /*isRequired=*/ false); + } + + @NonNull + T transform( + @NonNull Class resourceClass, + @NonNull Transformation transformation, + boolean isRequired) { + if (isAutoCloneEnabled) { + return clone().transform(resourceClass, transformation, isRequired); + } + + Preconditions.checkNotNull(resourceClass); + Preconditions.checkNotNull(transformation); + transformations.put(resourceClass, transformation); + fields |= TRANSFORMATION; + isTransformationAllowed = true; + fields |= TRANSFORMATION_ALLOWED; + // Always set to false here. Known scale only transformations will call this method and then + // set isScaleOnlyOrNoTransform to true immediately after. + isScaleOnlyOrNoTransform = false; + if (isRequired) { + fields |= TRANSFORMATION_REQUIRED; + isTransformationRequired = true; + } + return selfOrThrowIfLocked(); + } + + /** + * Applies the given {@link Transformation} for any decoded resource of + * the given type and throws if asked to transform an unknown resource type. + * + *

This will override previous calls to {@link #dontTransform()}. + * + * @param resourceClass The type of resource to transform. + * @param transformation The {@link Transformation} to apply. + * @see #optionalTransform(Class, Transformation) + */ + // Guaranteed to modify the current object by the isAutoCloneEnabledCheck. + @SuppressWarnings("CheckResult") + @NonNull + @CheckResult + public T transform( + @NonNull Class resourceClass, @NonNull Transformation transformation) { + return transform(resourceClass, transformation, /*isRequired=*/ true); + } + + /** + * Removes all applied {@link Transformation Transformations} for all + * resource classes and allows unknown resource types to be transformed without throwing an + * exception. + */ + @NonNull + @CheckResult + public T dontTransform() { + if (isAutoCloneEnabled) { + return clone().dontTransform(); + } + + transformations.clear(); + fields &= ~TRANSFORMATION; + isTransformationRequired = false; + fields &= ~TRANSFORMATION_REQUIRED; + isTransformationAllowed = false; + fields |= TRANSFORMATION_ALLOWED; + isScaleOnlyOrNoTransform = true; + return selfOrThrowIfLocked(); + } + + /** + * Disables resource decoders that return animated resources so any resource returned will be + * static. + * + *

To disable transitions (fades etc) use + * {@link com.bumptech.glide.TransitionOptions#dontTransition()}

+ */ + // Guaranteed to modify the current object by the isAutoCloneEnabledCheck. + @SuppressWarnings("CheckResult") + @NonNull + @CheckResult + public T dontAnimate() { + return set(GifOptions.DISABLE_ANIMATION, true); + } + + /** + * Updates this options set with any options that are explicitly set in the given + * {@code T} object and returns this object if {@link #autoClone()} is disabled or + * a new {@code T} object if {@link #autoClone()} is enabled. + * + *

{@code #apply} only replaces those values that are explicitly set in the given + * {@code T}. If you need to completely reset all previously set options, create a + * new {@code T} object instead of using this method. + * + *

The options that will be set to values in the returned {@code T} object is the + * intersection of the set of options in this {@code T} object and the given + * {@code T} object that were explicitly set. If the values of any of the options + * conflict, the values in the returned {@code T} object will be set to those in the + * given {@code T} object. + */ + @NonNull + @CheckResult + public T apply(@NonNull BaseRequestOptions o) { + if (isAutoCloneEnabled) { + return clone().apply(o); + } + BaseRequestOptions other = o; + + if (isSet(other.fields, SIZE_MULTIPLIER)) { + sizeMultiplier = other.sizeMultiplier; + } + if (isSet(other.fields, USE_UNLIMITED_SOURCE_GENERATORS_POOL)) { + useUnlimitedSourceGeneratorsPool = other.useUnlimitedSourceGeneratorsPool; + } + if (isSet(other.fields, USE_ANIMATION_POOL)) { + useAnimationPool = other.useAnimationPool; + } + if (isSet(other.fields, DISK_CACHE_STRATEGY)) { + diskCacheStrategy = other.diskCacheStrategy; + } + if (isSet(other.fields, PRIORITY)) { + priority = other.priority; + } + if (isSet(other.fields, ERROR_PLACEHOLDER)) { + errorPlaceholder = other.errorPlaceholder; + errorId = 0; + fields &= ~ERROR_ID; + } + if (isSet(other.fields, ERROR_ID)) { + errorId = other.errorId; + errorPlaceholder = null; + fields &= ~ERROR_PLACEHOLDER; + } + if (isSet(other.fields, PLACEHOLDER)) { + placeholderDrawable = other.placeholderDrawable; + placeholderId = 0; + fields &= ~PLACEHOLDER_ID; + } + if (isSet(other.fields, PLACEHOLDER_ID)) { + placeholderId = other.placeholderId; + placeholderDrawable = null; + fields &= ~PLACEHOLDER; + } + if (isSet(other.fields, IS_CACHEABLE)) { + isCacheable = other.isCacheable; + } + if (isSet(other.fields, OVERRIDE)) { + overrideWidth = other.overrideWidth; + overrideHeight = other.overrideHeight; + } + if (isSet(other.fields, SIGNATURE)) { + signature = other.signature; + } + if (isSet(other.fields, RESOURCE_CLASS)) { + resourceClass = other.resourceClass; + } + if (isSet(other.fields, FALLBACK)) { + fallbackDrawable = other.fallbackDrawable; + fallbackId = 0; + fields &= ~FALLBACK_ID; + } + if (isSet(other.fields, FALLBACK_ID)) { + fallbackId = other.fallbackId; + fallbackDrawable = null; + fields &= ~FALLBACK; + } + if (isSet(other.fields, THEME)) { + theme = other.theme; + } + if (isSet(other.fields, TRANSFORMATION_ALLOWED)) { + isTransformationAllowed = other.isTransformationAllowed; + } + if (isSet(other.fields, TRANSFORMATION_REQUIRED)) { + isTransformationRequired = other.isTransformationRequired; + } + if (isSet(other.fields, TRANSFORMATION)) { + transformations.putAll(other.transformations); + isScaleOnlyOrNoTransform = other.isScaleOnlyOrNoTransform; + } + if (isSet(other.fields, ONLY_RETRIEVE_FROM_CACHE)) { + onlyRetrieveFromCache = other.onlyRetrieveFromCache; + } + + // Applying options with dontTransform() is expected to clear our transformations. + if (!isTransformationAllowed) { + transformations.clear(); + fields &= ~TRANSFORMATION; + isTransformationRequired = false; + fields &= ~TRANSFORMATION_REQUIRED; + isScaleOnlyOrNoTransform = true; + } + + fields |= other.fields; + options.putAll(other.options); + + return selfOrThrowIfLocked(); + } + + + @Override + public boolean equals(Object o) { + if (o instanceof BaseRequestOptions) { + BaseRequestOptions other = (BaseRequestOptions) o; + return Float.compare(other.sizeMultiplier, sizeMultiplier) == 0 + && errorId == other.errorId + && Util.bothNullOrEqual(errorPlaceholder, other.errorPlaceholder) + && placeholderId == other.placeholderId + && Util.bothNullOrEqual(placeholderDrawable, other.placeholderDrawable) + && fallbackId == other.fallbackId + && Util.bothNullOrEqual(fallbackDrawable, other.fallbackDrawable) + && isCacheable == other.isCacheable + && overrideHeight == other.overrideHeight + && overrideWidth == other.overrideWidth + && isTransformationRequired == other.isTransformationRequired + && isTransformationAllowed == other.isTransformationAllowed + && useUnlimitedSourceGeneratorsPool == other.useUnlimitedSourceGeneratorsPool + && onlyRetrieveFromCache == other.onlyRetrieveFromCache + && diskCacheStrategy.equals(other.diskCacheStrategy) + && priority == other.priority + && options.equals(other.options) + && transformations.equals(other.transformations) + && resourceClass.equals(other.resourceClass) + && Util.bothNullOrEqual(signature, other.signature) + && Util.bothNullOrEqual(theme, other.theme); + } + return false; + } + + @Override + public int hashCode() { + int hashCode = Util.hashCode(sizeMultiplier); + hashCode = Util.hashCode(errorId, hashCode); + hashCode = Util.hashCode(errorPlaceholder, hashCode); + hashCode = Util.hashCode(placeholderId, hashCode); + hashCode = Util.hashCode(placeholderDrawable, hashCode); + hashCode = Util.hashCode(fallbackId, hashCode); + hashCode = Util.hashCode(fallbackDrawable, hashCode); + hashCode = Util.hashCode(isCacheable, hashCode); + hashCode = Util.hashCode(overrideHeight, hashCode); + hashCode = Util.hashCode(overrideWidth, hashCode); + hashCode = Util.hashCode(isTransformationRequired, hashCode); + hashCode = Util.hashCode(isTransformationAllowed, hashCode); + hashCode = Util.hashCode(useUnlimitedSourceGeneratorsPool, hashCode); + hashCode = Util.hashCode(onlyRetrieveFromCache, hashCode); + hashCode = Util.hashCode(diskCacheStrategy, hashCode); + hashCode = Util.hashCode(priority, hashCode); + hashCode = Util.hashCode(options, hashCode); + hashCode = Util.hashCode(transformations, hashCode); + hashCode = Util.hashCode(resourceClass, hashCode); + hashCode = Util.hashCode(signature, hashCode); + hashCode = Util.hashCode(theme, hashCode); + return hashCode; + } + + /** + * Throws if any further mutations are attempted. + * + *

Once locked, the only way to unlock is to use {@link #clone()}

+ */ + @NonNull + @SuppressWarnings("unchecked") + public T lock() { + isLocked = true; + // This is the only place we should not check locked. + return self(); + } + + /** + * Similar to {@link #lock()} except that mutations cause a {@link #clone()} operation to happen + * before the mutation resulting in all methods returning a new Object and leaving the original + * locked object unmodified. + * + *

Auto clone is not retained by cloned objects returned from mutations. The cloned objects + * are mutable and are not locked. + */ + @NonNull + public T autoClone() { + if (isLocked && !isAutoCloneEnabled) { + throw new IllegalStateException("You cannot auto lock an already locked options object" + + ", try clone() first"); + } + isAutoCloneEnabled = true; + return lock(); + } + + @NonNull + @SuppressWarnings("unchecked") + private T selfOrThrowIfLocked() { + if (isLocked) { + throw new IllegalStateException("You cannot modify locked T, consider clone()"); + } + return self(); + } + + protected boolean isAutoCloneEnabled() { + return isAutoCloneEnabled; + } + + public final boolean isDiskCacheStrategySet() { + return isSet(DISK_CACHE_STRATEGY); + } + + public final boolean isSkipMemoryCacheSet() { + return isSet(IS_CACHEABLE); + } + + @NonNull + public final Map, Transformation> getTransformations() { + return transformations; + } + + @SuppressWarnings("WeakerAccess") + public final boolean isTransformationRequired() { + return isTransformationRequired; + } + + @NonNull + public final Options getOptions() { + return options; + } + + @NonNull + public final Class getResourceClass() { + return resourceClass; + } + + @NonNull + public final DiskCacheStrategy getDiskCacheStrategy() { + return diskCacheStrategy; + } + + @SuppressWarnings("WeakerAccess") + @Nullable + public final Drawable getErrorPlaceholder() { + return errorPlaceholder; + } + + @SuppressWarnings("WeakerAccess") + public final int getErrorId() { + return errorId; + } + + @SuppressWarnings("WeakerAccess") + public final int getPlaceholderId() { + return placeholderId; + } + + @SuppressWarnings("WeakerAccess") + @Nullable + public final Drawable getPlaceholderDrawable() { + return placeholderDrawable; + } + + @SuppressWarnings("WeakerAccess") + public final int getFallbackId() { + return fallbackId; + } + + @SuppressWarnings("WeakerAccess") + @Nullable + public final Drawable getFallbackDrawable() { + return fallbackDrawable; + } + + @Nullable + public final Resources.Theme getTheme() { + return theme; + } + + @SuppressWarnings("WeakerAccess") + public final boolean isMemoryCacheable() { + return isCacheable; + } + + @NonNull + public final Key getSignature() { + return signature; + } + + public final boolean isPrioritySet() { + return isSet(PRIORITY); + } + + @NonNull + public final Priority getPriority() { + return priority; + } + + public final int getOverrideWidth() { + return overrideWidth; + } + + public final boolean isValidOverride() { + return Util.isValidDimensions(overrideWidth, overrideHeight); + } + + public final int getOverrideHeight() { + return overrideHeight; + } + + public final float getSizeMultiplier() { + return sizeMultiplier; + } + + boolean isScaleOnlyOrNoTransform() { + return isScaleOnlyOrNoTransform; + } + + private boolean isSet(int flag) { + return isSet(fields, flag); + } + + // get is just as clear. + @SuppressWarnings("PMD.BooleanGetMethodName") + public final boolean getUseUnlimitedSourceGeneratorsPool() { + return useUnlimitedSourceGeneratorsPool; + } + + // get is just as clear. + @SuppressWarnings("PMD.BooleanGetMethodName") + public final boolean getUseAnimationPool() { + return useAnimationPool; + } + + // get is just as clear. + @SuppressWarnings("PMD.BooleanGetMethodName") + public final boolean getOnlyRetrieveFromCache() { + return onlyRetrieveFromCache; + } + + @SuppressWarnings("unchecked") + private T self() { + return (T) this; + } +} diff --git a/library/src/main/java/com/bumptech/glide/request/RequestOptions.java b/library/src/main/java/com/bumptech/glide/request/RequestOptions.java index 75d3a23254..f712ce726a 100644 --- a/library/src/main/java/com/bumptech/glide/request/RequestOptions.java +++ b/library/src/main/java/com/bumptech/glide/request/RequestOptions.java @@ -1,8 +1,6 @@ package com.bumptech.glide.request; -import android.content.res.Resources; import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.support.annotation.CheckResult; import android.support.annotation.DrawableRes; @@ -13,56 +11,19 @@ import com.bumptech.glide.Priority; import com.bumptech.glide.load.DecodeFormat; import com.bumptech.glide.load.Key; -import com.bumptech.glide.load.MultiTransformation; import com.bumptech.glide.load.Option; -import com.bumptech.glide.load.Options; import com.bumptech.glide.load.Transformation; import com.bumptech.glide.load.engine.DiskCacheStrategy; -import com.bumptech.glide.load.model.stream.HttpGlideUrlLoader; -import com.bumptech.glide.load.resource.bitmap.BitmapEncoder; -import com.bumptech.glide.load.resource.bitmap.CenterCrop; -import com.bumptech.glide.load.resource.bitmap.CenterInside; -import com.bumptech.glide.load.resource.bitmap.CircleCrop; import com.bumptech.glide.load.resource.bitmap.DownsampleStrategy; -import com.bumptech.glide.load.resource.bitmap.Downsampler; -import com.bumptech.glide.load.resource.bitmap.DrawableTransformation; -import com.bumptech.glide.load.resource.bitmap.FitCenter; -import com.bumptech.glide.load.resource.bitmap.VideoDecoder; -import com.bumptech.glide.load.resource.gif.GifDrawable; -import com.bumptech.glide.load.resource.gif.GifDrawableTransformation; -import com.bumptech.glide.load.resource.gif.GifOptions; -import com.bumptech.glide.signature.EmptySignature; -import com.bumptech.glide.util.CachedHashCodeArrayMap; -import com.bumptech.glide.util.Preconditions; -import com.bumptech.glide.util.Util; -import java.util.Map; /** * Provides type independent options to customize loads with Glide. + * + *

Non-final to allow Glide's generated classes to be assignable to their non-generated + * equivalents. */ -@SuppressWarnings({"PMD.UseUtilityClass", "unused"}) -public class RequestOptions implements Cloneable { - private static final int UNSET = -1; - private static final int SIZE_MULTIPLIER = 1 << 1; - private static final int DISK_CACHE_STRATEGY = 1 << 2; - private static final int PRIORITY = 1 << 3; - private static final int ERROR_PLACEHOLDER = 1 << 4; - private static final int ERROR_ID = 1 << 5; - private static final int PLACEHOLDER = 1 << 6; - private static final int PLACEHOLDER_ID = 1 << 7; - private static final int IS_CACHEABLE = 1 << 8; - private static final int OVERRIDE = 1 << 9; - private static final int SIGNATURE = 1 << 10; - private static final int TRANSFORMATION = 1 << 11; - private static final int RESOURCE_CLASS = 1 << 12; - private static final int FALLBACK = 1 << 13; - private static final int FALLBACK_ID = 1 << 14; - private static final int THEME = 1 << 15; - private static final int TRANSFORMATION_ALLOWED = 1 << 16; - private static final int TRANSFORMATION_REQUIRED = 1 << 17; - private static final int USE_UNLIMITED_SOURCE_GENERATORS_POOL = 1 << 18; - private static final int ONLY_RETRIEVE_FROM_CACHE = 1 << 19; - private static final int USE_ANIMATION_POOL = 1 << 20; +@SuppressWarnings("PMD.UseUtilityClass") +public class RequestOptions extends BaseRequestOptions { @Nullable private static RequestOptions skipMemoryCacheTrueOptions; @@ -81,42 +42,6 @@ public class RequestOptions implements Cloneable { @Nullable private static RequestOptions noAnimationOptions; - private int fields; - private float sizeMultiplier = 1f; - @NonNull - private DiskCacheStrategy diskCacheStrategy = DiskCacheStrategy.AUTOMATIC; - @NonNull - private Priority priority = Priority.NORMAL; - @Nullable - private Drawable errorPlaceholder; - private int errorId; - @Nullable - private Drawable placeholderDrawable; - private int placeholderId; - private boolean isCacheable = true; - private int overrideHeight = RequestOptions.UNSET; - private int overrideWidth = RequestOptions.UNSET; - @NonNull - private Key signature = EmptySignature.obtain(); - private boolean isTransformationRequired; - private boolean isTransformationAllowed = true; - @Nullable - private Drawable fallbackDrawable; - private int fallbackId; - @NonNull - private Options options = new Options(); - @NonNull - private Map, Transformation> transformations = new CachedHashCodeArrayMap<>(); - @NonNull - private Class resourceClass = Object.class; - private boolean isLocked; - @Nullable - private Resources.Theme theme; - private boolean isAutoCloneEnabled; - private boolean useUnlimitedSourceGeneratorsPool; - private boolean onlyRetrieveFromCache; - private boolean isScaleOnlyOrNoTransform = true; - private boolean useAnimationPool; /** * Returns a {@link RequestOptions} object with {@link #sizeMultiplier(float)} set. @@ -139,7 +64,8 @@ public static RequestOptions diskCacheStrategyOf(@NonNull DiskCacheStrategy disk } /** - * Returns a {@link RequestOptions} object with {@link #priority(Priority)}} set. + * Returns a {@link RequestOptions} object with {@link BaseRequestOptions#priority(Priority)}} + * set. */ @SuppressWarnings("WeakerAccess") // Public API @NonNull @@ -415,1314 +341,4 @@ public static RequestOptions noAnimation() { return noAnimationOptions; } - private static boolean isSet(int fields, int flag) { - return (fields & flag) != 0; - } - - /** - * Applies a multiplier to the {@link com.bumptech.glide.request.target.Target}'s size before - * loading the resource. Useful for loading thumbnails or trying to avoid loading huge resources - * (particularly {@link Bitmap}s on devices with overly dense screens. - * - * @param sizeMultiplier The multiplier to apply to the - * {@link com.bumptech.glide.request.target.Target}'s dimensions when - * loading the resource. - * @return This request builder. - */ - @NonNull - @CheckResult - public RequestOptions sizeMultiplier(@FloatRange(from = 0, to = 1) float sizeMultiplier) { - if (isAutoCloneEnabled) { - return clone().sizeMultiplier(sizeMultiplier); - } - - if (sizeMultiplier < 0f || sizeMultiplier > 1f) { - throw new IllegalArgumentException("sizeMultiplier must be between 0 and 1"); - } - this.sizeMultiplier = sizeMultiplier; - fields |= SIZE_MULTIPLIER; - - return selfOrThrowIfLocked(); - } - - /** - * If set to {@code true}, uses a cached unlimited {@link java.util.concurrent.Executor} to run - * the request. - * - *

This method should ONLY be used when a Glide load is started recursively on one - * of Glide's threads as part of another request. Using this method in other scenarios can lead - * to excessive memory usage and OOMs and/or a significant decrease in performance across an - * application. - * - *

If both this method and {@link #useAnimationPool(boolean)} are set, this method will be - * preferred and {@link #useAnimationPool(boolean)} will be ignored. - */ - @NonNull - @CheckResult - public RequestOptions useUnlimitedSourceGeneratorsPool(boolean flag) { - if (isAutoCloneEnabled) { - return clone().useUnlimitedSourceGeneratorsPool(flag); - } - - this.useUnlimitedSourceGeneratorsPool = flag; - fields |= USE_UNLIMITED_SOURCE_GENERATORS_POOL; - - return selfOrThrowIfLocked(); - } - - /** - * If set to {@code true}, uses a special {@link java.util.concurrent.Executor} that is used - * exclusively for decoding frames of animated resources, like GIFs. - * - *

The animation executor disallows network operations and must not be used for loads that - * may load remote data. The animation executor has fewer threads available to it than Glide's - * normal executors and is only useful as a way of avoiding blocking on longer and more expensive - * reads for critical requests like those in an animating GIF. - * - *

If both {@link #useUnlimitedSourceGeneratorsPool(boolean)} and this method are set, - * {@link #useUnlimitedSourceGeneratorsPool(boolean)} will be preferred and this method will be - * ignored. - */ - @NonNull - @CheckResult - public RequestOptions useAnimationPool(boolean flag) { - if (isAutoCloneEnabled) { - return clone().useAnimationPool(flag); - } - - useAnimationPool = flag; - fields |= USE_ANIMATION_POOL; - - return selfOrThrowIfLocked(); - } - - /** - * - * If set to true, will only load an item if found in the cache, and will not fetch from source. - */ - @NonNull - @CheckResult - public RequestOptions onlyRetrieveFromCache(boolean flag) { - if (isAutoCloneEnabled) { - return clone().onlyRetrieveFromCache(flag); - } - - this.onlyRetrieveFromCache = flag; - fields |= ONLY_RETRIEVE_FROM_CACHE; - - return selfOrThrowIfLocked(); - } - - /** - * Sets the {@link DiskCacheStrategy} to use for this load. - * - *

Defaults to {@link DiskCacheStrategy#AUTOMATIC}.

- * - *

For most applications {@link DiskCacheStrategy#RESOURCE} is - * ideal. Applications that use the same resource multiple times in multiple sizes and are willing - * to trade off some speed and disk space in return for lower bandwidth usage may want to consider - * using {@link DiskCacheStrategy#DATA} or - * {@link DiskCacheStrategy#ALL}.

- * - * @param strategy The strategy to use. - * @return This request builder. - */ - @NonNull - @CheckResult - public RequestOptions diskCacheStrategy(@NonNull DiskCacheStrategy strategy) { - if (isAutoCloneEnabled) { - return clone().diskCacheStrategy(strategy); - } - this.diskCacheStrategy = Preconditions.checkNotNull(strategy); - fields |= DISK_CACHE_STRATEGY; - - return selfOrThrowIfLocked(); - } - - /** - * Sets the priority for this load. - * - * @param priority A priority. - * @return This request builder. - */ - @NonNull - @CheckResult - public RequestOptions priority(@NonNull Priority priority) { - if (isAutoCloneEnabled) { - return clone().priority(priority); - } - - this.priority = Preconditions.checkNotNull(priority); - fields |= PRIORITY; - - return selfOrThrowIfLocked(); - } - - /** - * Sets an {@link Drawable} to display while a resource is loading. - * - *

Replaces any previous calls to this method or {@link #placeholder(int)}. - * - * @param drawable The drawable to display as a placeholder. - * @return This request builder. - */ - @NonNull - @CheckResult - public RequestOptions placeholder(@Nullable Drawable drawable) { - if (isAutoCloneEnabled) { - return clone().placeholder(drawable); - } - - this.placeholderDrawable = drawable; - fields |= PLACEHOLDER; - - placeholderId = 0; - fields &= ~PLACEHOLDER_ID; - - return selfOrThrowIfLocked(); - } - - /** - * Sets an Android resource id for a {@link Drawable} resource to - * display while a resource is loading. - * - *

Replaces any previous calls to this method or {@link #placeholder(Drawable)} - * - * @param resourceId The id of the resource to use as a placeholder - * @return This request builder. - */ - @NonNull - @CheckResult - public RequestOptions placeholder(@DrawableRes int resourceId) { - if (isAutoCloneEnabled) { - return clone().placeholder(resourceId); - } - - this.placeholderId = resourceId; - fields |= PLACEHOLDER_ID; - - placeholderDrawable = null; - fields &= ~PLACEHOLDER; - - return selfOrThrowIfLocked(); - } - - /** - * Sets an {@link Drawable} to display if the model provided to - * {@link com.bumptech.glide.RequestBuilder#load(Object)} is {@code null}. - * - *

If a fallback is not set, null models will cause the error drawable to be displayed. If the - * error drawable is not set, the placeholder will be displayed. - * - *

Replaces any previous calls to this method or {@link #fallback(int)}. - * - * @see #placeholder(Drawable) - * @see #placeholder(int) - * - * @param drawable The drawable to display as a placeholder. - * @return This request builder. - */ - @NonNull - @CheckResult - public RequestOptions fallback(@Nullable Drawable drawable) { - if (isAutoCloneEnabled) { - return clone().fallback(drawable); - } - - this.fallbackDrawable = drawable; - fields |= FALLBACK; - - fallbackId = 0; - fields &= ~FALLBACK_ID; - - return selfOrThrowIfLocked(); - } - - /** - * Sets a resource to display if the model provided to - * {@link com.bumptech.glide.RequestBuilder#load(Object)} is {@code null}. - * - *

If a fallback is not set, null models will cause the error drawable to be displayed. If - * the error drawable is not set, the placeholder will be displayed. - * - *

Replaces any previous calls to this method or {@link #fallback(Drawable)}. - * - * @see #placeholder(Drawable) - * @see #placeholder(int) - * - * @param resourceId The id of the resource to use as a fallback. - * @return This request builder. - */ - @NonNull - @CheckResult - public RequestOptions fallback(@DrawableRes int resourceId) { - if (isAutoCloneEnabled) { - return clone().fallback(resourceId); - } - - this.fallbackId = resourceId; - fields |= FALLBACK_ID; - - fallbackDrawable = null; - fields &= ~FALLBACK; - - return selfOrThrowIfLocked(); - } - - /** - * Sets a {@link Drawable} to display if a load fails. - * - *

Replaces any previous calls to this method or {@link #error(int)} - * - * @param drawable The drawable to display. - * @return This request builder. - */ - @NonNull - @CheckResult - public RequestOptions error(@Nullable Drawable drawable) { - if (isAutoCloneEnabled) { - return clone().error(drawable); - } - - this.errorPlaceholder = drawable; - fields |= ERROR_PLACEHOLDER; - - this.errorId = 0; - fields &= ~ERROR_ID; - - return selfOrThrowIfLocked(); - } - - /** - * Sets a resource to display if a load fails. - * - *

Replaces any previous calls to this method or {@link #error(Drawable)} - * - * @param resourceId The id of the resource to use as a placeholder. - * @return This request builder. - */ - @NonNull - @CheckResult - public RequestOptions error(@DrawableRes int resourceId) { - if (isAutoCloneEnabled) { - return clone().error(resourceId); - } - this.errorId = resourceId; - fields |= ERROR_ID; - - this.errorPlaceholder = null; - fields &= ~ERROR_PLACEHOLDER; - - return selfOrThrowIfLocked(); - } - - /** - * Sets the {@link android.content.res.Resources.Theme} to apply when loading {@link Drawable}s - * for resource ids provided via {@link #error(int)}, {@link #placeholder(int)}, and - * {@link #fallback(Drawable)}. - * - *

The theme is NOT applied in the decoder that will attempt to decode a given - * resource id model on Glide's background threads. The theme is used exclusively on the main - * thread to obtain placeholder/error/fallback drawables to avoid leaking Activities. - * - *

If the {@link android.content.Context} of the {@link android.app.Fragment} or - * {@link android.app.Activity} used to start this load has a different - * {@link android.content.res.Resources.Theme}, the {@link android.content.res.Resources.Theme} - * provided here will override the {@link android.content.res.Resources.Theme} of the - * {@link android.content.Context}. - * - * @param theme The theme to use when loading Drawables. - * @return this request builder. - */ - @NonNull - @CheckResult - public RequestOptions theme(@Nullable Resources.Theme theme) { - if (isAutoCloneEnabled) { - return clone().theme(theme); - } - - this.theme = theme; - fields |= THEME; - - return selfOrThrowIfLocked(); - } - - /** - * Allows the loaded resource to skip the memory cache. - * - *

Note - this is not a guarantee. If a request is already pending for this resource and that - * request is not also skipping the memory cache, the resource will be cached in memory.

- * - * @param skip True to allow the resource to skip the memory cache. - * @return This request builder. - */ - @NonNull - @CheckResult - public RequestOptions skipMemoryCache(boolean skip) { - if (isAutoCloneEnabled) { - return clone().skipMemoryCache(true); - } - - this.isCacheable = !skip; - fields |= IS_CACHEABLE; - - return selfOrThrowIfLocked(); - } - - /** - * Overrides the {@link com.bumptech.glide.request.target.Target}'s width and height with the - * given values. This is useful for thumbnails, and should only be used for other cases when you - * need a very specific image size. - * - * @param width The width in pixels to use to load the resource. - * @param height The height in pixels to use to load the resource. - * @return This request builder. - */ - @NonNull - @CheckResult - public RequestOptions override(int width, int height) { - if (isAutoCloneEnabled) { - return clone().override(width, height); - } - - this.overrideWidth = width; - this.overrideHeight = height; - fields |= OVERRIDE; - - return selfOrThrowIfLocked(); - } - - /** - * Overrides the {@link com.bumptech.glide.request.target.Target}'s width and height with the - * given size. - * - * @see #override(int, int) - * @param size The width and height to use. - * @return This request builder. - */ - @NonNull - @CheckResult - public RequestOptions override(int size) { - return override(size, size); - } - - /** - * Sets some additional data to be mixed in to the memory and disk cache keys allowing the caller - * more control over when cached data is invalidated. - * - *

Note - The signature does not replace the cache key, it is purely additive.

- * - * @param signature A unique non-null {@link Key} representing the current - * state of the model that will be mixed in to the cache key. - * @return This request builder. - * @see com.bumptech.glide.signature.ObjectKey - */ - @NonNull - @CheckResult - public RequestOptions signature(@NonNull Key signature) { - if (isAutoCloneEnabled) { - return clone().signature(signature); - } - - this.signature = Preconditions.checkNotNull(signature); - fields |= SIGNATURE; - return selfOrThrowIfLocked(); - } - - /** - * Returns a copy of this request builder with all of the options put so far on this builder. - * - *

This method returns a "deep" copy in that all non-immutable arguments are copied such that - * changes to one builder will not affect the other builder. However, in addition to immutable - * arguments, the current model is not copied copied so changes to the model will affect both - * builders.

- * - *

Even if this object was locked, the cloned object returned from this method will not be - * locked.

- */ - @SuppressWarnings({ - "unchecked", - // we don't want to throw to be user friendly - "PMD.CloneThrowsCloneNotSupportedException" - }) - @CheckResult - @Override - public RequestOptions clone() { - try { - RequestOptions result = (RequestOptions) super.clone(); - result.options = new Options(); - result.options.putAll(options); - result.transformations = new CachedHashCodeArrayMap<>(); - result.transformations.putAll(transformations); - result.isLocked = false; - result.isAutoCloneEnabled = false; - return result; - } catch (CloneNotSupportedException e) { - throw new RuntimeException(e); - } - } - - @NonNull - @CheckResult - public RequestOptions set(@NonNull Option option, @NonNull T value) { - if (isAutoCloneEnabled) { - return clone().set(option, value); - } - - Preconditions.checkNotNull(option); - Preconditions.checkNotNull(value); - options.set(option, value); - return selfOrThrowIfLocked(); - } - - @NonNull - @CheckResult - public RequestOptions decode(@NonNull Class resourceClass) { - if (isAutoCloneEnabled) { - return clone().decode(resourceClass); - } - - this.resourceClass = Preconditions.checkNotNull(resourceClass); - fields |= RESOURCE_CLASS; - return selfOrThrowIfLocked(); - } - - public final boolean isTransformationAllowed() { - return isTransformationAllowed; - } - - public final boolean isTransformationSet() { - return isSet(TRANSFORMATION); - } - - public final boolean isLocked() { - return isLocked; - } - - /** - * Sets the value for key - * {@link com.bumptech.glide.load.resource.bitmap.BitmapEncoder#COMPRESSION_FORMAT}. - */ - @NonNull - @CheckResult - public RequestOptions encodeFormat(@NonNull Bitmap.CompressFormat format) { - return set(BitmapEncoder.COMPRESSION_FORMAT, Preconditions.checkNotNull(format)); - } - - /** - * Sets the value for key - * {@link BitmapEncoder#COMPRESSION_QUALITY}. - */ - @NonNull - @CheckResult - public RequestOptions encodeQuality(@IntRange(from = 0, to = 100) int quality) { - return set(BitmapEncoder.COMPRESSION_QUALITY, quality); - } - - /** - * Sets the time position of the frame to extract from a video. - * - *

This is a component option specific to {@link VideoDecoder}. If the default video - * decoder is replaced or skipped because of your configuration, this option may be ignored. - * - * @see VideoDecoder#TARGET_FRAME - * @param frameTimeMicros The time position in microseconds of the desired frame. If negative, the - * Android framework implementation return a representative frame. - */ - @NonNull - @CheckResult - public RequestOptions frame(@IntRange(from = 0) long frameTimeMicros) { - return set(VideoDecoder.TARGET_FRAME, frameTimeMicros); - } - - /** - * Sets the {@link DecodeFormat} to use when decoding {@link Bitmap} objects using - * {@link Downsampler} and Glide's default GIF decoders. - * - *

{@link DecodeFormat} is a request, not a requirement. It's possible the resource will be - * decoded using a decoder that cannot control the format - * ({@link android.media.MediaMetadataRetriever} for example), or that the decoder may choose to - * ignore the requested format if it can't display the image (i.e. RGB_565 is requested, but the - * image has alpha). - * - *

This is a component option specific to {@link Downsampler} and Glide's GIF decoders. If the - * default Bitmap decoders are replaced or skipped because of your configuration, this option may - * be ignored. - * - *

To set only the format used when decoding {@link Bitmap}s, use - * {@link #option(Option, Object)} and {@link Downsampler#DECODE_FORMAT}. To set only the format - * used when decoding GIF frames, use {@link #option(Option, Object)} and - * {@link GifOptions#DECODE_FORMAT}. - * - * @see Downsampler#DECODE_FORMAT - * @see GifOptions#DECODE_FORMAT - */ - @NonNull - @CheckResult - public RequestOptions format(@NonNull DecodeFormat format) { - Preconditions.checkNotNull(format); - return set(Downsampler.DECODE_FORMAT, format) - .set(GifOptions.DECODE_FORMAT, format); - } - - /** - * Disables the use of {@link android.graphics.Bitmap.Config#HARDWARE} in {@link Downsampler} to - * avoid errors caused by inspecting Bitmap pixels, drawing with hardware support disabled, - * drawing to {@link android.graphics.Canvas}s backed by {@link Bitmap}s etc. - * - *

It's almost never safe to set {@link Downsampler#ALLOW_HARDWARE_CONFIG} to {@code true} so - * we only provide a way to disable hardware configs entirely. If no option is set for - * {@link Downsampler#ALLOW_HARDWARE_CONFIG}, Glide will set the value per request based on - * whether or not a {@link Transformation} is applied and if one is, the type of - * {@link Transformation} applied. Built in transformations like {@link FitCenter} and - * {@link com.bumptech.glide.load.resource.bitmap.DownsampleStrategy.CenterOutside} can safely use - * {@link android.graphics.Bitmap.Config#HARDWARE} because they can be entirely replaced by - * scaling within {@link Downsampler}. {@link Transformation}s like {@link #circleCrop()} that - * can't be replicated by {@link Downsampler} cannot use {@link Bitmap.Config#HARDWARE} because - * {@link android.graphics.Bitmap.Config#HARDWARE} cannot be drawn to - * {@link android.graphics.Canvas}s, which is required by most {@link Transformation}s. - */ - @NonNull - @CheckResult - public RequestOptions disallowHardwareConfig() { - return set(Downsampler.ALLOW_HARDWARE_CONFIG, false); - } - - /** - * Sets the {@link DownsampleStrategy} to use when decoding {@link Bitmap Bitmaps} using - * {@link Downsampler}. - * - *

This is a component option specific to {@link Downsampler}. If the defautlt Bitmap decoder - * is replaced or skipped because of your configuration, this option may be ignored. - */ - @NonNull - @CheckResult - public RequestOptions downsample(@NonNull DownsampleStrategy strategy) { - return set(DownsampleStrategy.OPTION, Preconditions.checkNotNull(strategy)); - } - - /** - * Sets the read and write timeout for the http requests used to load the image. - * - *

This is a component option specific to Glide's default networking library and - * {@link com.bumptech.glide.load.model.stream.HttpGlideUrlLoader}. If you use any other - * networking library including Glide's Volley or OkHttp integration libraries, this option will - * be ignored. - * - * @see com.bumptech.glide.load.model.stream.HttpGlideUrlLoader#TIMEOUT - * @param timeoutMs The read and write timeout in milliseconds. - */ - @NonNull - @CheckResult - public RequestOptions timeout(@IntRange(from = 0) int timeoutMs) { - return set(HttpGlideUrlLoader.TIMEOUT, timeoutMs); - } - - /** - * Applies {@link com.bumptech.glide.load.resource.bitmap.CenterCrop} to all default types, and - * ignores unknown types. - * - *

This will override previous calls to {@link #dontTransform()}. - * - * @see #optionalTransform(Class, Transformation) - * @see #centerCrop() - */ - @NonNull - @CheckResult - public RequestOptions optionalCenterCrop() { - return optionalTransform(DownsampleStrategy.CENTER_OUTSIDE, new CenterCrop()); - } - - /** - * Applies {@link CenterCrop} to all default types and - * throws an exception if asked to transform an unknown type. - * - *

this will override previous calls to {@link #dontTransform()} ()}. - * - * @see #transform(Class, Transformation) - * @see #optionalCenterCrop() - */ - @NonNull - @CheckResult - public RequestOptions centerCrop() { - return transform(DownsampleStrategy.CENTER_OUTSIDE, new CenterCrop()); - } - - /** - * - * Applies {@link FitCenter} and to all default types, {@link DownsampleStrategy#FIT_CENTER} to - * image types, and ignores unknown types. - * - *

This will override previous calls to {@link #dontTransform()} and previous calls to - * {@link #downsample(DownsampleStrategy)}. - * - * @see #optionalTransform(Class, Transformation) - * @see #fitCenter() - */ - @NonNull - @CheckResult - public RequestOptions optionalFitCenter() { - return optionalScaleOnlyTransform(DownsampleStrategy.FIT_CENTER, new FitCenter()); - } - - /** - * Applies {@link FitCenter} and to all default types, {@link DownsampleStrategy#FIT_CENTER} to - * image types, and throws an exception if asked to transform an unknown - * type. - * - *

This will override previous calls to {@link #dontTransform()} and previous calls to - * {@link #downsample(DownsampleStrategy)}. - * - * @see #transform(Class, Transformation) - * @see #optionalFitCenter() - */ - @NonNull - @CheckResult - public RequestOptions fitCenter() { - return scaleOnlyTransform(DownsampleStrategy.FIT_CENTER, new FitCenter()); - } - - /** - * Applies {@link com.bumptech.glide.load.resource.bitmap.CenterInside} to all default types, - * {@link DownsampleStrategy#CENTER_INSIDE} to image types, and ignores unknown types. - * - *

This will override previous calls to {@link #dontTransform()} and previous calls to - * {@link #downsample(DownsampleStrategy)}. - * - * @see #optionalTransform(Class, Transformation) - * @see #centerInside() - */ - @NonNull - @CheckResult - public RequestOptions optionalCenterInside() { - return optionalScaleOnlyTransform(DownsampleStrategy.CENTER_INSIDE, new CenterInside()); - } - - /** - * Applies {@link CenterInside} to all default types, {@link DownsampleStrategy#CENTER_INSIDE} to - * image types and throws an exception if asked to transform an unknown type. - * - *

This will override previous calls to {@link #dontTransform()} and previous calls to - * {@link #downsample(DownsampleStrategy)}. - * - * @see #transform(Class, Transformation) - * @see #optionalCenterInside() - */ - @NonNull - @CheckResult - public RequestOptions centerInside() { - return scaleOnlyTransform(DownsampleStrategy.CENTER_INSIDE, new CenterInside()); - } - - /** - * Applies {@link CircleCrop} to all default types, and ignores unknown types. - * - *

This will override previous calls to {@link #dontTransform()}. - * - * @see #optionalTransform(Transformation) - * @see #circleCrop() - */ - @NonNull - @CheckResult - public RequestOptions optionalCircleCrop() { - return optionalTransform(DownsampleStrategy.CENTER_OUTSIDE, new CircleCrop()); - } - - /** - * Applies {@link CircleCrop} to all default types and throws an exception if asked to transform - * an unknown type. - * - *

This will override previous calls to {@link #dontTransform()}. - * - * @see #transform(Class, Transformation) - * @see #optionalCenterCrop() - */ - @NonNull - @CheckResult - public RequestOptions circleCrop() { - return transform(DownsampleStrategy.CENTER_INSIDE, new CircleCrop()); - } - - // calling optionalTransform() on the result of clone() requires greater access. - // calling downsample is guaranteed to modify the current object by the isAutoCloneEnabledCheck. - @SuppressWarnings({"WeakerAccess", "CheckResult"}) - @NonNull - final RequestOptions optionalTransform(@NonNull DownsampleStrategy downsampleStrategy, - @NonNull Transformation transformation) { - if (isAutoCloneEnabled) { - return clone().optionalTransform(downsampleStrategy, transformation); - } - - downsample(downsampleStrategy); - return transform(transformation, /*isRequired=*/ false); - } - - // calling transform() on the result of clone() requires greater access. - // calling downsample is guaranteed to modify the current object by the isAutoCloneEnabledCheck. - @SuppressWarnings({"WeakerAccess", "CheckResult"}) - @NonNull - @CheckResult - final RequestOptions transform(@NonNull DownsampleStrategy downsampleStrategy, - @NonNull Transformation transformation) { - if (isAutoCloneEnabled) { - return clone().transform(downsampleStrategy, transformation); - } - - downsample(downsampleStrategy); - return transform(transformation); - } - - @NonNull - private RequestOptions scaleOnlyTransform( - @NonNull DownsampleStrategy strategy, @NonNull Transformation transformation) { - return scaleOnlyTransform(strategy, transformation, true /*isTransformationRequired*/); - } - - @NonNull - private RequestOptions optionalScaleOnlyTransform( - @NonNull DownsampleStrategy strategy, @NonNull Transformation transformation) { - return scaleOnlyTransform(strategy, transformation, false /*isTransformationRequired*/); - } - - @NonNull - private RequestOptions scaleOnlyTransform( - @NonNull DownsampleStrategy strategy, - @NonNull Transformation transformation, - boolean isTransformationRequired) { - RequestOptions result = isTransformationRequired - ? transform(strategy, transformation) : optionalTransform(strategy, transformation); - result.isScaleOnlyOrNoTransform = true; - return result; - } - - /** - * Applies the given {@link Transformation} for - * {@link Bitmap Bitmaps} to the default types ({@link Bitmap}, - * {@link android.graphics.drawable.BitmapDrawable}, and - * {@link com.bumptech.glide.load.resource.gif.GifDrawable}) - * and throws an exception if asked to transform an unknown type. - * - *

This will override previous calls to {@link #dontTransform()}. - * - * @param transformation Any {@link Transformation} for {@link Bitmap}s. - * @see #optionalTransform(Transformation) - * @see #optionalTransform(Class, Transformation) - */ - // Guaranteed to modify the current object by the isAutoCloneEnabledCheck. - @SuppressWarnings("CheckResult") - @NonNull - @CheckResult - public RequestOptions transform(@NonNull Transformation transformation) { - return transform(transformation, /*isRequired=*/ true); - } - - /** - * Applies the given {@link Transformation}s in the given order for - * {@link Bitmap Bitmaps} to the default types ({@link Bitmap}, - * {@link android.graphics.drawable.BitmapDrawable}, and - * {@link com.bumptech.glide.load.resource.gif.GifDrawable}) - * and throws an exception if asked to transform an unknown type. - * - *

This will override previous calls to {@link #dontTransform()}. - * - * @param transformations One or more {@link Transformation}s for {@link Bitmap}s. - * @see #optionalTransform(Transformation) - * @see #optionalTransform(Class, Transformation) - */ - // Guaranteed to modify the current object by the isAutoCloneEnabledCheck. - @SuppressWarnings({"unchecked", "varargs", "CheckResult"}) - @NonNull - @CheckResult - public RequestOptions transforms(@NonNull Transformation... transformations) { - return transform(new MultiTransformation<>(transformations), /*isRequired=*/ true); - } - - /** - * Applies the given {@link Transformation} for - * {@link Bitmap Bitmaps} to the default types ({@link Bitmap}, - * {@link android.graphics.drawable.BitmapDrawable}, and - * {@link com.bumptech.glide.load.resource.gif.GifDrawable}) and ignores unknown types. - * - *

This will override previous calls to {@link #dontTransform()}. - * - * @param transformation Any {@link Transformation} for {@link Bitmap}s. - * @see #transform(Transformation) - * @see #transform(Class, Transformation) - */ - // Guaranteed to modify the current object by the isAutoCloneEnabledCheck. - @SuppressWarnings("CheckResult") - @NonNull - @CheckResult - public RequestOptions optionalTransform(@NonNull Transformation transformation) { - return transform(transformation, /*isRequired=*/ false); - } - - @NonNull - private RequestOptions transform( - @NonNull Transformation transformation, boolean isRequired) { - if (isAutoCloneEnabled) { - return clone().transform(transformation, isRequired); - } - - DrawableTransformation drawableTransformation = - new DrawableTransformation(transformation, isRequired); - transform(Bitmap.class, transformation, isRequired); - transform(Drawable.class, drawableTransformation, isRequired); - // TODO: remove BitmapDrawable decoder and this transformation. - // Registering as BitmapDrawable is simply an optimization to avoid some iteration and - // isAssignableFrom checks when obtaining the transformation later on. It can be removed without - // affecting the functionality. - transform(BitmapDrawable.class, drawableTransformation.asBitmapDrawable(), isRequired); - transform(GifDrawable.class, new GifDrawableTransformation(transformation), isRequired); - return selfOrThrowIfLocked(); - } - - /** - * Applies the given {@link Transformation} for any decoded resource of - * the given type and allows unknown resource types to be ignored. - * - *

Users can apply different transformations for each resource class. Applying a - * {@link Transformation} for a resource type that already has a - * {@link Transformation} will override the previous call.

- * - *

If any calls are made to the non-optional transform methods, then attempting to transform - * an unknown resource class will throw an exception. To allow unknown types, users must always - * call the optional version of each method.

- * - *

This will override previous calls to {@link #dontTransform()}. - * - * @param resourceClass The type of resource to transform. - * @param transformation The {@link Transformation} to apply. - */ - @NonNull - @CheckResult - public RequestOptions optionalTransform( - @NonNull Class resourceClass, @NonNull Transformation transformation) { - return transform(resourceClass, transformation, /*isRequired=*/ false); - } - - @NonNull - private RequestOptions transform( - @NonNull Class resourceClass, - @NonNull Transformation transformation, - boolean isRequired) { - if (isAutoCloneEnabled) { - return clone().transform(resourceClass, transformation, isRequired); - } - - Preconditions.checkNotNull(resourceClass); - Preconditions.checkNotNull(transformation); - transformations.put(resourceClass, transformation); - fields |= TRANSFORMATION; - isTransformationAllowed = true; - fields |= TRANSFORMATION_ALLOWED; - // Always set to false here. Known scale only transformations will call this method and then - // set isScaleOnlyOrNoTransform to true immediately after. - isScaleOnlyOrNoTransform = false; - if (isRequired) { - fields |= TRANSFORMATION_REQUIRED; - isTransformationRequired = true; - } - return selfOrThrowIfLocked(); - } - - /** - * Applies the given {@link Transformation} for any decoded resource of - * the given type and throws if asked to transform an unknown resource type. - * - *

This will override previous calls to {@link #dontTransform()}. - * - * @param resourceClass The type of resource to transform. - * @param transformation The {@link Transformation} to apply. - * @see #optionalTransform(Class, Transformation) - */ - // Guaranteed to modify the current object by the isAutoCloneEnabledCheck. - @SuppressWarnings("CheckResult") - @NonNull - @CheckResult - public RequestOptions transform( - @NonNull Class resourceClass, @NonNull Transformation transformation) { - return transform(resourceClass, transformation, /*isRequired=*/ true); - } - - /** - * Removes all applied {@link Transformation Transformations} for all - * resource classes and allows unknown resource types to be transformed without throwing an - * exception. - */ - @NonNull - @CheckResult - public RequestOptions dontTransform() { - if (isAutoCloneEnabled) { - return clone().dontTransform(); - } - - transformations.clear(); - fields &= ~TRANSFORMATION; - isTransformationRequired = false; - fields &= ~TRANSFORMATION_REQUIRED; - isTransformationAllowed = false; - fields |= TRANSFORMATION_ALLOWED; - isScaleOnlyOrNoTransform = true; - return selfOrThrowIfLocked(); - } - - /** - * Disables resource decoders that return animated resources so any resource returned will be - * static. - * - *

To disable transitions (fades etc) use - * {@link com.bumptech.glide.TransitionOptions#dontTransition()}

- */ - // Guaranteed to modify the current object by the isAutoCloneEnabledCheck. - @SuppressWarnings("CheckResult") - @NonNull - @CheckResult - public RequestOptions dontAnimate() { - return set(GifOptions.DISABLE_ANIMATION, true); - } - - /** - * Updates this options set with any options that are explicitly set in the given - * {@code RequestOptions} object and returns this object if {@link #autoClone()} is disabled or - * a new {@code RequestOptions} object if {@link #autoClone()} is enabled. - * - *

{@code #apply} only replaces those values that are explicitly set in the given - * {@code RequestOptions}. If you need to completely reset all previously set options, create a - * new {@code RequestOptions} object instead of using this method. - * - *

The options that will be set to values in the returned {@code RequestOptions} object is the - * intersection of the set of options in this {@code RequestOptions} object and the given - * {@code RequestOptions} object that were explicitly set. If the values of any of the options - * conflict, the values in the returned {@code RequestOptions} object will be set to those in the - * given {@code RequestOptions} object. - */ - @NonNull - @CheckResult - public RequestOptions apply(@NonNull RequestOptions other) { - if (isAutoCloneEnabled) { - return clone().apply(other); - } - - if (isSet(other.fields, SIZE_MULTIPLIER)) { - sizeMultiplier = other.sizeMultiplier; - } - if (isSet(other.fields, USE_UNLIMITED_SOURCE_GENERATORS_POOL)) { - useUnlimitedSourceGeneratorsPool = other.useUnlimitedSourceGeneratorsPool; - } - if (isSet(other.fields, USE_ANIMATION_POOL)) { - useAnimationPool = other.useAnimationPool; - } - if (isSet(other.fields, DISK_CACHE_STRATEGY)) { - diskCacheStrategy = other.diskCacheStrategy; - } - if (isSet(other.fields, PRIORITY)) { - priority = other.priority; - } - if (isSet(other.fields, ERROR_PLACEHOLDER)) { - errorPlaceholder = other.errorPlaceholder; - errorId = 0; - fields &= ~ERROR_ID; - } - if (isSet(other.fields, ERROR_ID)) { - errorId = other.errorId; - errorPlaceholder = null; - fields &= ~ERROR_PLACEHOLDER; - } - if (isSet(other.fields, PLACEHOLDER)) { - placeholderDrawable = other.placeholderDrawable; - placeholderId = 0; - fields &= ~PLACEHOLDER_ID; - } - if (isSet(other.fields, PLACEHOLDER_ID)) { - placeholderId = other.placeholderId; - placeholderDrawable = null; - fields &= ~PLACEHOLDER; - } - if (isSet(other.fields, IS_CACHEABLE)) { - isCacheable = other.isCacheable; - } - if (isSet(other.fields, OVERRIDE)) { - overrideWidth = other.overrideWidth; - overrideHeight = other.overrideHeight; - } - if (isSet(other.fields, SIGNATURE)) { - signature = other.signature; - } - if (isSet(other.fields, RESOURCE_CLASS)) { - resourceClass = other.resourceClass; - } - if (isSet(other.fields, FALLBACK)) { - fallbackDrawable = other.fallbackDrawable; - fallbackId = 0; - fields &= ~FALLBACK_ID; - } - if (isSet(other.fields, FALLBACK_ID)) { - fallbackId = other.fallbackId; - fallbackDrawable = null; - fields &= ~FALLBACK; - } - if (isSet(other.fields, THEME)) { - theme = other.theme; - } - if (isSet(other.fields, TRANSFORMATION_ALLOWED)) { - isTransformationAllowed = other.isTransformationAllowed; - } - if (isSet(other.fields, TRANSFORMATION_REQUIRED)) { - isTransformationRequired = other.isTransformationRequired; - } - if (isSet(other.fields, TRANSFORMATION)) { - transformations.putAll(other.transformations); - isScaleOnlyOrNoTransform = other.isScaleOnlyOrNoTransform; - } - if (isSet(other.fields, ONLY_RETRIEVE_FROM_CACHE)) { - onlyRetrieveFromCache = other.onlyRetrieveFromCache; - } - - // Applying options with dontTransform() is expected to clear our transformations. - if (!isTransformationAllowed) { - transformations.clear(); - fields &= ~TRANSFORMATION; - isTransformationRequired = false; - fields &= ~TRANSFORMATION_REQUIRED; - isScaleOnlyOrNoTransform = true; - } - - fields |= other.fields; - options.putAll(other.options); - - return selfOrThrowIfLocked(); - } - - - @Override - public boolean equals(Object o) { - if (o instanceof RequestOptions) { - RequestOptions other = (RequestOptions) o; - return Float.compare(other.sizeMultiplier, sizeMultiplier) == 0 - && errorId == other.errorId - && Util.bothNullOrEqual(errorPlaceholder, other.errorPlaceholder) - && placeholderId == other.placeholderId - && Util.bothNullOrEqual(placeholderDrawable, other.placeholderDrawable) - && fallbackId == other.fallbackId - && Util.bothNullOrEqual(fallbackDrawable, other.fallbackDrawable) - && isCacheable == other.isCacheable - && overrideHeight == other.overrideHeight - && overrideWidth == other.overrideWidth - && isTransformationRequired == other.isTransformationRequired - && isTransformationAllowed == other.isTransformationAllowed - && useUnlimitedSourceGeneratorsPool == other.useUnlimitedSourceGeneratorsPool - && onlyRetrieveFromCache == other.onlyRetrieveFromCache - && diskCacheStrategy.equals(other.diskCacheStrategy) - && priority == other.priority - && options.equals(other.options) - && transformations.equals(other.transformations) - && resourceClass.equals(other.resourceClass) - && Util.bothNullOrEqual(signature, other.signature) - && Util.bothNullOrEqual(theme, other.theme); - } - return false; - } - - @Override - public int hashCode() { - int hashCode = Util.hashCode(sizeMultiplier); - hashCode = Util.hashCode(errorId, hashCode); - hashCode = Util.hashCode(errorPlaceholder, hashCode); - hashCode = Util.hashCode(placeholderId, hashCode); - hashCode = Util.hashCode(placeholderDrawable, hashCode); - hashCode = Util.hashCode(fallbackId, hashCode); - hashCode = Util.hashCode(fallbackDrawable, hashCode); - hashCode = Util.hashCode(isCacheable, hashCode); - hashCode = Util.hashCode(overrideHeight, hashCode); - hashCode = Util.hashCode(overrideWidth, hashCode); - hashCode = Util.hashCode(isTransformationRequired, hashCode); - hashCode = Util.hashCode(isTransformationAllowed, hashCode); - hashCode = Util.hashCode(useUnlimitedSourceGeneratorsPool, hashCode); - hashCode = Util.hashCode(onlyRetrieveFromCache, hashCode); - hashCode = Util.hashCode(diskCacheStrategy, hashCode); - hashCode = Util.hashCode(priority, hashCode); - hashCode = Util.hashCode(options, hashCode); - hashCode = Util.hashCode(transformations, hashCode); - hashCode = Util.hashCode(resourceClass, hashCode); - hashCode = Util.hashCode(signature, hashCode); - hashCode = Util.hashCode(theme, hashCode); - return hashCode; - } - - /** - * Throws if any further mutations are attempted. - * - *

Once locked, the only way to unlock is to use {@link #clone()}

- */ - @NonNull - @SuppressWarnings("unchecked") - public RequestOptions lock() { - isLocked = true; - // This is the only place we should not check locked. - return this; - } - - /** - * Similar to {@link #lock()} except that mutations cause a {@link #clone()} operation to happen - * before the mutation resulting in all methods returning a new Object and leaving the original - * locked object unmodified. - * - *

Auto clone is not retained by cloned objects returned from mutations. The cloned objects - * are mutable and are not locked. - */ - @NonNull - public RequestOptions autoClone() { - if (isLocked && !isAutoCloneEnabled) { - throw new IllegalStateException("You cannot auto lock an already locked options object" - + ", try clone() first"); - } - isAutoCloneEnabled = true; - return lock(); - } - - @NonNull - @SuppressWarnings("unchecked") - private RequestOptions selfOrThrowIfLocked() { - if (isLocked) { - throw new IllegalStateException("You cannot modify locked RequestOptions, consider clone()"); - } - return this; - } - - protected boolean isAutoCloneEnabled() { - return isAutoCloneEnabled; - } - - public final boolean isDiskCacheStrategySet() { - return isSet(DISK_CACHE_STRATEGY); - } - - public final boolean isSkipMemoryCacheSet() { - return isSet(IS_CACHEABLE); - } - - @NonNull - public final Map, Transformation> getTransformations() { - return transformations; - } - - @SuppressWarnings("WeakerAccess") - public final boolean isTransformationRequired() { - return isTransformationRequired; - } - - @NonNull - public final Options getOptions() { - return options; - } - - @NonNull - public final Class getResourceClass() { - return resourceClass; - } - - @NonNull - public final DiskCacheStrategy getDiskCacheStrategy() { - return diskCacheStrategy; - } - - @SuppressWarnings("WeakerAccess") - @Nullable - public final Drawable getErrorPlaceholder() { - return errorPlaceholder; - } - - @SuppressWarnings("WeakerAccess") - public final int getErrorId() { - return errorId; - } - - @SuppressWarnings("WeakerAccess") - public final int getPlaceholderId() { - return placeholderId; - } - - @SuppressWarnings("WeakerAccess") - @Nullable - public final Drawable getPlaceholderDrawable() { - return placeholderDrawable; - } - - @SuppressWarnings("WeakerAccess") - public final int getFallbackId() { - return fallbackId; - } - - @SuppressWarnings("WeakerAccess") - @Nullable - public final Drawable getFallbackDrawable() { - return fallbackDrawable; - } - - @Nullable - public final Resources.Theme getTheme() { - return theme; - } - - @SuppressWarnings("WeakerAccess") - public final boolean isMemoryCacheable() { - return isCacheable; - } - - @NonNull - public final Key getSignature() { - return signature; - } - - public final boolean isPrioritySet() { - return isSet(PRIORITY); - } - - @NonNull - public final Priority getPriority() { - return priority; - } - - public final int getOverrideWidth() { - return overrideWidth; - } - - public final boolean isValidOverride() { - return Util.isValidDimensions(overrideWidth, overrideHeight); - } - - public final int getOverrideHeight() { - return overrideHeight; - } - - public final float getSizeMultiplier() { - return sizeMultiplier; - } - - boolean isScaleOnlyOrNoTransform() { - return isScaleOnlyOrNoTransform; - } - - private boolean isSet(int flag) { - return isSet(fields, flag); - } - - // get is just as clear. - @SuppressWarnings("PMD.BooleanGetMethodName") - public final boolean getUseUnlimitedSourceGeneratorsPool() { - return useUnlimitedSourceGeneratorsPool; - } - - // get is just as clear. - @SuppressWarnings("PMD.BooleanGetMethodName") - public final boolean getUseAnimationPool() { - return useAnimationPool; - } - - // get is just as clear. - @SuppressWarnings("PMD.BooleanGetMethodName") - public final boolean getOnlyRetrieveFromCache() { - return onlyRetrieveFromCache; - } } diff --git a/library/src/main/java/com/bumptech/glide/request/SingleRequest.java b/library/src/main/java/com/bumptech/glide/request/SingleRequest.java index d04890c111..7207bc57e5 100644 --- a/library/src/main/java/com/bumptech/glide/request/SingleRequest.java +++ b/library/src/main/java/com/bumptech/glide/request/SingleRequest.java @@ -91,7 +91,7 @@ private enum Status { @Nullable private Object model; private Class transcodeClass; - private RequestOptions requestOptions; + private BaseRequestOptions requestOptions; private int overrideWidth; private int overrideHeight; private Priority priority; @@ -114,7 +114,7 @@ public static SingleRequest obtain( GlideContext glideContext, Object model, Class transcodeClass, - RequestOptions requestOptions, + BaseRequestOptions requestOptions, int overrideWidth, int overrideHeight, Priority priority, @@ -158,7 +158,7 @@ private void init( GlideContext glideContext, Object model, Class transcodeClass, - RequestOptions requestOptions, + BaseRequestOptions requestOptions, int overrideWidth, int overrideHeight, Priority priority, diff --git a/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrGlideExtension.java b/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrGlideExtension.java index 1a5346d099..57c9ee173d 100644 --- a/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrGlideExtension.java +++ b/samples/flickr/src/main/java/com/bumptech/glide/samples/flickr/FlickrGlideExtension.java @@ -3,7 +3,7 @@ import android.support.annotation.NonNull; import com.bumptech.glide.annotation.GlideExtension; import com.bumptech.glide.annotation.GlideOption; -import com.bumptech.glide.request.RequestOptions; +import com.bumptech.glide.request.BaseRequestOptions; import com.bumptech.glide.samples.flickr.api.Api; /** @@ -20,13 +20,13 @@ private FlickrGlideExtension() { @NonNull @GlideOption - public static RequestOptions squareThumb(RequestOptions requestOptions) { + public static BaseRequestOptions squareThumb(BaseRequestOptions requestOptions) { return requestOptions.centerCrop(); } @NonNull @GlideOption - public static RequestOptions squareMiniThumb(RequestOptions requestOptions) { + public static BaseRequestOptions squareMiniThumb(BaseRequestOptions requestOptions) { return requestOptions.centerCrop().override(Api.SQUARE_THUMB_SIZE); } }