├── .gitignore ├── LICENSE ├── README.md ├── art ├── GooglePlay.png ├── ImagePickerSample.gif ├── linkedin.png └── twitter.png ├── build.gradle ├── config └── checkstyle │ └── checkstyle.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── mvc │ │ └── imagepicker │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── mvc │ │ │ └── imagepicker │ │ │ ├── ImagePicker.java │ │ │ ├── ImageRotator.java │ │ │ └── ImageUtils.java │ └── res │ │ ├── values │ │ └── strings.xml │ │ └── xml │ │ └── provider_paths.xml │ └── test │ └── java │ └── com │ └── mvc │ └── imagepicker │ └── ExampleUnitTest.java ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── mvc │ │ └── imagepicker │ │ └── sample │ │ ├── MainActivity.java │ │ ├── MainActivityWithFragment.java │ │ └── MainFragment.java │ └── res │ ├── layout │ ├── activity_main.xml │ ├── activity_main_with_fragment.xml │ └── fragment_main.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── script-git-version.gradle └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | 18 | # Proguard folder generated by Eclipse 19 | proguard/ 20 | 21 | # Log Files 22 | *.log 23 | 24 | # Mac rubbish 25 | .DS_Store 26 | 27 | # Key to sign 28 | *.keystore 29 | 30 | # Android Studio 31 | *.iml 32 | .gradle 33 | build/ 34 | /*/build/ 35 | # .idea/workspace.xml remove # and delete .idea if it better suit your needs. 36 | .idea 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2016 Mario Velasco Casquero 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ImagePicker [Deprecated] (Use Google API CameraX) 2 | =========== 3 | 4 | 5 | Min API 6 | 7 | 8 | Latest release 9 | 10 | 11 | ImagePicker is an Android library to easily pick an image from gallery or camera app. The users can select their prefered gallery/camera app on a unique Intent. 12 | Download the APK sample on Google Play: 13 | 14 | 15 | Add me to Linkedin 16 | 17 | 18 | 19 | Screenshots 20 | ----------- 21 | 22 | ![Sample screenshot][2] 23 | 24 | 25 | Usage 26 | ----- 27 | 28 | Add the following code to your *Activity*: 29 | 30 | ```java 31 | @Override 32 | protected void onCreate(Bundle savedInstanceState) { 33 | ... 34 | // width and height will be at least 600px long (optional). 35 | ImagePicker.setMinQuality(600, 600); 36 | } 37 | 38 | @Override 39 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 40 | Bitmap bitmap = ImagePicker.getImageFromResult(this, requestCode, resultCode, data); 41 | // TODO do something with the bitmap 42 | } 43 | 44 | public void onPickImage(View view) { 45 | // Click on image button 46 | ImagePicker.pickImage(this, "Select your image:"); 47 | } 48 | ``` 49 | 50 | 51 | Add it to your project 52 | ---------------------- 53 | 54 | Add this permission to your ``AndroidManifest``: 55 | 56 | ```xml 57 | 58 | ``` 59 | 60 | Add it in your *root* ``build.gradle`` at the end of repositories: 61 | 62 | ```groovy 63 | allprojects { 64 | repositories { 65 | // Add this line 66 | maven { url "https://jitpack.io" } 67 | } 68 | } 69 | ``` 70 | 71 | Add ``ImagePicker`` dependency to your *app* ``build.gradle`` file: 72 | 73 | ```groovy 74 | dependencies{ 75 | compile 'com.github.Mariovc:ImagePicker:x.x.x' 76 | } 77 | ``` 78 | 79 | where `x.x.x` corresponds to latest release version published in [ ![release](https://img.shields.io/github/release/Mariovc/ImagePicker.svg) ](https://github.com/Mariovc/ImagePicker/releases/latest) 80 | 81 | In order to display the `ImagePicker` and to make works correcly both gallery and camera you have add this `provider` section inside the `AndroidManifest.xml` file: 82 | ``` 83 | 84 | 87 | android:authorities="${applicationId}.provider" 88 | android:exported="false" 89 | android:grantUriPermissions="true"> 90 | 93 | 94 | ... 95 | 96 | ``` 97 | 98 | As you can see from the `android:resource="@xml/provider_paths"` line you also have to provide the `provider_paths.xml` file, that will contains these lines of code: 99 | ``` 100 | 101 | 102 | 105 | 106 | ``` 107 | 108 | 109 | Contributing 110 | -------------------------- 111 | 112 | Feel free to fork and make a pull request with your improvements. 113 | 114 | 115 | Developed By 116 | ------------ 117 | 118 | * Mario Velasco Casquero - 119 | 120 | 121 | Follow me on Twitter 122 | 123 | 124 | Add me to Linkedin 125 | 126 | 127 | License 128 | ------- 129 | 130 | Copyright 2016 Mario Velasco Casquero 131 | 132 | Licensed under the Apache License, Version 2.0 (the "License"); 133 | you may not use this file except in compliance with the License. 134 | You may obtain a copy of the License at 135 | 136 | http://www.apache.org/licenses/LICENSE-2.0 137 | 138 | Unless required by applicable law or agreed to in writing, software 139 | distributed under the License is distributed on an "AS IS" BASIS, 140 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 141 | See the License for the specific language governing permissions and 142 | limitations under the License. 143 | 144 | [1]: ./art/GooglePlay.png 145 | [2]: ./art/ImagePickerSample.gif 146 | -------------------------------------------------------------------------------- /art/GooglePlay.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mariovc/ImagePicker/0c075e65fe1a7bd97e36acb927e77117d7033f4e/art/GooglePlay.png -------------------------------------------------------------------------------- /art/ImagePickerSample.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mariovc/ImagePicker/0c075e65fe1a7bd97e36acb927e77117d7033f4e/art/ImagePickerSample.gif -------------------------------------------------------------------------------- /art/linkedin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mariovc/ImagePicker/0c075e65fe1a7bd97e36acb927e77117d7033f4e/art/linkedin.png -------------------------------------------------------------------------------- /art/twitter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mariovc/ImagePicker/0c075e65fe1a7bd97e36acb927e77117d7033f4e/art/twitter.png -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Mario Velasco Casquero 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 18 | 19 | ext { 20 | configuration = [ 21 | app_name : "ImagePicker", 22 | packageName : "com.mvc.imagepicker", 23 | compileVersion : 27, 24 | buildToolsVersion : "27.0.3", 25 | minSdk : 14, 26 | targetSdk : 27 27 | ] 28 | 29 | libraries = [ 30 | supportVersion : "27.0.2" 31 | ] 32 | } 33 | 34 | buildscript { 35 | repositories { 36 | jcenter() 37 | maven { 38 | url 'https://maven.google.com/' 39 | name 'Google' 40 | } 41 | google() 42 | } 43 | dependencies { 44 | classpath 'com.android.tools.build:gradle:3.1.4' 45 | 46 | // NOTE: Do not place your application dependencies here; they belong 47 | // in the individual module build.gradle files 48 | } 49 | } 50 | 51 | allprojects { 52 | repositories { 53 | jcenter() 54 | maven { 55 | url 'https://maven.google.com/' 56 | name 'Google' 57 | } 58 | } 59 | 60 | task checkstyle(type: Checkstyle) { 61 | showViolations = true 62 | configFile file("../config/checkstyle/checkstyle.xml") 63 | 64 | source 'src/main/java' 65 | include '**/*.java' 66 | exclude '**/gen/**' 67 | exclude '**/R.java' 68 | exclude '**/BuildConfig.java' 69 | 70 | // empty classpath 71 | classpath = files() 72 | } 73 | } 74 | 75 | task clean(type: Delete) { 76 | delete rootProject.buildDir 77 | } 78 | -------------------------------------------------------------------------------- /config/checkstyle/checkstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 20 | 21 | 22 | 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 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2016 Mario Velasco Casquero 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # 16 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mariovc/ImagePicker/0c075e65fe1a7bd97e36acb927e77117d7033f4e/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Sep 12 10:41:39 CEST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /library/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /library/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Mario Velasco Casquero 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'com.android.library' 18 | apply plugin: 'checkstyle' 19 | apply from: "$project.rootDir/script-git-version.gradle" 20 | 21 | preBuild.dependsOn('checkstyle') 22 | assemble.dependsOn('lint') 23 | check.dependsOn('checkstyle') 24 | 25 | def config = rootProject.ext.configuration; 26 | def libs = rootProject.ext.libraries; 27 | 28 | android { 29 | compileSdkVersion config.compileVersion 30 | buildToolsVersion config.buildToolsVersion 31 | 32 | defaultConfig { 33 | minSdkVersion config.minSdk 34 | targetSdkVersion config.targetSdk 35 | versionCode gitVersionCode 36 | versionName gitVersionName 37 | } 38 | 39 | buildTypes { 40 | release { 41 | minifyEnabled false 42 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 43 | } 44 | } 45 | } 46 | 47 | dependencies { 48 | compile fileTree(dir: 'libs', include: ['*.jar']) 49 | testCompile 'junit:junit:4.12' 50 | compile "com.android.support:appcompat-v7:${libs.supportVersion}" 51 | } 52 | -------------------------------------------------------------------------------- /library/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\mvc74255z\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 | -------------------------------------------------------------------------------- /library/src/androidTest/java/com/mvc/imagepicker/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Mario Velasco Casquero 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mvc.imagepicker; 18 | 19 | import android.app.Application; 20 | import android.test.ApplicationTestCase; 21 | 22 | /** 23 | * Testing Fundamentals 24 | */ 25 | public class ApplicationTest extends ApplicationTestCase { 26 | public ApplicationTest() { 27 | super(Application.class); 28 | } 29 | } -------------------------------------------------------------------------------- /library/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 19 | 20 | 23 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /library/src/main/java/com/mvc/imagepicker/ImagePicker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Mario Velasco Casquero 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mvc.imagepicker; 18 | 19 | import android.Manifest; 20 | import android.app.Activity; 21 | import android.content.Context; 22 | import android.content.Intent; 23 | import android.content.pm.PackageInfo; 24 | import android.content.pm.PackageManager; 25 | import android.content.pm.ResolveInfo; 26 | import android.content.res.AssetFileDescriptor; 27 | import android.graphics.Bitmap; 28 | import android.graphics.BitmapFactory; 29 | import android.net.Uri; 30 | import android.os.Parcelable; 31 | import android.provider.MediaStore; 32 | import android.support.annotation.Nullable; 33 | import android.support.v4.app.Fragment; 34 | import android.support.v4.content.ContextCompat; 35 | import android.support.v4.content.FileProvider; 36 | import android.util.Log; 37 | 38 | import java.io.File; 39 | import java.io.FileInputStream; 40 | import java.io.FileNotFoundException; 41 | import java.io.IOException; 42 | import java.io.InputStream; 43 | import java.util.ArrayList; 44 | import java.util.Arrays; 45 | import java.util.List; 46 | 47 | /** 48 | * Author: Mario Velasco Casquero 49 | * Date: 08/09/2015 50 | * Email: m3ario@gmail.com 51 | */ 52 | public final class ImagePicker { 53 | 54 | private static final int DEFAULT_REQUEST_CODE = 234; 55 | 56 | private static final int DEFAULT_MIN_WIDTH_QUALITY = 400; // min pixels 57 | private static final int DEFAULT_MIN_HEIGHT_QUALITY = 400; // min pixels 58 | private static final String TAG = ImagePicker.class.getSimpleName(); 59 | private static final String TEMP_IMAGE_NAME = "tempImage"; 60 | 61 | private static int minWidthQuality = DEFAULT_MIN_WIDTH_QUALITY; 62 | private static int minHeightQuality = DEFAULT_MIN_HEIGHT_QUALITY; 63 | 64 | private static String mChooserTitle; 65 | private static int mPickImageRequestCode = DEFAULT_REQUEST_CODE; 66 | private static boolean mGalleryOnly = false; 67 | 68 | private ImagePicker() { 69 | // not called 70 | } 71 | 72 | /** 73 | * Launch a dialog to pick an image from camera/gallery apps with custom request code. 74 | * 75 | * @param activity which will launch the dialog. 76 | * @param requestCode request code that will be returned in result. 77 | */ 78 | public static void pickImage(Activity activity, int requestCode) { 79 | pickImage(activity, activity.getString(R.string.pick_image_intent_text), requestCode, false); 80 | } 81 | 82 | /** 83 | * Launch a dialog to pick an image from camera/gallery apps with custom request code. 84 | * 85 | * @param activity which will launch the dialog. 86 | */ 87 | public static void pickImage(Activity activity) { 88 | pickImage(activity, activity.getString(R.string.pick_image_intent_text), DEFAULT_REQUEST_CODE, false); 89 | } 90 | 91 | /** 92 | * Launch a dialog to pick an image from camera/gallery apps with custom request code. 93 | * 94 | * @param fragment which will launch the dialog. 95 | * @param requestCode request code that will be returned in result. 96 | */ 97 | public static void pickImage(Fragment fragment, int requestCode) { 98 | pickImage(fragment, fragment.getString(R.string.pick_image_intent_text), requestCode, false); 99 | } 100 | 101 | /** 102 | * Launch a dialog to pick an image from camera/gallery apps with custom request code. 103 | * 104 | * @param fragment which will launch the dialog. 105 | */ 106 | public static void pickImage(Fragment fragment) { 107 | pickImage(fragment, fragment.getString(R.string.pick_image_intent_text), DEFAULT_REQUEST_CODE, false); 108 | } 109 | 110 | /** 111 | * Launch a dialog to pick an image from gallery apps only with custom request code. 112 | * 113 | * @param activity which will launch the dialog. 114 | * @param requestCode request code that will be returned in result. 115 | */ 116 | public static void pickImageGalleryOnly(Activity activity, int requestCode) { 117 | pickImage(activity, activity.getString(R.string.pick_image_intent_text), requestCode, true); 118 | 119 | } 120 | 121 | /** 122 | * Launch a dialog to pick an image from gallery apps only with custom request code. 123 | * 124 | * @param fragment which will launch the dialog. 125 | * @param requestCode request code that will be returned in result. 126 | */ 127 | public static void pickImageGalleryOnly(Fragment fragment, int requestCode) { 128 | pickImage(fragment, fragment.getString(R.string.pick_image_intent_text), requestCode, true); 129 | } 130 | 131 | /** 132 | * Launch a dialog to pick an image from camera/gallery apps. 133 | * 134 | * @param activity which will launch the dialog. 135 | * @param chooserTitle will appear on the picker dialog. 136 | */ 137 | public static void pickImage(Activity activity, String chooserTitle) { 138 | pickImage(activity, chooserTitle, DEFAULT_REQUEST_CODE, false); 139 | } 140 | 141 | /** 142 | * Launch a dialog to pick an image from camera/gallery apps. 143 | * 144 | * @param fragment which will launch the dialog and will get the result in 145 | * onActivityResult() 146 | * @param chooserTitle will appear on the picker dialog. 147 | */ 148 | public static void pickImage(Fragment fragment, String chooserTitle) { 149 | pickImage(fragment, chooserTitle, DEFAULT_REQUEST_CODE, false); 150 | } 151 | 152 | /** 153 | * Launch a dialog to pick an image from camera/gallery apps. 154 | * 155 | * @param fragment which will launch the dialog and will get the result in 156 | * onActivityResult() 157 | * @param chooserTitle will appear on the picker dialog. 158 | * @param requestCode request code that will be returned in result. 159 | */ 160 | public static void pickImage(Fragment fragment, String chooserTitle, 161 | int requestCode, boolean galleryOnly) { 162 | mGalleryOnly = galleryOnly; 163 | mPickImageRequestCode = requestCode; 164 | mChooserTitle = chooserTitle; 165 | startChooser(fragment); 166 | } 167 | 168 | /** 169 | * Launch a dialog to pick an image from camera/gallery apps. 170 | * 171 | * @param activity which will launch the dialog and will get the result in 172 | * onActivityResult() 173 | * @param chooserTitle will appear on the picker dialog. 174 | */ 175 | public static void pickImage(Activity activity, String chooserTitle, 176 | int requestCode, boolean galleryOnly) { 177 | mGalleryOnly = galleryOnly; 178 | mPickImageRequestCode = requestCode; 179 | mChooserTitle = chooserTitle; 180 | startChooser(activity); 181 | } 182 | 183 | private static void startChooser(Fragment fragmentContext) { 184 | Intent chooseImageIntent = getPickImageIntent(fragmentContext.getContext(), mChooserTitle); 185 | fragmentContext.startActivityForResult(chooseImageIntent, mPickImageRequestCode); 186 | } 187 | 188 | private static void startChooser(Activity activityContext) { 189 | Intent chooseImageIntent = getPickImageIntent(activityContext, mChooserTitle); 190 | activityContext.startActivityForResult(chooseImageIntent, mPickImageRequestCode); 191 | } 192 | 193 | /** 194 | * Get an Intent which will launch a dialog to pick an image from camera/gallery apps. 195 | * 196 | * @param context context. 197 | * @param chooserTitle will appear on the picker dialog. 198 | * @return intent launcher. 199 | */ 200 | public static Intent getPickImageIntent(Context context, String chooserTitle) { 201 | Intent chooserIntent = null; 202 | List intentList = new ArrayList<>(); 203 | 204 | Intent pickIntent = new Intent(Intent.ACTION_PICK, 205 | android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); 206 | intentList = addIntentsToList(context, intentList, pickIntent); 207 | 208 | // Check if we want gallery apps only 209 | if (!mGalleryOnly) { 210 | // Camera action will fail if the app does not have permission, check before adding intent. 211 | // We only need to add the camera intent if the app does not use the CAMERA permission 212 | // in the androidmanifest.xml 213 | // Or if the user has granted access to the camera. 214 | // See https://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE 215 | if (!appManifestContainsPermission(context, Manifest.permission.CAMERA) || hasCameraAccess(context)) { 216 | Intent takePhotoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 217 | takePhotoIntent.putExtra("return-data", true); 218 | takePhotoIntent.putExtra(MediaStore.EXTRA_OUTPUT, 219 | FileProvider.getUriForFile(context, context.getApplicationInfo().packageName + ".provider", 220 | ImageUtils.getTemporalFile(context, String.valueOf(mPickImageRequestCode)))); 221 | //Uri.fromFile(ImageUtils.getTemporalFile(context, String.valueOf(mPickImageRequestCode)))); 222 | intentList = addIntentsToList(context, intentList, takePhotoIntent); 223 | } 224 | } 225 | 226 | if (intentList.size() > 0) { 227 | chooserIntent = Intent.createChooser(intentList.remove(intentList.size() - 1), 228 | chooserTitle); 229 | chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, 230 | intentList.toArray(new Parcelable[intentList.size()])); 231 | } 232 | 233 | return chooserIntent; 234 | } 235 | 236 | private static List addIntentsToList(Context context, List list, Intent intent) { 237 | Log.i(TAG, "Adding intents of type: " + intent.getAction()); 238 | List resInfo = context.getPackageManager().queryIntentActivities(intent, 0); 239 | for (ResolveInfo resolveInfo : resInfo) { 240 | String packageName = resolveInfo.activityInfo.packageName; 241 | Intent targetedIntent = new Intent(intent); 242 | targetedIntent.setPackage(packageName); 243 | list.add(targetedIntent); 244 | Log.i(TAG, "App package: " + packageName); 245 | } 246 | return list; 247 | } 248 | 249 | /** 250 | * Checks if the current context has permission to access the camera. 251 | * @param context context. 252 | */ 253 | private static boolean hasCameraAccess(Context context) { 254 | return ContextCompat.checkSelfPermission(context, 255 | Manifest.permission.CAMERA) == PackageManager.PERMISSION_GRANTED; 256 | } 257 | 258 | /** 259 | * Checks if the androidmanifest.xml contains the given permission. 260 | * @param context context. 261 | * @return Boolean, indicating if the permission is present. 262 | */ 263 | private static boolean appManifestContainsPermission(Context context, String permission) { 264 | PackageManager pm = context.getPackageManager(); 265 | try { 266 | PackageInfo packageInfo = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS); 267 | String[] requestedPermissions = null; 268 | if (packageInfo != null) { 269 | requestedPermissions = packageInfo.requestedPermissions; 270 | } 271 | if (requestedPermissions == null) { 272 | return false; 273 | } 274 | 275 | if (requestedPermissions.length > 0) { 276 | List requestedPermissionsList = Arrays.asList(requestedPermissions); 277 | return requestedPermissionsList.contains(permission); 278 | } 279 | } catch (PackageManager.NameNotFoundException e) { 280 | e.printStackTrace(); 281 | } 282 | return false; 283 | } 284 | 285 | /** 286 | * Called after launching the picker with the same values of Activity.getImageFromResult 287 | * in order to resolve the result and get the image. 288 | * 289 | * @param context context. 290 | * @param requestCode used to identify the pick image action. 291 | * @param resultCode -1 means the result is OK. 292 | * @param imageReturnedIntent returned intent where is the image data. 293 | * @return image. 294 | */ 295 | @Nullable 296 | public static Bitmap getImageFromResult(Context context, int requestCode, int resultCode, 297 | Intent imageReturnedIntent) { 298 | Log.i(TAG, "getImageFromResult() called with: " + "resultCode = [" + resultCode + "]"); 299 | Bitmap bm = null; 300 | if (resultCode == Activity.RESULT_OK && requestCode == mPickImageRequestCode) { 301 | File imageFile = ImageUtils.getTemporalFile(context, String.valueOf(mPickImageRequestCode)); 302 | Uri selectedImage; 303 | boolean isCamera = (imageReturnedIntent == null 304 | || imageReturnedIntent.getData() == null 305 | || imageReturnedIntent.getData().toString().contains(imageFile.toString())); 306 | if (isCamera) { /** CAMERA **/ 307 | //selectedImage = Uri.fromFile(imageFile); 308 | selectedImage = FileProvider.getUriForFile(context, 309 | context.getApplicationInfo().packageName + ".provider", imageFile); 310 | 311 | 312 | } else { /** ALBUM **/ 313 | selectedImage = imageReturnedIntent.getData(); 314 | } 315 | Log.i(TAG, "selectedImage: " + selectedImage); 316 | 317 | bm = decodeBitmap(context, selectedImage); 318 | int rotation = ImageRotator.getRotation(context, selectedImage, isCamera); 319 | bm = ImageRotator.rotate(bm, rotation); 320 | } 321 | return bm; 322 | } 323 | 324 | /** 325 | * Called after launching the picker with the same values of Activity.getImageFromResult 326 | * in order to resolve the result and get the image path. 327 | * 328 | * @param context context. 329 | * @param requestCode used to identify the pick image action. 330 | * @param resultCode -1 means the result is OK. 331 | * @param imageReturnedIntent returned intent where is the image data. 332 | * @return path to the saved image. 333 | */ 334 | @Nullable 335 | public static String getImagePathFromResult(Context context, int requestCode, int resultCode, 336 | Intent imageReturnedIntent) { 337 | Log.i(TAG, "getImagePathFromResult() called with: " + "resultCode = [" + resultCode + "]"); 338 | Uri selectedImage = null; 339 | if (resultCode == Activity.RESULT_OK && requestCode == mPickImageRequestCode) { 340 | File imageFile = ImageUtils.getTemporalFile(context, String.valueOf(mPickImageRequestCode)); 341 | boolean isCamera = (imageReturnedIntent == null 342 | || imageReturnedIntent.getData() == null 343 | || imageReturnedIntent.getData().toString().contains(imageFile.toString())); 344 | if (isCamera) { 345 | return imageFile.getAbsolutePath(); 346 | } else { 347 | selectedImage = imageReturnedIntent.getData(); 348 | } 349 | Log.i(TAG, "selectedImage: " + selectedImage); 350 | } 351 | if (selectedImage == null) { 352 | return null; 353 | } 354 | return getFilePathFromUri(context, selectedImage); 355 | } 356 | 357 | /** 358 | * Get stream, save the picture to the temp file and return path. 359 | * 360 | * @param context context 361 | * @param uri uri of the incoming file 362 | * @return path to the saved image. 363 | */ 364 | private static String getFilePathFromUri(Context context, Uri uri) { 365 | InputStream is = null; 366 | if (uri.getAuthority() != null) { 367 | try { 368 | is = context.getContentResolver().openInputStream(uri); 369 | Bitmap bmp = BitmapFactory.decodeStream(is); 370 | return ImageUtils.savePicture(context, bmp, String.valueOf(uri.getPath().hashCode())); 371 | } catch (FileNotFoundException e) { 372 | e.printStackTrace(); 373 | } finally { 374 | try { 375 | is.close(); 376 | } catch (IOException e) { 377 | e.printStackTrace(); 378 | } 379 | } 380 | } 381 | return null; 382 | } 383 | 384 | /** 385 | * Called after launching the picker with the same values of Activity.getImageFromResult 386 | * in order to resolve the result and get the input stream for the image. 387 | * 388 | * @param context context. 389 | * @param requestCode used to identify the pick image action. 390 | * @param resultCode -1 means the result is OK. 391 | * @param imageReturnedIntent returned intent where is the image data. 392 | * @return stream. 393 | */ 394 | public static InputStream getInputStreamFromResult(Context context, int requestCode, int resultCode, 395 | Intent imageReturnedIntent) { 396 | Log.i(TAG, "getFileFromResult() called with: " + "resultCode = [" + resultCode + "]"); 397 | if (resultCode == Activity.RESULT_OK && requestCode == mPickImageRequestCode) { 398 | File imageFile = ImageUtils.getTemporalFile(context, String.valueOf(mPickImageRequestCode)); 399 | Uri selectedImage; 400 | boolean isCamera = (imageReturnedIntent == null 401 | || imageReturnedIntent.getData() == null 402 | || imageReturnedIntent.getData().toString().contains(imageFile.toString())); 403 | if (isCamera) { /** CAMERA **/ 404 | //selectedImage = Uri.fromFile(imageFile); 405 | selectedImage = FileProvider.getUriForFile(context, 406 | context.getApplicationInfo().packageName + ".provider", imageFile); 407 | } else { /** ALBUM **/ 408 | selectedImage = imageReturnedIntent.getData(); 409 | } 410 | Log.i(TAG, "selectedImage: " + selectedImage); 411 | 412 | try { 413 | if (isCamera) { 414 | // We can just open the temporary file stream and return it 415 | return new FileInputStream(imageFile); 416 | } else { 417 | // Otherwise use the ContentResolver 418 | return context.getContentResolver().openInputStream(selectedImage); 419 | } 420 | } catch (FileNotFoundException ex) { 421 | Log.e(TAG, "Could not open input stream for: " + selectedImage); 422 | return null; 423 | } 424 | } 425 | return null; 426 | } 427 | 428 | /** 429 | * Loads a bitmap and avoids using too much memory loading big images (e.g.: 2560*1920) 430 | */ 431 | private static Bitmap decodeBitmap(Context context, Uri theUri) { 432 | Bitmap outputBitmap = null; 433 | AssetFileDescriptor fileDescriptor = null; 434 | 435 | try { 436 | fileDescriptor = context.getContentResolver().openAssetFileDescriptor(theUri, "r"); 437 | 438 | // Get size of bitmap file 439 | BitmapFactory.Options boundsOptions = new BitmapFactory.Options(); 440 | boundsOptions.inJustDecodeBounds = true; 441 | BitmapFactory.decodeFileDescriptor(fileDescriptor.getFileDescriptor(), null, boundsOptions); 442 | 443 | // Get desired sample size. Note that these must be powers-of-two. 444 | int[] sampleSizes = new int[]{8, 4, 2, 1}; 445 | int selectedSampleSize = 1; // 1 by default (original image) 446 | 447 | for (int sampleSize : sampleSizes) { 448 | selectedSampleSize = sampleSize; 449 | int targetWidth = boundsOptions.outWidth / sampleSize; 450 | int targetHeight = boundsOptions.outHeight / sampleSize; 451 | if (targetWidth >= minWidthQuality && targetHeight >= minHeightQuality) { 452 | break; 453 | } 454 | } 455 | 456 | // Decode bitmap at desired size 457 | BitmapFactory.Options decodeOptions = new BitmapFactory.Options(); 458 | decodeOptions.inSampleSize = selectedSampleSize; 459 | outputBitmap = BitmapFactory.decodeFileDescriptor(fileDescriptor.getFileDescriptor(), null, decodeOptions); 460 | if (outputBitmap != null) { 461 | Log.i(TAG, "Loaded image with sample size " + decodeOptions.inSampleSize + "\t\t" 462 | + "Bitmap width: " + outputBitmap.getWidth() 463 | + "\theight: " + outputBitmap.getHeight()); 464 | } 465 | fileDescriptor.close(); 466 | } catch (FileNotFoundException e) { 467 | e.printStackTrace(); 468 | } catch (IOException e) { 469 | e.printStackTrace(); 470 | } 471 | 472 | return outputBitmap; 473 | } 474 | 475 | 476 | /* 477 | GETTERS AND SETTERS 478 | */ 479 | 480 | public static void setMinQuality(int minWidthQuality, int minHeightQuality) { 481 | ImagePicker.minWidthQuality = minWidthQuality; 482 | ImagePicker.minHeightQuality = minHeightQuality; 483 | } 484 | } 485 | -------------------------------------------------------------------------------- /library/src/main/java/com/mvc/imagepicker/ImageRotator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Mario Velasco Casquero 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mvc.imagepicker; 18 | 19 | import android.content.Context; 20 | import android.database.Cursor; 21 | import android.graphics.Bitmap; 22 | import android.graphics.Matrix; 23 | import android.net.Uri; 24 | import android.provider.MediaStore; 25 | import android.util.Log; 26 | 27 | import java.io.InputStream; 28 | 29 | import android.media.ExifInterface; 30 | 31 | 32 | /** 33 | * Author: Mario Velasco Casquero 34 | * Date: 21/07/2016 35 | */ 36 | public final class ImageRotator { 37 | 38 | private static final String TAG = ImageRotator.class.getSimpleName(); 39 | 40 | 41 | private ImageRotator() { 42 | // not called 43 | } 44 | 45 | /** 46 | * Get rotation degrees of the selected image. E.g.: 0º, 90º, 180º, 240º. 47 | * 48 | * @param context context. 49 | * @param imageUri URI of image which will be analyzed. 50 | * @param fromCamera true if the image was taken from camera, 51 | * false if it was selected from the gallery. 52 | * @return degrees of rotation. 53 | */ 54 | public static int getRotation(Context context, Uri imageUri, boolean fromCamera) { 55 | int rotation; 56 | if (fromCamera) { 57 | rotation = getRotationFromCamera(context, imageUri); 58 | } else { 59 | rotation = getRotationFromGallery(context, imageUri); 60 | } 61 | Log.i(TAG, "Image rotation: " + rotation); 62 | return rotation; 63 | } 64 | 65 | private static int getRotationFromCamera(Context context, Uri imageFile) { 66 | int rotate = 0; 67 | try { 68 | 69 | ExifInterface exif = null; 70 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { 71 | context.getContentResolver().notifyChange(imageFile, null); 72 | InputStream inputStream = context.getContentResolver().openInputStream(imageFile); 73 | exif = new ExifInterface(inputStream); 74 | } else { 75 | exif = new ExifInterface(imageFile.getPath()); 76 | } 77 | int orientation = exif.getAttributeInt( 78 | ExifInterface.TAG_ORIENTATION, 79 | ExifInterface.ORIENTATION_NORMAL); 80 | 81 | switch (orientation) { 82 | case ExifInterface.ORIENTATION_ROTATE_270: 83 | rotate = 270; 84 | break; 85 | case ExifInterface.ORIENTATION_ROTATE_180: 86 | rotate = 180; 87 | break; 88 | case ExifInterface.ORIENTATION_ROTATE_90: 89 | rotate = 90; 90 | break; 91 | default: 92 | rotate = 0; 93 | break; 94 | } 95 | } catch (Exception e) { 96 | e.printStackTrace(); 97 | } 98 | return rotate; 99 | } 100 | 101 | private static int getRotationFromGallery(Context context, Uri imageUri) { 102 | int result = 0; 103 | String[] columns = {MediaStore.Images.Media.ORIENTATION}; 104 | Cursor cursor = null; 105 | try { 106 | cursor = context.getContentResolver().query(imageUri, columns, null, null, null); 107 | if (cursor != null && cursor.moveToFirst()) { 108 | int orientationColumnIndex = cursor.getColumnIndex(columns[0]); 109 | result = cursor.getInt(orientationColumnIndex); 110 | } 111 | } catch (Exception e) { 112 | //Do nothing 113 | } finally { 114 | if (cursor != null) { 115 | cursor.close(); 116 | } 117 | } //End of try-catch block 118 | return result; 119 | } 120 | 121 | /** 122 | * Rotate image X degrees. 123 | */ 124 | public static Bitmap rotate(Bitmap bitmap, int degrees) { 125 | if (bitmap != null && degrees != 0) { 126 | Matrix matrix = new Matrix(); 127 | matrix.postRotate(degrees); 128 | bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); 129 | } 130 | return bitmap; 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /library/src/main/java/com/mvc/imagepicker/ImageUtils.java: -------------------------------------------------------------------------------- 1 | package com.mvc.imagepicker; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | 6 | import java.io.File; 7 | import java.io.FileOutputStream; 8 | import java.io.IOException; 9 | 10 | /** 11 | * Created by Anatol on 11/12/2016. 12 | */ 13 | 14 | public final class ImageUtils { 15 | 16 | private static final String BASE_IMAGE_NAME = "i_prefix_"; 17 | 18 | private ImageUtils() { 19 | } 20 | 21 | public static String savePicture(Context context, Bitmap bitmap, String imageSuffix) { 22 | File savedImage = getTemporalFile(context, imageSuffix + ".jpeg"); 23 | FileOutputStream fos = null; 24 | if (savedImage.exists()) { 25 | savedImage.delete(); 26 | } 27 | try { 28 | fos = new FileOutputStream(savedImage.getPath()); 29 | bitmap.compress(Bitmap.CompressFormat.JPEG, 80, fos); 30 | } catch (java.io.IOException e) { 31 | e.printStackTrace(); 32 | } finally { 33 | if (!bitmap.isRecycled()) { 34 | bitmap.recycle(); 35 | } 36 | if (fos != null) { 37 | try { 38 | fos.close(); 39 | } catch (IOException e) { 40 | e.printStackTrace(); 41 | } 42 | } 43 | } 44 | 45 | return savedImage.getAbsolutePath(); 46 | } 47 | 48 | public static File getTemporalFile(Context context, String payload) { 49 | return new File(context.getExternalCacheDir(), BASE_IMAGE_NAME + payload); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /library/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | ImagePicker 19 | Choose an image 20 | 21 | -------------------------------------------------------------------------------- /library/src/main/res/xml/provider_paths.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /library/src/test/java/com/mvc/imagepicker/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Mario Velasco Casquero 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mvc.imagepicker; 18 | 19 | import org.junit.Test; 20 | 21 | import static org.junit.Assert.*; 22 | 23 | /** 24 | * To work on unit tests, switch the Test Artifact in the Build Variants view. 25 | */ 26 | public class ExampleUnitTest { 27 | @Test 28 | public void addition_isCorrect() throws Exception { 29 | assertEquals(4, 2 + 2); 30 | } 31 | } -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Mario Velasco Casquero 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | apply plugin: 'com.android.application' 18 | apply plugin: 'checkstyle' 19 | apply from: "$project.rootDir/script-git-version.gradle" 20 | 21 | preBuild.dependsOn('checkstyle') 22 | assemble.dependsOn('lint') 23 | check.dependsOn('checkstyle') 24 | 25 | def config = rootProject.ext.configuration; 26 | def libs = rootProject.ext.libraries; 27 | 28 | android { 29 | compileSdkVersion config.compileVersion 30 | buildToolsVersion config.buildToolsVersion 31 | 32 | defaultConfig { 33 | applicationId config.packageName 34 | minSdkVersion config.minSdk 35 | targetSdkVersion config.targetSdk 36 | versionCode gitVersionCode 37 | versionName gitVersionName 38 | } 39 | 40 | buildTypes { 41 | debug { 42 | applicationVariants.all { variant -> 43 | if (variant.buildType.name == 'debug') { 44 | variant.mergedFlavor.versionName = gitVersionNameFull; 45 | } 46 | } 47 | } 48 | release { 49 | minifyEnabled false 50 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 51 | applicationVariants.all { variant -> 52 | variant.outputs.all { output -> 53 | def date = new Date().format("yyyy-MM-dd___(HH.mm.ss)") 54 | outputFileName = outputFileName.replace("release", String.format("v%d(%s)___%s", 55 | defaultConfig.versionCode, defaultConfig.versionName, date)) 56 | } 57 | } 58 | } 59 | } 60 | } 61 | 62 | dependencies { 63 | compile fileTree(dir: 'libs', include: ['*.jar']) 64 | testCompile 'junit:junit:4.12' 65 | compile 'com.squareup.picasso:picasso:2.5.2' 66 | compile "com.android.support:appcompat-v7:${libs.supportVersion}" 67 | compile project(':library') 68 | } 69 | -------------------------------------------------------------------------------- /sample/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\mvc74255z\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 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 19 | 20 | 21 | 22 | 28 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /sample/src/main/java/com/mvc/imagepicker/sample/MainActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Mario Velasco Casquero 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mvc.imagepicker.sample; 18 | 19 | import android.content.Intent; 20 | import android.graphics.Bitmap; 21 | import android.os.Bundle; 22 | import android.support.v7.app.AppCompatActivity; 23 | import android.view.View; 24 | import android.widget.ImageView; 25 | import android.widget.TextView; 26 | 27 | import com.mvc.imagepicker.ImagePicker; 28 | 29 | import java.io.IOException; 30 | import java.io.InputStream; 31 | 32 | public class MainActivity extends AppCompatActivity { 33 | 34 | private ImageView imageView; 35 | private TextView textView; 36 | 37 | @Override 38 | protected void onCreate(Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | setContentView(R.layout.activity_main); 41 | imageView = (ImageView) findViewById(R.id.image_view); 42 | textView = (TextView) findViewById(R.id.image_stream_indicator); 43 | // width and height will be at least 600px long (optional). 44 | ImagePicker.setMinQuality(600, 600); 45 | } 46 | 47 | @Override 48 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 49 | Bitmap bitmap = ImagePicker.getImageFromResult(this, requestCode, resultCode, data); 50 | if (bitmap != null) { 51 | imageView.setImageBitmap(bitmap); 52 | } 53 | InputStream is = ImagePicker.getInputStreamFromResult(this, requestCode, resultCode, data); 54 | if (is != null) { 55 | textView.setText("Got input stream!"); 56 | try { 57 | is.close(); 58 | } catch (IOException ex) { 59 | // ignore 60 | } 61 | } else { 62 | textView.setText("Failed to get input stream!"); 63 | } 64 | super.onActivityResult(requestCode, resultCode, data); 65 | } 66 | 67 | public void onPickImage(View view) { 68 | ImagePicker.pickImage(this, "Select your image:"); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /sample/src/main/java/com/mvc/imagepicker/sample/MainActivityWithFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Mario Velasco Casquero 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mvc.imagepicker.sample; 18 | 19 | import android.os.Bundle; 20 | import android.support.v7.app.AppCompatActivity; 21 | 22 | public class MainActivityWithFragment extends AppCompatActivity { 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_main_with_fragment); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sample/src/main/java/com/mvc/imagepicker/sample/MainFragment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Mario Velasco Casquero 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.mvc.imagepicker.sample; 18 | 19 | import android.content.Intent; 20 | import android.content.SharedPreferences; 21 | import android.graphics.Bitmap; 22 | import android.os.Bundle; 23 | import android.preference.PreferenceManager; 24 | import android.support.annotation.Nullable; 25 | import android.support.v4.app.Fragment; 26 | import android.view.LayoutInflater; 27 | import android.view.View; 28 | import android.view.ViewGroup; 29 | import android.widget.ImageView; 30 | import android.widget.TextView; 31 | 32 | import com.mvc.imagepicker.ImagePicker; 33 | import com.squareup.picasso.Picasso; 34 | 35 | import java.io.File; 36 | import java.io.IOException; 37 | import java.io.InputStream; 38 | 39 | /** 40 | * Author: Mario Velasco Casquero 41 | * Date: 21/03/2017 42 | */ 43 | 44 | public class MainFragment extends Fragment { 45 | 46 | public static final String CACHED_IMG_KEY = "img_key"; 47 | 48 | public static final int SECOND_PIC_REQ = 1313; 49 | public static final int GALLERY_ONLY_REQ = 1212; 50 | 51 | private ImageView imageView1; 52 | private ImageView imageView2; 53 | private ImageView imageViewGalleryOnly; 54 | private TextView textView; 55 | 56 | 57 | @Override 58 | public void onCreate(@Nullable Bundle savedInstanceState) { 59 | super.onCreate(savedInstanceState); 60 | // width and height will be at least 600px long (optional). 61 | ImagePicker.setMinQuality(600, 600); 62 | } 63 | 64 | @Override 65 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 66 | View v = inflater.inflate(R.layout.fragment_main, container, false); 67 | imageView1 = (ImageView) v.findViewById(R.id.image_view_1); 68 | imageView2 = (ImageView) v.findViewById(R.id.image_view_2); 69 | imageViewGalleryOnly = (ImageView) v.findViewById(R.id.image_view_gallery_only); 70 | textView = (TextView) v.findViewById(R.id.image_stream_indicator); 71 | imageView1.setOnClickListener(new View.OnClickListener() { 72 | @Override 73 | public void onClick(View v) { 74 | ImagePicker.pickImage(MainFragment.this, "Select your image:"); 75 | } 76 | }); 77 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); 78 | String path = prefs.getString(CACHED_IMG_KEY, ""); 79 | File cached = new File(path); 80 | if (cached.exists()) { 81 | Picasso.with(getActivity()).load(cached).into(imageView2); 82 | } 83 | imageView2.setOnClickListener(new View.OnClickListener() { 84 | @Override 85 | public void onClick(View v) { 86 | ImagePicker.pickImage(MainFragment.this, SECOND_PIC_REQ); 87 | } 88 | }); 89 | imageViewGalleryOnly.setOnClickListener(new View.OnClickListener() { 90 | @Override 91 | public void onClick(View v) { 92 | ImagePicker.pickImageGalleryOnly(MainFragment.this, GALLERY_ONLY_REQ); 93 | } 94 | }); 95 | return v; 96 | } 97 | 98 | @Override 99 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 100 | 101 | switch (requestCode) { 102 | case SECOND_PIC_REQ: 103 | String imagePathFromResult = ImagePicker.getImagePathFromResult(getActivity(), 104 | requestCode, resultCode, data); 105 | if (imagePathFromResult != null) { 106 | String path = "file:///" + imagePathFromResult; 107 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); 108 | prefs.edit().putString(CACHED_IMG_KEY, imagePathFromResult).apply(); 109 | Picasso.with(getActivity()).load(path).into(imageView2); 110 | } 111 | break; 112 | case GALLERY_ONLY_REQ: 113 | String pathFromGallery = "file:///" + ImagePicker.getImagePathFromResult(getActivity(), requestCode, 114 | resultCode, data); 115 | Picasso.with(getActivity()).load(pathFromGallery).into(imageViewGalleryOnly); 116 | break; 117 | default: 118 | Bitmap bitmap = ImagePicker.getImageFromResult(getActivity(), requestCode, resultCode, data); 119 | if (bitmap != null) { 120 | imageView1.setImageBitmap(bitmap); 121 | } 122 | } 123 | InputStream is = ImagePicker.getInputStreamFromResult(getActivity(), requestCode, resultCode, data); 124 | if (is != null) { 125 | textView.setText("Got input stream!"); 126 | try { 127 | is.close(); 128 | } catch (IOException ex) { 129 | // ignore 130 | } 131 | } else { 132 | textView.setText("Failed to get input stream!"); 133 | } 134 | super.onActivityResult(requestCode, resultCode, data); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 26 | 27 | 32 | 33 | 40 | 41 | 46 | 47 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main_with_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 23 | 24 | 29 | 30 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/fragment_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 26 | 27 | 32 | 33 | 39 | 40 | 46 | 47 | 53 | 54 | 59 | 60 | -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mariovc/ImagePicker/0c075e65fe1a7bd97e36acb927e77117d7033f4e/sample/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mariovc/ImagePicker/0c075e65fe1a7bd97e36acb927e77117d7033f4e/sample/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mariovc/ImagePicker/0c075e65fe1a7bd97e36acb927e77117d7033f4e/sample/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mariovc/ImagePicker/0c075e65fe1a7bd97e36acb927e77117d7033f4e/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mariovc/ImagePicker/0c075e65fe1a7bd97e36acb927e77117d7033f4e/sample/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /sample/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | #3F51B5 20 | #303F9F 21 | #FF4081 22 | 23 | -------------------------------------------------------------------------------- /sample/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 8dp 20 | 8dp 21 | -------------------------------------------------------------------------------- /sample/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | ImagePicker 19 | Click on the image to pick a new image: 20 | 21 | -------------------------------------------------------------------------------- /sample/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 16 | 17 | 18 | 19 | 20 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /script-git-version.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | jcenter() 4 | } 5 | dependencies { 6 | classpath 'org.ajoberstar:grgit:1.5.0' 7 | } 8 | } 9 | 10 | import org.ajoberstar.grgit.Grgit 11 | 12 | /** 13 | * gitVersionNameFull is the last tag name and the last commit id in the current branch 14 | * gitVersionNameFull example = 0.8.1-2fe71d2383512a8f0891e356f704377dddbe736b 15 | * 16 | * gitVersionName is the last tag name 17 | * gitVersionName example = 0.8.1 18 | * 19 | * gitVersionCode is the number of tags in the proyect 20 | * gitVersionCode example = 2 21 | */ 22 | 23 | ext { 24 | git = Grgit.open(currentDir: projectDir) 25 | gitVersionNameFull = String.format("%s-%s", git.tag.list().last().getName(), git.head().id) 26 | gitVersionName = git.tag.list().last().getName() 27 | gitVersionCode = git.tag.list().size() 28 | } 29 | 30 | task printVersion() { 31 | println("Version Name: $gitVersionNameFull") 32 | println("Version Name: $gitVersionName") 33 | println("Version Code: $gitVersionCode") 34 | } -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Mario Velasco Casquero 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | include ':sample', ':library' 18 | --------------------------------------------------------------------------------