Change copy/move destination to Downloads when home directory is hidden.
Bug: 27791217
Change-Id: If196441a57053ada9875c6cc29d4c7f13fcb57e8
diff --git a/src/com/android/documentsui/BaseActivity.java b/src/com/android/documentsui/BaseActivity.java
index 3b300d0..e68ed13 100644
--- a/src/com/android/documentsui/BaseActivity.java
+++ b/src/com/android/documentsui/BaseActivity.java
@@ -438,6 +438,17 @@
return mState;
}
+ /*
+ * Get the default directory to be presented after starting the activity.
+ * Method can be overridden if the change of the behavior of the the child activity is needed.
+ */
+ public Uri getDefaultRoot() {
+ return Shared.isHomeRootHidden(this)
+ ? DocumentsContract.buildRootUri("com.android.providers.downloads.documents",
+ "downloads")
+ : DocumentsContract.buildHomeUri();
+ }
+
void setDisplayFileSize(boolean display) {
LocalPreferences.setDisplayFileSize(this, display);
mState.showSize = display;
diff --git a/src/com/android/documentsui/DocumentsActivity.java b/src/com/android/documentsui/DocumentsActivity.java
index 770e35d..a94b40c 100644
--- a/src/com/android/documentsui/DocumentsActivity.java
+++ b/src/com/android/documentsui/DocumentsActivity.java
@@ -108,9 +108,7 @@
// we restore the stack as last used from that app.
if (mState.action == ACTION_PICK_COPY_DESTINATION) {
if (DEBUG) Log.d(TAG, "Launching directly into Home directory.");
- Uri homeUri = DocumentsContract.buildHomeUri();
- new LoadRootTask(this, homeUri).executeOnExecutor(
- ProviderExecutor.forAuthority(homeUri.getAuthority()));
+ loadRoot(getDefaultRoot());
} else {
if (DEBUG) Log.d(TAG, "Attempting to load last used stack for calling package.");
new LoadLastUsedStackTask(this).execute();
diff --git a/src/com/android/documentsui/FilesActivity.java b/src/com/android/documentsui/FilesActivity.java
index fe2dc8e..d3888e8 100644
--- a/src/com/android/documentsui/FilesActivity.java
+++ b/src/com/android/documentsui/FilesActivity.java
@@ -109,9 +109,7 @@
loadRoot(uri);
} else {
if (DEBUG) Log.d(TAG, "All other means skipped. Launching into default directory.");
- Uri defaultUri = DocumentsContract.buildRootUri(
- "com.android.providers.downloads.documents", "downloads");
- loadRoot(defaultUri);
+ loadRoot(getDefaultRoot());
}
final @DialogType int dialogType = intent.getIntExtra(
diff --git a/src/com/android/documentsui/RootsFragment.java b/src/com/android/documentsui/RootsFragment.java
index 1864431..35da8cc 100644
--- a/src/com/android/documentsui/RootsFragment.java
+++ b/src/com/android/documentsui/RootsFragment.java
@@ -318,9 +318,9 @@
for (final RootInfo root : roots) {
final RootItem item = new RootItem(root);
- if (root.isHome() && isHomeRootHidden(context)) {
+ if (root.isHome() && Shared.isHomeRootHidden(context)) {
continue;
- } else if (root.isAdvanced() && areAdvancedRootsHidden(context)) {
+ } else if (root.isAdvanced() && Shared.areAdvancedRootsHidden(context)) {
continue;
} else if (root.isLibrary()) {
if (DEBUG) Log.d(TAG, "Adding " + root + " as library.");
@@ -372,20 +372,6 @@
}
}
- /*
- * Indicates if the home directory should be hidden in the roots list.
- */
- private boolean isHomeRootHidden(Context context) {
- return context.getResources().getBoolean(R.bool.home_root_hidden);
- }
-
- /*
- * Indicates if the advanced roots should be hidden.
- */
- private boolean areAdvancedRootsHidden(Context context) {
- return context.getResources().getBoolean(R.bool.advanced_roots_hidden);
- }
-
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final Item item = getItem(position);
diff --git a/src/com/android/documentsui/Shared.java b/src/com/android/documentsui/Shared.java
index 6f1863e..e0d36d6 100644
--- a/src/com/android/documentsui/Shared.java
+++ b/src/com/android/documentsui/Shared.java
@@ -169,4 +169,18 @@
}
}
+ /*
+ * Indicates if the home directory should be hidden in the roots list.
+ */
+ public static boolean isHomeRootHidden(Context context) {
+ return context.getResources().getBoolean(R.bool.home_root_hidden);
+ }
+
+ /*
+ * Indicates if the advanced roots should be hidden.
+ */
+ public static boolean areAdvancedRootsHidden(Context context) {
+ return context.getResources().getBoolean(R.bool.advanced_roots_hidden);
+ }
+
}