Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Unified Diff: ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java

Issue 150283002: Figure out the display name for a content uri. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
diff --git a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
index 6d85a354c2c0e1a44aec3922e11e2c7a25254230..0115f4fa07c76bd2419f04f3be52406930c9e7ac 100644
--- a/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
+++ b/ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
@@ -7,6 +7,7 @@ package org.chromium.ui.base;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Intent;
+import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
@@ -129,6 +130,30 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
}
/**
+ * @return the display name of the @code uri if present in the data base
+ * or an empty string otherwise.
+ */
+ private String resolveFileName(Uri uri, ContentResolver contentResolver) {
+ Cursor cursor = null;
+ try {
+ cursor = contentResolver.query(uri, null, null, null, null);
+
+ if (cursor != null && cursor.getCount() >= 1) {
+ cursor.moveToFirst();
+ int index = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
+ if (index > -1) {
+ return cursor.getString(index);
+ }
+ }
+ } finally {
+ if (cursor != null ) {
+ cursor.close();
+ }
+ }
+ return "";
+ }
+
+ /**
* Callback method to handle the intent results and pass on the path to the native
* SelectFileDialog.
* @param window The window that has access to the application activity.
@@ -147,7 +172,7 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
if (results == null) {
// If we have a successful return but no data, then assume this is the camera returning
// the photo that we requested.
- nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.getPath());
+ nativeOnFileSelected(mNativeSelectFileDialog, mCameraOutputUri.getPath(), "");
// Broadcast to the media scanner that there's a new photo on the device so it will
// show up right away in the gallery (rather than waiting until the next time the media
@@ -157,15 +182,17 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
return;
}
- if ("file".equals(results.getData().getScheme())) {
+ if (ContentResolver.SCHEME_FILE.equals(results.getData().getScheme())) {
nativeOnFileSelected(mNativeSelectFileDialog,
- results.getData().getSchemeSpecificPart());
+ results.getData().getSchemeSpecificPart(), "");
return;
}
- if (results.getScheme() != null
- && results.getScheme().equals(ContentResolver.SCHEME_CONTENT)) {
- nativeOnFileSelected(mNativeSelectFileDialog, results.getData().toString());
+ if (ContentResolver.SCHEME_CONTENT.equals(results.getScheme())) {
+ nativeOnFileSelected(mNativeSelectFileDialog,
+ results.getData().toString(),
+ resolveFileName(results.getData(),
+ contentResolver));
return;
}
@@ -233,6 +260,6 @@ class SelectFileDialog implements WindowAndroid.IntentCallback{
}
private native void nativeOnFileSelected(long nativeSelectFileDialogImpl,
- String filePath);
+ String filePath, String displayName);
private native void nativeOnFileNotSelected(long nativeSelectFileDialogImpl);
}
« no previous file with comments | « no previous file | ui/shell_dialogs/select_file_dialog_android.h » ('j') | ui/shell_dialogs/select_file_dialog_android.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698