├── .idea ├── gradle.xml ├── libraries │ ├── android_arch_core_common_1_0_0_jar.xml │ ├── android_arch_lifecycle_common_1_0_3_jar.xml │ ├── android_arch_lifecycle_runtime_1_0_3.xml │ ├── com_android_databinding_adapters_1_3_1.xml │ ├── com_android_databinding_baseLibrary_3_0_1_jar.xml │ ├── com_android_databinding_library_1_3_1.xml │ ├── com_android_support_animated_vector_drawable_27_0_2.xml │ ├── com_android_support_appcompat_v7_27_0_2.xml │ ├── com_android_support_design_27_0_2.xml │ ├── com_android_support_exifinterface_27_0_2.xml │ ├── com_android_support_recyclerview_v7_27_0_2.xml │ ├── com_android_support_support_annotations_27_0_2_jar.xml │ ├── com_android_support_support_compat_27_0_2.xml │ ├── com_android_support_support_core_ui_27_0_2.xml │ ├── com_android_support_support_core_utils_27_0_2.xml │ ├── com_android_support_support_fragment_27_0_2.xml │ ├── com_android_support_support_media_compat_27_0_2.xml │ ├── com_android_support_support_v4_27_0_2.xml │ ├── com_android_support_support_vector_drawable_27_0_2.xml │ ├── com_android_support_test_espresso_espresso_core_2_2_2.xml │ ├── com_android_support_test_espresso_espresso_idling_resource_2_2_2.xml │ ├── com_android_support_test_exposed_instrumentation_api_publish_0_5.xml │ ├── com_android_support_test_rules_0_5.xml │ ├── com_android_support_test_runner_0_5.xml │ ├── com_android_support_transition_27_0_2.xml │ ├── com_google_code_findbugs_jsr305_2_0_1_jar.xml │ ├── com_squareup_javawriter_2_1_1_jar.xml │ ├── com_theartofdev_edmodo_android_image_cropper_2_6_0.xml │ ├── javax_annotation_javax_annotation_api_1_2_jar.xml │ ├── javax_inject_javax_inject_1_jar.xml │ ├── junit_junit_4_12_jar.xml │ ├── org_hamcrest_hamcrest_core_1_3_jar.xml │ ├── org_hamcrest_hamcrest_integration_1_3_jar.xml │ └── org_hamcrest_hamcrest_library_1_3_jar.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── README.md ├── SmartImagePicker.iml ├── app ├── .gitignore ├── app.iml ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── myhexaville │ │ └── androidimagepicker │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── myhexaville │ │ │ └── androidimagepicker │ │ │ ├── StartActivity.java │ │ │ ├── activity_example │ │ │ └── ActivityExample.java │ │ │ └── fragment_example │ │ │ ├── FragmentExample.java │ │ │ └── ImagePickerFragment.java │ └── res │ │ ├── layout │ │ ├── activity_start.xml │ │ ├── fragment_activity.xml │ │ └── main_layout.xml │ │ ├── menu │ │ └── menu_main.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── values-v21 │ │ └── styles.xml │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── myhexaville │ └── androidimagepicker │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ └── gradle-wrapper.properties ├── library ├── .gitignore ├── build.gradle ├── library.iml ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── myhexaville │ │ └── smartimagepicker │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── myhexaville │ │ │ └── smartimagepicker │ │ │ ├── CustomFileProvider.java │ │ │ ├── ImagePicker.java │ │ │ ├── ImagePickerContract.java │ │ │ └── OnImagePickedListener.java │ └── res │ │ ├── values │ │ ├── colors.xml │ │ └── strings.xml │ │ └── xml │ │ └── file_paths.xml │ └── test │ └── java │ └── com │ └── myhexaville │ └── smartimagepicker │ └── ExampleUnitTest.java └── settings.gradle /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/libraries/android_arch_core_common_1_0_0_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/android_arch_lifecycle_common_1_0_3_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/android_arch_lifecycle_runtime_1_0_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_databinding_adapters_1_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_databinding_baseLibrary_3_0_1_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_databinding_library_1_3_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_animated_vector_drawable_27_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_appcompat_v7_27_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_design_27_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_exifinterface_27_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_recyclerview_v7_27_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_annotations_27_0_2_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_compat_27_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_core_ui_27_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_core_utils_27_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_fragment_27_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_media_compat_27_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_v4_27_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_support_vector_drawable_27_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_test_espresso_espresso_core_2_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_test_espresso_espresso_idling_resource_2_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_test_exposed_instrumentation_api_publish_0_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_test_rules_0_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_test_runner_0_5.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /.idea/libraries/com_android_support_transition_27_0_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/com_google_code_findbugs_jsr305_2_0_1_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/libraries/com_squareup_javawriter_2_1_1_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/com_theartofdev_edmodo_android_image_cropper_2_6_0.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/libraries/javax_annotation_javax_annotation_api_1_2_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/libraries/javax_inject_javax_inject_1_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/junit_junit_4_12_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/org_hamcrest_hamcrest_core_1_3_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/org_hamcrest_hamcrest_integration_1_3_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/org_hamcrest_hamcrest_library_1_3_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### Simplified abstraction over [Android Image Cropper](https://github.com/ArthurHub/Android-Image-Cropper) library to pick images from gallery or camera and crop them if needed. 2 | 3 | 4 |

5 | 6 | 7 | 8 | 9 | ### Note 10 | This library is currently unsupported because I've switched my focus to Flutter and don't plan fixing any bugs any time soon 11 | 12 | 13 | ## Usage 14 | Add this line to build.gradle 15 | ```groovy 16 | compile 'com.myhexaville:smart-image-picker:1.0.4' 17 | ``` 18 | 19 | 20 | ### Create new instance and save it as field 21 | ```java 22 | imagePicker = new ImagePicker(this, /* activity non null*/ 23 | null, /* fragment nullable*/ 24 | imageUri -> {/*on image picked */ 25 | imageView.setImageURI(imageUri); 26 | }) 27 | .setWithImageCrop( 28 | 1 /*aspect ratio x*/ 29 | 1 /*aspect ratio y*/); 30 | ``` 31 | 32 | ### If calling from Activity 33 | Override Activity's methods to delegate permissions to ImagePicker and resulting image 34 | ```java 35 | @Override 36 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 37 | super.onActivityResult(requestCode, resultCode, data); 38 | imagePicker.handleActivityResult(resultCode,requestCode, data); 39 | } 40 | @Override 41 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 42 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 43 | imagePicker.handlePermission(requestCode, grantResults); 44 | } 45 | ``` 46 | ### Open Picker 47 | There's two methods available 48 | ```java 49 | imagePicker.openCamera(); 50 | imagePicker.choosePicture(true /*show camera intents*/); 51 | ``` 52 | First one opens camera directly, second shows an intent picker, where user picks from desired application. You can include/exclude camera intents with boolean. 53 | 54 | That's it, if you don't need to crop image, don't call *setWithImageCrop()* in the chain. By default it's disabled. And if you want to get a file after you picked image, you can get it with this method 55 | ```java 56 | File file = imagePicker.getImageFile(); 57 | ``` 58 | ### If calling from Fragment 59 | Create instance 60 | ```java 61 | imagePicker = new ImagePicker(getActivity(), 62 | this, 63 | imageUri -> {/*on image picked */ 64 | imageView.setImageURI(imageUri); 65 | }) 66 | .setWithImageCrop( 67 | 1 /*aspect ratio x*/ 68 | 1 /*aspect ratio y*/); 69 | ``` 70 | 71 | Overriden methods should be in your Fragment 72 | 73 | ```java 74 | @Override 75 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 76 | super.onActivityResult(requestCode, resultCode, data); 77 | imagePicker.handleActivityResult(resultCode, requestCode, data); 78 | } 79 | @Override 80 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 81 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 82 | imagePicker.handlePermission(requestCode, grantResults); 83 | } 84 | ``` 85 | But your fragment won't get activity result callback itself. You need to call it manually. Add this code to activity that hosts your fragment 86 | 87 | ```java 88 | @Override 89 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 90 | super.onActivityResult(requestCode, resultCode, data); 91 | List fragments = getSupportFragmentManager().getFragments(); 92 | if (fragments != null) { 93 | for (Fragment f : fragments) { 94 | if (f instanceof YourFragment) { 95 | f.onActivityResult(requestCode, resultCode, data); 96 | } 97 | } 98 | } 99 | } 100 | ``` 101 | 102 | ### You can get a sample app [here](https://github.com/IhorKlimov/SmartImagePicker/tree/master/app) 103 | ### You don't need to add any permissions to manifest, everything is merged automatically from library's manifest file 104 | -------------------------------------------------------------------------------- /SmartImagePicker.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/app.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | buildscript { 4 | repositories { 5 | mavenCentral() 6 | } 7 | } 8 | 9 | android { 10 | compileOptions { 11 | sourceCompatibility JavaVersion.VERSION_1_8 12 | targetCompatibility JavaVersion.VERSION_1_8 13 | } 14 | compileSdkVersion rootProject.ext.compileSdkVersion 15 | buildToolsVersion rootProject.ext.buildToolsVersion 16 | dataBinding { 17 | enabled true 18 | } 19 | defaultConfig { 20 | vectorDrawables.useSupportLibrary = true 21 | applicationId "com.myhexaville.androidimagepicker" 22 | minSdkVersion rootProject.ext.minSdkVersion 23 | targetSdkVersion rootProject.ext.targetSdkVersion 24 | versionCode 1 25 | versionName "1.0" 26 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 27 | } 28 | buildTypes { 29 | release { 30 | minifyEnabled false 31 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 32 | } 33 | } 34 | } 35 | 36 | dependencies { 37 | compile fileTree(include: ['*.jar'], dir: 'libs') 38 | testCompile 'junit:junit:4.12' 39 | 40 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 41 | exclude group: 'com.android.support', module: 'support-annotations' 42 | }) 43 | 44 | compile project(':library') 45 | 46 | implementation "com.android.support:appcompat-v7:$supportLibraryVersion" 47 | implementation "com.android.support:design:$supportLibraryVersion" 48 | implementation "com.android.support:support-v4:$supportLibraryVersion" 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\Ihor\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/myhexaville/androidimagepicker/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.myhexaville.androidimagepicker; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.myhexaville.androidimagepicker", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 15 | 16 | 20 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/myhexaville/androidimagepicker/StartActivity.java: -------------------------------------------------------------------------------- 1 | package com.myhexaville.androidimagepicker; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.design.widget.FloatingActionButton; 6 | import android.support.design.widget.Snackbar; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.support.v7.widget.Toolbar; 9 | import android.view.View; 10 | import android.databinding.DataBindingUtil; 11 | 12 | import com.myhexaville.androidimagepicker.activity_example.ActivityExample; 13 | import com.myhexaville.androidimagepicker.databinding.ActivityStartBinding; 14 | import com.myhexaville.androidimagepicker.fragment_example.FragmentExample; 15 | 16 | 17 | public class StartActivity extends AppCompatActivity { 18 | 19 | @Override 20 | protected void onCreate(Bundle savedInstanceState) { 21 | super.onCreate(savedInstanceState); 22 | ActivityStartBinding binding = 23 | DataBindingUtil.setContentView(this, R.layout.activity_start); 24 | setSupportActionBar(binding.toolbar); 25 | } 26 | 27 | public void fragmentExample(View view) { 28 | startActivity(new Intent(this, FragmentExample.class)); 29 | } 30 | 31 | public void activityExample(View view) { 32 | startActivity(new Intent(this, ActivityExample.class)); 33 | } 34 | } -------------------------------------------------------------------------------- /app/src/main/java/com/myhexaville/androidimagepicker/activity_example/ActivityExample.java: -------------------------------------------------------------------------------- 1 | package com.myhexaville.androidimagepicker.activity_example; 2 | 3 | import android.content.Intent; 4 | import android.databinding.DataBindingUtil; 5 | import android.os.Bundle; 6 | import android.support.annotation.NonNull; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.util.Log; 9 | import android.view.View; 10 | 11 | import com.myhexaville.androidimagepicker.R; 12 | import com.myhexaville.androidimagepicker.databinding.MainLayoutBinding; 13 | import com.myhexaville.smartimagepicker.ImagePicker; 14 | 15 | 16 | public class ActivityExample extends AppCompatActivity { 17 | private static final String TAG = "ActivityExample"; 18 | private ImagePicker imagePicker; 19 | private MainLayoutBinding binding; 20 | 21 | @Override 22 | protected void onCreate(Bundle savedInstanceState) { 23 | super.onCreate(savedInstanceState); 24 | binding = DataBindingUtil.setContentView(this, R.layout.main_layout); 25 | setSupportActionBar(binding.toolbar); 26 | } 27 | 28 | @Override 29 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 30 | super.onActivityResult(requestCode, resultCode, data); 31 | imagePicker.handleActivityResult(resultCode,requestCode, data); 32 | } 33 | 34 | @Override 35 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 36 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 37 | imagePicker.handlePermission(requestCode, grantResults); 38 | } 39 | 40 | public void showAll(View view) { 41 | refreshImagePicker(); 42 | imagePicker.choosePicture(true); 43 | } 44 | 45 | public void chooseFromGallery(View view) { 46 | refreshImagePicker(); 47 | imagePicker.choosePicture(false); 48 | } 49 | 50 | public void openCamera(View view) { 51 | refreshImagePicker(); 52 | imagePicker.openCamera(); 53 | } 54 | 55 | private void refreshImagePicker() { 56 | imagePicker = new ImagePicker(this, 57 | null, 58 | imageUri -> { 59 | Log.d(TAG, "refreshImagePicker: "+ imageUri); 60 | Log.d(TAG, "refreshImagePicker: "+ imagePicker.getImageFile().getName()); 61 | binding.image.setImageURI(imageUri); 62 | }); 63 | if (binding.withCrop.isChecked()) { 64 | imagePicker.setWithImageCrop( 65 | Integer.parseInt(binding.aspectRatioX.getText().toString()), 66 | Integer.parseInt(binding.aspectRatioY.getText().toString()) 67 | ); 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /app/src/main/java/com/myhexaville/androidimagepicker/fragment_example/FragmentExample.java: -------------------------------------------------------------------------------- 1 | package com.myhexaville.androidimagepicker.fragment_example; 2 | 3 | import android.content.Intent; 4 | import android.databinding.DataBindingUtil; 5 | import android.os.Bundle; 6 | import android.support.v4.app.Fragment; 7 | import android.support.v7.app.AppCompatActivity; 8 | 9 | import com.myhexaville.androidimagepicker.R; 10 | import com.myhexaville.androidimagepicker.databinding.FragmentActivityBinding; 11 | 12 | import java.util.List; 13 | 14 | 15 | public class FragmentExample extends AppCompatActivity { 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | 21 | FragmentActivityBinding binding = DataBindingUtil.setContentView(this, R.layout.fragment_activity); 22 | } 23 | 24 | @Override 25 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 26 | super.onActivityResult(requestCode, resultCode, data); 27 | List fragments = getSupportFragmentManager().getFragments(); 28 | if (fragments != null) { 29 | for (Fragment f : fragments) { 30 | if (f instanceof ImagePickerFragment) { 31 | f.onActivityResult(requestCode, resultCode, data); 32 | } 33 | } 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /app/src/main/java/com/myhexaville/androidimagepicker/fragment_example/ImagePickerFragment.java: -------------------------------------------------------------------------------- 1 | package com.myhexaville.androidimagepicker.fragment_example; 2 | 3 | 4 | import android.content.Intent; 5 | import android.databinding.DataBindingUtil; 6 | import android.os.Bundle; 7 | import android.support.annotation.NonNull; 8 | import android.support.v4.app.Fragment; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | 13 | import com.myhexaville.androidimagepicker.R; 14 | import com.myhexaville.androidimagepicker.databinding.MainLayoutBinding; 15 | import com.myhexaville.smartimagepicker.ImagePicker; 16 | 17 | public class ImagePickerFragment extends Fragment { 18 | 19 | private ImagePicker imagePicker; 20 | private MainLayoutBinding binding; 21 | 22 | public ImagePickerFragment() { 23 | // Required empty public constructor 24 | } 25 | 26 | @Override 27 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 28 | Bundle savedInstanceState) { 29 | binding = DataBindingUtil.inflate(inflater, R.layout.main_layout, container, false); 30 | 31 | binding.openCamera.setOnClickListener(v -> openCamera()); 32 | binding.showAll.setOnClickListener(v -> showAll()); 33 | binding.showGallery.setOnClickListener(v -> chooseFromGallery()); 34 | 35 | return binding.getRoot(); 36 | } 37 | 38 | @Override 39 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 40 | super.onActivityResult(requestCode, resultCode, data); 41 | imagePicker.handleActivityResult(resultCode, requestCode, data); 42 | } 43 | 44 | @Override 45 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 46 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 47 | imagePicker.handlePermission(requestCode, grantResults); 48 | } 49 | 50 | public void showAll() { 51 | refreshImagePicker(); 52 | imagePicker.choosePicture(true); 53 | } 54 | 55 | public void chooseFromGallery() { 56 | refreshImagePicker(); 57 | imagePicker.choosePicture(false); 58 | } 59 | 60 | public void openCamera() { 61 | refreshImagePicker(); 62 | imagePicker.openCamera(); 63 | } 64 | 65 | private void refreshImagePicker() { 66 | imagePicker = new ImagePicker(getActivity(), 67 | this, 68 | imageUri -> { 69 | binding.image.setImageURI(imageUri); 70 | }); 71 | if (binding.withCrop.isChecked()) { 72 | imagePicker.setWithImageCrop( 73 | Integer.parseInt(binding.aspectRatioX.getText().toString()), 74 | Integer.parseInt(binding.aspectRatioY.getText().toString()) 75 | ); 76 | } 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_start.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 16 | 17 | 23 | 24 | 25 | 26 | 32 | 33 |