Make DocumentProvider Support Thumbnail
This will make DocumentUI or the built-in Android System Internal Files Manager app showing Thumbnail of Image file instead of image type icon.
This commit is contained in:
parent
d667fca8d3
commit
45d3c41d68
|
@ -9,9 +9,10 @@
|
|||
package org.dolphinemu.dolphinemu.features
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.content.Context
|
||||
import android.content.res.AssetFileDescriptor
|
||||
import android.database.Cursor
|
||||
import android.database.MatrixCursor
|
||||
import android.graphics.Point
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.CancellationSignal
|
||||
|
@ -29,7 +30,7 @@ class DocumentProvider : DocumentsProvider() {
|
|||
private var rootDirectory: File? = null
|
||||
|
||||
companion object {
|
||||
public const val ROOT_ID = "root"
|
||||
const val ROOT_ID = "root"
|
||||
|
||||
private val DEFAULT_ROOT_PROJECTION = arrayOf(
|
||||
DocumentsContract.Root.COLUMN_ROOT_ID,
|
||||
|
@ -111,6 +112,16 @@ class DocumentProvider : DocumentsProvider() {
|
|||
return ParcelFileDescriptor.open(file, ParcelFileDescriptor.parseMode(mode))
|
||||
}
|
||||
|
||||
override fun openDocumentThumbnail(
|
||||
documentId: String,
|
||||
sizeHint: Point,
|
||||
signal: CancellationSignal
|
||||
): AssetFileDescriptor {
|
||||
val file = documentIdToPath(documentId)
|
||||
val pfd = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY)
|
||||
return AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH)
|
||||
}
|
||||
|
||||
override fun createDocument(
|
||||
parentDocumentId: String,
|
||||
mimeType: String,
|
||||
|
@ -178,6 +189,10 @@ class DocumentProvider : DocumentsProvider() {
|
|||
} else {
|
||||
file.name
|
||||
}
|
||||
val mimeType = getTypeForFile(file)
|
||||
if (file.exists() && mimeType.startsWith("image/")) {
|
||||
flags = flags or DocumentsContract.Document.FLAG_SUPPORTS_THUMBNAIL
|
||||
}
|
||||
cursor.newRow().apply {
|
||||
add(DocumentsContract.Document.COLUMN_DOCUMENT_ID, pathToDocumentId(file))
|
||||
add(DocumentsContract.Document.COLUMN_MIME_TYPE, getTypeForFile(file))
|
||||
|
|
Loading…
Reference in New Issue