CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-github-bumptech-glide--glide

A fast and efficient open source media management and image loading framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.

Pending
Overview
Eval results
Files

request-configuration.mddocs/

Glide Request Configuration System

The Glide request configuration system provides comprehensive control over how images are loaded, cached, transformed, and displayed. At its core is the RequestOptions class, which offers an immutable, fluent API for configuring all aspects of image requests.

RequestOptions Class

The RequestOptions class is the primary configuration interface for Glide requests. It provides a builder pattern for setting up request parameters and can be applied globally or per-request.

public class RequestOptions {
    /**
     * Creates a new RequestOptions instance
     */
    public static RequestOptions new() {
        // Implementation creates new instance
    }
    
    /**
     * Creates RequestOptions with placeholder
     * @param placeholderDrawable The placeholder drawable
     */
    public static RequestOptions placeholderOf(Drawable placeholderDrawable) {
        // Implementation creates instance with placeholder
    }
    
    /**
     * Creates RequestOptions with error drawable
     * @param errorDrawable The error drawable
     */
    public static RequestOptions errorOf(Drawable errorDrawable) {
        // Implementation creates instance with error drawable
    }
    
    /**
     * Creates RequestOptions with format
     * @param format The decode format preference
     */
    public static RequestOptions formatOf(DecodeFormat format) {
        // Implementation creates instance with format
    }
    
    /**
     * Creates RequestOptions with priority
     * @param priority The request priority level
     */
    public static RequestOptions priorityOf(Priority priority) {
        // Implementation creates instance with priority
    }
    
    /**
     * Creates RequestOptions with disk cache strategy
     * @param strategy The caching strategy
     */
    public static RequestOptions diskCacheStrategyOf(DiskCacheStrategy strategy) {
        // Implementation creates instance with strategy
    }
    
    /**
     * Creates RequestOptions with size override
     * @param width Target width in pixels
     * @param height Target height in pixels
     */
    public static RequestOptions overrideOf(int width, int height) {
        // Implementation creates instance with size override
    }
}

Core Configuration Methods

Placeholder and Error Handling

Control what displays during loading states and error conditions:

/**
 * Sets the placeholder drawable to display while loading
 * @param placeholderDrawable Drawable to show during loading
 */
public RequestOptions placeholder(Drawable placeholderDrawable);

/**
 * Sets placeholder using resource ID
 * @param placeholderResourceId Resource ID for placeholder
 */
public RequestOptions placeholder(@DrawableRes int placeholderResourceId);

/**
 * Sets the error drawable for failed loads
 * @param errorDrawable Drawable to show on error
 */
public RequestOptions error(Drawable errorDrawable);

/**
 * Sets error drawable using resource ID
 * @param errorResourceId Resource ID for error drawable
 */
public RequestOptions error(@DrawableRes int errorResourceId);

/**
 * Sets fallback drawable for null models
 * @param fallbackDrawable Drawable for null/empty sources
 */
public RequestOptions fallback(Drawable fallbackDrawable);

/**
 * Sets fallback using resource ID
 * @param fallbackResourceId Resource ID for fallback
 */
public RequestOptions fallback(@DrawableRes int fallbackResourceId);

Size and Scaling Configuration

Control image dimensions and scaling behavior:

/**
 * Overrides the target size for the request
 * @param width Target width in pixels
 * @param height Target height in pixels
 */
public RequestOptions override(int width, int height);

/**
 * Sets a multiplier for the target size
 * @param sizeMultiplier Multiplier (0.1f to 1.0f)
 */
public RequestOptions sizeMultiplier(float sizeMultiplier);

Priority and Timeout Settings

Control request execution priority and timing:

/**
 * Sets the priority for this request
 * @param priority Priority level for execution
 */
public RequestOptions priority(Priority priority);

/**
 * Sets timeout for the request
 * @param timeoutMs Timeout in milliseconds
 */
public RequestOptions timeout(int timeoutMs);

Format and Quality Options

Control image format and compression:

/**
 * Sets the decode format preference
 * @param format Preferred bitmap configuration
 */
public RequestOptions format(DecodeFormat format);

/**
 * Sets the class to decode into
 * @param resourceClass Target class (Bitmap, Drawable, etc.)
 */
public <T> RequestOptions decode(Class<T> resourceClass);

/**
 * Sets bitmap compress format for encoding
 * @param format Compression format (JPEG, PNG, WEBP)
 */
public RequestOptions encodeFormat(Bitmap.CompressFormat format);

/**
 * Sets encoding quality (0-100)
 * @param quality Quality percentage
 */
public RequestOptions encodeQuality(int quality);

Memory and Disk Cache Controls

Manage caching behavior:

/**
 * Sets disk cache strategy
 * @param strategy How to cache on disk
 */
public RequestOptions diskCacheStrategy(DiskCacheStrategy strategy);

/**
 * Controls memory cache usage
 * @param skip True to skip memory cache
 */
public RequestOptions skipMemoryCache(boolean skip);

/**
 * Only load from cache, don't fetch
 * @param onlyCache True to use cache only
 */
public RequestOptions onlyRetrieveFromCache(boolean onlyCache);

Video Frame Extraction

Configure video frame loading:

/**
 * Sets the time position for video frame extraction
 * @param frameTimeMicros Time in microseconds
 */
public RequestOptions frame(long frameTimeMicros);

Advanced Configuration

Additional configuration options:

/**
 * Controls unlimited source generators pool usage
 * @param flag True to use unlimited pool
 */
public RequestOptions useUnlimitedSourceGeneratorsPool(boolean flag);

Enum Types

Priority Levels

public enum Priority {
    /**
     * Lowest priority - loaded when system is idle
     */
    LOW,
    
    /**
     * Normal priority - default for most requests
     */
    NORMAL,
    
    /**
     * High priority - important images
     */
    HIGH,
    
    /**
     * Immediate priority - critical images
     */
    IMMEDIATE
}

Decode Formats

public enum DecodeFormat {
    /**
     * Prefer ARGB_8888 for quality (default)
     */
    PREFER_ARGB_8888,
    
    /**
     * Prefer RGB_565 for memory efficiency
     */
    PREFER_RGB_565,
    
    /**
     * Use system default format
     */
    DEFAULT
}

Disk Cache Strategies

public enum DiskCacheStrategy {
    /**
     * Cache both original and transformed resources
     */
    ALL,
    
    /**
     * Cache nothing to disk
     */
    NONE,
    
    /**
     * Cache only original untransformed data
     */
    DATA,
    
    /**
     * Cache only transformed resources
     */
    RESOURCE,
    
    /**
     * Intelligently cache based on data source (default)
     */
    AUTOMATIC
}

Configuration Chaining and Application

Creating and Applying Options

// Create base options
RequestOptions baseOptions = new RequestOptions()
    .placeholder(R.drawable.loading)
    .error(R.drawable.error)
    .diskCacheStrategy(DiskCacheStrategy.ALL)
    .priority(Priority.HIGH);

// Apply to specific request
Glide.with(context)
    .load(imageUrl)
    .apply(baseOptions)
    .into(imageView);

// Chain additional options
Glide.with(context)
    .load(imageUrl)
    .apply(baseOptions)
    .override(300, 300)
    .format(DecodeFormat.PREFER_RGB_565)
    .into(imageView);

Global Default Options

// Set global defaults in GlideModule
public class MyGlideModule extends AppGlideModule {
    @Override
    public void applyOptions(Context context, GlideBuilder builder) {
        RequestOptions defaultOptions = new RequestOptions()
            .format(DecodeFormat.PREFER_RGB_565)
            .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)
            .timeout(30000);
            
        builder.setDefaultRequestOptions(defaultOptions);
    }
}

Practical Usage Examples

Performance-Optimized Configuration

// Memory-efficient configuration
RequestOptions memoryEfficientOptions = new RequestOptions()
    .format(DecodeFormat.PREFER_RGB_565)  // Use less memory
    .sizeMultiplier(0.8f)                 // Scale down slightly
    .diskCacheStrategy(DiskCacheStrategy.RESOURCE)  // Cache processed images
    .skipMemoryCache(false);               // Keep memory caching

Glide.with(context)
    .load(imageUrl)
    .apply(memoryEfficientOptions)
    .into(imageView);

High-Quality Configuration

// High-quality configuration
RequestOptions highQualityOptions = new RequestOptions()
    .format(DecodeFormat.PREFER_ARGB_8888)  // Best quality
    .encodeFormat(Bitmap.CompressFormat.PNG)  // Lossless compression
    .encodeQuality(100)                     // Maximum quality
    .diskCacheStrategy(DiskCacheStrategy.ALL)  // Cache everything
    .priority(Priority.HIGH);                // High priority loading

Glide.with(context)
    .load(imageUrl)
    .apply(highQualityOptions)
    .into(imageView);

Video Thumbnail Configuration

// Extract frame from video
RequestOptions videoThumbnailOptions = new RequestOptions()
    .frame(1000000)  // 1 second in microseconds
    .placeholder(R.drawable.video_placeholder)
    .error(R.drawable.video_error)
    .override(200, 150)  // Thumbnail size
    .diskCacheStrategy(DiskCacheStrategy.RESOURCE);

Glide.with(context)
    .load(videoUri)
    .apply(videoThumbnailOptions)
    .into(thumbnailView);

List/RecyclerView Optimized

// Optimized for list scrolling
RequestOptions listItemOptions = new RequestOptions()
    .placeholder(new ColorDrawable(Color.LTGRAY))  // Lightweight placeholder
    .format(DecodeFormat.PREFER_RGB_565)       // Memory efficient
    .diskCacheStrategy(DiskCacheStrategy.AUTOMATIC)  // Smart caching
    .priority(Priority.NORMAL)                 // Standard priority
    .timeout(10000);                           // Shorter timeout

// In adapter
Glide.with(holder.itemView.getContext())
    .load(item.imageUrl)
    .apply(listItemOptions)
    .into(holder.imageView);

Cache-First Configuration

// Prefer cached content
RequestOptions cacheFirstOptions = new RequestOptions()
    .onlyRetrieveFromCache(true)  // Only use cache
    .fallback(R.drawable.offline_placeholder)  // Show when no cache
    .skipMemoryCache(false)       // Use memory cache
    .diskCacheStrategy(DiskCacheStrategy.ALL);

Glide.with(context)
    .load(imageUrl)
    .apply(cacheFirstOptions)
    .into(imageView);

Progressive Loading Configuration

// Progressive loading with thumbnail
RequestOptions progressiveOptions = new RequestOptions()
    .placeholder(R.drawable.loading)
    .sizeMultiplier(0.1f);  // Small thumbnail first

RequestOptions fullSizeOptions = new RequestOptions()
    .diskCacheStrategy(DiskCacheStrategy.ALL)
    .priority(Priority.HIGH);

Glide.with(context)
    .load(imageUrl)
    .thumbnail(
        Glide.with(context)
            .load(imageUrl)
            .apply(progressiveOptions)
    )
    .apply(fullSizeOptions)
    .into(imageView);

Configuration Best Practices

Memory Management

  1. Use RGB_565 for non-transparent images to save 50% memory
  2. Set appropriate size multipliers for scaled-down contexts
  3. Configure memory cache appropriately for your app's needs
  4. Use disk caching strategically based on content type

Performance Optimization

  1. Set timeouts to prevent hanging requests
  2. Use priority levels to load critical images first
  3. Configure appropriate cache strategies for different content types
  4. Skip memory cache for large images that won't be reused

Quality vs. Size Trade-offs

  1. Use PREFER_ARGB_8888 only when transparency or quality is critical
  2. Adjust encode quality based on content importance
  3. Consider Progressive JPEG for large images
  4. Use appropriate compression formats (WEBP when possible)

Error Handling

  1. Always provide error drawables for network-dependent content
  2. Use fallback drawables for null/empty sources
  3. Provide meaningful placeholders that match expected content
  4. Consider offline scenarios with cache-only options

The RequestOptions system provides fine-grained control over every aspect of image loading in Glide. By understanding these configuration options and applying them appropriately, you can optimize your app's performance, memory usage, and user experience while maintaining high image quality where needed.

Install with Tessl CLI

npx tessl i tessl/maven-com-github-bumptech-glide--glide

docs

caching-strategies.md

error-handling-debugging.md

index.md

modules-configuration.md

request-configuration.md

request-management.md

targets-loading.md

transformations.md

transitions-animations.md

tile.json