Loading src/com/android/documentsui/files/ActivityInputHandler.java 0 → 100644 +49 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.documentsui.files; import android.view.KeyEvent; import com.android.documentsui.selection.SelectionManager; import com.android.documentsui.ActionHandler; /** * Used by {@link FilesActivity} to manage global keyboard shortcuts tied to file actions */ final class ActivityInputHandler { private final SelectionManager mSelectionMgr; private final ActionHandler mActions; ActivityInputHandler(SelectionManager selectionMgr, ActionHandler actionHandler) { mSelectionMgr = selectionMgr; mActions = actionHandler; } boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_DEL && event.isAltPressed()) || keyCode == KeyEvent.KEYCODE_FORWARD_DEL) { if (mSelectionMgr.hasSelection()) { mActions.deleteSelectedDocuments(); return true; } else { return false; } } return false; } } No newline at end of file src/com/android/documentsui/files/FilesActivity.java +5 −10 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ public class FilesActivity private DialogController mDialogs; private DocumentClipper mClipper; private ActionModeController mActionModeController; private ActivityInputHandler mActivityInputHandler; public FilesActivity() { super(R.layout.files_activity, TAG); Loading Loading @@ -121,6 +122,8 @@ public class FilesActivity mClipper, DocumentsApplication.getClipStore(this)); mActivityInputHandler = new ActivityInputHandler(mSelectionMgr, mActions); RootsFragment.show(getFragmentManager(), null); final Intent intent = getIntent(); Loading Loading @@ -288,16 +291,8 @@ public class FilesActivity @CallSuper @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_DEL && event.isAltPressed()) || keyCode == KeyEvent.KEYCODE_FORWARD_DEL) { if (mSelectionMgr.hasSelection()) { mActions.deleteSelectedDocuments(); return true; } else { return false; } } return super.onKeyDown(keyCode, event); return mActivityInputHandler.onKeyDown(keyCode, event) ? true : super.onKeyDown(keyCode, event); } @Override Loading tests/common/com/android/documentsui/testing/TestActionHandler.java +6 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ public class TestActionHandler extends AbstractActionHandler<TestActivity> { public final TestEventHandler<DocumentDetails> open = new TestEventHandler<>(); public final TestEventHandler<DocumentDetails> view = new TestEventHandler<>(); public final TestEventHandler<DocumentDetails> preview = new TestEventHandler<>(); public boolean mDeleteHappened; public TestActionHandler() { this(TestEnv.create()); Loading Loading @@ -59,6 +60,11 @@ public class TestActionHandler extends AbstractActionHandler<TestActivity> { return preview.accept(doc); } @Override public void deleteSelectedDocuments() { mDeleteHappened = true; } @Override public void openRoot(RootInfo root) { throw new UnsupportedOperationException(); Loading tests/unit/com/android/documentsui/dirlist/DragStartListenerTest.java +0 −5 Original line number Diff line number Diff line Loading @@ -92,11 +92,6 @@ public class DragStartListenerTest extends AndroidTestCase { .primary(); } @Override protected void tearDown() throws Exception { mMultiSelectManager.clearSelection(); } public void testDragStarted_OnMouseMove() { assertTrue(mListener.onMouseDragEvent(mEvent.build())); assertTrue(mDragStarted); Loading tests/unit/com/android/documentsui/files/ActivityInputHandlerTest.java 0 → 100644 +73 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.documentsui.files; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.support.test.filters.MediumTest; import android.support.test.runner.AndroidJUnit4; import android.view.KeyEvent; import android.view.MotionEvent; import com.android.documentsui.dirlist.TestData; import com.android.documentsui.selection.SelectionManager; import com.android.documentsui.selection.SelectionProbe; import com.android.documentsui.testing.SelectionManagers; import com.android.documentsui.testing.TestActionHandler; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.util.List; @RunWith(AndroidJUnit4.class) @MediumTest public class ActivityInputHandlerTest { private static final List<String> ITEMS = TestData.create(100); private SelectionProbe mSelection; private TestActionHandler mActionHandler; private ActivityInputHandler mActivityInputHandler; @Before public void setUp() { SelectionManager selectionMgr = SelectionManagers.createTestInstance(ITEMS); mSelection = new SelectionProbe(selectionMgr); mActionHandler = new TestActionHandler(); mActivityInputHandler = new ActivityInputHandler(selectionMgr, mActionHandler); } @Test public void testDelete_noSelection() { KeyEvent event = new KeyEvent(0, 0, MotionEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL, 0, KeyEvent.META_ALT_ON); assertFalse(mActivityInputHandler.onKeyDown(event.getKeyCode(), event)); assertFalse(mActionHandler.mDeleteHappened); } @Test public void testDelete_hasSelection() { mSelection.select(1); KeyEvent event = new KeyEvent(0, 0, MotionEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL, 0, KeyEvent.META_ALT_ON); assertTrue(mActivityInputHandler.onKeyDown(event.getKeyCode(), event)); assertTrue(mActionHandler.mDeleteHappened); } } Loading
src/com/android/documentsui/files/ActivityInputHandler.java 0 → 100644 +49 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.documentsui.files; import android.view.KeyEvent; import com.android.documentsui.selection.SelectionManager; import com.android.documentsui.ActionHandler; /** * Used by {@link FilesActivity} to manage global keyboard shortcuts tied to file actions */ final class ActivityInputHandler { private final SelectionManager mSelectionMgr; private final ActionHandler mActions; ActivityInputHandler(SelectionManager selectionMgr, ActionHandler actionHandler) { mSelectionMgr = selectionMgr; mActions = actionHandler; } boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_DEL && event.isAltPressed()) || keyCode == KeyEvent.KEYCODE_FORWARD_DEL) { if (mSelectionMgr.hasSelection()) { mActions.deleteSelectedDocuments(); return true; } else { return false; } } return false; } } No newline at end of file
src/com/android/documentsui/files/FilesActivity.java +5 −10 Original line number Diff line number Diff line Loading @@ -78,6 +78,7 @@ public class FilesActivity private DialogController mDialogs; private DocumentClipper mClipper; private ActionModeController mActionModeController; private ActivityInputHandler mActivityInputHandler; public FilesActivity() { super(R.layout.files_activity, TAG); Loading Loading @@ -121,6 +122,8 @@ public class FilesActivity mClipper, DocumentsApplication.getClipStore(this)); mActivityInputHandler = new ActivityInputHandler(mSelectionMgr, mActions); RootsFragment.show(getFragmentManager(), null); final Intent intent = getIntent(); Loading Loading @@ -288,16 +291,8 @@ public class FilesActivity @CallSuper @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_DEL && event.isAltPressed()) || keyCode == KeyEvent.KEYCODE_FORWARD_DEL) { if (mSelectionMgr.hasSelection()) { mActions.deleteSelectedDocuments(); return true; } else { return false; } } return super.onKeyDown(keyCode, event); return mActivityInputHandler.onKeyDown(keyCode, event) ? true : super.onKeyDown(keyCode, event); } @Override Loading
tests/common/com/android/documentsui/testing/TestActionHandler.java +6 −0 Original line number Diff line number Diff line Loading @@ -28,6 +28,7 @@ public class TestActionHandler extends AbstractActionHandler<TestActivity> { public final TestEventHandler<DocumentDetails> open = new TestEventHandler<>(); public final TestEventHandler<DocumentDetails> view = new TestEventHandler<>(); public final TestEventHandler<DocumentDetails> preview = new TestEventHandler<>(); public boolean mDeleteHappened; public TestActionHandler() { this(TestEnv.create()); Loading Loading @@ -59,6 +60,11 @@ public class TestActionHandler extends AbstractActionHandler<TestActivity> { return preview.accept(doc); } @Override public void deleteSelectedDocuments() { mDeleteHappened = true; } @Override public void openRoot(RootInfo root) { throw new UnsupportedOperationException(); Loading
tests/unit/com/android/documentsui/dirlist/DragStartListenerTest.java +0 −5 Original line number Diff line number Diff line Loading @@ -92,11 +92,6 @@ public class DragStartListenerTest extends AndroidTestCase { .primary(); } @Override protected void tearDown() throws Exception { mMultiSelectManager.clearSelection(); } public void testDragStarted_OnMouseMove() { assertTrue(mListener.onMouseDragEvent(mEvent.build())); assertTrue(mDragStarted); Loading
tests/unit/com/android/documentsui/files/ActivityInputHandlerTest.java 0 → 100644 +73 −0 Original line number Diff line number Diff line /* * Copyright (C) 2016 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.documentsui.files; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import android.support.test.filters.MediumTest; import android.support.test.runner.AndroidJUnit4; import android.view.KeyEvent; import android.view.MotionEvent; import com.android.documentsui.dirlist.TestData; import com.android.documentsui.selection.SelectionManager; import com.android.documentsui.selection.SelectionProbe; import com.android.documentsui.testing.SelectionManagers; import com.android.documentsui.testing.TestActionHandler; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.util.List; @RunWith(AndroidJUnit4.class) @MediumTest public class ActivityInputHandlerTest { private static final List<String> ITEMS = TestData.create(100); private SelectionProbe mSelection; private TestActionHandler mActionHandler; private ActivityInputHandler mActivityInputHandler; @Before public void setUp() { SelectionManager selectionMgr = SelectionManagers.createTestInstance(ITEMS); mSelection = new SelectionProbe(selectionMgr); mActionHandler = new TestActionHandler(); mActivityInputHandler = new ActivityInputHandler(selectionMgr, mActionHandler); } @Test public void testDelete_noSelection() { KeyEvent event = new KeyEvent(0, 0, MotionEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL, 0, KeyEvent.META_ALT_ON); assertFalse(mActivityInputHandler.onKeyDown(event.getKeyCode(), event)); assertFalse(mActionHandler.mDeleteHappened); } @Test public void testDelete_hasSelection() { mSelection.select(1); KeyEvent event = new KeyEvent(0, 0, MotionEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL, 0, KeyEvent.META_ALT_ON); assertTrue(mActivityInputHandler.onKeyDown(event.getKeyCode(), event)); assertTrue(mActionHandler.mDeleteHappened); } }