SSImagePicker

Easy to use and configurable library to Pick an image from the Gallery or Capture image using Camera.

  • You can easily select image from camera and gallery and upload it wherever you want. We have created this library to simplify pick or capture image feature.
  • Handled permissions for camera and gallery, also supports scoped storage.
  • Returns contentUri of selected image.
  • Easy to use and supports all major devices.

Features :

  • Capture Image Using Camera
  • Pick Image From Gallery
  • Handle Runtime Permission For Storage And Camera
  • ImagePicker Bottomsheet
  • Retrieve Image Result In Uri Format
  • Crop Image
  • Rotate Image
  • Image Zoom In, Zoom Out
  • Customize Image Picker BottomSheet Options Like :
    • Customize only text of buttons
    • Customize only text color of buttons
    • Customize multiple values of buttons like:
      • Text color, size, font family, padding using your own styles.xml
    • Customize bottomsheet's background shape and color

?Preview

Capture Image Using Camera Pick Image From Gallery Customize Bottomsheet
Crop Image Rotate Image Image Zoom in, Zoom out

How it works:

  1. Gradle Dependency
  • Add the JitPack repository to your project's build.gradle file
    allprojects {
        repositories {
            ...
    	    maven { url 'https://jitpack.io' }
        }
    }
  • Add plugin in your app's build.gradle file
    plugins {
        ...
        id 'kotlin-kapt'
    } 
  • Add buildFeature in your app's build.gradle file
    android {
        ...
        buildFeatures {
            dataBinding = true
        }
    }
  • Add the dependency in your app's build.gradle file
    dependencies {
        implementation 'com.github.SimformSolutionsPvtLtd:SSImagePicker:1.5'
    }
  1. Use ImagePicker Bottomsheet To Choose Option For Pick Image From Gallery Or Camera
    val fragment = ImagePickerBottomsheet()
    fragment.show(FragmentManager, String) 
  1. Call ImagePickerActivityClass in your onCreate() To Handle Camera, Gallery Click And Permission Result. Pass Context, Activity , Request Permission Result Callback And activityResultRegistry :
    var imagePicker = ImagePickerActivityClass(context,activity,onResult_Callback,activityResultRegistry)
  1. To Enable All Features(crop,rotate,zoomIn,zoomOut) call cropOptions(isAllCropFeaturesRequired: Boolean) And Pass true. By Default It's Set To False And Provides Only Crop Feature.
    override fun onCreate(savedInstanceState: Bundle?) {
        ...
        imagePicker.cropOptions(true)
    }
  1. Allow Camera And Storage Permission To Pick Image And Send Your onRequestPermissionsResult To ImagePickerActivity
    override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
        imagePicker.onRequestPermissionsResult(requestCode, permissions, grantResults)
    }
  1. To Capture Image From Camera Use takePhotoFromCamera()
    imagePicker.takePhotoFromCamera()
  1. To Pick Image From Gallery Use choosePhotoFromGallary()
    imagePicker.choosePhotoFromGallary()
  1. Send Your onActivityResult to ImagePickerActivity
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)  (required)
        imagePicker.onActivityResult(requestCode, resultCode, data)
    }
  1. You Will Get Image Result In Uri Format In returnString() And Customize It To Upload
    override fun returnString(item: Uri?) {
        **Here You Will Get Your Image Result In Uri Format**
    }
  1. You can load image in your imageview using loadImage() func. (If you want to apply circleCrop() then pass isCircle = true, by default it's false)
    override fun returnString(item: Uri?) {
        imageViewEditProfile.loadImage(item, isCircle = true) {}
    }

To customize bottomsheet:

  • To customize bottomsheet, first override below method in your activity.
    override fun doCustomisations(fragment: ImagePickerBottomsheet) {
        //Do customizations here...
    }
  • To customize text of buttons in Bottomsheet.
    fragment.setButtonText("Select Camera","Select Gallery","Remove")
  • To only change text color of buttons in Bottomsheet.
    fragment.setButtonColors(ContextCompat.getColor(requireContext(), R.color.colorPrimary))
  • To customize multiple values of buttons (Text color, size, font family, padding), you need to create a style in your style.xml.
    fragment.setTextAppearance(R.style.fontForNotificationLandingPage)

In styles.xml (Note: parent must be "Widget.AppCompat.TextView")

    <style name="fontForNotificationLandingPage" parent="Widget.AppCompat.TextView">
        <item name="android:fontFamily">@font/poppins_medium</item>
        <item name="android:textColor">@color/white</item>
        <item name="android:textSize">@dimen/_18ssp</item>
    </style>

Note: if setTextAppearance and setButtonColors both are used than whichever function is last called will override other one.

  • To change bottomsheet's background (shape, color).
    fragment.setBottomSheetBackgroundStyle(R.drawable.drawable_bottom_sheet_dialog)

You need to make one drawable file of type shape.

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
        <corners
            android:topLeftRadius="@dimen/_25sdp"
            android:topRightRadius="@dimen/_25sdp" />
        <padding android:top="@dimen/_5sdp" />
        <solid android:color="@color/colorPrimary" />
    </shape>

GitHub

https://github.com/SimformSolutionsPvtLtd/SSImagePicker