summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaesung Chung <jaesung@google.com>2016-03-22 21:27:31 -0700
committerArne Coucheron <arco68@gmail.com>2017-04-12 00:58:52 +0200
commitaad548ed3db782a2f86f684841e39270ff6d37c5 (patch)
treee50d375214f02aba50e1341e3cc107ab73144505
parent99a5354e436ccf30876ea56e2fed479db3e5773e (diff)
downloadandroid_packages_apps_Gallery2-staging/cm-14.1_android-7.1.2_r2.tar.gz
android_packages_apps_Gallery2-staging/cm-14.1_android-7.1.2_r2.tar.bz2
android_packages_apps_Gallery2-staging/cm-14.1_android-7.1.2_r2.zip
Gallery2: support the newly added media file types in MTP modestaging/cm-14.1_android-7.1.2_r2
And also allows to import RAW images introduced from N. Bug: 27125321 Change-Id: I8eda0503b7b07938a05655c9ae321bedfd2123b9
-rw-r--r--src/com/android/gallery3d/ingest/data/MtpDeviceIndex.java50
-rw-r--r--src/com/android/gallery3d/ingest/data/MtpDeviceIndexRunnable.java5
2 files changed, 48 insertions, 7 deletions
diff --git a/src/com/android/gallery3d/ingest/data/MtpDeviceIndex.java b/src/com/android/gallery3d/ingest/data/MtpDeviceIndex.java
index b21ad8355..ebfbc9227 100644
--- a/src/com/android/gallery3d/ingest/data/MtpDeviceIndex.java
+++ b/src/com/android/gallery3d/ingest/data/MtpDeviceIndex.java
@@ -3,10 +3,15 @@ package com.android.gallery3d.ingest.data;
import android.annotation.TargetApi;
import android.mtp.MtpConstants;
import android.mtp.MtpDevice;
+import android.mtp.MtpObjectInfo;
import android.os.Build;
+import android.webkit.MimeTypeMap;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Locale;
+import java.util.Map;
import java.util.Set;
/**
@@ -84,12 +89,18 @@ public class MtpDeviceIndex {
supportedImageFormats.add(MtpConstants.FORMAT_PNG);
supportedImageFormats.add(MtpConstants.FORMAT_GIF);
supportedImageFormats.add(MtpConstants.FORMAT_BMP);
+ supportedImageFormats.add(MtpConstants.FORMAT_TIFF);
+ supportedImageFormats.add(MtpConstants.FORMAT_TIFF_EP);
+ if (Build.VERSION.SDK_INT >= 24) {
+ supportedImageFormats.add(MtpConstants.FORMAT_DNG);
+ }
SUPPORTED_IMAGE_FORMATS = Collections.unmodifiableSet(supportedImageFormats);
Set<Integer> supportedVideoFormats = new HashSet<Integer>();
supportedVideoFormats.add(MtpConstants.FORMAT_3GP_CONTAINER);
supportedVideoFormats.add(MtpConstants.FORMAT_AVI);
supportedVideoFormats.add(MtpConstants.FORMAT_MP4_CONTAINER);
+ supportedVideoFormats.add(MtpConstants.FORMAT_MP2);
supportedVideoFormats.add(MtpConstants.FORMAT_MPEG);
// TODO(georgescu): add FORMAT_MOV once Android Media Scanner supports .mov files
SUPPORTED_VIDEO_FORMATS = Collections.unmodifiableSet(supportedVideoFormats);
@@ -104,6 +115,8 @@ public class MtpDeviceIndex {
private static final MtpDeviceIndex sInstance = new MtpDeviceIndex(
MtpDeviceIndexRunnable.getFactory());
+ private static final Map<String, Boolean> sCachedSupportedExtenstions = new HashMap<>();
+
public static MtpDeviceIndex getInstance() {
return sInstance;
}
@@ -121,12 +134,41 @@ public class MtpDeviceIndex {
}
/**
- * @param format Media format from {@link MtpConstants}
+ * @param mtpObjectInfo MTP object info
* @return Whether the format is supported by this index.
*/
- public boolean isFormatSupported(int format) {
- return SUPPORTED_IMAGE_FORMATS.contains(format)
- || SUPPORTED_VIDEO_FORMATS.contains(format);
+ public boolean isFormatSupported(MtpObjectInfo mtpObjectInfo) {
+ // Checks whether the format is supported or not.
+ final int format = mtpObjectInfo.getFormat();
+ if (SUPPORTED_IMAGE_FORMATS.contains(format)
+ || SUPPORTED_VIDEO_FORMATS.contains(format)) {
+ return true;
+ }
+
+ // Checks whether the extension is supported or not.
+ final String name = mtpObjectInfo.getName();
+ if (name == null) {
+ return false;
+ }
+ final int lastDot = name.lastIndexOf('.');
+ if (lastDot >= 0) {
+ final String extension = name.substring(lastDot + 1);
+
+ Boolean result = sCachedSupportedExtenstions.get(extension);
+ if (result != null) {
+ return result;
+ }
+ final String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
+ extension.toLowerCase(Locale.US));
+ if (mime != null) {
+ // This will also accept the newly added mimetypes for images and videos.
+ result = mime.startsWith("image/") || mime.startsWith("video/");
+ sCachedSupportedExtenstions.put(extension, result);
+ return result;
+ }
+ }
+
+ return false;
}
/**
diff --git a/src/com/android/gallery3d/ingest/data/MtpDeviceIndexRunnable.java b/src/com/android/gallery3d/ingest/data/MtpDeviceIndexRunnable.java
index 32275898e..fe558157a 100644
--- a/src/com/android/gallery3d/ingest/data/MtpDeviceIndexRunnable.java
+++ b/src/com/android/gallery3d/ingest/data/MtpDeviceIndexRunnable.java
@@ -171,10 +171,9 @@ public class MtpDeviceIndexRunnable implements Runnable {
if (mtpObjectInfo == null) {
throw new IndexingException();
}
- int format = mtpObjectInfo.getFormat();
- if (format == MtpConstants.FORMAT_ASSOCIATION) {
+ if (mtpObjectInfo.getFormat() == MtpConstants.FORMAT_ASSOCIATION) {
pendingDirectories.add(objectHandle);
- } else if (mIndex.isFormatSupported(format)) {
+ } else if (mIndex.isFormatSupported(mtpObjectInfo)) {
numObjects++;
addObject(new IngestObjectInfo(mtpObjectInfo), bucketsTemp, numObjects);
}