Package com.example.lottery.util
Class ProfileImageHelper
java.lang.Object
com.example.lottery.util.ProfileImageHelper
Shared helper for profile image operations.
Used by AdminProfileActivity, EntrantProfileActivity, and OrganizerProfileActivity.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classHolds the result of processing a picked image. -
Method Summary
Modifier and TypeMethodDescriptionstatic voiddisplayProfileImage(String base64String, android.widget.ImageView imageView, android.widget.ImageView placeholderView, String seed) Displays a profile image from a Base64 string, or falls back to a generated default avatar.static booleanhasCustomImage(String selectedImageBase64, String savedImageBase64) Determines whether a custom profile image currently exists, considering both the in-progress selection and the persisted state.static voidopenImagePicker(androidx.activity.result.ActivityResultLauncher<android.content.Intent> launcher) Launches the system image picker.processSelectedImage(android.content.ContentResolver contentResolver, android.net.Uri imageUri) Processes a picked image URI: decodes, scales to avatar size, compresses to JPEG, and returns both the Base64 string and the scaled bitmap.static voidshowAvatarOptions(android.app.Activity activity, boolean hasImage, Runnable onPickImage, Runnable onRemoveImage) Shows avatar options: if no image exists, runs onPickImage directly; otherwise shows a bottom sheet with "Change photo" and "Remove photo" options.static voidshowDefaultAvatar(android.widget.ImageView imageView, android.widget.ImageView placeholderView, String seed) Shows a deterministic, initial-based default avatar.
-
Method Details
-
displayProfileImage
public static void displayProfileImage(String base64String, android.widget.ImageView imageView, android.widget.ImageView placeholderView, String seed) Displays a profile image from a Base64 string, or falls back to a generated default avatar. -
showDefaultAvatar
public static void showDefaultAvatar(android.widget.ImageView imageView, android.widget.ImageView placeholderView, String seed) Shows a deterministic, initial-based default avatar. -
processSelectedImage
public static ProfileImageHelper.ProcessedImage processSelectedImage(android.content.ContentResolver contentResolver, android.net.Uri imageUri) throws IOException Processes a picked image URI: decodes, scales to avatar size, compresses to JPEG, and returns both the Base64 string and the scaled bitmap. Properly closes the InputStream via try-with-resources.- Returns:
- a ProcessedImage on success, or null if decoding fails.
- Throws:
IOException- if the content resolver cannot open the URI.
-
showAvatarOptions
public static void showAvatarOptions(android.app.Activity activity, boolean hasImage, Runnable onPickImage, Runnable onRemoveImage) Shows avatar options: if no image exists, runs onPickImage directly; otherwise shows a bottom sheet with "Change photo" and "Remove photo" options. -
openImagePicker
public static void openImagePicker(androidx.activity.result.ActivityResultLauncher<android.content.Intent> launcher) Launches the system image picker. -
hasCustomImage
Determines whether a custom profile image currently exists, considering both the in-progress selection and the persisted state.
-