Skip to content

Commit 3e5527e

Browse files
committed
Add method to set http timeouts in Glide’s default networking library.
Progress toward #2220.
1 parent c393ebc commit 3e5527e

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

library/src/main/java/com/bumptech/glide/request/RequestOptions.java

+44-9
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.bumptech.glide.load.Options;
1515
import com.bumptech.glide.load.Transformation;
1616
import com.bumptech.glide.load.engine.DiskCacheStrategy;
17+
import com.bumptech.glide.load.model.stream.HttpGlideUrlLoader;
1718
import com.bumptech.glide.load.resource.bitmap.BitmapDrawableTransformation;
1819
import com.bumptech.glide.load.resource.bitmap.BitmapEncoder;
1920
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
@@ -314,6 +315,13 @@ public static RequestOptions downsampleOf(@NonNull DownsampleStrategy strategy)
314315
return new RequestOptions().downsample(strategy);
315316
}
316317

318+
/**
319+
* Returns a {@link RequestOptions} object with {@link #timeout(int)} set.
320+
*/
321+
public static RequestOptions timeoutOf(int timeout) {
322+
return new RequestOptions().timeout(timeout);
323+
}
324+
317325
/**
318326
* Returns a {@link com.bumptech.glide.request.RequestOptions} with {@link
319327
* #encodeQuality(int)} called with the given quality.
@@ -726,6 +734,20 @@ public RequestOptions encodeQuality(int quality) {
726734
return set(BitmapEncoder.COMPRESSION_QUALITY, quality);
727735
}
728736

737+
/**
738+
* Sets the time position of the frame to extract from a video.
739+
*
740+
* <p>This is a component option specific to {@link VideoBitmapDecoder}. If the default video
741+
* decoder is replaced or skipped because of your configuration, this option may be ignored.
742+
*
743+
* @see VideoBitmapDecoder#TARGET_FRAME
744+
* @param frameTimeMicros The time position in microseconds of the desired frame. If negative, the
745+
* Android framework implementation return a representative frame.
746+
*/
747+
public RequestOptions frame(long frameTimeMicros) {
748+
return set(VideoBitmapDecoder.TARGET_FRAME, frameTimeMicros);
749+
}
750+
729751
/**
730752
* Sets the {@link DecodeFormat} to use when decoding {@link Bitmap} objects using
731753
* {@link Downsampler}.
@@ -735,27 +757,40 @@ public RequestOptions encodeQuality(int quality) {
735757
* ({@link android.media.MediaMetadataRetriever} for example), or that the decoder may choose to
736758
* ignore the requested format if it can't display the image (i.e. RGB_565 is requested, but the
737759
* image has alpha).
760+
*
761+
* <p>This is a component option specific to {@link Downsampler}. If the defautlt Bitmap decoder
762+
* is replaced or skipped because of your configuration, this option may be ignored.
763+
*
764+
* @see Downsampler#DECODE_FORMAT
738765
*/
739766
public RequestOptions format(@NonNull DecodeFormat format) {
740767
return set(Downsampler.DECODE_FORMAT, Preconditions.checkNotNull(format));
741768
}
742769

743770
/**
744-
* Sets the time position of the frame to extract from a video.
771+
* Sets the {@link DownsampleStrategy} to use when decoding {@link Bitmap Bitmaps} using
772+
* {@link Downsampler}.
745773
*
746-
* @param frameTimeMicros The time position in microseconds of the desired frame. If negative, the
747-
* Android framework implementation return a representative frame.
774+
* <p>This is a component option specific to {@link Downsampler}. If the defautlt Bitmap decoder
775+
* is replaced or skipped because of your configuration, this option may be ignored.
748776
*/
749-
public RequestOptions frame(long frameTimeMicros) {
750-
return set(VideoBitmapDecoder.TARGET_FRAME, frameTimeMicros);
777+
public RequestOptions downsample(@NonNull DownsampleStrategy strategy) {
778+
return set(Downsampler.DOWNSAMPLE_STRATEGY, Preconditions.checkNotNull(strategy));
751779
}
752780

753781
/**
754-
* Sets the {@link DownsampleStrategy} to use when decoding {@link Bitmap Bitmaps} using
755-
* {@link Downsampler}.
782+
* Sets the read and write timeout for the http requests used to load the image.
783+
*
784+
* <p>This is a component option specific to Glide's default networking library and
785+
* {@link com.bumptech.glide.load.model.stream.HttpGlideUrlLoader}. If you use any other
786+
* networking library including Glide's Volley or OkHttp integration libraries, this option will
787+
* be ignored.
788+
*
789+
* @see com.bumptech.glide.load.model.stream.HttpGlideUrlLoader#TIMEOUT
790+
* @param timeoutMs The read and write timeout in milliseconds.
756791
*/
757-
public RequestOptions downsample(@NonNull DownsampleStrategy strategy) {
758-
return set(Downsampler.DOWNSAMPLE_STRATEGY, Preconditions.checkNotNull(strategy));
792+
public RequestOptions timeout(int timeoutMs) {
793+
return set(HttpGlideUrlLoader.TIMEOUT, timeoutMs);
759794
}
760795

761796
/**

0 commit comments

Comments
 (0)