├── .gitignore ├── .idea ├── .gitignore ├── compiler.xml ├── gradle.xml ├── misc.xml └── vcs.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── raj │ │ └── jadon │ │ └── filepicker │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── raj │ │ │ └── jadon │ │ │ └── filepicker │ │ │ ├── FilePickerApp.kt │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── values-night │ │ └── themes.xml │ │ ├── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ │ └── xml │ │ ├── backup_rules.xml │ │ └── data_extraction_rules.xml │ └── test │ └── java │ └── com │ └── raj │ └── jadon │ └── filepicker │ └── ExampleUnitTest.kt ├── build.gradle ├── filePicker ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── raj │ │ └── jadon │ │ └── filepicker │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── raj │ │ │ └── jadon │ │ │ └── filepicker │ │ │ ├── customStartActivityResult │ │ │ ├── StartActivityForResultEnum.kt │ │ │ ├── StartActivityResultContractListenerImplement.kt │ │ │ ├── StartActivityResultCustomContract.kt │ │ │ └── contract │ │ │ │ ├── StartActivityContracts.kt │ │ │ │ └── StartActivityCustomOnResult.kt │ │ │ ├── imageAndFilePicker │ │ │ ├── ImageAndFilePicker.kt │ │ │ └── contract │ │ │ │ └── ImageAndFilePickerContract.kt │ │ │ └── mannualDi │ │ │ └── ImageAndFilePickerInjector.kt │ └── res │ │ ├── values │ │ └── colors.xml │ │ └── xml │ │ └── file_paths.xml │ └── test │ └── java │ └── com │ └── raj │ └── jadon │ └── filepicker │ └── ExampleUnitTest.kt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── jitpack.yml └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | 13 | 14 | 16 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Raj Pratap Singh Jadon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FilePicker 2 | 3 | #### This project aims to provide an ultimate and flexible image picking from Gallery, Camera and cropping experience as well as PDF picking from system. 4 | 5 | #### For the Image Cropping [UCrop](https://github.com/Yalantis/uCrop) library being used. 6 | 7 | #### For the Permission [Dexter](https://github.com/Karumi/Dexter) library being used. 8 | 9 | # [![](https://jitpack.io/v/rajjadon/FilePicker.svg)](https://jitpack.io/#rajjadon/FilePicker) 10 | 11 | # Usage 12 | 13 | *For a working implementation, please have a look at the Sample Project - sample* 14 | 15 | 1. Include the library as a local library project in setting.gradle. 16 | 17 | ``` 18 | allprojects { 19 | repositories { 20 | jcenter() 21 | maven { url "https://jitpack.io" } 22 | } 23 | } 24 | ``` 25 | 26 | i Add dependencies in app level build.gradle file 27 | 28 | ``` 29 | dependencies { 30 | implementation 'com.github.rajjadon:FilePicker:Tag' 31 | } 32 | 33 | ``` 34 | 35 | 2. Initialize Library in to Application class 36 | 37 | ``` 38 | ImageAndFilePickerInjector.initInjectorInstance(this) 39 | ``` 40 | 3. Register Result Registry in onCreate/OnViewCreated of Activity/Fragment by calling below method 41 | 42 | ``` 43 | imageAndFilePicker.registerResultRegistry( 44 | onResult = this, 45 | lifecycle = lifecycle, 46 | activityResultRegistry = activityResultRegistry 47 | ) 48 | ``` 49 | 50 | 4. Call following method as per need 51 | 52 | ``` 53 | i. imageAndFilePicker.openCamera() // For capturing un-compressed image directly from Camera 54 | ii. imageAndFilePicker.openCamera(compressPercentage: Int) // For capturing compressed image directly from Camera. pass compressed percentage between 0-100. 55 | ii. imageAndFilePicker.openGallery() // For selecting image from Gallery 56 | iii. imageAndFilePicker.pickDOCFile() // For Pic DOC form file manager 57 | iv. imageAndFilePicker.getDataFromActivityResult( 58 | resultECode: StartActivityForResultEnum, 59 | result: Intent, 60 | fragment: Fragment? = null, 61 | isCroppingEnable: Boolean = false, 62 | ) // Use this function in OnResult it will return URI of selected image and PDF file. by passing true in isCroppingEnable argument you can enable the image Cropping as well 63 | 64 | v. getFileName(fileUri: Uri) // For get the File name by passing the File Uri. 65 | v. getCameraImageFile() // It will return un-compressed capture image 66 | ``` 67 | 68 | ## License 69 | 70 | ``` 71 | MIT License 72 | 73 | Copyright (c) 2022 Raj Pratap Singh Jadon 74 | 75 | Permission is hereby granted, free of charge, to any person obtaining a copy 76 | of this software and associated documentation files (the "Software"), to deal 77 | in the Software without restriction, including without limitation the rights 78 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 79 | copies of the Software, and to permit persons to whom the Software is 80 | furnished to do so, subject to the following conditions: 81 | 82 | The above copyright notice and this permission notice shall be included in all 83 | copies or substantial portions of the Software. 84 | 85 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 86 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 87 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 88 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 89 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 90 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 91 | SOFTWARE. 92 | 93 | ``` 94 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'org.jetbrains.kotlin.android' 4 | id("kotlin-kapt") 5 | } 6 | 7 | android { 8 | compileSdk 32 9 | 10 | defaultConfig { 11 | applicationId "com.raj.jadon.filepicker" 12 | minSdk 21 13 | targetSdk 32 14 | versionCode 1 15 | versionName "1.0" 16 | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | } 19 | 20 | buildTypes { 21 | release { 22 | minifyEnabled false 23 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 24 | } 25 | } 26 | compileOptions { 27 | sourceCompatibility JavaVersion.VERSION_1_8 28 | targetCompatibility JavaVersion.VERSION_1_8 29 | } 30 | kotlinOptions { 31 | jvmTarget = '1.8' 32 | } 33 | buildFeatures { 34 | viewBinding true 35 | dataBinding true 36 | } 37 | } 38 | 39 | dependencies { 40 | 41 | implementation project(':filePicker') 42 | 43 | implementation 'androidx.core:core-ktx:1.8.0' 44 | implementation 'androidx.appcompat:appcompat:1.4.2' 45 | implementation 'com.google.android.material:material:1.6.1' 46 | implementation 'androidx.constraintlayout:constraintlayout:2.1.4' 47 | testImplementation 'junit:junit:4.13.2' 48 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 49 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 50 | 51 | // Timber 52 | api 'com.jakewharton.timber:timber:5.0.1' 53 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/androidTest/java/com/raj/jadon/filepicker/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.raj.jadon.filepicker 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.raj.jadon.filepicker", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/raj/jadon/filepicker/FilePickerApp.kt: -------------------------------------------------------------------------------- 1 | package com.raj.jadon.filepicker 2 | 3 | import android.app.Application 4 | import com.raj.jadon.filepicker.mannualDi.ImageAndFilePickerInjector 5 | import timber.log.Timber 6 | 7 | class FilePickerApp : Application() { 8 | override fun onCreate() { 9 | super.onCreate() 10 | ImageAndFilePickerInjector.initInjectorInstance(this) 11 | if (BuildConfig.DEBUG) 12 | Timber.plant(Timber.DebugTree()) 13 | } 14 | } -------------------------------------------------------------------------------- /app/src/main/java/com/raj/jadon/filepicker/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.raj.jadon.filepicker 2 | 3 | import android.os.Bundle 4 | import androidx.activity.result.ActivityResult 5 | import androidx.appcompat.app.AppCompatActivity 6 | import androidx.core.net.toUri 7 | import com.raj.jadon.filepicker.customStartActivityResult.StartActivityForResultEnum 8 | import com.raj.jadon.filepicker.customStartActivityResult.contract.StartActivityCustomOnResult 9 | import com.raj.jadon.filepicker.databinding.ActivityMainBinding 10 | import com.raj.jadon.filepicker.imageAndFilePicker.contract.ImageAndFilePickerContract 11 | import com.raj.jadon.filepicker.mannualDi.ImageAndFilePickerInjector 12 | import timber.log.Timber 13 | 14 | class MainActivity : AppCompatActivity(), StartActivityCustomOnResult { 15 | private lateinit var mainBinding: ActivityMainBinding 16 | 17 | private val imageAndFilePicker: ImageAndFilePickerContract by lazy { ImageAndFilePickerInjector.getInstance() } 18 | 19 | override fun onCreate(savedInstanceState: Bundle?) { 20 | super.onCreate(savedInstanceState) 21 | mainBinding = ActivityMainBinding.inflate(layoutInflater) 22 | setContentView(mainBinding.root) 23 | 24 | imageAndFilePicker.registerResultRegistry( 25 | onResult = this, 26 | lifecycle = lifecycle, 27 | activityResultRegistry = activityResultRegistry 28 | ) 29 | 30 | mainBinding.imageAndFilePicker = imageAndFilePicker 31 | } 32 | 33 | override fun onResult(resultECode: StartActivityForResultEnum, result: ActivityResult) { 34 | result.data?.let { it -> 35 | 36 | val imageUri = 37 | imageAndFilePicker.getDataFromActivityResult( 38 | resultECode, 39 | it 40 | ) 41 | Timber.e(imageUri) 42 | imageUri?.let { uri -> 43 | mainBinding.imageView.setImageURI(uri.toUri()) 44 | } 45 | } 46 | 47 | if (resultECode == StartActivityForResultEnum.CAMERA_WITHOUT_COMPRESSION) { 48 | mainBinding.imageView.setImageURI(imageAndFilePicker.getCameraImageFile().toUri()) 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 11 | 12 | 13 | 14 | 17 | 18 | 26 | 27 | 33 | 34 |