Skip to content

Commit 05a0123

Browse files
committed
Merge
2 parents b1a2f1f + 07029ef commit 05a0123

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3+
org.eclipse.jdt.core.compiler.compliance=1.6
4+
org.eclipse.jdt.core.compiler.source=1.6

library/AndroidManifest.xml

+1-1
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

+29-9
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;
@@ -171,11 +172,20 @@ protected InputStream getStreamFromFile(String imageUri, Object extra) throws IO
171172
protected InputStream getStreamFromContent(String imageUri, Object extra) throws FileNotFoundException {
172173
ContentResolver res = context.getContentResolver();
173174
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);
175+
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+
byte[] bmpData = bos.toByteArray();
184+
return new ByteArrayInputStream(bmpData);
185+
}
178186
}
187+
188+
return res.openInputStream(uri);
179189
}
180190

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

0 commit comments

Comments
 (0)