Skip to content

Commit

Permalink
Add method to set http timeouts in Glide’s default networking library.
Browse files Browse the repository at this point in the history
Progress toward #2220.
  • Loading branch information
sjudd committed Aug 8, 2017
1 parent c393ebc commit 3e5527e
Showing 1 changed file with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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.BitmapDrawableTransformation;
import com.bumptech.glide.load.resource.bitmap.BitmapEncoder;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
Expand Down Expand Up @@ -314,6 +315,13 @@ public static RequestOptions downsampleOf(@NonNull DownsampleStrategy strategy)
return new RequestOptions().downsample(strategy);
}

/**
* Returns a {@link RequestOptions} object with {@link #timeout(int)} set.
*/
public static RequestOptions timeoutOf(int timeout) {
return new RequestOptions().timeout(timeout);
}

/**
* Returns a {@link com.bumptech.glide.request.RequestOptions} with {@link
* #encodeQuality(int)} called with the given quality.
Expand Down Expand Up @@ -726,6 +734,20 @@ public RequestOptions encodeQuality(int quality) {
return set(BitmapEncoder.COMPRESSION_QUALITY, quality);
}

/**
* Sets the time position of the frame to extract from a video.
*
* <p>This is a component option specific to {@link VideoBitmapDecoder}. If the default video
* decoder is replaced or skipped because of your configuration, this option may be ignored.
*
* @see VideoBitmapDecoder#TARGET_FRAME
* @param frameTimeMicros The time position in microseconds of the desired frame. If negative, the
* Android framework implementation return a representative frame.
*/
public RequestOptions frame(long frameTimeMicros) {
return set(VideoBitmapDecoder.TARGET_FRAME, frameTimeMicros);
}

/**
* Sets the {@link DecodeFormat} to use when decoding {@link Bitmap} objects using
* {@link Downsampler}.
Expand All @@ -735,27 +757,40 @@ public RequestOptions encodeQuality(int quality) {
* ({@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).
*
* <p>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.
*
* @see Downsampler#DECODE_FORMAT
*/
public RequestOptions format(@NonNull DecodeFormat format) {
return set(Downsampler.DECODE_FORMAT, Preconditions.checkNotNull(format));
}

/**
* Sets the time position of the frame to extract from a video.
* Sets the {@link DownsampleStrategy} to use when decoding {@link Bitmap Bitmaps} using
* {@link Downsampler}.
*
* @param frameTimeMicros The time position in microseconds of the desired frame. If negative, the
* Android framework implementation return a representative frame.
* <p>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.
*/
public RequestOptions frame(long frameTimeMicros) {
return set(VideoBitmapDecoder.TARGET_FRAME, frameTimeMicros);
public RequestOptions downsample(@NonNull DownsampleStrategy strategy) {
return set(Downsampler.DOWNSAMPLE_STRATEGY, Preconditions.checkNotNull(strategy));
}

/**
* Sets the {@link DownsampleStrategy} to use when decoding {@link Bitmap Bitmaps} using
* {@link Downsampler}.
* Sets the read and write timeout for the http requests used to load the image.
*
* <p>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.
*/
public RequestOptions downsample(@NonNull DownsampleStrategy strategy) {
return set(Downsampler.DOWNSAMPLE_STRATEGY, Preconditions.checkNotNull(strategy));
public RequestOptions timeout(int timeoutMs) {
return set(HttpGlideUrlLoader.TIMEOUT, timeoutMs);
}

/**
Expand Down

0 comments on commit 3e5527e

Please sign in to comment.