Anroid library handling media picker from camera and gallery
From Activity | From Fragment | Take Permissions |
---|---|---|
Customize Your Component | Capture Image | Easy Getting Media Path |
---|---|---|
Multi Choose Images
|:————————-:|
Gradle:
repositories {
maven { url 'https://jitpack.io' }
}
build.gradle (app)
android {
.
.
.
.
// for solving Problem duplicate class androidx.lifecycle.viewmodel found in modules add this
// add this only if you import the same version of lifecycle viewmodel in easypicker
configurations {
all {
exclude group: 'androidx.lifecycle', module: 'lifecycle-viewmodel-ktx'
}
}
}
dependencies {
implementation 'com.github.BasemNasr:EasyMediaPicker:v0.1.4'
}
class MainActivity : AppCompatActivity(), OnCaptureMedia {
private lateinit var easyPicker: EasyPicker
var mProfileImagePath = ""
.
.
.
override fun onCreate(savedInstanceState: Bundle?) {
.
setUpImagePicker()
btn.setOnClickListener {
easyPicker.chooseImage()
}
}
private fun setUpImagePicker() {
easyPicker = EasyPicker.Builder(this@MainActivity)
.setRequestCode(PICK_PROFILE_IMAGE)
.setIconsAndTextColor(R.drawable.camera,R.drawable.gallery,R.color.black)
.setSheetBackgroundColor(R.color.white)
.setListener(this@MainActivity)
.build()
}
override fun onCaptureMedia(request: Int, files: ArrayList<FileResource>?) {
when (request) {
PICK_PROFILE_IMAGE -> {
// getting file path (file.path)
val imagePath = if (files?.get(0)?.path!!.isNotEmpty()) {
UploadImages.resizeAndCompressImageBeforeSend(
this@MainActivity, files[0].path, File(files[0].path).name
)
} else files[0].path
mProfileImagePath = imagePath!!
Glide.with(this@MainActivity).load(mProfileImagePath)
.into(findViewById<AppCompatImageView>(R.id.ivCaptainProfileImg))
}
}
}
}
class PickerProfileFragment : Fragment(), OnCaptureMedia {
private lateinit var easyPicker: FragmentEasyPicker
var mProfileImagePath = ""
.
.
.
override fun onCreate(savedInstanceState: Bundle?) {
.
setUpImagePicker()
btn.setOnClickListener {
easyPicker.chooseImage()
}
}
private fun setUpImagePicker() {
easyPicker = FragmentEasyPicker.Builder(this@PickerProfileFragment)
.setRequestCode(MainActivity.PICK_PROFILE_IMAGE)
.setListener(this@PickerProfileFragment).build()
}
override fun onCaptureMedia(request: Int, files: ArrayList<FileResource>?) {
when (request) {
PICK_PROFILE_IMAGE -> {
// getting file path (file.path)
files?.let {
mProfileImagePath = files[0]?.path ?: ""
Glide.with(requireActivity()).load(mProfileImagePath)
.into(requireView().findViewById<AppCompatImageView>(R.id.ivCaptainProfileImg))
}
}
}
}
}
// choose image
easyPicker.chooseImage()
// choose And Compress Image
easyPicker.chooseAndCompressImage()
// choose Video From Gallery
easyPicker.chooseVideo()
//choose file and getting file path
easyPicker.chooseFile()
//chooseMultipleImages
private lateinit var multiImagesEasyPicker: EasyPicker
multiImagesEasyPicker =
EasyPicker.Builder(this@SecondFragment)
.setRequestCode(MainActivity.PICK_IMAGES)
.setListener(this@SecondFragment)
.setMaxSelectionLimit(5)
.build()
multiImagesEasyPicker.chooseMultipleImages()
Pull requests are the best way to propose changes to the codebase (we use Github Flow). We actively welcome your pull requests:
master
.README
and/or requirements.txt
to your added code.We use GitHub issues to track public bugs. Report a bug by opening a new issue it’s that easy!
Great Bug Reports tend to have:
People love thorough bug reports. I’m not even kidding.