diff options
author | Jeff Sharkey <jsharkey@android.com> | 2014-05-22 05:45:29 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-05-22 05:45:29 +0000 |
commit | 9f561c367b9b084222acbe97580dca04f5e469ee (patch) | |
tree | 9727168b121711dab52bad1e12526205a1e21929 /core/java/android/provider/DocumentsContract.java | |
parent | 842dd77bb9c002af5364237f46b63c826f1c4082 (diff) | |
parent | b7e1255d5c8d9e4fa8dd389afb9f5aab35434df3 (diff) | |
download | frameworks_base-9f561c367b9b084222acbe97580dca04f5e469ee.zip frameworks_base-9f561c367b9b084222acbe97580dca04f5e469ee.tar.gz frameworks_base-9f561c367b9b084222acbe97580dca04f5e469ee.tar.bz2 |
Merge "Support for renaming documents."
Diffstat (limited to 'core/java/android/provider/DocumentsContract.java')
-rw-r--r-- | core/java/android/provider/DocumentsContract.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/core/java/android/provider/DocumentsContract.java b/core/java/android/provider/DocumentsContract.java index b907375..6b8e2de 100644 --- a/core/java/android/provider/DocumentsContract.java +++ b/core/java/android/provider/DocumentsContract.java @@ -287,6 +287,16 @@ public final class DocumentsContract { public static final int FLAG_DIR_PREFERS_LAST_MODIFIED = 1 << 5; /** + * Flag indicating that a document can be renamed. + * + * @see #COLUMN_FLAGS + * @see DocumentsContract#renameDocument(ContentProviderClient, Uri, + * String) + * @see DocumentsProvider#renameDocument(String, String) + */ + public static final int FLAG_SUPPORTS_RENAME = 1 << 6; + + /** * Flag indicating that document titles should be hidden when viewing * this directory in a larger format grid. For example, a directory * containing only images may want the image thumbnails to speak for @@ -494,6 +504,8 @@ public final class DocumentsContract { /** {@hide} */ public static final String METHOD_CREATE_DOCUMENT = "android:createDocument"; /** {@hide} */ + public static final String METHOD_RENAME_DOCUMENT = "android:renameDocument"; + /** {@hide} */ public static final String METHOD_DELETE_DOCUMENT = "android:deleteDocument"; /** {@hide} */ @@ -898,6 +910,45 @@ public final class DocumentsContract { } /** + * Change the display name of an existing document. + * <p> + * If the underlying provider needs to create a new + * {@link Document#COLUMN_DOCUMENT_ID} to represent the updated display + * name, that new document is returned and the original document is no + * longer valid. Otherwise, the original document is returned. + * + * @param documentUri document with {@link Document#FLAG_SUPPORTS_RENAME} + * @param displayName updated name for document + * @return the existing or new document after the rename, or {@code null} if + * failed. + */ + public static Uri renameDocument(ContentResolver resolver, Uri documentUri, + String displayName) { + final ContentProviderClient client = resolver.acquireUnstableContentProviderClient( + documentUri.getAuthority()); + try { + return renameDocument(client, documentUri, displayName); + } catch (Exception e) { + Log.w(TAG, "Failed to rename document", e); + return null; + } finally { + ContentProviderClient.releaseQuietly(client); + } + } + + /** {@hide} */ + public static Uri renameDocument(ContentProviderClient client, Uri documentUri, + String displayName) throws RemoteException { + final Bundle in = new Bundle(); + in.putParcelable(DocumentsContract.EXTRA_URI, documentUri); + in.putString(Document.COLUMN_DISPLAY_NAME, displayName); + + final Bundle out = client.call(METHOD_RENAME_DOCUMENT, null, in); + final Uri outUri = out.getParcelable(DocumentsContract.EXTRA_URI); + return (outUri != null) ? outUri : documentUri; + } + + /** * Delete the given document. * * @param documentUri document with {@link Document#FLAG_SUPPORTS_DELETE} |