Skip to content

Commit e56bc0d

Browse files
committed
Merge branch 'lolevsky-master'
2 parents b1a2f1f + f45ea99 commit e56bc0d

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

library/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
<uses-sdk
88
android:minSdkVersion="5"
9-
android:targetSdkVersion="16" />
9+
android:targetSdkVersion="19" />
1010

1111
</manifest>

library/src/com/nostra13/universalimageloader/core/download/BaseImageDownloader.java

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717

1818
import android.content.ContentResolver;
1919
import android.content.Context;
20+
import android.graphics.Bitmap;
21+
import android.graphics.Bitmap.CompressFormat;
2022
import android.net.Uri;
21-
import android.provider.ContactsContract;
22-
23+
import android.provider.MediaStore;
2324
import com.nostra13.universalimageloader.core.DisplayImageOptions;
2425
import com.nostra13.universalimageloader.core.assist.ContentLengthInputStream;
2526
import com.nostra13.universalimageloader.utils.IoUtils;
2627

2728
import java.io.BufferedInputStream;
29+
import java.io.ByteArrayInputStream;
30+
import java.io.ByteArrayOutputStream;
2831
import java.io.File;
2932
import java.io.FileInputStream;
3033
import java.io.FileNotFoundException;
@@ -39,7 +42,6 @@
3942
* {@link URLConnection} is used to retrieve image stream from network.
4043
*
4144
* @author Sergey Tarasevich (nostra13[at]gmail[dot]com)
42-
* @see HttpClientImageDownloader
4345
* @since 1.8.0
4446
*/
4547
public class BaseImageDownloader implements ImageDownloader {
@@ -57,8 +59,7 @@ public class BaseImageDownloader implements ImageDownloader {
5759

5860
protected static final String CONTENT_CONTACTS_URI_PREFIX = "content://com.android.contacts/";
5961

60-
private static final String ERROR_UNSUPPORTED_SCHEME = "UIL doesn't support scheme(protocol) by default [%s]. "
61-
+ "You should implement this support yourself (BaseImageDownloader.getStreamFromOtherSource(...))";
62+
private static final String ERROR_UNSUPPORTED_SCHEME = "UIL doesn't support scheme(protocol) by default [%s]. " + "You should implement this support yourself (BaseImageDownloader.getStreamFromOtherSource(...))";
6263

6364
protected final Context context;
6465
protected final int connectTimeout;
@@ -170,12 +171,20 @@ protected InputStream getStreamFromFile(String imageUri, Object extra) throws IO
170171
*/
171172
protected InputStream getStreamFromContent(String imageUri, Object extra) throws FileNotFoundException {
172173
ContentResolver res = context.getContentResolver();
174+
173175
Uri uri = Uri.parse(imageUri);
174-
if (imageUri.startsWith(CONTENT_CONTACTS_URI_PREFIX)) {
175-
return ContactsContract.Contacts.openContactPhotoInputStream(res, uri);
176-
} else {
177-
return res.openInputStream(uri);
176+
if (isVideoUri(uri)) {
177+
Long origId = Long.valueOf(uri.getLastPathSegment());
178+
Bitmap bitmap = MediaStore.Video.Thumbnails
179+
.getThumbnail(res, origId, MediaStore.Images.Thumbnails.MINI_KIND, null);
180+
if (bitmap != null) {
181+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
182+
bitmap.compress(CompressFormat.PNG, 0, bos);
183+
return new ByteArrayInputStream(bos.toByteArray());
184+
}
178185
}
186+
187+
return res.openInputStream(uri);
179188
}
180189

181190
/**
@@ -222,4 +231,14 @@ protected InputStream getStreamFromDrawable(String imageUri, Object extra) {
222231
protected InputStream getStreamFromOtherSource(String imageUri, Object extra) throws IOException {
223232
throw new UnsupportedOperationException(String.format(ERROR_UNSUPPORTED_SCHEME, imageUri));
224233
}
234+
235+
private boolean isVideoUri(Uri uri) {
236+
String mimeType = context.getContentResolver().getType(uri);
237+
238+
if (mimeType == null) {
239+
return false;
240+
}
241+
242+
return mimeType.startsWith("video/");
243+
}
225244
}

0 commit comments

Comments
 (0)