summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaesung Chung <jaesung@google.com>2016-03-22 21:27:31 -0700
committerLuK1337 <priv.luk@gmail.com>2019-10-21 21:42:08 +0200
commit3dfa4fcbf82f5aa63a3cdaced3a11024acc55789 (patch)
tree9eb2299f3fbee45b9cb2d5bda5cb499ba4daa17e
parent9f7d20916e3ca8ace1a6a0389ea71ec6d7ca972f (diff)
downloadandroid_packages_apps_Gallery2-3dfa4fcbf82f5aa63a3cdaced3a11024acc55789.tar.gz
android_packages_apps_Gallery2-3dfa4fcbf82f5aa63a3cdaced3a11024acc55789.tar.bz2
android_packages_apps_Gallery2-3dfa4fcbf82f5aa63a3cdaced3a11024acc55789.zip
Gallery2: Support the newly added media file types in MTP mode
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);
}