From bbe2292bc671f74d77c9a0e4e0e1d5ea5714d939 Mon Sep 17 00:00:00 2001 From: Daichi Hirono Date: Fri, 10 Apr 2015 15:50:38 +0900 Subject: [PATCH] DocumentsUI: Add new private intent action to select copy destination. The CL adds INTENT_ACTION_OPEN_COPY_DESTINATION, and implements the behavior to respond the intent action. The directory picker: * filter out read only roots * return document URI instead of document tree URI for the intent action. BUG=b:20146034 Change-Id: I96c565100c3cdaa57cc7abd8cf6d895d148941a7 --- .../com/android/documentsui/BaseActivity.java | 4 ++ .../documentsui/DirectoryFragment.java | 6 ++- .../documentsui/DocumentsActivity.java | 48 ++++++++++++++----- .../com/android/documentsui/RootsCache.java | 5 +- 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java index bf3a9407d1b6b..bd174012c3676 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java +++ b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java @@ -33,6 +33,9 @@ import com.android.documentsui.model.RootInfo; import com.google.common.collect.Maps; abstract class BaseActivity extends Activity { + /** Intent action name to open copy destination. */ + public static String ACTION_OPEN_COPY_DESTINATION_STRING = + "com.android.documentsui.OPEN_COPY_DESTINATION"; public abstract State getDisplayState(); public abstract RootInfo getCurrentRoot(); @@ -90,6 +93,7 @@ abstract class BaseActivity extends Activity { public static final int ACTION_MANAGE = 5; public static final int ACTION_BROWSE = 6; public static final int ACTION_BROWSE_ALL = 7; + public static final int ACTION_OPEN_COPY_DESTINATION = 8; public static final int MODE_UNKNOWN = 0; public static final int MODE_LIST = 1; diff --git a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java index 4cf0180a327f5..61fcad2c67d5e 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java +++ b/packages/DocumentsUI/src/com/android/documentsui/DirectoryFragment.java @@ -682,7 +682,11 @@ public class DirectoryFragment extends Fragment { // Pop up a dialog to pick a destination. This is inadequate but works for now. // TODO: Implement a picker that is to spec. - Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE); + final Intent intent = new Intent( + BaseActivity.ACTION_OPEN_COPY_DESTINATION_STRING, + Uri.EMPTY, + getActivity(), + DocumentsActivity.class); startActivityForResult(intent, REQUEST_COPY_DESTINATION); } diff --git a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java index 11fa63dd9d099..6ce9a3d7081c5 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java +++ b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java @@ -22,6 +22,7 @@ import static com.android.documentsui.BaseActivity.State.ACTION_GET_CONTENT; import static com.android.documentsui.BaseActivity.State.ACTION_MANAGE; import static com.android.documentsui.BaseActivity.State.ACTION_OPEN; import static com.android.documentsui.BaseActivity.State.ACTION_OPEN_TREE; +import static com.android.documentsui.BaseActivity.State.ACTION_OPEN_COPY_DESTINATION; import static com.android.documentsui.BaseActivity.State.MODE_GRID; import static com.android.documentsui.BaseActivity.State.MODE_LIST; import static com.android.documentsui.DirectoryFragment.ANIM_DOWN; @@ -190,7 +191,8 @@ public class DocumentsActivity extends BaseActivity { final String mimeType = getIntent().getType(); final String title = getIntent().getStringExtra(Intent.EXTRA_TITLE); SaveFragment.show(getFragmentManager(), mimeType, title); - } else if (mState.action == ACTION_OPEN_TREE) { + } else if (mState.action == ACTION_OPEN_TREE || + mState.action == ACTION_OPEN_COPY_DESTINATION) { PickFragment.show(getFragmentManager()); } @@ -199,8 +201,10 @@ public class DocumentsActivity extends BaseActivity { moreApps.setComponent(null); moreApps.setPackage(null); RootsFragment.show(getFragmentManager(), moreApps); - } else if (mState.action == ACTION_OPEN - || mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE) { + } else if (mState.action == ACTION_OPEN || + mState.action == ACTION_CREATE || + mState.action == ACTION_OPEN_TREE || + mState.action == ACTION_OPEN_COPY_DESTINATION) { RootsFragment.show(getFragmentManager(), null); } @@ -233,6 +237,8 @@ public class DocumentsActivity extends BaseActivity { mState.action = ACTION_MANAGE; } else if (DocumentsContract.ACTION_BROWSE_ROOT.equals(action)) { mState.action = ACTION_BROWSE; + } else if (ACTION_OPEN_COPY_DESTINATION_STRING.equals(action)) { + mState.action = ACTION_OPEN_COPY_DESTINATION; } if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT) { @@ -408,10 +414,12 @@ public class DocumentsActivity extends BaseActivity { public void updateActionBar() { if (mRootsToolbar != null) { - if (mState.action == ACTION_OPEN || mState.action == ACTION_GET_CONTENT - || mState.action == ACTION_OPEN_TREE) { + if (mState.action == ACTION_OPEN || + mState.action == ACTION_GET_CONTENT || + mState.action == ACTION_OPEN_TREE) { mRootsToolbar.setTitle(R.string.title_open); - } else if (mState.action == ACTION_CREATE) { + } else if (mState.action == ACTION_CREATE || + mState.action == ACTION_OPEN_COPY_DESTINATION) { mRootsToolbar.setTitle(R.string.title_save); } } @@ -850,7 +858,9 @@ public class DocumentsActivity extends BaseActivity { if (cwd == null) { // No directory means recents - if (mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE) { + if (mState.action == ACTION_CREATE || + mState.action == ACTION_OPEN_TREE || + mState.action == ACTION_OPEN_COPY_DESTINATION) { RecentsCreateFragment.show(fm); } else { DirectoryFragment.showRecentsOpen(fm, anim); @@ -879,7 +889,8 @@ public class DocumentsActivity extends BaseActivity { } } - if (mState.action == ACTION_OPEN_TREE) { + if (mState.action == ACTION_OPEN_TREE || + mState.action == ACTION_OPEN_COPY_DESTINATION) { final PickFragment pick = PickFragment.get(fm); if (pick != null) { final CharSequence displayName = (mState.stack.size() <= 1) ? root.title @@ -1062,9 +1073,17 @@ public class DocumentsActivity extends BaseActivity { @Override public void onPickRequested(DocumentInfo pickTarget) { - final Uri viaUri = DocumentsContract.buildTreeDocumentUri(pickTarget.authority, - pickTarget.documentId); - new PickFinishTask(viaUri).executeOnExecutor(getCurrentExecutor()); + Uri result; + if (mState.action == ACTION_OPEN_TREE) { + result = DocumentsContract.buildTreeDocumentUri( + pickTarget.authority, pickTarget.documentId); + } else if (mState.action == ACTION_OPEN_COPY_DESTINATION) { + result = pickTarget.derivedUri; + } else { + // Should not be reached. + throw new IllegalStateException("Invalid mState.action."); + } + new PickFinishTask(result).executeOnExecutor(getCurrentExecutor()); } private void saveStackBlocking() { @@ -1072,7 +1091,9 @@ public class DocumentsActivity extends BaseActivity { final ContentValues values = new ContentValues(); final byte[] rawStack = DurableUtils.writeToArrayOrNull(mState.stack); - if (mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE) { + if (mState.action == ACTION_CREATE || + mState.action == ACTION_OPEN_TREE || + mState.action == ACTION_OPEN_COPY_DESTINATION) { // Remember stack for last create values.clear(); values.put(RecentColumns.KEY, mState.stack.buildKey()); @@ -1105,7 +1126,8 @@ public class DocumentsActivity extends BaseActivity { if (mState.action == ACTION_GET_CONTENT) { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - } else if (mState.action == ACTION_OPEN_TREE) { + } else if (mState.action == ACTION_OPEN_TREE || + mState.action == ACTION_OPEN_COPY_DESTINATION) { intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION diff --git a/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java b/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java index ec71a045f7aa5..d2267b10f1df6 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java +++ b/packages/DocumentsUI/src/com/android/documentsui/RootsCache.java @@ -360,6 +360,7 @@ public class RootsCache { // Exclude read-only devices when creating if (state.action == State.ACTION_CREATE && !supportsCreate) continue; + if (state.action == State.ACTION_OPEN_COPY_DESTINATION && !supportsCreate) continue; // Exclude roots that don't support directory picking if (state.action == State.ACTION_OPEN_TREE && !supportsIsChild) continue; // Exclude advanced devices when not requested @@ -367,7 +368,9 @@ public class RootsCache { // Exclude non-local devices when local only if (state.localOnly && !localOnly) continue; // Only show empty roots when creating - if (state.action != State.ACTION_CREATE && empty) continue; + if ((state.action != State.ACTION_CREATE || + state.action != State.ACTION_OPEN_TREE || + state.action != State.ACTION_OPEN_COPY_DESTINATION) && empty) continue; // Only include roots that serve requested content final boolean overlap =