Source link: https://github.com/SimformSolutionsPvtLtd/SSImagePicker
Is a Library for pick an image from gallery
� 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:
- 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.6
}
-
Implement ImagePickerBottomsheet.ItemClickListener, ImagePickerActivityClass.OnResult interface in your activity or fragment
-
Use ImagePicker Bottomsheet To Choose Option For Pick Image From Gallery Or Camera
val fragment = ImagePickerBottomsheet()
fragment.show(FragmentManager, String)
- Call ImagePickerActivityClass in your onCreate() To Handle Camera, Gallery Click And Permission Result. Pass Context, Request Permission Result Callback And activityResultRegistry, Activity or Fragment. :
//From activity
var imagePicker = ImagePickerActivityClass(context,onResult_Callback,activityResultRegistry,activity = this)
//From fragment
var imagePicker = ImagePickerActivityClass(context,onResult_Callback,activityResultRegistry,fragment = this)
- 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)
}
- 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) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults) (required)
}
- To Capture Image From Camera Use takePhotoFromCamera()
imagePicker.takePhotoFromCamera()
- To Pick Image From Gallery Use choosePhotoFromGallary()
imagePicker.choosePhotoFromGallary()
- 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)
}
- 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**
}
- 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>
Other Library used:
❤️
Find this library useful? Support it by joining stargazers for this repository.
� How to Contribute
Whether you re helping us fix bugs, improve the docs, or a feature request, we d love to have you!
Check out our Contributing Guide for ideas on contributing.
Bugs and Feedback
For bugs, feature requests, and discussion please use GitHub Issues.
License
Copyright 2020 Simform Solutions
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.