Skip to content

Core Module Wiki

Sieun Ju edited this page Apr 3, 2023 · 11 revisions

Util related modules required to use the Gallery.

Developer Guide

  • DI Hilt Library Used
com.gallery.core.Factory.kt
class Factory {
    companion object {

        /**
         * Do not Activity Context!
         * @param context Application Context
         */
        fun create(context: Context): GalleryProvider {
            return GalleryProviderImpl(context)
        }
    }
}     
Hilt.kt
@Singleton
@Provides
fun provideGalleryCore(
@ApplicationContext context: Context
): GalleryProvider = Factory.create(context)

public methods

fetchDirectories()

Find information about the album in the gallery.

  • Return Type
    • List GalleryFilterData
  • Return Data Model
    data class GalleryFilterData(
    val bucketId: String, // Album Id
    val bucketName: String, // Album Name
    val photoUri: String, // Album First Image Thumb
    val count: Int // Album Total Count
    )

fetchGallery(params: GalleryQueryParameter)

Find information about the album you want to view in the gallery.

  • Parameter Data Model
class GalleryQueryParameter {
    var filterId: String = "" // Album id
    var isAscOrder: Boolean = false // is Ascending order
}
  • Return Type
    • Cursor

fetchGallery()

Search for all the pictures in the gallery.

  • Return Type
    • Cursor

cursorToPhotoUri(cursor: Cursor)

Converter Current Cursor -> Images Local Uri content://

  • Return Type
    • String (Nullable)
  • Return Example
    • content://....

pathToBitmap(path: String)

Converter Local Path -> Bitmap

  • Return Type
    • Bitmap
  • Return Exception
    • IOException, IllegalArgumentException, FileNotFoundException

pathToBitmap(path: String, limitWidth: Int)

Converter Local Path -> Resize Bitmap (Limit Width Type)

  • Return Type
    • Bitmap
  • Return Exception
    • IOException, IllegalArgumentException, FileNotFoundException

pathToBitmap(@DrawableRes resId: Int)

Converter Local Drawable Resource Id -> Bitmap

  • Return Type
    • Bitmap
  • Return Exception
    • IOException, IllegalArgumentException, FileNotFoundException

pathToMultipart(path: String, name: String, resizeWidth: Int)

Converter Contents Path to Multipart

  • Return Type
    • MultipartBody.Part
  • Return Exception
    • NullPointerException, IllegalArgumentException

bitmapToMultipart(bitmap: Bitmap, name: String)

Converter Bitmap -> okhttp3.MultipartBody.Part.
File Format .jpg

  • Parameter 'name'
    • MultipartBody key Name
  • Return Type
    • okhttp3.MultipartBody.part

bitmapToMultipart(bitmap: Bitmap, name: String, fileName: String, suffix: String)

Converter Bitmap -> okhttp3.MultipartBody.Part.
Custom FileName, Custom File Format Overriding Func Type

  • Parameter
    • 'name' -> MultipartBody key Name
    • 'fileName' -> MultipartBody File Name
    • 'suffix' -> .jpg, .png
  • Return Type
    • okhttp3.MultipartBody.part

copyBitmapToFile(bitmap: Bitmap, fos: FileOutputStream)

Copy the bitmap to a file.


deleteFile(path: String?)

DeleteFile

  • Return Type
    • Boolean
    • Success True, Fail False

deleteCacheDirectory()

Delete Cache Directory

  • Return Type
    • Boolean
    • Success True, Fail False

ratioResizeBitmap(bitmap: Bitmap, width: Int, height: Int)

A function that resizes the bitmap according to the ratio. Calculate the desired width and height value and resize it to the largest value according to the ratio. It's a logic similar to ImageView centerCrop.

  • Parameter

    • width -> Resize Width
    • height -> Resize Height
  • Return Type

    • Bitmap

createTempFile()

create Temp File .jpg

createFile(name: String, suffix: String)

create Temp File Custom File Format


getFlexibleImageToBitmap(originalImagePath: String, flexibleItem: FlexibleStateItem)

Return to bitmap according to the settings edited in 'Flexible ImageEditView'.

  • Return Type
    • Bitmap

getFlexibleImageToBitmap(originalBitmap: Bitmap, srcRect: RectF, width: Int, height: Int)

Return to bitmap according to the settings edited in 'Flexible ImageEditView'.

  • Parameter

    • srcRect
      • FlexibleImageEditView Edit State Item
      • @see FlexibleImageEditView.getStateItem()
    • width
      • FlexibleImageEditView Root Width
    • height
      • FlexibleImageEditView Root Height
  • Return Type

    • Bitmap

getFlexibleImageToBitmap(originalBitmap: Bitmap, srcRect: RectF, width: Int, height: Int, @colorInt color: Int)

getFlexibleImageToBitmap Function Custom Background Color Type.

  • Return Type
    • Bitmap

getFlexibleImageToMultipart(originalImagePath: String, flexibleItem: FlexibleStateItem, multipartKey: String

FlexibleImageView Capture Bitmap And MultipartBody

  • Return Exception
    • NullPointerException, IllegalArgumentException

saveBitmapToFile(bitmap: Bitmap)

Save Bitmap File Completed File Info Return.
File Location Cache Directory

  • Return Type
    • File (Nullable)

getCropImageEditToBitmap(editModel: CropImageEditModel)

Return to bitmap according to the settings edited in 'CropImageEditView'.

  • Parameter Data Model
data class CropImageEditModel(
    val bitmap: Bitmap?,
    val points: FloatArray,
    val degreesRotated: Int,
    val fixAspectRatio: Boolean,
    val aspectRatioX: Int,
    val aspectRatioY: Int,
    val flipHorizontally: Boolean,
    val flipVertically: Boolean
)
  • Return Type
    • Bitmap (Nullable)

getCropImageEditToBitmap(parameter...)

Return to bitmap according to the settings edited in 'CropImageEditView'.
Not CropImageEditModel Type

  • Parameter

    • originalBitmap: Bitmap?
    • points: FloatArray
    • degreesRotated: Int
    • fixAspectRatio: Boolean
    • aspectRatioX: Int
    • aspectRatioY: Int
    • flipHorizontally: Boolean
    • flipVertically: Boolean
  • Return Type

    • Bitmap (Nullable)

createGalleryPhotoUri(authority: String)

A function that generates the uri required by the camera.

  • Parameter

    • authority: String
    • Example. 'com.gallery.example.provider'
    <provider
            android:name="androidx.core.content.FileProvider"
            android:authorities="com.gallery.example.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths" />
        </provider>
  • Return Type

    • Uri (Nullable)

saveGalleryPicture(pictureUri: String, name: String)

A function that takes pictures from a camera and saves them in a gallery.

  • Parameter

    • pictureUri: String (@see createGalleryPhotoUri Uri)
    • name: String (Save File Name)
  • Return Type

    • Pair Boolean, String
    • Success True, PictureUri
    • Fail False, Error Message

getImageType(imagePath: String)

This function returns the image type.

  • Parameter

    • imagePath: String ex) content://media/external/images/media/1
  • Return Type

    • ImageType (Camera, ScreenShot, Etc)
Clone this wiki locally