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

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

Issue 157573002: Merge 248707 "Figure out the display name for a content uri." (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1750/src/
Patch Set: Created 6 years, 10 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
« no previous file with comments | « no previous file | ui/shell_dialogs/OWNERS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java
===================================================================
--- ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java (revision 249688)
+++ ui/android/java/src/org/chromium/ui/base/SelectFileDialog.java (working copy)
@@ -7,6 +7,7 @@
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,28 @@
}
/**
+ * @return the display name of the @code uri if present in the database
+ * 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 +170,7 @@
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 +180,17 @@
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 +258,6 @@
}
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/OWNERS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698