Overview
TheImageSetter class provides a static method to asynchronously load user profile pictures from Firebase Storage into ImageView components. It uses the Glide library for efficient image loading with circular crop transformation.
This utility implements image compression optimization mentioned in the app’s advanced features, reducing bandwidth usage when displaying profile pictures.
Class Definition
ImageSetter.java
Methods
setImage
Application or activity context for Glide image loading
The ImageView where the profile picture will be displayed
The user’s email address used to look up their profile image in Firebase
ProgressBar widget to show loading state while fetching the image
How It Works
- Shows Loading Indicator - Sets the ProgressBar to visible
- Queries Firebase Database - Searches the uploads node for matching email
- Loads Image with Glide - Applies circular crop transformation and placeholder
- Hides Loading Indicator - Removes ProgressBar when complete
Usage Example
MyTeam.java
AccountManager.java
Image Transformation
The method applies a circular crop transformation to all profile images using Glide’sRequestOptions.circleCropTransform(), creating a consistent circular avatar appearance throughout the app.
Placeholder
If no image is found or while loading, a default placeholder is shown:- Resource:
R.mipmap.boy - Applied via:
.placeholder(R.mipmap.boy)
Firebase Database Structure
The method queries the database path defined inConstants.DATABASE_UPLOADS:
Dependencies
Glide
Image loading library with caching and transformations
Firebase Database
Real-time database for storing image metadata
Performance Optimization
Image Compression
Image Compression
Before uploading to Firebase Storage, images are compressed to reduce storage costs and improve loading times. This compression happens in the upload flow within
AccountManager.Glide Caching
Glide Caching
Glide automatically caches loaded images, preventing redundant network requests when the same profile picture is displayed multiple times.
Error Handling
The method includes anonCancelled callback for database errors, though it doesn’t implement specific error handling. The ProgressBar is always hidden even if the image fails to load, preventing UI freezing.
Related Classes
Upload
Data model for image upload metadata
Constants
Contains
DATABASE_UPLOADS constant for Firebase pathSource Reference
File:~/workspace/source/app/src/main/java/project/avishkar/salesmanagement/ImageSetter.java