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 |
34 |
35 |
42 |
43 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_home.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
17 |
18 |
27 |
28 |
39 |
40 |
50 |
51 |
60 |
61 |
69 |
70 |
76 |
77 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_image_chooser.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
20 |
21 |
32 |
33 |
41 |
42 |
51 |
52 |
58 |
59 |
65 |
66 |
67 |
74 |
75 |
81 |
82 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_media_chooser.xml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
18 |
19 |
29 |
30 |
36 |
37 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_video_chooser.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
15 |
16 |
24 |
25 |
32 |
33 |
40 |
41 |
42 |
51 |
52 |
61 |
62 |
69 |
70 |
77 |
78 |
79 |
87 |
88 |
94 |
95 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/ad_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_image_chooser_activity.xml:
--------------------------------------------------------------------------------
1 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ads.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | ca-app-pub-0799630550074661/9551745600
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Image Chooser App
5 | Image Chooser
6 | Video Chooser
7 | Pick Video or Image
8 | Pick a file
9 | Image Chooser (Fragment)
10 | Version 1.4.4
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/analytics.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 300
4 |
5 |
6 | false
7 | UA-58826399-6
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/app_tracker.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 300
5 |
6 |
7 | true
8 |
9 |
10 | UA-2507579-10
11 |
12 |
16 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | buildscript {
2 | repositories {
3 | jcenter()
4 | }
5 | dependencies {
6 | classpath 'com.android.tools.build:gradle:1.3.0'
7 |
8 | // NOTE: Do not place your application dependencies here; they belong
9 | // in the individual module build.gradle files
10 | }
11 | }
12 |
13 | // To avoid manually setting the same values in all Android modules, set the value on the root
14 | // project and then reference this from the modules
15 | ext {
16 | compileSdkVersion = 22
17 | targetSdkVersion = 22
18 | buildToolsVersion = "22.0.1"
19 | }
20 |
21 | allprojects {
22 | repositories {
23 | jcenter()
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/gradle-example.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Settings specified in this file will override any Gradle settings
5 | # configured through the IDE.
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 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
19 |
20 | signing.keyId=***
21 | signing.password=***
22 | signing.secretKeyRingFile=key-file.gpg
23 | sonatypeRepo=https://oss.sonatype.org/service/local/staging/deploy/maven2/
24 | sonatypeUsername=***
25 | sonatypePassword=***
26 |
27 | version=1.0.0
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/image-chooser-library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | key-file.gpg
3 | gradle.properties
--------------------------------------------------------------------------------
/image-chooser-library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'maven'
3 | apply plugin: 'signing'
4 |
5 | version = "1.6.0"
6 | group = "com.kbeanie"
7 |
8 | configurations {
9 | archives {
10 | extendsFrom configurations.default
11 | }
12 | }
13 |
14 | signing {
15 | required {
16 | has("release") && gradle.taskGraph.hasTask("uploadArchives")
17 | }
18 | sign configurations.archives
19 | }
20 |
21 | uploadArchives {
22 | configuration = configurations.archives
23 | repositories.mavenDeployer {
24 | beforeDeployment {
25 | MavenDeployment deployment -> signing.signPom(deployment)
26 | }
27 |
28 | pom.groupId = "com.kbeanie"
29 | pom.artifactId = "image-chooser-library"
30 | pom.version = version
31 |
32 | repository(url: sonatypeRepo) {
33 | authentication(userName: sonatypeUsername,
34 | password: sonatypePassword)
35 | }
36 |
37 | pom.project {
38 | name 'Image Chooser Library'
39 | packaging 'aar'
40 | description 'Image Chooser Library for Android Applications'
41 | url 'https://github.com/coomar2841/image-chooser-library'
42 |
43 | scm {
44 | url scmUrl
45 | connection scmUrl
46 | developerConnection scmUrl
47 | }
48 |
49 | licenses {
50 | license {
51 | name 'The Apache Software License, Version 2.0'
52 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
53 | distribution 'repo'
54 | }
55 | }
56 |
57 | developers {
58 | developer {
59 | id 'coomar2841'
60 | name 'Kumar Bibek'
61 | email 'coomar.101@gmail.com'
62 | }
63 | }
64 | }
65 | }
66 | }
67 |
68 | android {
69 | compileSdkVersion 23
70 | buildToolsVersion '23.0.2'
71 |
72 | defaultConfig {
73 | minSdkVersion 8
74 | targetSdkVersion rootProject.ext.targetSdkVersion
75 | versionCode 1
76 | versionName version
77 | }
78 | buildTypes {
79 | release {
80 | minifyEnabled false
81 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
82 | }
83 | }
84 |
85 | signingConfigs {
86 | debug {
87 | storeFile file("debug.keystore")
88 | }
89 | release {
90 | // keyAlias chooserReleaseKeyAlias
91 | // keyPassword chooserReleaseKeyPassword
92 | // storeFile file(chooserReleaseStoreFile)
93 | // storePassword chooserReleaseStorePassword
94 | }
95 | }
96 | }
97 |
98 | dependencies {
99 | compile fileTree(dir: 'libs', include: ['*.jar'])
100 | compile 'com.android.support:support-v4:23.2.1'
101 | }
102 |
--------------------------------------------------------------------------------
/image-chooser-library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in 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 |
--------------------------------------------------------------------------------
/image-chooser-library/src/androidTest/java/com/kbeanie/imagechooser/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.kbeanie.imagechooser;
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 | }
--------------------------------------------------------------------------------
/image-chooser-library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/image-chooser-library/src/main/java/com/kbeanie/imagechooser/api/BChooser.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.kbeanie.imagechooser.api;
20 |
21 | import java.io.File;
22 |
23 | import android.annotation.SuppressLint;
24 | import android.annotation.TargetApi;
25 | import android.app.Activity;
26 | import android.content.ContentResolver;
27 | import android.content.Context;
28 | import android.content.Intent;
29 | import android.database.Cursor;
30 | import android.net.Uri;
31 | import android.os.Build;
32 | import android.os.Bundle;
33 | import android.provider.OpenableColumns;
34 | import android.support.v4.app.Fragment;
35 |
36 | import com.kbeanie.imagechooser.exceptions.ChooserException;
37 | import com.kbeanie.imagechooser.factory.UriFactory;
38 |
39 | import static com.kbeanie.imagechooser.helpers.StreamHelper.closeSilent;
40 | import static com.kbeanie.imagechooser.helpers.StreamHelper.verifyCursor;
41 |
42 | public abstract class BChooser {
43 |
44 | static final String TAG = BChooser.class.getSimpleName();
45 |
46 | protected Activity activity;
47 |
48 | protected Fragment fragment;
49 |
50 | protected android.app.Fragment appFragment;
51 |
52 | protected int type;
53 |
54 | protected String foldername;
55 |
56 | protected boolean shouldCreateThumbnails;
57 |
58 | protected String filePathOriginal;
59 |
60 | protected Bundle extras;
61 |
62 | protected boolean clearOldFiles;
63 |
64 | @Deprecated
65 | public BChooser(Activity activity, int type, String folderName,
66 | boolean shouldCreateThumbnails) {
67 | this.activity = activity;
68 | this.type = type;
69 | this.foldername = folderName;
70 | this.shouldCreateThumbnails = shouldCreateThumbnails;
71 | }
72 |
73 | @Deprecated
74 | public BChooser(Fragment fragment, int type, String foldername,
75 | boolean shouldCreateThumbnails) {
76 | this.fragment = fragment;
77 | this.type = type;
78 | this.foldername = foldername;
79 | this.shouldCreateThumbnails = shouldCreateThumbnails;
80 | }
81 |
82 | @Deprecated
83 | public BChooser(android.app.Fragment fragment, int type, String foldername,
84 | boolean shouldCreateThumbnails) {
85 | this.appFragment = fragment;
86 | this.type = type;
87 | this.foldername = foldername;
88 | this.shouldCreateThumbnails = shouldCreateThumbnails;
89 | }
90 |
91 | public BChooser(Activity activity, int type,
92 | boolean shouldCreateThumbnails) {
93 | this.activity = activity;
94 | this.type = type;
95 | this.shouldCreateThumbnails = shouldCreateThumbnails;
96 | initDirectory(activity.getApplicationContext());
97 | }
98 |
99 | public BChooser(Fragment fragment, int type,
100 | boolean shouldCreateThumbnails) {
101 | this.fragment = fragment;
102 | this.type = type;
103 | this.shouldCreateThumbnails = shouldCreateThumbnails;
104 | initDirectory(fragment.getActivity().getApplicationContext());
105 | }
106 |
107 | @TargetApi(Build.VERSION_CODES.HONEYCOMB)
108 | public BChooser(android.app.Fragment fragment, int type,
109 | boolean shouldCreateThumbnails) {
110 | this.appFragment = fragment;
111 | this.type = type;
112 | this.shouldCreateThumbnails = shouldCreateThumbnails;
113 | initDirectory(fragment.getActivity().getApplicationContext());
114 | }
115 |
116 | /**
117 | * Call this method, to start the chooser, i.e, The camera app or the
118 | * gallery depending upon the type.
119 | *
120 | * Returns the path, in case, a capture is requested. You will need to save
121 | * this path, so that, in case, the ChooserManager is destoryed due to
122 | * activity lifecycle, you will use this information to create the
123 | * ChooserManager instance again
124 | *
125 | *
126 | * In case of picking a video or image, null would be returned.
127 | *
128 | *
129 | * @throws IllegalArgumentException
130 | * @throws Exception
131 | */
132 | public abstract String choose() throws ChooserException;
133 |
134 | /**
135 | * Call this method to process the result from within your onActivityResult
136 | * method. You don't need to do any processing at all. Just pass in the
137 | * request code and the data, and everything else will be taken care of.
138 | *
139 | * @param requestCode
140 | * @param data
141 | */
142 | public abstract void submit(int requestCode, Intent data);
143 |
144 | protected void checkDirectory() throws ChooserException {
145 | File directory;
146 | directory = new File(FileUtils.getDirectory(foldername));
147 | if (!directory.exists()) {
148 | if (!directory.mkdirs() && !directory.isDirectory()) {
149 | throw new ChooserException("Error creating directory: " + directory);
150 | }
151 | }
152 | }
153 |
154 | @SuppressLint("NewApi")
155 | protected void startActivity(Intent intent) {
156 | if (activity != null) {
157 | activity.startActivityForResult(intent, type);
158 | } else if (fragment != null) {
159 | fragment.startActivityForResult(intent, type);
160 | } else if (appFragment != null) {
161 | appFragment.startActivityForResult(intent, type);
162 | }
163 | }
164 |
165 | /**
166 | * This method should be used to re-initialize the ChooserManagers in case your activity of
167 | * fragments are destroyed for some reason, and you need to recreate this object in onActivityResult
168 | *
169 | * @param path
170 | */
171 | public void reinitialize(String path) {
172 | filePathOriginal = path;
173 | }
174 |
175 | // Change the URI only when the returned string contains "file:/" prefix.
176 | // For all the other situations the URI doesn't need to be changed
177 | protected void sanitizeURI(String uri) {
178 | filePathOriginal = uri;
179 | // Picasa on Android < 3.0
180 | if (uri.matches("https?://\\w+\\.googleusercontent\\.com/.+")) {
181 | filePathOriginal = uri;
182 | }
183 | // Local storage
184 | if (uri.startsWith("file://")) {
185 | filePathOriginal = uri.substring(7);
186 | }
187 | }
188 |
189 | @SuppressLint("NewApi")
190 | protected Context getContext() {
191 | if (activity != null) {
192 | return activity.getApplicationContext();
193 | } else if (fragment != null) {
194 | return fragment.getActivity().getApplicationContext();
195 | } else if (appFragment != null) {
196 | return appFragment.getActivity().getApplicationContext();
197 | }
198 | return null;
199 | }
200 |
201 | protected boolean wasVideoSelected(Intent data) {
202 | if (data == null) {
203 | return false;
204 | }
205 |
206 | if (data.getType() != null && data.getType().startsWith("video")) {
207 | return true;
208 | }
209 |
210 | ContentResolver cR = getContext().getContentResolver();
211 | String type = cR.getType(data.getData());
212 | return type != null && type.startsWith("video");
213 |
214 | }
215 |
216 | public void setExtras(Bundle extras) {
217 | this.extras = extras;
218 | }
219 |
220 | public Bundle getExtras() {
221 | return this.extras;
222 | }
223 |
224 | /**
225 | * Utility method which quickly looks up the file size. Use this, if you want to set a limit to
226 | * the media chosen, and which your application can safely handle.
227 | *
228 | * For example, you might not want a video of 1 GB to be imported into your app.
229 | *
230 | * @param uri
231 | * @param context
232 | * @return
233 | */
234 | public long queryProbableFileSize(Uri uri, Context context) {
235 |
236 | if (uri.toString().startsWith("file")) {
237 | File file = new File(uri.getPath());
238 | return file.length();
239 | } else if (uri.toString().startsWith("content")) {
240 | Cursor cursor = null;
241 | try {
242 | cursor = context.getContentResolver().query(uri, null, null, null, null);
243 | verifyCursor(uri, cursor);
244 | if (cursor.moveToFirst()) {
245 | return cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
246 | }
247 | return 0;
248 | } catch (ChooserException e) {
249 | return 0;
250 | } finally {
251 | closeSilent(cursor);
252 | }
253 | }
254 |
255 | return 0;
256 | }
257 |
258 | private void initDirectory(Context context) {
259 | BChooserPreferences preferences = new BChooserPreferences(context);
260 | foldername = preferences.getFolderName();
261 | }
262 |
263 | protected String buildFilePathOriginal(String foldername, String extension) {
264 | return UriFactory.getInstance().getFilePathOriginal(foldername, extension);
265 | }
266 |
267 | protected Uri buildCaptureUri(String filePathOriginal) {
268 | return Uri.fromFile(new File(filePathOriginal));
269 | }
270 |
271 | public void clearOldFiles() {
272 | this.clearOldFiles = true;
273 | }
274 | }
275 |
--------------------------------------------------------------------------------
/image-chooser-library/src/main/java/com/kbeanie/imagechooser/api/BChooserPreferences.java:
--------------------------------------------------------------------------------
1 | package com.kbeanie.imagechooser.api;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 |
6 | /**
7 | * Preferences for ICL
8 | * Created by kbibek on 5/22/15.
9 | */
10 | public class BChooserPreferences {
11 | private final static String FILE = "b_chooser_prefs";
12 | private final static String FOLDER_NAME = "folder_name";
13 | private SharedPreferences preferences;
14 |
15 | public BChooserPreferences(Context context) {
16 | preferences = context.getSharedPreferences(FILE, Context.MODE_PRIVATE);
17 | }
18 |
19 | /**
20 | * Set the folder name to be used for all files or temporary files
21 | * @param folderName
22 | */
23 | public void setFolderName(String folderName){
24 | SharedPreferences.Editor editor = preferences.edit();
25 | editor.putString(FOLDER_NAME, folderName);
26 | editor.commit();
27 | }
28 |
29 | public String getFolderName(){
30 | return preferences.getString(FOLDER_NAME, "bichooser");
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/image-chooser-library/src/main/java/com/kbeanie/imagechooser/api/ChooserType.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright 2013 Kumar Bibek
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *******************************************************************************/
16 | package com.kbeanie.imagechooser.api;
17 |
18 | public interface ChooserType {
19 | int REQUEST_PICK_PICTURE = 291;
20 |
21 | int REQUEST_CAPTURE_PICTURE = 294;
22 |
23 | int REQUEST_CAPTURE_VIDEO = 292;
24 |
25 | int REQUEST_PICK_VIDEO = 295;
26 |
27 | int REQUEST_PICK_PICTURE_OR_VIDEO = 300;
28 |
29 | int REQUEST_PICK_FILE = 500;
30 | }
31 |
--------------------------------------------------------------------------------
/image-chooser-library/src/main/java/com/kbeanie/imagechooser/api/ChosenFile.java:
--------------------------------------------------------------------------------
1 | package com.kbeanie.imagechooser.api;
2 |
3 | /**
4 | * Created by kbibek on 14/11/14.
5 | */
6 | public class ChosenFile {
7 | private String filePath;
8 | private String mimeType;
9 | private String fileName;
10 | private long fileSize;
11 | private String extension;
12 |
13 | public String getFilePath() {
14 | return filePath;
15 | }
16 |
17 | public void setFilePath(String filePath) {
18 | this.filePath = filePath;
19 | }
20 |
21 | public String getFileName() {
22 | return fileName;
23 | }
24 |
25 | public void setFileName(String fileName) {
26 | this.fileName = fileName;
27 | }
28 |
29 | public long getFileSize() {
30 | return fileSize;
31 | }
32 |
33 | public void setFileSize(long fileSize) {
34 | this.fileSize = fileSize;
35 | }
36 |
37 | public String getMimeType() {
38 | if (mimeType == null) {
39 | for (String ext : imagesExtensions) {
40 | if (extension.startsWith(ext)) {
41 | mimeType = "image";
42 | break;
43 | }
44 | }
45 | if (mimeType == null) {
46 | for (String ext : videoExtensions) {
47 | if (extension.startsWith(ext)) {
48 | mimeType = "video";
49 | break;
50 | }
51 | }
52 | }
53 | }
54 | return mimeType;
55 | }
56 |
57 | public void setMimeType(String mimeType) {
58 | this.mimeType = mimeType;
59 | }
60 |
61 | public String getExtension() {
62 | return extension;
63 | }
64 |
65 | public void setExtension(String extension) {
66 | this.extension = extension;
67 | }
68 |
69 | private String[] imagesExtensions = {".jpg", ".jpeg", ".bpm", ".png", "gif"};
70 | private String[] videoExtensions = {".mp4", ".mpeg", ".3gp"};
71 | }
72 |
--------------------------------------------------------------------------------
/image-chooser-library/src/main/java/com/kbeanie/imagechooser/api/ChosenImage.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright 2013 Kumar Bibek
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *******************************************************************************/
16 |
17 | package com.kbeanie.imagechooser.api;
18 |
19 |
20 | public class ChosenImage extends ChosenMedia {
21 | private String filePathOriginal;
22 |
23 | private String fileThumbnail;
24 |
25 | private String fileThumbnailSmall;
26 |
27 | public String getFilePathOriginal() {
28 | return filePathOriginal;
29 | }
30 |
31 | public void setFilePathOriginal(String filePathOriginal) {
32 | this.filePathOriginal = filePathOriginal;
33 | }
34 |
35 | public String getFileThumbnail() {
36 | return fileThumbnail;
37 | }
38 |
39 | public void setFileThumbnail(String fileThumbnail) {
40 | this.fileThumbnail = fileThumbnail;
41 | }
42 |
43 | public String getFileThumbnailSmall() {
44 | return fileThumbnailSmall;
45 | }
46 |
47 | public void setFileThumbnailSmall(String fileThumbnailSmall) {
48 | this.fileThumbnailSmall = fileThumbnailSmall;
49 | }
50 |
51 | @Override
52 | public String getMediaHeight() {
53 | return getHeight(filePathOriginal);
54 | }
55 |
56 | @Override
57 | public String getMediaWidth() {
58 | return getWidth(filePathOriginal);
59 | }
60 |
61 | public String getExtension(){
62 | return getFileExtension(filePathOriginal);
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/image-chooser-library/src/main/java/com/kbeanie/imagechooser/api/ChosenImages.java:
--------------------------------------------------------------------------------
1 | package com.kbeanie.imagechooser.api;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * Created by kbibek on 2/11/16.
8 | */
9 | public class ChosenImages {
10 | private List images;
11 |
12 | public ChosenImages() {
13 | this.images = new ArrayList<>();
14 | }
15 |
16 | public void addImage(ChosenImage image) {
17 | this.images.add(image);
18 | }
19 |
20 | public int size(){
21 | return images.size();
22 | }
23 |
24 | public ChosenImage getImage(int index){
25 | return images.get(index);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/image-chooser-library/src/main/java/com/kbeanie/imagechooser/api/ChosenMedia.java:
--------------------------------------------------------------------------------
1 |
2 | package com.kbeanie.imagechooser.api;
3 |
4 | import java.io.File;
5 | import java.io.FileInputStream;
6 | import java.io.FileNotFoundException;
7 | import java.io.IOException;
8 | import java.lang.ref.SoftReference;
9 |
10 | import android.graphics.Bitmap;
11 | import android.graphics.BitmapFactory;
12 | import android.media.ExifInterface;
13 |
14 | public abstract class ChosenMedia {
15 |
16 | protected SoftReference getBitmap(String path) {
17 | SoftReference bitmap = null;
18 | try {
19 | bitmap = new SoftReference(BitmapFactory.decodeStream(new FileInputStream(
20 | new File(path))));
21 |
22 | } catch (FileNotFoundException e) {
23 | e.printStackTrace();
24 | }
25 | return bitmap;
26 | }
27 |
28 | public String getFileExtension(String path) {
29 | return FileUtils.getFileExtension(path);
30 | }
31 |
32 | protected String getWidth(String path){
33 | String width = "";
34 | try {
35 | ExifInterface exif = new ExifInterface(path);
36 | width = exif.getAttribute(ExifInterface.TAG_IMAGE_WIDTH);
37 | if (width.equals("0")) {
38 | width = Integer.toString(getBitmap(path).get().getWidth());
39 | }
40 | } catch (IOException e) {
41 | e.printStackTrace();
42 | }
43 | return width;
44 | }
45 |
46 | protected String getHeight(String path){
47 | String height = "";
48 | try {
49 | ExifInterface exif = new ExifInterface(path);
50 | height = exif.getAttribute(ExifInterface.TAG_IMAGE_LENGTH);
51 | if (height.equals("0")) {
52 | height = Integer.toString(getBitmap(path).get().getHeight());
53 | }
54 | } catch (IOException e) {
55 | e.printStackTrace();
56 | }
57 | return height;
58 | }
59 |
60 | public abstract String getMediaHeight();
61 |
62 | public abstract String getMediaWidth();
63 | }
64 |
--------------------------------------------------------------------------------
/image-chooser-library/src/main/java/com/kbeanie/imagechooser/api/ChosenVideo.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright 2013 Kumar Bibek
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *******************************************************************************/
16 |
17 | package com.kbeanie.imagechooser.api;
18 |
19 | public class ChosenVideo extends ChosenMedia {
20 |
21 | String videoPreviewImage;
22 |
23 | String videoFilePath;
24 |
25 | private String thumbnailPath;
26 |
27 | private String thumbnailSmallPath;
28 |
29 | public String getVideoFilePath() {
30 | return videoFilePath;
31 | }
32 |
33 | public void setVideoFilePath(String videoFilePath) {
34 | this.videoFilePath = videoFilePath;
35 | }
36 |
37 | public String getThumbnailPath() {
38 | return thumbnailPath;
39 | }
40 |
41 | public void setThumbnailPath(String thumbnailPath) {
42 | this.thumbnailPath = thumbnailPath;
43 | }
44 |
45 | public String getThumbnailSmallPath() {
46 | return thumbnailSmallPath;
47 | }
48 |
49 | public void setThumbnailSmallPath(String thumbnailSmallPath) {
50 | this.thumbnailSmallPath = thumbnailSmallPath;
51 | }
52 |
53 | public String getVideoPreviewImage() {
54 | return videoPreviewImage;
55 | }
56 |
57 | public void setVideoPreviewImage(String videoPreviewImage) {
58 | this.videoPreviewImage = videoPreviewImage;
59 | }
60 |
61 | @Override
62 | public String getMediaHeight() {
63 | return getHeight(videoPreviewImage);
64 | }
65 |
66 | @Override
67 | public String getMediaWidth() {
68 | return getWidth(videoPreviewImage);
69 | }
70 |
71 | public String getExtension() {
72 | return getFileExtension(videoFilePath);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/image-chooser-library/src/main/java/com/kbeanie/imagechooser/api/ChosenVideos.java:
--------------------------------------------------------------------------------
1 | package com.kbeanie.imagechooser.api;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * Created by kbibek on 2/12/16.
8 | */
9 | public class ChosenVideos {
10 | private List videos;
11 |
12 | public ChosenVideos() {
13 | this.videos = new ArrayList<>();
14 | }
15 |
16 | public void addVideo(ChosenVideo video) {
17 | this.videos.add(video);
18 | }
19 |
20 | public int size(){
21 | return videos.size();
22 | }
23 |
24 | public ChosenVideo getImage(int index){
25 | return videos.get(index);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/image-chooser-library/src/main/java/com/kbeanie/imagechooser/api/FileChooserListener.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright 2013 Kumar Bibek
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *******************************************************************************/
16 |
17 | package com.kbeanie.imagechooser.api;
18 |
19 | public interface FileChooserListener {
20 | /**
21 | * When the processing is complete, you will receive this callback with
22 | * {@link com.kbeanie.imagechooser.api.ChosenImage}
23 | *
24 | * @param file
25 | */
26 | public void onFileChosen(ChosenFile file);
27 |
28 | /**
29 | * Handle any error conditions if at all, when you receieve this callback
30 | *
31 | * @param reason
32 | */
33 | public void onError(String reason);
34 | }
35 |
--------------------------------------------------------------------------------
/image-chooser-library/src/main/java/com/kbeanie/imagechooser/api/FileChooserManager.java:
--------------------------------------------------------------------------------
1 | package com.kbeanie.imagechooser.api;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Activity;
5 | import android.content.ActivityNotFoundException;
6 | import android.content.Intent;
7 | import android.os.Build;
8 | import android.support.v4.app.Fragment;
9 |
10 | import com.kbeanie.imagechooser.exceptions.ChooserException;
11 | import com.kbeanie.imagechooser.threads.FileProcessorListener;
12 | import com.kbeanie.imagechooser.threads.FileProcessorThread;
13 |
14 | /**
15 | * Created by kbibek on 14/11/14.
16 | */
17 | public class FileChooserManager extends MediaChooserManager implements FileProcessorListener {
18 |
19 | private final static String TAG = FileChooserManager.class.getSimpleName();
20 |
21 | private FileChooserListener listener;
22 |
23 | private String mimeType;
24 |
25 | public FileChooserManager(Activity activity) {
26 | super(activity, ChooserType.REQUEST_PICK_FILE);
27 | }
28 |
29 | public FileChooserManager(Fragment fragment) {
30 | super(fragment, ChooserType.REQUEST_PICK_FILE);
31 | }
32 |
33 | public FileChooserManager(android.app.Fragment fragment) {
34 | super(fragment, ChooserType.REQUEST_PICK_FILE);
35 | }
36 |
37 | public FileChooserManager(Activity activity, String foldername) {
38 | super(activity, ChooserType.REQUEST_PICK_FILE, foldername);
39 | }
40 |
41 | public FileChooserManager(Fragment fragment, String foldername) {
42 | super(fragment, ChooserType.REQUEST_PICK_FILE, foldername);
43 | }
44 |
45 | public FileChooserManager(android.app.Fragment fragment, String foldername) {
46 | super(fragment, ChooserType.REQUEST_PICK_FILE, foldername);
47 | }
48 |
49 | public FileChooserManager(Activity activity, boolean shouldCreateThumbnails) {
50 | super(activity, ChooserType.REQUEST_PICK_FILE, shouldCreateThumbnails);
51 | }
52 |
53 | public FileChooserManager(Fragment fragment, boolean shouldCreateThumbnails) {
54 | super(fragment, ChooserType.REQUEST_PICK_FILE, shouldCreateThumbnails);
55 | }
56 |
57 | public FileChooserManager(android.app.Fragment fragment, boolean shouldCreateThumbnails) {
58 | super(fragment, ChooserType.REQUEST_PICK_FILE, shouldCreateThumbnails);
59 | }
60 |
61 | public FileChooserManager(Activity activity, String foldername, boolean shouldCreateThumbnails) {
62 | super(activity, ChooserType.REQUEST_PICK_FILE, foldername, shouldCreateThumbnails);
63 | }
64 |
65 | public FileChooserManager(Fragment fragment, String foldername, boolean shouldCreateThumbnails) {
66 | super(fragment, ChooserType.REQUEST_PICK_FILE, foldername, shouldCreateThumbnails);
67 | }
68 |
69 | public FileChooserManager(android.app.Fragment fragment, String foldername, boolean shouldCreateThumbnails) {
70 | super(fragment, ChooserType.REQUEST_PICK_FILE, foldername, shouldCreateThumbnails);
71 | }
72 |
73 | public void setFileChooserListener(FileChooserListener listener) {
74 | this.listener = listener;
75 | }
76 |
77 | public void setMimeType(String mimeType) {
78 | this.mimeType = mimeType;
79 | }
80 |
81 | @Override
82 | public String choose() throws ChooserException {
83 | if (listener == null) {
84 | throw new IllegalArgumentException(
85 | "FileChooserListener cannot be null. Forgot to set FileChooserListener???");
86 | }
87 | if (mimeType == null) {
88 | mimeType = "*/*";
89 | }
90 | String action = Intent.ACTION_GET_CONTENT;
91 | try {
92 | Intent intent = new Intent(action);
93 | intent.setType(mimeType);
94 | intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
95 | intent.addCategory(Intent.CATEGORY_OPENABLE);
96 | startActivity(intent);
97 | } catch (ActivityNotFoundException e) {
98 | throw new ChooserException(e);
99 | }
100 | return null;
101 | }
102 |
103 | @Override
104 | public void submit(int requestCode, Intent data) {
105 | try {
106 | if (requestCode != type) {
107 | onError("onActivityResult requestCode is different from the type the chooser was initialized with.");
108 | } else {
109 | processFile(data);
110 | }
111 | } catch (Exception e) {
112 | onError(e.getMessage());
113 | }
114 | }
115 |
116 | @TargetApi(Build.VERSION_CODES.HONEYCOMB)
117 | private void processFile(Intent data) {
118 | String dataString = data.getDataString();
119 |
120 | FileProcessorThread thread = new FileProcessorThread(dataString,
121 | foldername, shouldCreateThumbnails);
122 | thread.clearOldFiles(clearOldFiles);
123 | thread.setListener(this);
124 | if (activity != null) {
125 | thread.setContext(activity.getApplicationContext());
126 | } else if (fragment != null) {
127 | thread.setContext(fragment.getActivity()
128 | .getApplicationContext());
129 | } else if (appFragment != null) {
130 | thread.setContext(appFragment.getActivity()
131 | .getApplicationContext());
132 | }
133 | thread.start();
134 | }
135 |
136 | @Override
137 | public void onProcessedFile(ChosenFile file) {
138 | if (listener != null) {
139 | listener.onFileChosen(file);
140 | }
141 | }
142 |
143 | @Override
144 | public void onError(String reason) {
145 | super.onError(reason);
146 | if (listener != null) {
147 | listener.onError(reason);
148 | }
149 | }
150 | }
151 |
--------------------------------------------------------------------------------
/image-chooser-library/src/main/java/com/kbeanie/imagechooser/api/FileUtils.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright 2013 Kumar Bibek
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *******************************************************************************/
16 |
17 | package com.kbeanie.imagechooser.api;
18 |
19 | import java.io.File;
20 |
21 | import android.os.Environment;
22 |
23 | public class FileUtils {
24 | /**
25 | * Returns the path of the folder specified in external storage
26 | * @param foldername
27 | * @return
28 | */
29 | public static String getDirectory(String foldername) {
30 | File directory = null;
31 | directory = new File(Environment.getExternalStorageDirectory().getAbsolutePath()
32 | + File.separator + foldername);
33 | if (!directory.exists()) {
34 | directory.mkdirs();
35 | }
36 | return directory.getAbsolutePath();
37 | }
38 |
39 | public static String getFileExtension(String filename) {
40 | String extension = "";
41 | try {
42 | extension = filename.substring(filename.lastIndexOf(".") + 1);
43 | } catch (Exception e) {
44 | e.printStackTrace();
45 | }
46 | return extension;
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/image-chooser-library/src/main/java/com/kbeanie/imagechooser/api/ImageChooserListener.java:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright 2013 Kumar Bibek
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | *******************************************************************************/
16 |
17 | package com.kbeanie.imagechooser.api;
18 |
19 | public interface ImageChooserListener {
20 | /**
21 | * When the processing is complete, you will receive this callback with
22 | * {@link ChosenImage}
23 | *
24 | * @param image
25 | */
26 | void onImageChosen(ChosenImage image);
27 |
28 | /**
29 | * Handle any error conditions if at all, when you receieve this callback
30 | *
31 | * @param reason
32 | */
33 | void onError(String reason);
34 |
35 |
36 | /**
37 | * Callback when multiple images are chosen
38 | * @param images
39 | */
40 | void onImagesChosen(ChosenImages images);
41 | }
42 |
--------------------------------------------------------------------------------
/image-chooser-library/src/main/java/com/kbeanie/imagechooser/api/ImageChooserManager.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.kbeanie.imagechooser.api;
20 |
21 | import android.annotation.SuppressLint;
22 | import android.app.Activity;
23 | import android.content.ActivityNotFoundException;
24 | import android.content.ClipData;
25 | import android.content.Intent;
26 | import android.net.Uri;
27 | import android.os.Parcelable;
28 | import android.provider.MediaStore;
29 | import android.support.v4.app.Fragment;
30 | import android.text.TextUtils;
31 | import android.util.Log;
32 |
33 | import com.kbeanie.imagechooser.BuildConfig;
34 | import com.kbeanie.imagechooser.exceptions.ChooserException;
35 | import com.kbeanie.imagechooser.threads.ImageProcessorListener;
36 | import com.kbeanie.imagechooser.threads.ImageProcessorThread;
37 |
38 | import java.util.ArrayList;
39 |
40 | /**
41 | * Easy Image Chooser Library for Android Apps. Forget about coding workarounds
42 | * for different devices, OSes and folders.
43 | *
44 | * @author Beanie
45 | */
46 | public class ImageChooserManager extends BChooser implements
47 | ImageProcessorListener {
48 |
49 | private final static String TAG = ImageChooserManager.class.getSimpleName();
50 |
51 | private ImageChooserListener listener;
52 |
53 | /**
54 | * Simplest constructor. Specify the type
55 | * {@link ChooserType}
56 | *
57 | * @param activity
58 | * @param type
59 | */
60 | public ImageChooserManager(Activity activity, int type) {
61 | super(activity, type, true);
62 | }
63 |
64 | /**
65 | * Simple constructor for using with a fragment from the support library
66 | *
67 | * @param fragment
68 | * @param type
69 | */
70 | public ImageChooserManager(Fragment fragment, int type) {
71 | super(fragment, type, true);
72 | }
73 |
74 | /**
75 | * Simple constructor for using with a fragment
76 | *
77 | * @param fragment
78 | * @param type
79 | */
80 | public ImageChooserManager(android.app.Fragment fragment, int type) {
81 | super(fragment, type, true);
82 | }
83 |
84 | /**
85 | * Specify the type {@link ChooserType}
86 | *
87 | * Optionally, you can control where the exported images with their
88 | * thumbnails would be stored.
89 | *
90 | *
91 | * @param activity
92 | * @param type
93 | * @param folderName
94 | * @deprecated Use BChooserPreferences to set your desired folder name
95 | */
96 | @Deprecated
97 | public ImageChooserManager(Activity activity, int type, String folderName) {
98 | super(activity, type, folderName, true);
99 | }
100 |
101 | /**
102 | * @param fragment
103 | * @param type
104 | * @param folderName
105 | * @deprecated Use BChooserPreferences to set your desired folder name
106 | */
107 | @Deprecated
108 | public ImageChooserManager(Fragment fragment, int type, String folderName) {
109 | super(fragment, type, folderName, true);
110 | }
111 |
112 | /**
113 | * @param fragment
114 | * @param type
115 | * @param folderName
116 | * @deprecated Use BChooserPreferences to set your desired folder name
117 | */
118 | @Deprecated
119 | public ImageChooserManager(android.app.Fragment fragment, int type,
120 | String folderName) {
121 | super(fragment, type, folderName, true);
122 | }
123 |
124 | /**
125 | * Specify the type {@link ChooserType}
126 | *
127 | * Optionally, you can set whether you need thumbnail generation or not. If
128 | * not, you would get the original image for the thumbnails as well
129 | *
96 | * Optionally, you can set whether you need thumbnail generation or not. If
97 | * not, you would get the original image for the thumbnails as well
98 | *