summaryrefslogtreecommitdiffstats
path: root/packages/DocumentsUI/src
diff options
context:
space:
mode:
authorTomasz Mikolajewski <mtomasz@google.com>2015-04-10 10:30:33 +0900
committerTomasz Mikolajewski <mtomasz@google.com>2015-04-13 11:35:27 +0900
commite1a03f8eec2719279037ab348df306764dc45a70 (patch)
tree44818cde6c9c141637473a6c5b12bf8489a329e4 /packages/DocumentsUI/src
parent9e3cb0461ce56146e2ed67082431c052dc4fee1d (diff)
downloadframeworks_base-e1a03f8eec2719279037ab348df306764dc45a70.zip
frameworks_base-e1a03f8eec2719279037ab348df306764dc45a70.tar.gz
frameworks_base-e1a03f8eec2719279037ab348df306764dc45a70.tar.bz2
Show copy destination when clicking on the copy notification in Documents UI.
Change-Id: I3d955595bc46903c134c0633a6d32663cc2d0c05
Diffstat (limited to 'packages/DocumentsUI/src')
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/CopyService.java35
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java16
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java3
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/StandaloneActivity.java30
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/model/DocumentInfo.java3
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/model/DocumentStack.java28
6 files changed, 59 insertions, 56 deletions
diff --git a/packages/DocumentsUI/src/com/android/documentsui/CopyService.java b/packages/DocumentsUI/src/com/android/documentsui/CopyService.java
index c826aba..e140f33 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/CopyService.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/CopyService.java
@@ -30,6 +30,7 @@ import android.database.Cursor;
import android.net.Uri;
import android.os.CancellationSignal;
import android.os.ParcelFileDescriptor;
+import android.os.Parcelable;
import android.os.RemoteException;
import android.os.SystemClock;
import android.provider.DocumentsContract;
@@ -38,6 +39,7 @@ import android.text.format.DateUtils;
import android.util.Log;
import com.android.documentsui.model.DocumentInfo;
+import com.android.documentsui.model.DocumentStack;
import libcore.io.IoUtils;
@@ -51,8 +53,10 @@ import java.util.Objects;
public class CopyService extends IntentService {
public static final String TAG = "CopyService";
- public static final String EXTRA_SRC_LIST = "com.android.documentsui.SRC_LIST";
+
private static final String EXTRA_CANCEL = "com.android.documentsui.CANCEL";
+ public static final String EXTRA_SRC_LIST = "com.android.documentsui.SRC_LIST";
+ public static final String EXTRA_STACK = "com.android.documentsui.STACK";
private NotificationManager mNotificationManager;
private Notification.Builder mProgressBuilder;
@@ -98,20 +102,20 @@ public class CopyService extends IntentService {
return;
}
- ArrayList<DocumentInfo> srcs = intent.getParcelableArrayListExtra(EXTRA_SRC_LIST);
- Uri destinationUri = intent.getData();
+ final ArrayList<DocumentInfo> srcs = intent.getParcelableArrayListExtra(EXTRA_SRC_LIST);
+ final DocumentStack stack = intent.getParcelableExtra(EXTRA_STACK);
try {
// Acquire content providers.
mSrcClient = DocumentsApplication.acquireUnstableProviderOrThrow(getContentResolver(),
srcs.get(0).authority);
mDstClient = DocumentsApplication.acquireUnstableProviderOrThrow(getContentResolver(),
- destinationUri.getAuthority());
+ stack.peek().authority);
- setupCopyJob(srcs, destinationUri);
+ setupCopyJob(srcs, stack);
for (int i = 0; i < srcs.size() && !mIsCancelled; ++i) {
- copy(srcs.get(i), destinationUri);
+ copy(srcs.get(i), stack.peek());
}
} catch (Exception e) {
// Catch-all to prevent any copy errors from wedging the app.
@@ -142,29 +146,32 @@ public class CopyService extends IntentService {
* files.
*
* @param srcs A list of src files to copy.
- * @param destinationUri The URI of the destination directory.
+ * @param stack The copy destination stack.
* @throws RemoteException
*/
- private void setupCopyJob(ArrayList<DocumentInfo> srcs, Uri destinationUri)
+ private void setupCopyJob(ArrayList<DocumentInfo> srcs, DocumentStack stack)
throws RemoteException {
// Create an ID for this copy job. Use the timestamp.
mJobId = String.valueOf(SystemClock.elapsedRealtime());
// Reset the cancellation flag.
mIsCancelled = false;
+ final Context context = getApplicationContext();
+ final Intent navigateIntent = new Intent(context, StandaloneActivity.class);
+ navigateIntent.putExtra(EXTRA_STACK, (Parcelable)stack);
+
mProgressBuilder = new Notification.Builder(this)
.setContentTitle(getString(R.string.copy_notification_title))
+ .setContentIntent(PendingIntent.getActivity(context, 0, navigateIntent, 0))
.setCategory(Notification.CATEGORY_PROGRESS)
.setSmallIcon(R.drawable.ic_menu_copy).setOngoing(true);
- Intent cancelIntent = new Intent(this, CopyService.class);
+ final Intent cancelIntent = new Intent(this, CopyService.class);
cancelIntent.putExtra(EXTRA_CANCEL, mJobId);
mProgressBuilder.addAction(R.drawable.ic_cab_cancel,
getString(R.string.cancel), PendingIntent.getService(this, 0,
cancelIntent, PendingIntent.FLAG_ONE_SHOT));
- // TODO: Add a content intent to open the destination folder.
-
// Send an initial progress notification.
mProgressBuilder.setProgress(0, 0, true); // Indeterminate progress while setting up.
mProgressBuilder.setContentText(getString(R.string.copy_preparing));
@@ -322,11 +329,11 @@ public class CopyService extends IntentService {
* Copies a the given documents to the given location.
*
* @param srcInfo DocumentInfos for the documents to copy.
- * @param dstDirUri The URI of the destination directory.
+ * @param dstDirInfo The destination directory.
* @throws RemoteException
*/
- private void copy(DocumentInfo srcInfo, Uri dstDirUri) throws RemoteException {
- final Uri dstUri = DocumentsContract.createDocument(mDstClient, dstDirUri,
+ private void copy(DocumentInfo srcInfo, DocumentInfo dstDirInfo) throws RemoteException {
+ final Uri dstUri = DocumentsContract.createDocument(mDstClient, dstDirInfo.derivedUri,
srcInfo.mimeType, srcInfo.displayName);
if (dstUri == null) {
// If this is a directory, the entire subdir will not be copied over.
diff --git a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java
index 9ffdd33..4cf0180 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java
@@ -358,18 +358,10 @@ public class DirectoryFragment extends Fragment {
return;
}
- // Because the destination picker is launched using an open tree intent, the URI returned is
- // a tree URI. Convert it to a document URI.
- // TODO: Remove this step when the destination picker returns a document URI.
- final Uri destinationTree = data.getData();
- final Uri destination = DocumentsContract.buildDocumentUriUsingTree(destinationTree,
- DocumentsContract.getTreeDocumentId(destinationTree));
-
- List<DocumentInfo> docs = mSelectedDocumentsForCopy;
- Intent copyIntent = new Intent(context, CopyService.class);
- copyIntent.putParcelableArrayListExtra(CopyService.EXTRA_SRC_LIST,
- new ArrayList<DocumentInfo>(docs));
- copyIntent.setData(destination);
+ final List<DocumentInfo> docs = mSelectedDocumentsForCopy;
+ final Intent copyIntent = new Intent(context, CopyService.class);
+ copyIntent.putParcelableArrayListExtra(CopyService.EXTRA_SRC_LIST, new ArrayList<DocumentInfo>(docs));
+ copyIntent.putExtra(CopyService.EXTRA_STACK, data.getParcelableExtra(CopyService.EXTRA_STACK));
Toast.makeText(context,
res.getQuantityString(R.plurals.copy_begin, docs.size(), docs.size()),
diff --git a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java
index d3db44a..11fa63d 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java
@@ -46,6 +46,7 @@ import android.graphics.Point;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
+import android.os.Parcelable;
import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Root;
import android.support.v4.app.ActionBarDrawerToggle;
@@ -1109,6 +1110,8 @@ public class DocumentsActivity extends BaseActivity {
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION
| Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
| Intent.FLAG_GRANT_PREFIX_URI_PERMISSION);
+ // TODO: Move passing the stack to the separate ACTION_COPY action once it's implemented.
+ intent.putExtra(CopyService.EXTRA_STACK, (Parcelable)mState.stack);
} else {
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
| Intent.FLAG_GRANT_WRITE_URI_PERMISSION
diff --git a/packages/DocumentsUI/src/com/android/documentsui/StandaloneActivity.java b/packages/DocumentsUI/src/com/android/documentsui/StandaloneActivity.java
index cc30150..f542838 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/StandaloneActivity.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/StandaloneActivity.java
@@ -171,33 +171,9 @@ public class StandaloneActivity extends BaseActivity {
mState.showAdvanced = mState.forceAdvanced
| LocalPreferences.getDisplayAdvancedDevices(this);
mState.showSize = true;
- }
-
- private class RestoreRootTask extends AsyncTask<Void, Void, RootInfo> {
- private Uri mRootUri;
-
- public RestoreRootTask(Uri rootUri) {
- mRootUri = rootUri;
- }
-
- @Override
- protected RootInfo doInBackground(Void... params) {
- final String rootId = DocumentsContract.getRootId(mRootUri);
- return mRoots.getRootOneshot(mRootUri.getAuthority(), rootId);
- }
-
- @Override
- protected void onPostExecute(RootInfo root) {
- if (isDestroyed()) return;
- mState.restored = true;
-
- if (root != null) {
- onRootPicked(root, true);
- } else {
- Log.w(TAG, "Failed to find root: " + mRootUri);
- finish();
- }
- }
+ final DocumentStack stack = intent.getParcelableExtra(CopyService.EXTRA_STACK);
+ if (stack != null)
+ mState.stack = stack;
}
private class RestoreStackTask extends AsyncTask<Void, Void, Void> {
diff --git a/packages/DocumentsUI/src/com/android/documentsui/model/DocumentInfo.java b/packages/DocumentsUI/src/com/android/documentsui/model/DocumentInfo.java
index 1c5ca86..5d5f2eb 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/model/DocumentInfo.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/model/DocumentInfo.java
@@ -24,6 +24,7 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.provider.DocumentsContract;
import android.provider.DocumentsContract.Document;
+import android.provider.DocumentsContract.Root;
import android.provider.DocumentsProvider;
import android.text.TextUtils;
@@ -161,8 +162,6 @@ public class DocumentInfo implements Durable, Parcelable {
this.authority = authority;
this.documentId = getCursorString(cursor, Document.COLUMN_DOCUMENT_ID);
this.mimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
- this.documentId = getCursorString(cursor, Document.COLUMN_DOCUMENT_ID);
- this.mimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
this.displayName = getCursorString(cursor, Document.COLUMN_DISPLAY_NAME);
this.lastModified = getCursorLong(cursor, Document.COLUMN_LAST_MODIFIED);
this.flags = getCursorInt(cursor, Document.COLUMN_FLAGS);
diff --git a/packages/DocumentsUI/src/com/android/documentsui/model/DocumentStack.java b/packages/DocumentsUI/src/com/android/documentsui/model/DocumentStack.java
index 28bab6c..34bd696 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/model/DocumentStack.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/model/DocumentStack.java
@@ -17,6 +17,8 @@
package com.android.documentsui.model;
import android.content.ContentResolver;
+import android.os.Parcel;
+import android.os.Parcelable;
import android.provider.DocumentsProvider;
import java.io.DataInputStream;
@@ -31,7 +33,7 @@ import java.util.LinkedList;
* Representation of a stack of {@link DocumentInfo}, usually the result of a
* user-driven traversal.
*/
-public class DocumentStack extends LinkedList<DocumentInfo> implements Durable {
+public class DocumentStack extends LinkedList<DocumentInfo> implements Durable, Parcelable {
private static final int VERSION_INIT = 1;
private static final int VERSION_ADD_ROOT = 2;
@@ -135,4 +137,28 @@ public class DocumentStack extends LinkedList<DocumentInfo> implements Durable {
doc.write(out);
}
}
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ DurableUtils.writeToParcel(dest, this);
+ }
+
+ public static final Creator<DocumentStack> CREATOR = new Creator<DocumentStack>() {
+ @Override
+ public DocumentStack createFromParcel(Parcel in) {
+ final DocumentStack stack = new DocumentStack();
+ DurableUtils.readFromParcel(in, stack);
+ return stack;
+ }
+
+ @Override
+ public DocumentStack[] newArray(int size) {
+ return new DocumentStack[size];
+ }
+ };
}