summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java43
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java35
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/DownloadsActivity.java2
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java40
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/LoadRootTask.java (renamed from packages/DocumentsUI/src/com/android/documentsui/RestoreRootTask.java)4
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/RecentsProvider.java1
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/State.java4
-rw-r--r--packages/DocumentsUI/src/com/android/documentsui/dirlist/FragmentTuner.java25
8 files changed, 87 insertions, 67 deletions
diff --git a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java
index 845e32cebd0f..95c49ffe8a92 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java
@@ -33,7 +33,6 @@ import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ProviderInfo;
-import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
@@ -66,9 +65,6 @@ import java.util.concurrent.Executor;
public abstract class BaseActivity extends Activity
implements SearchManagerListener, NavigationView.Environment {
- // See comments where this const is referenced for details.
- private static final int DRAWER_NO_FIDDLE_DELAY = 1500;
-
State mState;
RootsCache mRoots;
SearchViewManager mSearchManager;
@@ -80,10 +76,6 @@ public abstract class BaseActivity extends Activity
@LayoutRes
private int mLayoutId;
- // Track the time we opened the drawer in response to back being pressed.
- // We use the time gap to figure out whether to close app or reopen the drawer.
- private long mDrawerLastFiddled;
-
private boolean mNavDrawerHasFocus;
public abstract void onDocumentPicked(DocumentInfo doc, Model model);
@@ -368,6 +360,11 @@ public abstract class BaseActivity extends Activity
invalidateOptionsMenu();
}
+ final void loadRoot(final Uri uri) {
+ new LoadRootTask(this, uri).executeOnExecutor(
+ ProviderExecutor.forAuthority(uri.getAuthority()));
+ }
+
/**
* Called when search results changed.
* Refreshes the content of the directory. It doesn't refresh elements on the action bar.
@@ -543,36 +540,18 @@ public abstract class BaseActivity extends Activity
return;
}
- int size = mState.stack.size();
-
- // Do some "do what a I want" drawer fiddling, but don't
- // do it if user already hit back recently and we recently
- // did some fiddling.
- if (mDrawer.isPresent()
- && (System.currentTimeMillis() - mDrawerLastFiddled) > DRAWER_NO_FIDDLE_DELAY) {
- // Close drawer if it is open.
- if (mDrawer.isOpen()) {
- mDrawer.setOpen(false);
- mDrawerLastFiddled = System.currentTimeMillis();
- return;
- }
-
- // Open the Close drawer if it is closed and we're at the top of a root.
- if (size == 1) {
- mDrawer.setOpen(true);
- // Remember so we don't just close it again if back is pressed again.
- mDrawerLastFiddled = System.currentTimeMillis();
- return;
- }
- }
-
- if (popDir()) {
+ if (onBeforePopDir() || popDir()) {
return;
}
super.onBackPressed();
}
+ boolean onBeforePopDir() {
+ // Files app overrides this with some fancy logic.
+ return false;
+ }
+
public void onStackPicked(DocumentStack stack) {
try {
// Update the restored stack to ensure we have freshest data
diff --git a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java
index 6ecdc905a60b..ed531a8e1be3 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/DocumentsActivity.java
@@ -95,13 +95,27 @@ public class DocumentsActivity extends BaseActivity {
RootsFragment.show(getFragmentManager(), null);
}
- if (!mState.restored) {
- // In this case, we set the activity title in AsyncTask.onPostExecute(). To prevent
- // talkback from reading aloud the default title, we clear it here.
- setTitle("");
- new RestoreStackTask(this).execute();
- } else {
+ if (mState.restored) {
refreshCurrentRootAndDirectory(ANIM_NONE);
+ } else {
+ // We set the activity title in AsyncTask.onPostExecute().
+ // To prevent talkback from reading aloud the default title, we clear it here.
+ setTitle("");
+
+ // As a matter of policy we don't load the last used stack for the copy
+ // destination picker (user is already in Files app).
+ // Concensus was that the experice was too confusing.
+ // In all other cases, where the user is visiting us from another app
+ // 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()));
+ } else {
+ if (DEBUG) Log.d(TAG, "Attempting to load last used stack for calling package.");
+ new LoadLastUsedStackTask(this).execute();
+ }
}
}
@@ -443,16 +457,19 @@ public class DocumentsActivity extends BaseActivity {
}
/**
- * Restores the stack from Recents for the specified package.
+ * Loads the last used path (stack) from Recents (history).
+ * The path selected is based on the calling package name. So the last
+ * path for an app like Gmail can be different than the last path
+ * for an app like DropBox.
*/
- private static final class RestoreStackTask
+ private static final class LoadLastUsedStackTask
extends PairedTask<DocumentsActivity, Void, Void> {
private volatile boolean mRestoredStack;
private volatile boolean mExternal;
private State mState;
- public RestoreStackTask(DocumentsActivity activity) {
+ public LoadLastUsedStackTask(DocumentsActivity activity) {
super(activity);
mState = activity.mState;
}
diff --git a/packages/DocumentsUI/src/com/android/documentsui/DownloadsActivity.java b/packages/DocumentsUI/src/com/android/documentsui/DownloadsActivity.java
index 9609dee16489..536feeb4ecc8 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/DownloadsActivity.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/DownloadsActivity.java
@@ -71,7 +71,7 @@ public class DownloadsActivity extends BaseActivity {
// talkback from reading aloud the default title, we clear it here.
setTitle("");
final Uri rootUri = getIntent().getData();
- new RestoreRootTask(this, rootUri).executeOnExecutor(getExecutorForCurrentDirectory());
+ new LoadRootTask(this, rootUri).executeOnExecutor(getExecutorForCurrentDirectory());
} else {
refreshCurrentRootAndDirectory(ANIM_NONE);
}
diff --git a/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java b/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java
index 8b42ac5811b5..a3378ad7e3bd 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/FilesActivity.java
@@ -62,6 +62,12 @@ public class FilesActivity extends BaseActivity {
public static final String TAG = "FilesActivity";
+ // See comments where this const is referenced for details.
+ private static final int DRAWER_NO_FIDDLE_DELAY = 1500;
+
+ // Track the time we opened the drawer in response to back being pressed.
+ // We use the time gap to figure out whether to close app or reopen the drawer.
+ private long mDrawerLastFiddled;
private DocumentClipper mClipper;
public FilesActivity() {
@@ -102,14 +108,12 @@ public class FilesActivity extends BaseActivity {
if (DEBUG) Log.d(TAG, "Launching with root URI.");
// If we've got a specific root to display, restore that root using a dedicated
// authority. That way a misbehaving provider won't result in an ANR.
- new RestoreRootTask(this, uri).executeOnExecutor(
- ProviderExecutor.forAuthority(uri.getAuthority()));
+ loadRoot(uri);
} else {
if (DEBUG) Log.d(TAG, "Launching into Home directory.");
// If all else fails, try to load "Home" directory.
final Uri homeUri = DocumentsContract.buildHomeUri();
- new RestoreRootTask(this, homeUri).executeOnExecutor(
- ProviderExecutor.forAuthority(homeUri.getAuthority()));
+ loadRoot(homeUri);
}
final @DialogType int dialogType = intent.getIntExtra(
@@ -340,6 +344,34 @@ public class FilesActivity extends BaseActivity {
}
}
+ // Do some "do what a I want" drawer fiddling, but don't
+ // do it if user already hit back recently and we recently
+ // did some fiddling.
+ @Override
+ boolean onBeforePopDir() {
+ int size = mState.stack.size();
+
+ if (mDrawer.isPresent()
+ && (System.currentTimeMillis() - mDrawerLastFiddled) > DRAWER_NO_FIDDLE_DELAY) {
+ // Close drawer if it is open.
+ if (mDrawer.isOpen()) {
+ mDrawer.setOpen(false);
+ mDrawerLastFiddled = System.currentTimeMillis();
+ return true;
+ }
+
+ // Open the Close drawer if it is closed and we're at the top of a root.
+ if (size == 1) {
+ mDrawer.setOpen(true);
+ // Remember so we don't just close it again if back is pressed again.
+ mDrawerLastFiddled = System.currentTimeMillis();
+ return true;
+ }
+ }
+
+ return false;
+ }
+
// Turns out only DocumentsActivity was ever calling saveStackBlocking.
// There may be a case where we want to contribute entries from
// Behavior here in FilesActivity, but it isn't yet obvious.
diff --git a/packages/DocumentsUI/src/com/android/documentsui/RestoreRootTask.java b/packages/DocumentsUI/src/com/android/documentsui/LoadRootTask.java
index 9048b9d45ee7..c5d359b1246b 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/RestoreRootTask.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/LoadRootTask.java
@@ -22,12 +22,12 @@ import android.util.Log;
import com.android.documentsui.model.RootInfo;
-final class RestoreRootTask extends PairedTask<BaseActivity, Void, RootInfo> {
+final class LoadRootTask extends PairedTask<BaseActivity, Void, RootInfo> {
private static final String TAG = "RestoreRootTask";
private final Uri mRootUri;
- public RestoreRootTask(BaseActivity activity, Uri rootUri) {
+ public LoadRootTask(BaseActivity activity, Uri rootUri) {
super(activity);
mRootUri = rootUri;
}
diff --git a/packages/DocumentsUI/src/com/android/documentsui/RecentsProvider.java b/packages/DocumentsUI/src/com/android/documentsui/RecentsProvider.java
index 92ffb93365d2..e1b1c09be364 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/RecentsProvider.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/RecentsProvider.java
@@ -95,6 +95,7 @@ public class RecentsProvider extends ContentProvider {
public static final String PACKAGE_NAME = "package_name";
public static final String STACK = "stack";
public static final String TIMESTAMP = "timestamp";
+ // Indicates handler was an external app, like photos.
public static final String EXTERNAL = "external";
}
diff --git a/packages/DocumentsUI/src/com/android/documentsui/State.java b/packages/DocumentsUI/src/com/android/documentsui/State.java
index 2ecbdf615b0e..62f9ea7ed804 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/State.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/State.java
@@ -157,11 +157,13 @@ public class State implements android.os.Parcelable {
mStackTouched = true;
}
+ // This will return true even when the initial location is set.
+ // To get a read on if the user has changed something, use #hasInitialLocationChanged.
public boolean hasLocationChanged() {
return mStackTouched;
}
- public boolean initialLocationHasChanged() {
+ public boolean hasInitialLocationChanged() {
return mInitialRootChanged || mInitialDocChanged;
}
diff --git a/packages/DocumentsUI/src/com/android/documentsui/dirlist/FragmentTuner.java b/packages/DocumentsUI/src/com/android/documentsui/dirlist/FragmentTuner.java
index 59efed66535e..8ef891033901 100644
--- a/packages/DocumentsUI/src/com/android/documentsui/dirlist/FragmentTuner.java
+++ b/packages/DocumentsUI/src/com/android/documentsui/dirlist/FragmentTuner.java
@@ -16,7 +16,6 @@
package com.android.documentsui.dirlist;
-import static com.android.documentsui.Shared.DEBUG;
import static com.android.documentsui.State.ACTION_BROWSE;
import static com.android.documentsui.State.ACTION_CREATE;
import static com.android.documentsui.State.ACTION_GET_CONTENT;
@@ -27,12 +26,10 @@ import static com.android.internal.util.Preconditions.checkArgument;
import android.content.Context;
import android.provider.DocumentsContract.Document;
-import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
-import com.android.documentsui.DocumentsActivity;
-import com.android.documentsui.FilesActivity;
+import com.android.documentsui.BaseActivity;
import com.android.documentsui.Menus;
import com.android.documentsui.MimePredicate;
import com.android.documentsui.R;
@@ -155,11 +152,10 @@ public abstract class FragmentTuner {
@Override
void onModelLoaded(Model model, @ResultType int resultType, boolean isSearch) {
- // When launched into empty recents, show drawer
- if (resultType == DirectoryFragment.TYPE_RECENT_OPEN
- && model.isEmpty()
- && !mState.hasLocationChanged()) {
- ((DocumentsActivity) mContext).setRootsDrawerOpen(true);
+ // When launched into empty root, open drawer.
+ if (model.isEmpty() && !mState.hasInitialLocationChanged() && !isSearch) {
+ // This noops on layouts without drawer, so no need to guard.
+ ((BaseActivity) mContext).setRootsDrawerOpen(true);
}
}
}
@@ -204,8 +200,6 @@ public abstract class FragmentTuner {
*/
private static final class FilesTuner extends FragmentTuner {
- private static final String TAG = "FilesTuner";
-
public FilesTuner(Context context, State state) {
super(context, state);
}
@@ -234,20 +228,15 @@ public abstract class FragmentTuner {
@Override
void onModelLoaded(Model model, @ResultType int resultType, boolean isSearch) {
- if (DEBUG) Log.d(TAG, "Handling model loaded. Has Location shcnage: " + mState.initialLocationHasChanged());
// When launched into empty root, open drawer.
- if (model.isEmpty() && !mState.initialLocationHasChanged() && !isSearch) {
- if (DEBUG) Log.d(TAG, "Showing roots drawer cuz stuffs empty.");
-
+ if (model.isEmpty() && !mState.hasInitialLocationChanged() && !isSearch) {
// This noops on layouts without drawer, so no need to guard.
- ((FilesActivity) mContext).setRootsDrawerOpen(true);
+ ((BaseActivity) mContext).setRootsDrawerOpen(true);
}
- if (DEBUG) Log.d(TAG, "Donezo.");
}
}
private static boolean isDirectory(String mimeType) {
return Document.MIME_TYPE_DIR.equals(mimeType);
}
-
}