Class ProfileImageHelper

java.lang.Object
com.example.lottery.util.ProfileImageHelper

public final class ProfileImageHelper extends Object
Shared helper for profile image operations. Used by AdminProfileActivity, EntrantProfileActivity, and OrganizerProfileActivity.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Holds the result of processing a picked image.
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    static boolean
    hasCustomImage(String selectedImageBase64, String savedImageBase64)
    Determines whether a custom profile image currently exists, considering both the in-progress selection and the persisted state.
    static void
    openImagePicker(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 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.
    static void
    showDefaultAvatar(android.widget.ImageView imageView, android.widget.ImageView placeholderView, String seed)
    Shows a deterministic, initial-based default avatar.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public static boolean hasCustomImage(String selectedImageBase64, String savedImageBase64)
      Determines whether a custom profile image currently exists, considering both the in-progress selection and the persisted state.