From 359bbebb6d4c1eb6a4ad8df754c22d151aa22556 Mon Sep 17 00:00:00 2001 From: Ben Kwa Date: Wed, 17 Feb 2016 10:48:57 -0800 Subject: [PATCH] Implement backspace support. Pressing backspace pops the user up a directory level if they aren't at the root directory of the current root. BUG=27123794 Change-Id: I8f0a88a1194bf8f082d0b057a288a0c3da3068f6 --- .../com/android/documentsui/BaseActivity.java | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java index 4a55906e56c12..69d4bb9a79912 100644 --- a/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java +++ b/packages/DocumentsUI/src/com/android/documentsui/BaseActivity.java @@ -284,7 +284,7 @@ public abstract class BaseActivity extends Activity if (dir != null) { dir.pasteFromClipboard(); } - return true; + return true; case R.id.menu_advanced: setDisplayAdvancedDevices(!LocalPreferences.getDisplayAdvancedDevices(this)); @@ -456,7 +456,7 @@ public abstract class BaseActivity extends Activity DirectoryFragment dir = getDirectoryFragment(); if (dir != null) { dir.onSortOrderChanged(); - }; + } } /** @@ -474,7 +474,7 @@ public abstract class BaseActivity extends Activity DirectoryFragment dir = getDirectoryFragment(); if (dir != null) { dir.onViewModeChanged(); - }; + } } public void setPending(boolean pending) { @@ -562,9 +562,7 @@ public abstract class BaseActivity extends Activity } } - if (size > 1) { - mState.stack.pop(); - refreshCurrentRootAndDirectory(ANIM_LEAVE); + if (popDir()) { return; } @@ -604,8 +602,12 @@ public abstract class BaseActivity extends Activity return true; } } else if (keyCode == KeyEvent.KEYCODE_TAB) { + // Tab toggles focus on the navigation drawer. toggleNavDrawerFocus(); return true; + } else if (keyCode == KeyEvent.KEYCODE_DEL) { + popDir(); + return true; } return super.onKeyDown(keyCode, event); } @@ -642,6 +644,21 @@ public abstract class BaseActivity extends Activity } } + /** + * Pops the top entry off the directory stack, and returns the user to the previous directory. + * If the directory stack only contains one item, this method does nothing. + * + * @return Whether the stack was popped. + */ + private boolean popDir() { + if (mState.stack.size() > 1) { + mState.stack.pop(); + refreshCurrentRootAndDirectory(ANIM_LEAVE); + return true; + } + return false; + } + private static final class PickRootTask extends PairedTask { private RootInfo mRoot;