├── .gitignore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── beanie │ │ └── imagechooserapp │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── beanie │ │ └── imagechooserapp │ │ ├── AnalyticsTrackers.java │ │ ├── BasicActivity.java │ │ ├── Config.java │ │ ├── FileChooserActivity.java │ │ ├── FragmentImageChooserActivity.java │ │ ├── HomeActivity.java │ │ ├── ImageChooserActivity.java │ │ ├── MediaChooserActivity.java │ │ ├── VideoChooserActivity.java │ │ └── fragments │ │ └── ImageChooserFragment.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── drawable │ └── image_border.9.png │ ├── layout │ ├── activity_file_chooser.xml │ ├── activity_home.xml │ ├── activity_image_chooser.xml │ ├── activity_media_chooser.xml │ ├── activity_video_chooser.xml │ ├── ad_layout.xml │ └── fragment_image_chooser_activity.xml │ ├── values │ ├── ads.xml │ ├── strings.xml │ └── styles.xml │ └── xml │ ├── analytics.xml │ └── app_tracker.xml ├── build.gradle ├── gradle-example.properties ├── gradlew ├── gradlew.bat ├── image-chooser-library ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── kbeanie │ │ └── imagechooser │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ └── java │ └── com │ └── kbeanie │ └── imagechooser │ ├── api │ ├── BChooser.java │ ├── BChooserPreferences.java │ ├── ChooserType.java │ ├── ChosenFile.java │ ├── ChosenImage.java │ ├── ChosenImages.java │ ├── ChosenMedia.java │ ├── ChosenVideo.java │ ├── ChosenVideos.java │ ├── FileChooserListener.java │ ├── FileChooserManager.java │ ├── FileUtils.java │ ├── ImageChooserListener.java │ ├── ImageChooserManager.java │ ├── IntentUtils.java │ ├── MediaChooserListener.java │ ├── MediaChooserManager.java │ ├── VideoChooserListener.java │ ├── VideoChooserManager.java │ └── utils │ │ ├── ImageChooserBuilder.java │ │ └── VideoChooserBuilder.java │ ├── exceptions │ └── ChooserException.java │ ├── factory │ ├── DateFactory.java │ └── UriFactory.java │ ├── helpers │ └── StreamHelper.java │ └── threads │ ├── FileProcessorListener.java │ ├── FileProcessorThread.java │ ├── ImageProcessorListener.java │ ├── ImageProcessorThread.java │ ├── MediaProcessorThread.java │ ├── VideoProcessorListener.java │ └── VideoProcessorThread.java ├── libs └── android-support-v4.jar └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | app/src/main/assets/crashlytics-build.properties 2 | app/src/main/res/values/com_crashlytics_export_strings.xml 3 | gradle.properties 4 | .gradle 5 | app/local.properties 6 | /local.properties 7 | /.idea/workspace.xml 8 | /.idea/libraries 9 | .DS_Store 10 | /build 11 | *.iml 12 | *.ipr 13 | *.iws 14 | .idea/gradle.xml 15 | app/app.iml 16 | app/crashlytics.properties 17 | 18 | 19 | gradle/ 20 | 21 | # Library 22 | image-chooser-library/gradle.properties 23 | image-chooser-library/build 24 | image-chooser-library/image-chooser-library-image-chooser-library.iml 25 | 26 | .idea 27 | .idea/workspace.xml 28 | 29 | image-chooser-library.iml 30 | ImageChooserApp.iml 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | >Sorry, I will not be making any updates to this library. Will strongly recommend to switch to the option below. The library below still has all the same features. You might have to spend 2-3 hours for the migration, but I think it will be worth. Sorry again. 2 | 3 | _**A completely re-designed library is in the works. Check it out here**_ 4 | 5 | [Android Multipicker Library](https://github.com/coomar2841/android-multipicker-library) 6 | 7 | **Makes it easy and simple to integrate "Attach that photo/video" feature into your android apps.** 8 | 9 | >Don't worry about various devices/OS variations. 10 | 11 | >Don't worry about out-of-memory errors. 12 | 13 | >Don't worry about creating thumbnails to show a preview. 14 | 15 | >Picking up any file for your app, and it's details. 16 | 17 | 18 | Get it on Google Play 19 | 20 | 21 | ##### Code less for capturing images/videos 22 | - Supports picking up images/videos from phone gallery. 23 | - Supports capturing images/videos using the phone camera. 24 | - Generates thumb-nails for the any chosen media. 25 | - Works on most(99%) of the phones/os versions. 26 | - (New) Supports picking up files in general. 27 | - Similar code base to implement irrespective of Android version of device. 28 | 29 | ##### Maven 30 |
 31 | 
 32 | <dependency>
 33 |     <groupId>com.kbeanie</groupId>
 34 |     <artifactId>image-chooser-library</artifactId>
 35 |     <version>1.5.8</version>
 36 | </dependency>
 37 | 
 38 | 
39 | 40 | ##### Configuring on Android Studio 41 | > compile 'com.kbeanie:image-chooser-library:1.5.8@aar' 42 | 43 | ##### Apps using Image Chooser Library 44 | 45 | App | Link to Play Store |App | Link to Play Store 46 | --------------------| -----------------------| ------------------| -------------------- 47 | |Image Chooser App||Blogaway 48 | |Timelike 49 | 50 | 51 | 52 | If you would like to add your app to this list, drop me an email. 53 | 54 | ### Release Notes 55 | 56 | ##### Version "1.6.0" 57 | 1. Minor improvements 58 | 2. Issue #155 59 | 3. Issue #160 60 | 4. Issue #50 61 | 62 | ##### Version "1.5.8" 63 | 1. File chooser should not show "Contacts" as an option. 64 | 65 | ##### Version "1.5.7" 66 | 1. Multiple Image handling 67 | 2. Multiple Video handling 68 | 69 | ##### Version "1.5.4" 70 | 1. Thumbnail issue is fixed. 71 | 2. Some minor bugs. 72 | 73 | ##### Version "1.5.2" 74 | 1. Out of Memory Errors Fix. (Issue 204) 75 | 76 | ##### Version "1.5.1" 77 | 1. Important fix for attaching video files. 78 | 79 | ##### Version "1.5.0" 80 | 1. Removed launcher icon from the library source 81 | 2. Bug Fixes 82 | 83 | 84 | ##### License 85 | ----------------------------------------------------------------------------------- 86 | 87 | Copyright 2013 Kumar Bibek 88 | 89 | Licensed under the Apache License, Version 2.0 (the "License");
90 | you may not use this file except in compliance with the License.
91 | You may obtain a copy of the License at 92 | 93 | [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0) 94 | 95 | Unless required by applicable law or agreed to in writing, software
96 | distributed under the License is distributed on an "AS IS" BASIS,
97 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
98 | See the License for the specific language governing permissions and
99 | limitations under the License. 100 | 101 | ----------------------------------------------------------------------------------- 102 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | maven { url 'https://maven.fabric.io/public' } 4 | } 5 | 6 | dependencies { 7 | classpath 'io.fabric.tools:gradle:1.+' 8 | } 9 | } 10 | apply plugin: 'com.android.application' 11 | apply plugin: 'io.fabric' 12 | 13 | repositories { 14 | maven { url 'https://maven.fabric.io/public' } 15 | } 16 | 17 | 18 | android { 19 | compileSdkVersion 23 20 | buildToolsVersion '23.0.2' 21 | 22 | defaultConfig { 23 | applicationId "com.beanie.imagechooserapp" 24 | minSdkVersion 9 25 | targetSdkVersion rootProject.ext.targetSdkVersion 26 | versionCode 57 27 | versionName "1.6.0" 28 | } 29 | buildTypes { 30 | release { 31 | minifyEnabled false 32 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 33 | } 34 | } 35 | } 36 | 37 | dependencies { 38 | compile fileTree(dir: 'libs', include: ['*.jar']) 39 | compile 'com.android.support:appcompat-v7:23.2.1' 40 | compile project(':image-chooser-library') 41 | // compile 'com.kbeanie:image-chooser-library:+@aar' 42 | compile 'com.google.android.gms:play-services-base:8.4.0' 43 | compile 'com.google.android.gms:play-services-ads:8.4.0' 44 | compile 'com.google.android.gms:play-services-analytics:8.4.0' 45 | compile 'com.squareup.picasso:picasso:2.5.2' 46 | compile('com.crashlytics.sdk.android:crashlytics:2.5.5@aar') { 47 | transitive = true; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /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 D:\android-sdks/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/beanie/imagechooserapp/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.beanie.imagechooserapp; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | // For SkyDrive 12 | 13 | 14 | 19 | 20 | 21 | 24 | 25 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 70 | 73 | 77 | 78 | 79 | 83 | 84 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /app/src/main/java/com/beanie/imagechooserapp/AnalyticsTrackers.java: -------------------------------------------------------------------------------- 1 | package com.beanie.imagechooserapp; 2 | 3 | import android.content.Context; 4 | 5 | import com.google.android.gms.analytics.GoogleAnalytics; 6 | import com.google.android.gms.analytics.Tracker; 7 | 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | /** 12 | * A collection of Google Analytics trackers. Fetch the tracker you need using 13 | * {@code AnalyticsTrackers.getInstance().get(...)} 14 | *

15 | * This code was generated by Android Studio but can be safely modified by 16 | * hand at this point. 17 | *

18 | * TODO: Call {@link #initialize(Context)} from an entry point in your app 19 | * before using this! 20 | */ 21 | public final class AnalyticsTrackers { 22 | 23 | public enum Target { 24 | APP, 25 | // Add more trackers here if you need, and update the code in #get(Target) below 26 | } 27 | 28 | private static AnalyticsTrackers sInstance; 29 | 30 | public static synchronized void initialize(Context context) { 31 | if (sInstance != null) { 32 | throw new IllegalStateException("Extra call to initialize analytics trackers"); 33 | } 34 | 35 | sInstance = new AnalyticsTrackers(context); 36 | } 37 | 38 | public static synchronized AnalyticsTrackers getInstance() { 39 | if (sInstance == null) { 40 | throw new IllegalStateException("Call initialize() before getInstance()"); 41 | } 42 | 43 | return sInstance; 44 | } 45 | 46 | private final Map mTrackers = new HashMap(); 47 | private final Context mContext; 48 | 49 | /** 50 | * Don't instantiate directly - use {@link #getInstance()} instead. 51 | */ 52 | private AnalyticsTrackers(Context context) { 53 | mContext = context.getApplicationContext(); 54 | } 55 | 56 | public synchronized Tracker get(Target target) { 57 | if (!mTrackers.containsKey(target)) { 58 | Tracker tracker; 59 | switch (target) { 60 | case APP: 61 | tracker = GoogleAnalytics.getInstance(mContext).newTracker(R.xml.app_tracker); 62 | break; 63 | default: 64 | throw new IllegalArgumentException("Unhandled analytics target " + target); 65 | } 66 | mTrackers.put(target, tracker); 67 | } 68 | 69 | return mTrackers.get(target); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/src/main/java/com/beanie/imagechooserapp/BasicActivity.java: -------------------------------------------------------------------------------- 1 | package com.beanie.imagechooserapp; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.support.v7.app.ActionBarActivity; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.view.MenuItem; 8 | 9 | import com.google.android.gms.ads.AdRequest; 10 | import com.google.android.gms.ads.AdView; 11 | import com.google.android.gms.analytics.GoogleAnalytics; 12 | import com.google.android.gms.analytics.HitBuilders; 13 | import com.google.android.gms.analytics.Tracker; 14 | 15 | /** 16 | * Created by kbibek on 1/26/15. 17 | */ 18 | public class BasicActivity extends AppCompatActivity { 19 | private Tracker tracker; 20 | private AdView adView; 21 | 22 | @Override 23 | protected void onCreate(Bundle savedInstanceState) { 24 | super.onCreate(savedInstanceState); 25 | if (tracker == null) { 26 | tracker = GoogleAnalytics.getInstance(this).newTracker(R.xml.analytics); 27 | } 28 | 29 | tracker.setScreenName(getClass().getSimpleName()); 30 | tracker.send(new HitBuilders.ScreenViewBuilder().build()); 31 | 32 | if (!(this instanceof HomeActivity)) { 33 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 34 | } 35 | } 36 | 37 | @Override 38 | public boolean onOptionsItemSelected(MenuItem item) { 39 | if (item.getItemId() == android.R.id.home) { 40 | finish(); 41 | } 42 | return super.onOptionsItemSelected(item); 43 | } 44 | 45 | protected void setupAds() { 46 | adView = (AdView) findViewById(R.id.adView); 47 | 48 | AdRequest.Builder builder = new AdRequest.Builder(); 49 | builder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR) 50 | .addTestDevice(Config.NEXUS_S) 51 | .addTestDevice(Config.TEST_DEVICE_ID_2) 52 | .addTestDevice(Config.TEST_GALAXY_NEXUS) 53 | .addTestDevice(Config.TEST_TEMP_DEVICE) 54 | .addTestDevice(Config.TEST_OPO); 55 | AdRequest request = builder.build(); 56 | adView.loadAd(request); 57 | } 58 | 59 | @Override 60 | public void onDestroy() { 61 | if (adView != null) { 62 | adView.destroy(); 63 | } 64 | super.onDestroy(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /app/src/main/java/com/beanie/imagechooserapp/Config.java: -------------------------------------------------------------------------------- 1 | package com.beanie.imagechooserapp; 2 | 3 | public class Config { 4 | public final static String PUBLISHER_ID = "a151e43f37ee7e0"; 5 | public final static String NEXUS_S = "55958F02BF66EEC31424761A58B1733B"; 6 | public final static String TEST_DEVICE_ID_2 = "79B7F70DBE55777CD06F8FE2EBEB92A1"; 7 | public final static String TEST_GALAXY_NEXUS = "EC4FF024718202E6D9E05CAE6C7815E9"; 8 | public final static String TEST_OPO = "BF997DF77ED76DCABEC05DC2B9BF44D3"; 9 | public final static String TEST_TEMP_DEVICE = "51EE6FFC47E761D31C514DCFF0E8AB93"; 10 | } 11 | -------------------------------------------------------------------------------- /app/src/main/java/com/beanie/imagechooserapp/FileChooserActivity.java: -------------------------------------------------------------------------------- 1 | package com.beanie.imagechooserapp; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.util.Log; 7 | import android.view.View; 8 | import android.widget.ProgressBar; 9 | import android.widget.TextView; 10 | import android.widget.Toast; 11 | 12 | import com.google.android.gms.ads.AdRequest; 13 | import com.google.android.gms.ads.AdView; 14 | import com.kbeanie.imagechooser.api.ChooserType; 15 | import com.kbeanie.imagechooser.api.ChosenFile; 16 | import com.kbeanie.imagechooser.api.FileChooserListener; 17 | import com.kbeanie.imagechooser.api.FileChooserManager; 18 | 19 | /** 20 | * Created by kbibek on 14/11/14. 21 | */ 22 | public class FileChooserActivity extends BasicActivity implements FileChooserListener { 23 | private final static String TAG = "FileChooserActivity"; 24 | private FileChooserManager fm; 25 | private TextView textViewFileDetails; 26 | private ProgressBar pBar; 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_file_chooser); 32 | textViewFileDetails = (TextView) findViewById(R.id.fileDetails); 33 | pBar = (ProgressBar) findViewById(R.id.pBar); 34 | pBar.setVisibility(View.INVISIBLE); 35 | 36 | setupAds(); 37 | } 38 | 39 | public void pickFile(View view) { 40 | fm = new FileChooserManager(this); 41 | fm.setFileChooserListener(this); 42 | try { 43 | pBar.setVisibility(View.VISIBLE); 44 | fm.choose(); 45 | } catch (Exception e) { 46 | pBar.setVisibility(View.INVISIBLE); 47 | e.printStackTrace(); 48 | } 49 | } 50 | 51 | @Override 52 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 53 | super.onActivityResult(requestCode, resultCode, data); 54 | if (requestCode == ChooserType.REQUEST_PICK_FILE && resultCode == RESULT_OK) { 55 | if (fm == null) { 56 | fm = new FileChooserManager(this); 57 | fm.setFileChooserListener(this); 58 | } 59 | Log.i(TAG, "Probable file size: " + fm.queryProbableFileSize(data.getData(), this)); 60 | fm.submit(requestCode, data); 61 | } 62 | } 63 | 64 | @Override 65 | public void onFileChosen(final ChosenFile file) { 66 | runOnUiThread(new Runnable() { 67 | @Override 68 | public void run() { 69 | pBar.setVisibility(View.INVISIBLE); 70 | populateFileDetails(file); 71 | } 72 | }); 73 | } 74 | 75 | @Override 76 | public void onError(final String reason) { 77 | runOnUiThread(new Runnable() { 78 | @Override 79 | public void run() { 80 | pBar.setVisibility(View.INVISIBLE); 81 | Toast.makeText(FileChooserActivity.this, reason, Toast.LENGTH_LONG).show(); 82 | } 83 | }); 84 | } 85 | 86 | private void populateFileDetails(ChosenFile file) { 87 | StringBuffer text = new StringBuffer(); 88 | text.append("File name: " + file.getFileName() + "\n\n"); 89 | text.append("File path: " + file.getFilePath() + "\n\n"); 90 | text.append("Mime type: " + file.getMimeType() + "\n\n"); 91 | text.append("File extn: " + file.getExtension() + "\n\n"); 92 | text.append("File size: " + file.getFileSize() / 1024 + "KB"); 93 | textViewFileDetails.setText(text.toString()); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /app/src/main/java/com/beanie/imagechooserapp/FragmentImageChooserActivity.java: -------------------------------------------------------------------------------- 1 | package com.beanie.imagechooserapp; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | 6 | public class FragmentImageChooserActivity extends BasicActivity { 7 | @Override 8 | protected void onCreate(Bundle savedInstanceState) { 9 | super.onCreate(savedInstanceState); 10 | setContentView(R.layout.fragment_image_chooser_activity); 11 | 12 | setupAds(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/beanie/imagechooserapp/HomeActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * **************************************************************************** 3 | * Copyright 2013 Kumar Bibek 4 | *

5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ***************************************************************************** 17 | */ 18 | 19 | package com.beanie.imagechooserapp; 20 | 21 | import android.app.Activity; 22 | import android.content.Intent; 23 | import android.graphics.Bitmap; 24 | import android.graphics.BitmapFactory; 25 | import android.os.Bundle; 26 | import android.util.Log; 27 | import android.view.View; 28 | 29 | import com.beanie.imagechooserapp.fragments.ImageChooserFragment; 30 | import com.crashlytics.android.Crashlytics; 31 | import com.google.android.gms.ads.AdRequest; 32 | import com.google.android.gms.ads.AdView; 33 | import com.kbeanie.imagechooser.api.BChooser; 34 | import com.kbeanie.imagechooser.api.BChooserPreferences; 35 | 36 | import io.fabric.sdk.android.Fabric; 37 | 38 | public class HomeActivity extends BasicActivity { 39 | 40 | @Override 41 | protected void onCreate(Bundle savedInstanceState) { 42 | super.onCreate(savedInstanceState); 43 | Fabric.with(this, new Crashlytics()); 44 | setContentView(R.layout.activity_home); 45 | setupAds(); 46 | 47 | // One time call to setup the folder to be used for all files 48 | BChooserPreferences preferences = new BChooserPreferences(getApplicationContext()); 49 | preferences.setFolderName("ICL"); 50 | } 51 | 52 | public void gotoImageChooserFragment(View view) { 53 | Intent intent = new Intent(this, FragmentImageChooserActivity.class); 54 | startActivity(intent); 55 | } 56 | 57 | public void gotoImageChooser(View view) { 58 | Intent intent = new Intent(this, ImageChooserActivity.class); 59 | startActivity(intent); 60 | } 61 | 62 | public void gotoVideoChooser(View view) { 63 | Intent intent = new Intent(this, VideoChooserActivity.class); 64 | startActivity(intent); 65 | } 66 | 67 | public void gotoMediaChooser(View view) { 68 | Intent intent = new Intent(this, MediaChooserActivity.class); 69 | startActivity(intent); 70 | } 71 | 72 | public void gotoFileChooser(View view) { 73 | Intent intent = new Intent(this, FileChooserActivity.class); 74 | startActivity(intent); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/com/beanie/imagechooserapp/ImageChooserActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * **************************************************************************** 3 | * Copyright 2013 Kumar Bibek 4 | *

5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ***************************************************************************** 17 | */ 18 | 19 | package com.beanie.imagechooserapp; 20 | 21 | import java.io.File; 22 | import java.util.ArrayList; 23 | 24 | import android.app.Activity; 25 | import android.content.Intent; 26 | import android.net.Uri; 27 | import android.os.Bundle; 28 | import android.provider.MediaStore; 29 | import android.support.annotation.NonNull; 30 | import android.util.Log; 31 | import android.view.View; 32 | import android.view.View.OnClickListener; 33 | import android.widget.Button; 34 | import android.widget.ImageView; 35 | import android.widget.ProgressBar; 36 | import android.widget.TextView; 37 | import android.widget.Toast; 38 | 39 | import com.crashlytics.android.Crashlytics; 40 | import com.google.android.gms.ads.AdRequest; 41 | import com.google.android.gms.ads.AdView; 42 | import com.kbeanie.imagechooser.api.ChooserType; 43 | import com.kbeanie.imagechooser.api.ChosenFile; 44 | import com.kbeanie.imagechooser.api.ChosenImage; 45 | import com.kbeanie.imagechooser.api.ChosenImages; 46 | import com.kbeanie.imagechooser.api.FileChooserListener; 47 | import com.kbeanie.imagechooser.api.FileChooserManager; 48 | import com.kbeanie.imagechooser.api.ImageChooserListener; 49 | import com.kbeanie.imagechooser.api.ImageChooserManager; 50 | import com.kbeanie.imagechooser.api.IntentUtils; 51 | import com.squareup.picasso.Callback; 52 | import com.squareup.picasso.Picasso; 53 | 54 | public class ImageChooserActivity extends BasicActivity implements 55 | ImageChooserListener { 56 | 57 | private final static String TAG = "ICA"; 58 | 59 | private ImageView imageViewThumbnail; 60 | 61 | private ImageView imageViewThumbSmall; 62 | 63 | private TextView textViewFile; 64 | 65 | private ImageChooserManager imageChooserManager; 66 | 67 | private ProgressBar pbar; 68 | 69 | private String filePath; 70 | 71 | private int chooserType; 72 | 73 | private boolean isActivityResultOver = false; 74 | 75 | private String originalFilePath; 76 | private String thumbnailFilePath; 77 | private String thumbnailSmallFilePath; 78 | 79 | @Override 80 | protected void onCreate(Bundle savedInstanceState) { 81 | super.onCreate(savedInstanceState); 82 | Log.i(TAG, "Activity Created"); 83 | setContentView(R.layout.activity_image_chooser); 84 | 85 | Button buttonTakePicture = (Button) findViewById(R.id.buttonTakePicture); 86 | buttonTakePicture.setOnClickListener(new OnClickListener() { 87 | 88 | @Override 89 | public void onClick(View v) { 90 | takePicture(); 91 | } 92 | }); 93 | Button buttonChooseImage = (Button) findViewById(R.id.buttonChooseImage); 94 | buttonChooseImage.setOnClickListener(new OnClickListener() { 95 | 96 | @Override 97 | public void onClick(View v) { 98 | chooseImage(); 99 | } 100 | }); 101 | 102 | imageViewThumbnail = (ImageView) findViewById(R.id.imageViewThumb); 103 | imageViewThumbSmall = (ImageView) findViewById(R.id.imageViewThumbSmall); 104 | textViewFile = (TextView) findViewById(R.id.textViewFile); 105 | 106 | pbar = (ProgressBar) findViewById(R.id.progressBar); 107 | pbar.setVisibility(View.GONE); 108 | 109 | setupAds(); 110 | 111 | checkForSharedImage(getIntent()); 112 | } 113 | 114 | private void chooseImage() { 115 | chooserType = ChooserType.REQUEST_PICK_PICTURE; 116 | imageChooserManager = new ImageChooserManager(this, 117 | ChooserType.REQUEST_PICK_PICTURE, true); 118 | Bundle bundle = new Bundle(); 119 | bundle.putBoolean(Intent.EXTRA_ALLOW_MULTIPLE, true); 120 | imageChooserManager.setExtras(bundle); 121 | imageChooserManager.setImageChooserListener(this); 122 | imageChooserManager.clearOldFiles(); 123 | try { 124 | pbar.setVisibility(View.VISIBLE); 125 | filePath = imageChooserManager.choose(); 126 | } catch (IllegalArgumentException e) { 127 | e.printStackTrace(); 128 | } catch (Exception e) { 129 | e.printStackTrace(); 130 | } 131 | } 132 | 133 | private void takePicture() { 134 | chooserType = ChooserType.REQUEST_CAPTURE_PICTURE; 135 | imageChooserManager = new ImageChooserManager(this, 136 | ChooserType.REQUEST_CAPTURE_PICTURE, true); 137 | imageChooserManager.setImageChooserListener(this); 138 | try { 139 | pbar.setVisibility(View.VISIBLE); 140 | filePath = imageChooserManager.choose(); 141 | } catch (IllegalArgumentException e) { 142 | e.printStackTrace(); 143 | } catch (Exception e) { 144 | e.printStackTrace(); 145 | } 146 | } 147 | 148 | @Override 149 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 150 | Log.i(TAG, "OnActivityResult"); 151 | Log.i(TAG, "File Path : " + filePath); 152 | Log.i(TAG, "Chooser Type: " + chooserType); 153 | if (resultCode == RESULT_OK 154 | && (requestCode == ChooserType.REQUEST_PICK_PICTURE || requestCode == ChooserType.REQUEST_CAPTURE_PICTURE)) { 155 | if (imageChooserManager == null) { 156 | reinitializeImageChooser(); 157 | } 158 | imageChooserManager.submit(requestCode, data); 159 | } else { 160 | pbar.setVisibility(View.GONE); 161 | } 162 | } 163 | 164 | @Override 165 | public void onImageChosen(final ChosenImage image) { 166 | runOnUiThread(new Runnable() { 167 | 168 | @Override 169 | public void run() { 170 | Log.i(TAG, "Chosen Image: O - " + image.getFilePathOriginal()); 171 | Log.i(TAG, "Chosen Image: T - " + image.getFileThumbnail()); 172 | Log.i(TAG, "Chosen Image: Ts - " + image.getFileThumbnailSmall()); 173 | isActivityResultOver = true; 174 | originalFilePath = image.getFilePathOriginal(); 175 | thumbnailFilePath = image.getFileThumbnail(); 176 | thumbnailSmallFilePath = image.getFileThumbnailSmall(); 177 | pbar.setVisibility(View.GONE); 178 | if (image != null) { 179 | Log.i(TAG, "Chosen Image: Is not null"); 180 | textViewFile.setText(image.getFilePathOriginal()); 181 | loadImage(imageViewThumbnail, image.getFileThumbnail()); 182 | loadImage(imageViewThumbSmall, image.getFileThumbnailSmall()); 183 | } else { 184 | Log.i(TAG, "Chosen Image: Is null"); 185 | } 186 | } 187 | }); 188 | } 189 | 190 | @Override 191 | public void onImagesChosen(final ChosenImages images) { 192 | runOnUiThread(new Runnable() { 193 | @Override 194 | public void run() { 195 | Log.i(TAG, "On Images Chosen: " + images.size()); 196 | onImageChosen(images.getImage(0)); 197 | } 198 | }); 199 | } 200 | 201 | private void loadImage(ImageView iv, final String path) { 202 | Picasso.with(ImageChooserActivity.this) 203 | .load(Uri.fromFile(new File(path))) 204 | .fit() 205 | .centerInside() 206 | .into(iv, new Callback() { 207 | @Override 208 | public void onSuccess() { 209 | Log.i(TAG, "Picasso Success Loading Thumbnail - " + path); 210 | } 211 | 212 | @Override 213 | public void onError() { 214 | Log.i(TAG, "Picasso Error Loading Thumbnail Small - " + path); 215 | } 216 | }); 217 | } 218 | 219 | @Override 220 | public void onError(final String reason) { 221 | runOnUiThread(new Runnable() { 222 | 223 | @Override 224 | public void run() { 225 | Log.i(TAG, "OnError: " + reason); 226 | pbar.setVisibility(View.GONE); 227 | Toast.makeText(ImageChooserActivity.this, reason, 228 | Toast.LENGTH_LONG).show(); 229 | } 230 | }); 231 | } 232 | 233 | // Should be called if for some reason the ImageChooserManager is null (Due 234 | // to destroying of activity for low memory situations) 235 | private void reinitializeImageChooser() { 236 | imageChooserManager = new ImageChooserManager(this, chooserType, true); 237 | Bundle bundle = new Bundle(); 238 | bundle.putBoolean(Intent.EXTRA_ALLOW_MULTIPLE, true); 239 | imageChooserManager.setExtras(bundle); 240 | imageChooserManager.setImageChooserListener(this); 241 | imageChooserManager.reinitialize(filePath); 242 | } 243 | 244 | @Override 245 | protected void onSaveInstanceState(Bundle outState) { 246 | Log.i(TAG, "Saving Stuff"); 247 | Log.i(TAG, "File Path: " + filePath); 248 | Log.i(TAG, "Chooser Type: " + chooserType); 249 | outState.putBoolean("activity_result_over", isActivityResultOver); 250 | outState.putInt("chooser_type", chooserType); 251 | outState.putString("media_path", filePath); 252 | outState.putString("orig", originalFilePath); 253 | outState.putString("thumb", thumbnailFilePath); 254 | outState.putString("thumbs", thumbnailSmallFilePath); 255 | super.onSaveInstanceState(outState); 256 | } 257 | 258 | @Override 259 | protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { 260 | if (savedInstanceState != null) { 261 | if (savedInstanceState.containsKey("chooser_type")) { 262 | chooserType = savedInstanceState.getInt("chooser_type"); 263 | } 264 | if (savedInstanceState.containsKey("media_path")) { 265 | filePath = savedInstanceState.getString("media_path"); 266 | } 267 | if (savedInstanceState.containsKey("activity_result_over")) { 268 | isActivityResultOver = savedInstanceState.getBoolean("activity_result_over"); 269 | originalFilePath = savedInstanceState.getString("orig"); 270 | thumbnailFilePath = savedInstanceState.getString("thumb"); 271 | thumbnailSmallFilePath = savedInstanceState.getString("thumbs"); 272 | } 273 | } 274 | Log.i(TAG, "Restoring Stuff"); 275 | Log.i(TAG, "File Path: " + filePath); 276 | Log.i(TAG, "Chooser Type: " + chooserType); 277 | Log.i(TAG, "Activity Result Over: " + isActivityResultOver); 278 | if (isActivityResultOver) { 279 | populateData(); 280 | } 281 | super.onRestoreInstanceState(savedInstanceState); 282 | } 283 | 284 | private void populateData() { 285 | Log.i(TAG, "Populating Data"); 286 | loadImage(imageViewThumbnail, thumbnailFilePath); 287 | loadImage(imageViewThumbSmall, thumbnailSmallFilePath); 288 | } 289 | 290 | @Override 291 | public void onDestroy() { 292 | super.onDestroy(); 293 | Log.i(TAG, "Activity Destroyed"); 294 | } 295 | 296 | private void checkForSharedImage(Intent intent) { 297 | if (intent != null) { 298 | if (intent.getAction() != null && intent.getType() != null && intent.getExtras() != null) { 299 | ImageChooserManager m = new ImageChooserManager(this, ChooserType.REQUEST_PICK_PICTURE); 300 | m.setImageChooserListener(this); 301 | 302 | m.submit(ChooserType.REQUEST_PICK_PICTURE, IntentUtils.getIntentForMultipleSelection(intent)); 303 | } 304 | } 305 | } 306 | } 307 | -------------------------------------------------------------------------------- /app/src/main/java/com/beanie/imagechooserapp/MediaChooserActivity.java: -------------------------------------------------------------------------------- 1 | package com.beanie.imagechooserapp; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.util.Log; 7 | import android.view.View; 8 | 9 | import com.kbeanie.imagechooser.api.ChooserType; 10 | import com.kbeanie.imagechooser.api.ChosenImage; 11 | import com.kbeanie.imagechooser.api.ChosenImages; 12 | import com.kbeanie.imagechooser.api.ChosenVideo; 13 | import com.kbeanie.imagechooser.api.ChosenVideos; 14 | import com.kbeanie.imagechooser.api.MediaChooserListener; 15 | import com.kbeanie.imagechooser.api.MediaChooserManager; 16 | 17 | public class MediaChooserActivity extends BasicActivity implements 18 | MediaChooserListener { 19 | 20 | private final static String TAG = "MediaChooserActivity"; 21 | 22 | private MediaChooserManager chooserManager; 23 | 24 | @Override 25 | protected void onCreate(Bundle savedInstanceState) { 26 | super.onCreate(savedInstanceState); 27 | setContentView(R.layout.activity_media_chooser); 28 | 29 | setupAds(); 30 | } 31 | 32 | public void pickMedia(View view) { 33 | chooserManager = new MediaChooserManager(this, 34 | ChooserType.REQUEST_PICK_PICTURE_OR_VIDEO); 35 | chooserManager.setMediaChooserListener(this); 36 | try { 37 | String path = chooserManager.choose(); 38 | } catch (Exception e) { 39 | e.printStackTrace(); 40 | } 41 | } 42 | 43 | @Override 44 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 45 | if (resultCode == RESULT_OK 46 | && requestCode == ChooserType.REQUEST_PICK_PICTURE_OR_VIDEO) { 47 | chooserManager.submit(requestCode, data); 48 | } 49 | super.onActivityResult(requestCode, resultCode, data); 50 | } 51 | 52 | @Override 53 | public void onImageChosen(ChosenImage image) { 54 | Log.i(TAG, "Image chosen: " + image.getFilePathOriginal()); 55 | } 56 | 57 | @Override 58 | public void onError(String reason) { 59 | Log.i(TAG, "Error: " + reason); 60 | } 61 | 62 | @Override 63 | public void onVideosChosen(ChosenVideos videos) { 64 | 65 | } 66 | 67 | @Override 68 | public void onImagesChosen(ChosenImages images) { 69 | 70 | } 71 | 72 | @Override 73 | public void onVideoChosen(ChosenVideo video) { 74 | Log.i(TAG, "Video chosen: " + video.getVideoFilePath()); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/java/com/beanie/imagechooserapp/VideoChooserActivity.java: -------------------------------------------------------------------------------- 1 | /** 2 | * **************************************************************************** 3 | * Copyright 2013 Kumar Bibek 4 | *

5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | *

9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | *

11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | * ***************************************************************************** 17 | */ 18 | 19 | package com.beanie.imagechooserapp; 20 | 21 | import java.io.File; 22 | 23 | import android.content.Intent; 24 | import android.net.Uri; 25 | import android.os.Bundle; 26 | import android.util.Log; 27 | import android.view.View; 28 | import android.widget.ImageView; 29 | import android.widget.ProgressBar; 30 | import android.widget.Toast; 31 | import android.widget.VideoView; 32 | 33 | import com.kbeanie.imagechooser.api.ChooserType; 34 | import com.kbeanie.imagechooser.api.ChosenVideo; 35 | import com.kbeanie.imagechooser.api.ChosenVideos; 36 | import com.kbeanie.imagechooser.api.IntentUtils; 37 | import com.kbeanie.imagechooser.api.VideoChooserListener; 38 | import com.kbeanie.imagechooser.api.VideoChooserManager; 39 | 40 | public class VideoChooserActivity extends BasicActivity implements 41 | VideoChooserListener { 42 | private VideoChooserManager videoChooserManager; 43 | 44 | private ProgressBar pbar; 45 | 46 | private ImageView imageViewThumb; 47 | 48 | private ImageView imageViewThumbSmall; 49 | 50 | private VideoView videoView; 51 | 52 | private String filePath; 53 | 54 | private int chooserType; 55 | 56 | @Override 57 | protected void onCreate(Bundle savedInstanceState) { 58 | super.onCreate(savedInstanceState); 59 | setContentView(R.layout.activity_video_chooser); 60 | 61 | pbar = (ProgressBar) findViewById(R.id.pBar); 62 | pbar.setVisibility(View.GONE); 63 | 64 | imageViewThumb = (ImageView) findViewById(R.id.imageViewThumbnail); 65 | imageViewThumbSmall = (ImageView) findViewById(R.id.imageViewThumbnailSmall); 66 | 67 | videoView = (VideoView) findViewById(R.id.videoView); 68 | 69 | setupAds(); 70 | 71 | checkForSharedVideo(getIntent()); 72 | } 73 | 74 | public void captureVideo(View view) { 75 | chooserType = ChooserType.REQUEST_CAPTURE_VIDEO; 76 | videoChooserManager = new VideoChooserManager(this, 77 | ChooserType.REQUEST_CAPTURE_VIDEO); 78 | videoChooserManager.setVideoChooserListener(this); 79 | try { 80 | pbar.setVisibility(View.VISIBLE); 81 | filePath = videoChooserManager.choose(); 82 | } catch (IllegalArgumentException e) { 83 | e.printStackTrace(); 84 | } catch (Exception e) { 85 | e.printStackTrace(); 86 | } 87 | } 88 | 89 | public void pickVideo(View view) { 90 | chooserType = ChooserType.REQUEST_PICK_VIDEO; 91 | videoChooserManager = new VideoChooserManager(this, 92 | ChooserType.REQUEST_PICK_VIDEO); 93 | Bundle bundle = new Bundle(); 94 | bundle.putBoolean(Intent.EXTRA_ALLOW_MULTIPLE, true); 95 | videoChooserManager.setExtras(bundle); 96 | videoChooserManager.setVideoChooserListener(this); 97 | try { 98 | videoChooserManager.choose(); 99 | pbar.setVisibility(View.VISIBLE); 100 | } catch (IllegalArgumentException e) { 101 | e.printStackTrace(); 102 | } catch (Exception e) { 103 | e.printStackTrace(); 104 | } 105 | } 106 | 107 | @Override 108 | public void onVideoChosen(final ChosenVideo video) { 109 | runOnUiThread(new Runnable() { 110 | 111 | @Override 112 | public void run() { 113 | pbar.setVisibility(View.GONE); 114 | if (video != null) { 115 | videoView.setVideoURI(Uri.parse(new File(video 116 | .getVideoFilePath()).toString())); 117 | videoView.start(); 118 | imageViewThumb.setImageURI(Uri.parse(new File(video 119 | .getThumbnailPath()).toString())); 120 | imageViewThumbSmall.setImageURI(Uri.parse(new File(video 121 | .getThumbnailSmallPath()).toString())); 122 | } 123 | } 124 | }); 125 | } 126 | 127 | @Override 128 | public void onError(final String reason) { 129 | runOnUiThread(new Runnable() { 130 | 131 | @Override 132 | public void run() { 133 | pbar.setVisibility(View.GONE); 134 | Toast.makeText(VideoChooserActivity.this, reason, 135 | Toast.LENGTH_LONG).show(); 136 | } 137 | }); 138 | } 139 | 140 | @Override 141 | public void onVideosChosen(final ChosenVideos videos) { 142 | runOnUiThread(new Runnable() { 143 | @Override 144 | public void run() { 145 | Log.i(getClass().getName(), "run: Videos Chosen: " + videos.size()); 146 | onVideoChosen(videos.getImage(0)); 147 | } 148 | }); 149 | } 150 | 151 | @Override 152 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 153 | if (resultCode == RESULT_OK 154 | && (requestCode == ChooserType.REQUEST_CAPTURE_VIDEO || requestCode == ChooserType.REQUEST_PICK_VIDEO)) { 155 | if (videoChooserManager == null) { 156 | reinitializeVideoChooser(); 157 | } 158 | videoChooserManager.submit(requestCode, data); 159 | } else { 160 | pbar.setVisibility(View.GONE); 161 | } 162 | } 163 | 164 | // Should be called if for some reason the VideoChooserManager is null (Due 165 | // to destroying of activity for low memory situations) 166 | private void reinitializeVideoChooser() { 167 | videoChooserManager = new VideoChooserManager(this, chooserType, true); 168 | videoChooserManager.setVideoChooserListener(this); 169 | videoChooserManager.reinitialize(filePath); 170 | } 171 | 172 | @Override 173 | protected void onSaveInstanceState(Bundle outState) { 174 | outState.putInt("chooser_type", chooserType); 175 | outState.putString("media_path", filePath); 176 | super.onSaveInstanceState(outState); 177 | } 178 | 179 | @Override 180 | protected void onRestoreInstanceState(Bundle savedInstanceState) { 181 | if (savedInstanceState != null) { 182 | if (savedInstanceState.containsKey("chooser_type")) { 183 | chooserType = savedInstanceState.getInt("chooser_type"); 184 | } 185 | 186 | if (savedInstanceState.containsKey("media_path")) { 187 | filePath = savedInstanceState.getString("media_path"); 188 | } 189 | } 190 | super.onRestoreInstanceState(savedInstanceState); 191 | } 192 | 193 | private void checkForSharedVideo(Intent intent) { 194 | if (intent != null) { 195 | if (intent.getAction() != null && intent.getType() != null && intent.getExtras() != null) { 196 | VideoChooserManager m = new VideoChooserManager(this, ChooserType.REQUEST_PICK_VIDEO); 197 | m.setVideoChooserListener(this); 198 | 199 | m.submit(ChooserType.REQUEST_PICK_VIDEO, IntentUtils.getIntentForMultipleSelection(intent)); 200 | } 201 | } 202 | } 203 | } 204 | -------------------------------------------------------------------------------- /app/src/main/java/com/beanie/imagechooserapp/fragments/ImageChooserFragment.java: -------------------------------------------------------------------------------- 1 | package com.beanie.imagechooserapp.fragments; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Activity; 5 | import android.app.Fragment; 6 | import android.content.Context; 7 | import android.content.Intent; 8 | import android.net.Uri; 9 | import android.os.Bundle; 10 | import android.util.Log; 11 | import android.view.LayoutInflater; 12 | import android.view.View; 13 | import android.view.View.OnClickListener; 14 | import android.view.ViewGroup; 15 | import android.widget.Button; 16 | import android.widget.ImageView; 17 | import android.widget.ProgressBar; 18 | import android.widget.TextView; 19 | import android.widget.Toast; 20 | 21 | import com.beanie.imagechooserapp.R; 22 | import com.crashlytics.android.Crashlytics; 23 | import com.kbeanie.imagechooser.api.ChooserType; 24 | import com.kbeanie.imagechooser.api.ChosenImage; 25 | import com.kbeanie.imagechooser.api.ChosenImages; 26 | import com.kbeanie.imagechooser.api.ImageChooserListener; 27 | import com.kbeanie.imagechooser.api.ImageChooserManager; 28 | 29 | import java.io.File; 30 | 31 | @SuppressLint("NewApi") 32 | public class ImageChooserFragment extends Fragment implements 33 | ImageChooserListener { 34 | private ImageChooserManager imageChooserManager; 35 | private int chooserType; 36 | private String mediaPath; 37 | 38 | private String finalPath; 39 | 40 | private String thumbPath; 41 | private String thumbPathSmall; 42 | 43 | private ImageView imageViewThumbnail; 44 | 45 | private ImageView imageViewThumbSmall; 46 | 47 | private TextView textViewFile; 48 | 49 | private ProgressBar pbar; 50 | 51 | @Override 52 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 53 | Bundle savedInstanceState) { 54 | View view = inflater.inflate(R.layout.activity_image_chooser, null); 55 | Button buttonChooseImage = (Button) view 56 | .findViewById(R.id.buttonChooseImage); 57 | buttonChooseImage.setOnClickListener(new OnClickListener() { 58 | 59 | @Override 60 | public void onClick(View v) { 61 | chooseImage(); 62 | } 63 | }); 64 | 65 | Button buttonTakePicture = (Button) view.findViewById(R.id.buttonTakePicture); 66 | buttonTakePicture.setOnClickListener(new OnClickListener() { 67 | @Override 68 | public void onClick(View view) { 69 | takePicture(); 70 | } 71 | }); 72 | 73 | imageViewThumbnail = (ImageView) view.findViewById(R.id.imageViewThumb); 74 | imageViewThumbSmall = (ImageView) view.findViewById(R.id.imageViewThumbSmall); 75 | textViewFile = (TextView) view.findViewById(R.id.textViewFile); 76 | 77 | pbar = (ProgressBar) view.findViewById(R.id.progressBar); 78 | pbar.setVisibility(View.GONE); 79 | 80 | return view; 81 | } 82 | 83 | private void takePicture() { 84 | chooserType = ChooserType.REQUEST_CAPTURE_PICTURE; 85 | imageChooserManager = new ImageChooserManager(this, 86 | ChooserType.REQUEST_CAPTURE_PICTURE, true); 87 | imageChooserManager.setImageChooserListener(this); 88 | try { 89 | mediaPath = imageChooserManager.choose(); 90 | } catch (IllegalArgumentException e) { 91 | e.printStackTrace(); 92 | } catch (Exception e) { 93 | e.printStackTrace(); 94 | } 95 | } 96 | 97 | private void chooseImage() { 98 | chooserType = ChooserType.REQUEST_PICK_PICTURE; 99 | imageChooserManager = new ImageChooserManager(this, 100 | ChooserType.REQUEST_PICK_PICTURE, true); 101 | imageChooserManager.setImageChooserListener(this); 102 | try { 103 | mediaPath = imageChooserManager.choose(); 104 | } catch (IllegalArgumentException e) { 105 | e.printStackTrace(); 106 | } catch (Exception e) { 107 | e.printStackTrace(); 108 | } 109 | } 110 | 111 | @Override 112 | public void onActivityCreated(Bundle savedInstanceState) { 113 | super.onActivityCreated(savedInstanceState); 114 | if (savedInstanceState != null) { 115 | if (savedInstanceState.containsKey("media_path")) { 116 | mediaPath = savedInstanceState.getString("media_path"); 117 | } 118 | if (savedInstanceState.containsKey("chooser_type")) { 119 | chooserType = savedInstanceState.getInt("chooser_type"); 120 | } 121 | if (savedInstanceState.containsKey("final_path")) { 122 | finalPath = savedInstanceState.getString("final_path"); 123 | thumbPath = savedInstanceState.getString("thumb_path"); 124 | thumbPathSmall = savedInstanceState.getString("thumb_path_small"); 125 | textViewFile.setText(finalPath); 126 | imageViewThumbnail.setImageURI(Uri.parse(new File(thumbPath).toString())); 127 | imageViewThumbSmall.setImageURI(Uri.parse(new File(thumbPathSmall).toString())); 128 | } 129 | } 130 | 131 | Log.d(getClass().getName(), "onActivityCreated: " + mediaPath + " T: " + chooserType); 132 | } 133 | 134 | @Override 135 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 136 | Log.d(getClass().getName(), requestCode + ""); 137 | super.onActivityResult(requestCode, resultCode, data); 138 | if (resultCode == Activity.RESULT_OK) { 139 | if (imageChooserManager == null) { 140 | imageChooserManager = new ImageChooserManager(this, requestCode, true); 141 | imageChooserManager.setImageChooserListener(this); 142 | imageChooserManager.reinitialize(mediaPath); 143 | } 144 | imageChooserManager.submit(requestCode, data); 145 | } 146 | } 147 | 148 | private Activity activity; 149 | 150 | @Override 151 | public void onAttach(Activity activity) { 152 | super.onAttach(activity); 153 | this.activity = activity; 154 | Log.d(getClass().getName(), "onAttach: "); 155 | } 156 | 157 | @Override 158 | public void onImageChosen(final ChosenImage image) { 159 | Log.d(getClass().getName(), "onImageChosen: " + image.getFilePathOriginal()); 160 | finalPath = image.getFilePathOriginal(); 161 | thumbPath = image.getFileThumbnail(); 162 | thumbPathSmall = image.getFileThumbnailSmall(); 163 | this.activity.runOnUiThread(new Runnable() { 164 | 165 | @Override 166 | public void run() { 167 | pbar.setVisibility(View.GONE); 168 | if (image != null) { 169 | textViewFile.setText(image.getFilePathOriginal()); 170 | imageViewThumbnail.setImageURI(Uri.parse(new File(image 171 | .getFileThumbnail()).toString())); 172 | imageViewThumbSmall.setImageURI(Uri.parse(new File(image 173 | .getFileThumbnailSmall()).toString())); 174 | } 175 | } 176 | }); 177 | } 178 | 179 | @Override 180 | public void onError(final String reason) { 181 | getActivity().runOnUiThread(new Runnable() { 182 | 183 | @Override 184 | public void run() { 185 | pbar.setVisibility(View.GONE); 186 | Toast.makeText(ImageChooserFragment.this.getActivity(), reason, 187 | Toast.LENGTH_LONG).show(); 188 | } 189 | }); 190 | } 191 | 192 | @Override 193 | public void onImagesChosen(ChosenImages images) { 194 | 195 | } 196 | 197 | @Override 198 | public void onSaveInstanceState(Bundle outState) { 199 | super.onSaveInstanceState(outState); 200 | if (chooserType != 0) { 201 | outState.putInt("chooser_type", chooserType); 202 | } 203 | if (mediaPath != null) { 204 | outState.putString("media_path", mediaPath); 205 | } 206 | 207 | if (finalPath != null) { 208 | outState.putString("final_path", finalPath); 209 | outState.putString("thumb_path", thumbPath); 210 | outState.putString("thumb_path_small", thumbPathSmall); 211 | } 212 | } 213 | } 214 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coomar2841/image-chooser-library/17642ff04c1d0c58f54b6485bd183d9c17d83c60/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coomar2841/image-chooser-library/17642ff04c1d0c58f54b6485bd183d9c17d83c60/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coomar2841/image-chooser-library/17642ff04c1d0c58f54b6485bd183d9c17d83c60/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coomar2841/image-chooser-library/17642ff04c1d0c58f54b6485bd183d9c17d83c60/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/image_border.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/coomar2841/image-chooser-library/17642ff04c1d0c58f54b6485bd183d9c17d83c60/app/src/main/res/drawable/image_border.9.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_file_chooser.xml: -------------------------------------------------------------------------------- 1 | 9 | 10 | 22 | 23 |