90 lines
2.7 KiB
Java
90 lines
2.7 KiB
Java
package com.twitter.sdk.android.tweetcomposer;
|
|
|
|
import android.annotation.TargetApi;
|
|
import android.content.Context;
|
|
import android.database.Cursor;
|
|
import android.net.Uri;
|
|
import android.os.Build;
|
|
import android.provider.DocumentsContract;
|
|
import android.provider.MediaStore;
|
|
import android.text.TextUtils;
|
|
import android.webkit.MimeTypeMap;
|
|
import java.io.File;
|
|
|
|
/* loaded from: classes.dex */
|
|
class FileUtils {
|
|
@TargetApi(19)
|
|
static String a(Context context, Uri uri) {
|
|
if ((Build.VERSION.SDK_INT >= 19) && c(uri)) {
|
|
String[] split = DocumentsContract.getDocumentId(uri).split(":");
|
|
if ("image".equals(split[0])) {
|
|
return a(context, MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "_id=?", new String[]{split[1]});
|
|
}
|
|
return null;
|
|
}
|
|
if (a(uri)) {
|
|
return a(context, uri, null, null);
|
|
}
|
|
if (b(uri)) {
|
|
return uri.getPath();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static boolean b(Uri uri) {
|
|
return "file".equalsIgnoreCase(uri.getScheme());
|
|
}
|
|
|
|
public static boolean c(Uri uri) {
|
|
return "com.android.providers.media.documents".equalsIgnoreCase(uri.getAuthority());
|
|
}
|
|
|
|
public static boolean a(Uri uri) {
|
|
return "content".equalsIgnoreCase(uri.getScheme());
|
|
}
|
|
|
|
static String a(Context context, Uri uri, String str, String[] strArr) {
|
|
Cursor cursor;
|
|
try {
|
|
cursor = context.getContentResolver().query(uri, new String[]{"_data"}, str, strArr, null);
|
|
if (cursor != null) {
|
|
try {
|
|
if (cursor.moveToFirst()) {
|
|
String string = cursor.getString(cursor.getColumnIndexOrThrow("_data"));
|
|
if (cursor != null) {
|
|
cursor.close();
|
|
}
|
|
return string;
|
|
}
|
|
} catch (Throwable th) {
|
|
th = th;
|
|
if (cursor != null) {
|
|
cursor.close();
|
|
}
|
|
throw th;
|
|
}
|
|
}
|
|
if (cursor != null) {
|
|
cursor.close();
|
|
}
|
|
return null;
|
|
} catch (Throwable th2) {
|
|
th = th2;
|
|
cursor = null;
|
|
}
|
|
}
|
|
|
|
static String a(File file) {
|
|
String a = a(file.getName());
|
|
return !TextUtils.isEmpty(a) ? MimeTypeMap.getSingleton().getMimeTypeFromExtension(a) : "application/octet-stream";
|
|
}
|
|
|
|
static String a(String str) {
|
|
if (str == null) {
|
|
return null;
|
|
}
|
|
int lastIndexOf = str.lastIndexOf(".");
|
|
return lastIndexOf < 0 ? "" : str.substring(lastIndexOf + 1);
|
|
}
|
|
}
|