├── app ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ ├── dimens.xml │ │ │ │ └── styles.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-w820dp │ │ │ │ └── dimens.xml │ │ │ └── layout │ │ │ │ └── activity_file_picker.xml │ │ ├── java │ │ │ └── dk │ │ │ │ └── nodes │ │ │ │ └── filepicker │ │ │ │ ├── processors │ │ │ │ ├── UriProcessListener.java │ │ │ │ ├── IUriProcessor.java │ │ │ │ ├── GoogleMediaProcessor.java │ │ │ │ ├── GooglePhotosProcessor.java │ │ │ │ ├── GoogleDriveProcessor.java │ │ │ │ ├── UriProcessor.java │ │ │ │ ├── tasks │ │ │ │ │ ├── GetPhotosTask.java │ │ │ │ │ ├── GetFileTask.java │ │ │ │ │ └── GetGoogleDriveFileTask.java │ │ │ │ ├── GoogleDocumentsProcessor.java │ │ │ │ └── GenericContentProviderProcessor.java │ │ │ │ ├── utils │ │ │ │ └── Logger.java │ │ │ │ ├── intentHelper │ │ │ │ ├── FilePickerFileIntent.java │ │ │ │ ├── FilePickerCameraIntent.java │ │ │ │ └── FilePickerChooserIntent.java │ │ │ │ ├── permissionHelper │ │ │ │ └── FilePickerPermissionHelper.java │ │ │ │ ├── FilePickerConstants.java │ │ │ │ ├── bitmapHelper │ │ │ │ └── FilePickerBitmapHelper.java │ │ │ │ ├── uriHelper │ │ │ │ └── FilePickerUriHelper.java │ │ │ │ └── FilePickerActivity.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── dk │ │ │ └── nodes │ │ │ └── filepicker │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── dk │ │ └── nodes │ │ └── filepicker │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro ├── build.gradle └── maven-push.gradle ├── filepicker.example ├── .gitignore ├── src │ ├── main │ │ ├── res │ │ │ ├── values │ │ │ │ ├── strings.xml │ │ │ │ ├── colors.xml │ │ │ │ └── styles.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 │ │ │ └── layout │ │ │ │ └── activity_file_picker_example.xml │ │ ├── AndroidManifest.xml │ │ └── java │ │ │ └── dk │ │ │ └── nodes │ │ │ └── filepickerexample │ │ │ ├── ImgurManager.java │ │ │ └── FilePickerExampleActivity.java │ ├── test │ │ └── java │ │ │ └── dk │ │ │ └── nodes │ │ │ └── filepickerexample │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── dk │ │ └── nodes │ │ └── filepickerexample │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── .idea ├── copyright │ └── profiles_settings.xml ├── vcs.xml ├── modules.xml ├── runConfigurations.xml ├── gradle.xml ├── compiler.xml └── misc.xml ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── gradle.properties ├── gradlew.bat ├── README.md └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /filepicker.example/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app', ':filepicker.example' 2 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | filepicker 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-archive/filepicker/master/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /filepicker.example/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | filepicker.example 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-archive/filepicker/master/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-archive/filepicker/master/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-archive/filepicker/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-archive/filepicker/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-archive/filepicker/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /filepicker.example/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-archive/filepicker/master/filepicker.example/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /filepicker.example/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-archive/filepicker/master/filepicker.example/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /filepicker.example/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-archive/filepicker/master/filepicker.example/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /filepicker.example/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-archive/filepicker/master/filepicker.example/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /filepicker.example/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ml-archive/filepicker/master/filepicker.example/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | -------------------------------------------------------------------------------- /filepicker.example/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Fri Mar 03 11:12:04 CET 2017 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-3.3-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/java/dk/nodes/filepicker/processors/UriProcessListener.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker.processors; 2 | 3 | import android.content.Intent; 4 | 5 | /** 6 | * Created by bison on 31/10/17. 7 | */ 8 | 9 | public interface UriProcessListener { 10 | void onProcessingSuccess(Intent intent); 11 | void onProcessingFailure(); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/java/dk/nodes/filepicker/processors/IUriProcessor.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker.processors; 2 | 3 | import android.content.Context; 4 | import android.net.Uri; 5 | 6 | /** 7 | * Created by bison on 31/10/17. 8 | */ 9 | 10 | public interface IUriProcessor { 11 | void process(Context context, Uri uri, UriProcessListener uriProcessListener); 12 | } 13 | -------------------------------------------------------------------------------- /app/src/main/res/values-w820dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 64dp 6 | 7 | -------------------------------------------------------------------------------- /filepicker.example/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/dk/nodes/filepicker/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /filepicker.example/src/test/java/dk/nodes/filepickerexample/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepickerexample; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() throws Exception { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_file_picker.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 12 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/java/dk/nodes/filepicker/utils/Logger.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker.utils; 2 | 3 | import android.util.Log; 4 | 5 | import dk.nodes.filepicker.BuildConfig; 6 | 7 | /** 8 | * Created by bison on 31/10/17. 9 | */ 10 | 11 | public class Logger { 12 | public static void loge(String tag, String msg) 13 | { 14 | if(BuildConfig.DEBUG) 15 | { 16 | Log.e(tag, msg); 17 | } 18 | } 19 | 20 | public static void logd(String tag, String msg) 21 | { 22 | if(BuildConfig.DEBUG) 23 | { 24 | Log.d(tag, msg); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | # Files for the ART/Dalvik VM 5 | *.dex 6 | # Java class files 7 | *.class 8 | # Generated files 9 | bin/ 10 | gen/ 11 | out/ 12 | # Gradle files 13 | .gradle/ 14 | build/ 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | # Log Files 18 | *.log 19 | # Android Studio Navigation editor temp files 20 | .navigation/ 21 | # Android Studio captures folder 22 | captures/ 23 | # Intellij 24 | *.iml 25 | .idea/workspace.xml 26 | .idea/libraries 27 | projectFilesBackup/ 28 | # External native build folder generated in Android Studio 2.2 and later 29 | .externalNativeBuild 30 | # Windows thumbnail db 31 | Thumbs.db 32 | # OSX files 33 | .DS_Store 34 | #NDK 35 | obj/ -------------------------------------------------------------------------------- /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 /Users/Mario/Library/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 | -------------------------------------------------------------------------------- /filepicker.example/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 /Users/joso/sdk/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 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/java/dk/nodes/filepicker/intentHelper/FilePickerFileIntent.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker.intentHelper; 2 | 3 | import android.annotation.TargetApi; 4 | import android.content.Intent; 5 | 6 | public class FilePickerFileIntent { 7 | 8 | public static Intent fileIntent(String type) { 9 | type = null != type ? type : "image/*"; 10 | return new Intent().setAction(Intent.ACTION_GET_CONTENT).setType(type); 11 | } 12 | 13 | public static void setType(Intent intent, String type) { 14 | intent.setType(type); 15 | } 16 | 17 | @TargetApi(19) 18 | public static void setTypes(Intent intent, String[] types) { 19 | intent.setType("*/*"); 20 | intent.putExtra(Intent.EXTRA_MIME_TYPES, types); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 9 | 10 | 11 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | org.gradle.jvmargs=-Xmx1536m 13 | 14 | # When configured, Gradle will run in incubating parallel mode. 15 | # This option should only be used with decoupled projects. More details, visit 16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 17 | # org.gradle.parallel=true 18 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/dk/nodes/filepicker/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker; 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("dk.nodes.filepicker", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /filepicker.example/src/androidTest/java/dk/nodes/filepickerexample/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepickerexample; 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("dk.nodes.filepickerexample", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/java/dk/nodes/filepicker/permissionHelper/FilePickerPermissionHelper.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker.permissionHelper; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.content.pm.PackageManager; 6 | import android.support.annotation.NonNull; 7 | import android.support.v4.app.ActivityCompat; 8 | 9 | public class FilePickerPermissionHelper { 10 | 11 | public static boolean requirePermission(Context context, String... permissions) { 12 | for (String permission : permissions) { 13 | if (PackageManager.PERMISSION_DENIED == ActivityCompat.checkSelfPermission(context, permission)) { 14 | return true; 15 | } 16 | } 17 | return false; 18 | } 19 | 20 | public static void askPermission(Activity activity, int requestCode, @NonNull String... permissions) { 21 | ActivityCompat.requestPermissions(activity, permissions, requestCode); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/dk/nodes/filepicker/intentHelper/FilePickerCameraIntent.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker.intentHelper; 2 | 3 | import android.app.Activity; 4 | import android.content.ContentValues; 5 | import android.content.Intent; 6 | import android.net.Uri; 7 | import android.provider.MediaStore; 8 | import android.support.annotation.NonNull; 9 | 10 | public class FilePickerCameraIntent { 11 | public static Intent cameraIntent(@NonNull Uri uri) { 12 | return new Intent(MediaStore.ACTION_IMAGE_CAPTURE) 13 | .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION) 14 | .putExtra(MediaStore.EXTRA_OUTPUT, uri); 15 | } 16 | 17 | public static Uri setUri(@NonNull Activity activity) { 18 | ContentValues contentValues = new ContentValues(1); 19 | contentValues.put(MediaStore.Images.Media.MIME_TYPE, "image/jpg"); 20 | return activity.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, contentValues); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /filepicker.example/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 9 | 10 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /filepicker.example/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion "25.0.2" 6 | 7 | defaultConfig { 8 | applicationId "dk.nodes.filepickerexample" 9 | minSdkVersion 16 10 | targetSdkVersion 25 11 | versionCode 1 12 | versionName "1.0" 13 | 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | 16 | } 17 | buildTypes { 18 | release { 19 | minifyEnabled false 20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 21 | } 22 | } 23 | } 24 | 25 | dependencies { 26 | compile project(':app') 27 | compile fileTree(dir: 'libs', include: ['*.jar']) 28 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 29 | exclude group: 'com.android.support', module: 'support-annotations' 30 | }) 31 | compile 'com.android.support:appcompat-v7:25.1.0' 32 | testCompile 'junit:junit:4.12' 33 | compile 'com.github.bumptech.glide:glide:3.7.0' 34 | compile 'com.squareup.retrofit2:retrofit:2.1.0' 35 | compile 'com.squareup.retrofit2:converter-gson:2.1.0' 36 | } 37 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply from: 'maven-push.gradle' 3 | 4 | android { 5 | compileSdkVersion 25 6 | buildToolsVersion "25.0.2" 7 | defaultConfig { 8 | minSdkVersion 14 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:25.1.0' 28 | testCompile 'junit:junit:4.12' 29 | } 30 | 31 | // right click function below to execute if you like me can never find them in that retarded sidepane 32 | task installArchives(type: Upload) { 33 | description "Installs the artifacts to the local Maven repository." 34 | repositories.mavenInstaller { 35 | configuration = configurations.default 36 | pom.groupId = 'dk.nodes.filepicker' 37 | pom.artifactId = 'filepicker' 38 | pom.version = '12-LOCAL' 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/dk/nodes/filepicker/FilePickerConstants.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker; 2 | 3 | public class FilePickerConstants { 4 | 5 | public final static String CHOOSER_TEXT = "CHOOSER_TEXT"; 6 | 7 | public final static String URI = "URI"; 8 | /** 9 | * INTENT EXTRAS 10 | */ 11 | public final static String DOWNLOAD_IF_NON_LOCAL = "DOWNLOAD_IF_NON_LOCAL"; 12 | public final static String CAMERA = "CAMERA"; 13 | public final static String FILE = "FILE"; 14 | public final static String TYPE = "TYPE"; 15 | public final static String MULTIPLE_TYPES = "MULTIPLE_TYPES"; 16 | /** 17 | * MIME IMAGE 18 | */ 19 | public final static String MIME_IMAGE = "image/*"; 20 | public final static String MIME_IMAGE_PNG = "image/png"; 21 | public final static String MIME_IMAGE_BMP = "image/bmp"; 22 | public final static String MIME_IMAGE_JPG = "image/jpg"; 23 | public final static String MIME_IMAGE_GIF = "image/gif"; 24 | /** 25 | * MIME VIDEO 26 | */ 27 | public final static String MIME_VIDEO = "video/*"; 28 | public final static String MIME_VIDEO_WAV = "video/wav"; 29 | public final static String MIME_VIDEO_MP4 = "video/mp4"; 30 | /** 31 | * MIME OTHERS 32 | */ 33 | public final static String MIME_PDF = "application/pdf"; 34 | public final static String MIME_TEXT_PLAIN = "text/plain"; 35 | /** 36 | * Response codes 37 | */ 38 | public static final int RESULT_CODE_FAILURE = 10; 39 | final static int REQUEST_CODE = 2; 40 | final static int PERMISSION_REQUEST_CODE = 3; 41 | 42 | } 43 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /app/src/main/java/dk/nodes/filepicker/intentHelper/FilePickerChooserIntent.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker.intentHelper; 2 | 3 | import android.content.Intent; 4 | import android.net.Uri; 5 | 6 | public class FilePickerChooserIntent { 7 | 8 | public static Intent chooserIntent(String chooserText, Uri uri) { 9 | return Intent.createChooser(new Intent().setType("image/*").setAction(Intent.ACTION_GET_CONTENT) 10 | .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION), chooserText) 11 | .putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{FilePickerCameraIntent.cameraIntent(uri)}); 12 | } 13 | 14 | public static Intent chooserSingleIntent(String chooserText, Uri uri, String type) { 15 | return Intent.createChooser( 16 | new Intent() 17 | .setType(type) 18 | .setAction(Intent.ACTION_GET_CONTENT) 19 | .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION), chooserText) 20 | .putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{FilePickerCameraIntent.cameraIntent(uri)}); 21 | } 22 | 23 | public static Intent chooserMultiIntent(String chooserText, Uri uri, String[] types) { 24 | return Intent.createChooser( 25 | new Intent() 26 | .setType("*/*") 27 | .setAction(Intent.ACTION_GET_CONTENT) 28 | .putExtra(Intent.EXTRA_MIME_TYPES, types) 29 | .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION), chooserText) 30 | .putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[]{FilePickerCameraIntent.cameraIntent(uri)}); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/dk/nodes/filepicker/processors/GoogleMediaProcessor.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker.processors; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | 7 | import dk.nodes.filepicker.processors.tasks.GetFileTask; 8 | import dk.nodes.filepicker.utils.Logger; 9 | 10 | import static dk.nodes.filepicker.FilePickerConstants.URI; 11 | 12 | /** 13 | * Created by bison on 31/10/17. 14 | */ 15 | 16 | public class GoogleMediaProcessor implements IUriProcessor { 17 | public static final String TAG = GoogleMediaProcessor.class.getSimpleName(); 18 | UriProcessListener uriProcessListener; 19 | 20 | @Override 21 | public void process(Context context, Uri uri, final UriProcessListener uriProcessListener) { 22 | this.uriProcessListener = uriProcessListener; 23 | if(!isValidUri(uri)) 24 | { 25 | if(uriProcessListener != null) { 26 | Logger.loge(TAG, "URI not recognized, bailing out"); 27 | uriProcessListener.onProcessingFailure(); 28 | return; 29 | } 30 | } 31 | 32 | final String mimeType = context.getContentResolver().getType(uri); 33 | 34 | new GetFileTask(context, uri, new GetFileTask.TaskListener() { 35 | @Override 36 | public void didSucceed(String newPath) { 37 | Intent intent = new Intent(); 38 | if(mimeType != null) 39 | intent.putExtra("mimeType", mimeType); 40 | intent.putExtra(URI, newPath); 41 | if(uriProcessListener != null) 42 | uriProcessListener.onProcessingSuccess(intent); 43 | } 44 | 45 | @Override 46 | public void didFail() { 47 | if(uriProcessListener != null) 48 | uriProcessListener.onProcessingFailure(); 49 | } 50 | }).execute(); 51 | } 52 | 53 | private static boolean isValidUri(Uri uri) { 54 | return "com.google.android.apps.photos.contentprovider".equals(uri.getAuthority()); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/dk/nodes/filepicker/processors/GooglePhotosProcessor.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker.processors; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | 7 | import dk.nodes.filepicker.processors.tasks.GetPhotosTask; 8 | import dk.nodes.filepicker.utils.Logger; 9 | 10 | import static dk.nodes.filepicker.FilePickerConstants.URI; 11 | 12 | /** 13 | * Created by bison on 31/10/17. 14 | */ 15 | 16 | public class GooglePhotosProcessor implements IUriProcessor { 17 | public static final String TAG = GooglePhotosProcessor.class.getSimpleName(); 18 | UriProcessListener uriProcessListener; 19 | 20 | @Override 21 | public void process(Context context, Uri uri, final UriProcessListener uriProcessListener) { 22 | this.uriProcessListener = uriProcessListener; 23 | if(!isValidUri(uri)) 24 | { 25 | if(uriProcessListener != null) { 26 | Logger.loge(TAG, "URI not recognized, bailing out"); 27 | uriProcessListener.onProcessingFailure(); 28 | return; 29 | } 30 | } 31 | 32 | final String mimeType = context.getContentResolver().getType(uri); 33 | 34 | new GetPhotosTask(context, uri, new GetPhotosTask.PhotosListener() { 35 | @Override 36 | public void didDownloadBitmap(String path) { 37 | Intent intent = new Intent(); 38 | if(mimeType != null) 39 | intent.putExtra("mimeType", mimeType); 40 | intent.putExtra(URI, path); 41 | if(uriProcessListener != null) 42 | uriProcessListener.onProcessingSuccess(intent); 43 | } 44 | 45 | @Override 46 | public void didFail() { 47 | if(uriProcessListener != null) 48 | uriProcessListener.onProcessingFailure(); 49 | return; 50 | } 51 | }).execute(); 52 | } 53 | 54 | private static boolean isValidUri(Uri uri) { 55 | return "com.google.android.apps.photos.content".equals(uri.getAuthority()); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /app/src/main/java/dk/nodes/filepicker/bitmapHelper/FilePickerBitmapHelper.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker.bitmapHelper; 2 | 3 | import android.content.Context; 4 | import android.graphics.Bitmap; 5 | import android.graphics.BitmapFactory; 6 | import android.net.Uri; 7 | import android.os.ParcelFileDescriptor; 8 | import android.support.annotation.NonNull; 9 | 10 | import java.io.File; 11 | import java.io.FileDescriptor; 12 | import java.io.FileNotFoundException; 13 | import java.io.FileOutputStream; 14 | 15 | public class FilePickerBitmapHelper { 16 | 17 | public static File writeBitmap(@NonNull Context context, @NonNull Bitmap bitmap, @NonNull Boolean externalStorage) throws Exception { 18 | return writeBitmap(context, bitmap, Bitmap.CompressFormat.PNG, externalStorage); 19 | } 20 | 21 | public static File writeBitmap(@NonNull Context context, @NonNull Bitmap bitmap, Bitmap.CompressFormat compressFormat, @NonNull Boolean externalStorage) throws Exception { 22 | File filesDir = externalStorage ? context.getExternalCacheDir() : context.getCacheDir(); 23 | File file = new File(filesDir, "image.png"); 24 | FileOutputStream fileOutputStream = new FileOutputStream(file); 25 | bitmap.compress(compressFormat, 90, fileOutputStream); 26 | return file; 27 | } 28 | 29 | public static BitmapFactory.Options getBitmapOptions(@NonNull Uri uri, @NonNull Context context) { 30 | BitmapFactory.Options o; 31 | o = new BitmapFactory.Options(); 32 | o.inJustDecodeBounds = true; 33 | try { 34 | ParcelFileDescriptor parcelFileDescriptor = 35 | context.getContentResolver().openFileDescriptor(uri, "r"); 36 | FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); 37 | BitmapFactory.decodeFileDescriptor(fileDescriptor, null, o); 38 | 39 | // If the uri is a "file path", this will throw java.io.FileNotFoundException: No content provider 40 | // Try the old way 41 | } catch (FileNotFoundException fnfe) { 42 | File file = new File(uri.getPath()); 43 | if (file.exists()) { 44 | BitmapFactory.decodeFile(uri.getPath(), o); 45 | } 46 | } 47 | 48 | return o; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /app/src/main/java/dk/nodes/filepicker/processors/GoogleDriveProcessor.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker.processors; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | 7 | import dk.nodes.filepicker.processors.tasks.GetGoogleDriveFileTask; 8 | import dk.nodes.filepicker.utils.Logger; 9 | 10 | import static dk.nodes.filepicker.FilePickerConstants.URI; 11 | 12 | /** 13 | * Created by bison on 31/10/17. 14 | */ 15 | 16 | public class GoogleDriveProcessor implements IUriProcessor { 17 | public static final String TAG = GoogleDriveProcessor.class.getSimpleName(); 18 | UriProcessListener uriProcessListener; 19 | 20 | @Override 21 | public void process(Context context, Uri uri, final UriProcessListener uriProcessListener) { 22 | this.uriProcessListener = uriProcessListener; 23 | if(!isValidUri(uri)) 24 | { 25 | if(uriProcessListener != null) { 26 | Logger.loge(TAG, "URI not recognized, bailing out"); 27 | uriProcessListener.onProcessingFailure(); 28 | return; 29 | } 30 | } 31 | 32 | final String mimeType = context.getContentResolver().getType(uri); 33 | 34 | new GetGoogleDriveFileTask(context, uri, new GetGoogleDriveFileTask.TaskListener() { 35 | @Override 36 | public void didSucceed(String newPath) { 37 | Intent intent = new Intent(); 38 | if(mimeType != null) 39 | intent.putExtra("mimeType", mimeType); 40 | intent.putExtra(URI, newPath); 41 | if(uriProcessListener != null) 42 | uriProcessListener.onProcessingSuccess(intent); 43 | } 44 | 45 | @Override 46 | public void didFail() { 47 | if(uriProcessListener != null) 48 | uriProcessListener.onProcessingFailure(); 49 | } 50 | }).execute(); 51 | } 52 | 53 | private static boolean isValidUri(Uri uri) { 54 | return "com.google.android.apps.docs.storage".equals(uri.getAuthority()) 55 | || "com.google.android.apps.docs.files".equals(uri.getAuthority()) 56 | || "com.google.android.apps.docs.storage.legacy".equals(uri.getAuthority()); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/dk/nodes/filepicker/processors/UriProcessor.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker.processors; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.util.Log; 7 | 8 | import java.util.ArrayList; 9 | import java.util.Iterator; 10 | import java.util.List; 11 | 12 | import dk.nodes.filepicker.utils.Logger; 13 | 14 | /** 15 | * Created by bison on 31/10/17. 16 | */ 17 | 18 | public class UriProcessor implements UriProcessListener { 19 | private static final String TAG = UriProcessor.class.getSimpleName(); 20 | private List processors = new ArrayList<>(); 21 | private Iterator currentProcessorIt; 22 | private Uri uri; 23 | private Context context; 24 | private UriProcessListener listener; 25 | 26 | public UriProcessor() { 27 | // register URI processors 28 | processors.add(new GooglePhotosProcessor()); 29 | processors.add(new GoogleDocumentsProcessor()); 30 | processors.add(new GoogleMediaProcessor()); 31 | processors.add(new GoogleDriveProcessor()); 32 | processors.add(new GenericContentProviderProcessor()); 33 | } 34 | 35 | public void process(Context context, Uri uri, UriProcessListener listener) 36 | { 37 | this.listener = listener; 38 | this.uri = uri; 39 | this.context = context; 40 | currentProcessorIt = processors.iterator(); 41 | processNext(context, uri); 42 | } 43 | 44 | private void processNext(Context context, Uri uri) 45 | { 46 | if(currentProcessorIt.hasNext()) 47 | { 48 | Logger.logd(TAG, "Processing next"); 49 | IUriProcessor processor = currentProcessorIt.next(); 50 | processor.process(context, uri, this); 51 | } 52 | else { 53 | Logger.loge(TAG, "No more processors to process, propagate failure back to caller"); 54 | if(listener != null) 55 | listener.onProcessingFailure(); 56 | } 57 | } 58 | 59 | 60 | @Override 61 | public void onProcessingSuccess(Intent intent) { 62 | Logger.logd(TAG, "onProcessingSuccess"); 63 | if(listener != null) 64 | listener.onProcessingSuccess(intent); 65 | 66 | } 67 | 68 | @Override 69 | public void onProcessingFailure() { 70 | processNext(context, uri); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /filepicker.example/src/main/java/dk/nodes/filepickerexample/ImgurManager.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepickerexample; 2 | 3 | import android.util.Log; 4 | 5 | import java.io.File; 6 | 7 | import okhttp3.MediaType; 8 | import okhttp3.RequestBody; 9 | import retrofit2.Call; 10 | import retrofit2.Callback; 11 | import retrofit2.Response; 12 | import retrofit2.Retrofit; 13 | import retrofit2.converter.gson.GsonConverterFactory; 14 | import retrofit2.http.Headers; 15 | import retrofit2.http.Multipart; 16 | import retrofit2.http.POST; 17 | import retrofit2.http.Part; 18 | 19 | /** 20 | * Created by joso on 16/11/2016. 21 | */ 22 | 23 | public class ImgurManager { 24 | 25 | ImgurService service; 26 | 27 | public ImgurManager() { 28 | Retrofit retrofit = new Retrofit.Builder() 29 | .baseUrl("https://api.imgur.com") 30 | .addConverterFactory(GsonConverterFactory.create()) 31 | .build(); 32 | 33 | service = retrofit.create(ImgurService.class); 34 | } 35 | 36 | public void uploadImage(File file, final UploadCallback callback) { 37 | RequestBody requestBody = RequestBody.create(MediaType.parse("image/*"), file); 38 | 39 | Call call = service.postImage(requestBody); 40 | call.enqueue(new Callback() { 41 | @Override 42 | public void onResponse(Call call, Response response) { 43 | if (response.isSuccessful() && callback != null) { 44 | callback.onUploaded(response.body()); 45 | } else { 46 | Log.e("UploadImage", response.errorBody().toString()); 47 | } 48 | } 49 | 50 | @Override 51 | public void onFailure(Call call, Throwable t) { 52 | Log.e("UploadImage", t.toString()); 53 | } 54 | }); 55 | } 56 | 57 | 58 | public interface ImgurService { 59 | @POST("3/image") 60 | @Multipart 61 | @Headers("Authorization: Client-ID c006fb01daee987") 62 | Call postImage(@Part("image") RequestBody image); 63 | } 64 | 65 | public interface UploadCallback { 66 | void onUploaded(ImageResponse response); 67 | } 68 | 69 | public class Image { 70 | public String id; 71 | public String title; 72 | public String link; 73 | } 74 | 75 | public class ImageResponse { 76 | public Image data; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /app/src/main/java/dk/nodes/filepicker/processors/tasks/GetPhotosTask.java: -------------------------------------------------------------------------------- 1 | package dk.nodes.filepicker.processors.tasks; 2 | 3 | 4 | import android.content.Context; 5 | import android.net.Uri; 6 | import android.os.AsyncTask; 7 | import android.os.ParcelFileDescriptor; 8 | import android.util.Log; 9 | 10 | import java.io.BufferedInputStream; 11 | import java.io.BufferedOutputStream; 12 | import java.io.FileDescriptor; 13 | import java.io.FileInputStream; 14 | import java.io.FileOutputStream; 15 | import java.io.InputStream; 16 | 17 | import dk.nodes.filepicker.BuildConfig; 18 | import dk.nodes.filepicker.uriHelper.FilePickerUriHelper; 19 | import dk.nodes.filepicker.utils.Logger; 20 | 21 | /** 22 | * Created by joso on 26/03/15. 23 | */ 24 | public class GetPhotosTask extends AsyncTask { 25 | public static final String TAG = GetPhotosTask.class.getSimpleName(); 26 | 27 | private Context context; 28 | private Uri uri; 29 | private PhotosListener listener; 30 | 31 | public GetPhotosTask( Context context, Uri uri, PhotosListener listener ) { 32 | this.context = context; 33 | this.uri = uri; 34 | this.listener = listener; 35 | } 36 | 37 | @Override 38 | protected String doInBackground(Void... params) { 39 | try { 40 | ParcelFileDescriptor parcelFileDescriptor = context.getContentResolver() 41 | .openFileDescriptor(uri,"r"); 42 | 43 | FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); 44 | InputStream inputStream = new FileInputStream(fileDescriptor); 45 | BufferedInputStream reader = new BufferedInputStream(inputStream); 46 | 47 | String outputPath = FilePickerUriHelper.makeImageUri().toString(); 48 | 49 | // Create an output stream to a file that you want to save to 50 | BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(outputPath)); 51 | byte[] buf = new byte[2048]; 52 | int len; 53 | while ((len = reader.read(buf)) > 0) { 54 | outStream.write(buf, 0, len); 55 | } 56 | return outputPath; 57 | 58 | } catch( Exception e ) { 59 | Logger.loge(TAG, e.toString()); 60 | } 61 | return null; 62 | } 63 | 64 | @Override 65 | protected void onPostExecute(String s) { 66 | if( listener != null && context != null ) { 67 | if( s != null ) { 68 | listener.didDownloadBitmap(s); 69 | } else { 70 | listener.didFail(); 71 | } 72 | } 73 | } 74 | 75 | public interface PhotosListener { 76 | public void didDownloadBitmap(String path); 77 | public void didFail(); 78 | } 79 | } 80 | 81 | -------------------------------------------------------------------------------- /app/maven-push.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'signing' 2 | apply plugin: 'maven' 3 | apply plugin: 'io.codearte.nexus-staging' 4 | 5 | // Username & password for Sonatype, stored in gradle.properties 6 | def _ossrhUsername = System.getenv('NEXUS_USERNAME') 7 | def _ossrhPassword = System.getenv('NEXUS_PASSWORD') 8 | 9 | allprojects { ext."signing.keyId" = System.getenv('keyId') } 10 | allprojects { ext."signing.secretKeyRingFile" = System.getenv('secretKeyRingFile') } 11 | allprojects { ext."signing.password" = System.getenv('password') } 12 | 13 | // Artifact settings 14 | def _group = 'dk.nodes.filepicker' 15 | def _version = '2.0.1' 16 | def _archivesBaseName = 'filepicker' 17 | 18 | nexusStaging { 19 | packageGroup = "dk.nodes" 20 | } 21 | 22 | def _name = 'FilePicker Library' 23 | def _description = 'Various tools used in android app development.' 24 | 25 | 26 | afterEvaluate { project -> 27 | uploadArchives { 28 | repositories { 29 | mavenDeployer { 30 | beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } 31 | 32 | pom.groupId = _group 33 | pom.artifactId = _archivesBaseName 34 | pom.version = _version 35 | 36 | repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { 37 | authentication(userName: _ossrhUsername, password: _ossrhPassword) 38 | } 39 | 40 | snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { 41 | authentication(userName: _ossrhUsername, password: _ossrhPassword) 42 | } 43 | 44 | pom.project { 45 | name _name 46 | packaging 'aar' 47 | description _description 48 | url 'https://github.com/nodes-android/filepicker' 49 | inceptionYear '2016' 50 | 51 | scm { 52 | url 'https://github.com/nodes-android/filepicker' 53 | connection 'scm:https://github.com/nodes-android/filepicker.git' 54 | } 55 | 56 | licenses { 57 | license { 58 | name 'The Apache License, Version 2.0' 59 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt' 60 | } 61 | } 62 | 63 | developers { 64 | developer { 65 | id 'sanogueralorenzo' 66 | name 'Mario Sanoguera' 67 | email 'sanogueralorenzo@gmail.com' 68 | } 69 | } 70 | 71 | issueManagement { 72 | system 'GitHub issues' 73 | url 'https://github.com/nodes-android/filepicker/issues' 74 | } 75 | } 76 | } 77 | } 78 | } 79 | 80 | signing { 81 | required { gradle.taskGraph.hasTask("uploadArchives") } 82 | sign configurations.archives 83 | } 84 | 85 | task androidSourcesJar(type: Jar) { 86 | classifier = 'sources' 87 | from android.sourceSets.main.java.sourceFiles 88 | } 89 | 90 | artifacts { 91 | archives androidSourcesJar 92 | } 93 | 94 | } -------------------------------------------------------------------------------- /filepicker.example/src/main/res/layout/activity_file_picker_example.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 17 | 18 |