parent
d6157f2df9
commit
14e85727cd
|
|
@ -44,5 +44,5 @@ dependencies {
|
|||
compile project(':library')
|
||||
|
||||
// Image loading sample
|
||||
compile 'com.github.bumptech.glide:glide:3.5.2'
|
||||
compile 'com.github.bumptech.glide:glide:3.6.1'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@
|
|||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.nononsenseapps.filepicker.sample.ImagePickerActivity"
|
||||
android:name=".MultimediaPickerActivity"
|
||||
android:label="@string/title_activity_no_nonsense_file_picker"
|
||||
android:theme="@style/SampleTheme">
|
||||
<intent-filter>
|
||||
|
|
@ -74,7 +74,7 @@
|
|||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.nononsenseapps.filepicker.sample.ImagePickerActivity2"
|
||||
android:name=".MultimediaPickerActivity2"
|
||||
android:label="@string/title_activity_no_nonsense_file_picker"
|
||||
android:theme="@style/SampleThemeLight">
|
||||
<intent-filter>
|
||||
|
|
|
|||
|
|
@ -27,9 +27,9 @@ import java.io.File;
|
|||
/**
|
||||
* All this class does is return a suitable fragment.
|
||||
*/
|
||||
public class ImagePickerActivity extends AbstractFilePickerActivity {
|
||||
public class MultimediaPickerActivity extends AbstractFilePickerActivity {
|
||||
|
||||
public ImagePickerActivity() {
|
||||
public MultimediaPickerActivity() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +37,7 @@ public class ImagePickerActivity extends AbstractFilePickerActivity {
|
|||
protected AbstractFilePickerFragment<File> getFragment(
|
||||
final String startPath, final int mode, final boolean allowMultiple,
|
||||
final boolean allowCreateDir) {
|
||||
AbstractFilePickerFragment<File> fragment = new ImagePickerFragment();
|
||||
AbstractFilePickerFragment<File> fragment = new MultimediaPickerFragment();
|
||||
// startPath is allowed to be null. In that case, default folder should be SD-card and not "/"
|
||||
fragment.setArgs(startPath != null ? startPath : Environment.getExternalStorageDirectory().getPath(),
|
||||
mode, allowMultiple, allowCreateDir);
|
||||
|
|
@ -20,5 +20,5 @@ package com.nononsenseapps.filepicker.sample;
|
|||
/**
|
||||
* Duplicate to allow second theme to be used.
|
||||
*/
|
||||
public class ImagePickerActivity2 extends ImagePickerActivity {
|
||||
public class MultimediaPickerActivity2 extends MultimediaPickerActivity {
|
||||
}
|
||||
|
|
@ -28,16 +28,16 @@ import java.io.File;
|
|||
/**
|
||||
* A sample which demonstrates how appropriate methods
|
||||
* can be overwritten in order to enable enhanced
|
||||
* capabilities, in this case showing thumbnails of images.
|
||||
* capabilities, in this case showing thumbnails of images and thumbnail of videos.
|
||||
* <p/>
|
||||
* I am still listing all files, so I extend from the ready made
|
||||
* SD-card browser classes. This allows this class to focus
|
||||
* entirely on the image side of things.
|
||||
*
|
||||
* <p/>
|
||||
* To load the image I am using the super great Glide library
|
||||
* which only requires a single line of code in this file.
|
||||
*/
|
||||
public class ImagePickerFragment extends FilePickerFragment {
|
||||
public class MultimediaPickerFragment extends FilePickerFragment {
|
||||
|
||||
/**
|
||||
* An extremely simple method for identifying images. This
|
||||
|
|
@ -60,7 +60,22 @@ public class ImagePickerFragment extends FilePickerFragment {
|
|||
}
|
||||
|
||||
/**
|
||||
* Overriding this method allows us to inject a preview image
|
||||
* An extremely simple method for identifying videos. This
|
||||
* could be improved, but it's good enough for this example.
|
||||
*
|
||||
* @param file which could be an video
|
||||
* @return true if the file can be previewed, false otherwise
|
||||
*/
|
||||
private boolean isVideo(File file) {
|
||||
if (isDir(file)) {
|
||||
return false;
|
||||
}
|
||||
return file.getPath().endsWith(".mp4")||
|
||||
file.getPath().endsWith(".MP4");
|
||||
}
|
||||
|
||||
/**
|
||||
* Overriding this method allows us to inject a preview image and thumbnail of videos
|
||||
* in the layout
|
||||
*
|
||||
* @param vh to bind data from either a file or directory
|
||||
|
|
@ -78,6 +93,10 @@ public class ImagePickerFragment extends FilePickerFragment {
|
|||
if (isImage(file)) {
|
||||
vh.icon.setVisibility(View.VISIBLE);
|
||||
Glide.with(this).load(file).centerCrop().into((ImageView) vh.icon);
|
||||
} else if (isVideo(file)) {
|
||||
vh.icon.setVisibility(View.VISIBLE);
|
||||
Glide.with(this).load(file).centerCrop().into((ImageView) vh.icon);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -115,10 +115,10 @@ public class NoNonsenseFilePicker extends Activity {
|
|||
|
||||
if (checkLightTheme.isChecked()) {
|
||||
i = new Intent(NoNonsenseFilePicker.this,
|
||||
ImagePickerActivity2.class);
|
||||
MultimediaPickerActivity2.class);
|
||||
} else {
|
||||
i = new Intent(NoNonsenseFilePicker.this,
|
||||
ImagePickerActivity.class);
|
||||
MultimediaPickerActivity.class);
|
||||
}
|
||||
i.setAction(Intent.ACTION_GET_CONTENT);
|
||||
|
||||
|
|
|
|||
|
|
@ -125,7 +125,7 @@
|
|||
<Button
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:text="Pick SD-card with image preview"
|
||||
android:text="Pick SD-card with multimedia preview"
|
||||
android:layout_marginTop="16dp"
|
||||
android:id="@+id/button_image"
|
||||
android:gravity="center"
|
||||
|
|
|
|||
Loading…
Reference in New Issue