Loading src/com/android/documentsui/ActionHandler.java +14 −3 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.content.pm.ResolveInfo; import com.android.documentsui.base.DocumentInfo; import com.android.documentsui.base.RootInfo; import com.android.documentsui.clipping.DocumentClipper; import com.android.documentsui.dirlist.DocumentDetails; import com.android.documentsui.sidebar.EjectRootTask; import com.android.documentsui.sidebar.RootsFragment; Loading @@ -31,7 +32,7 @@ import java.util.function.Consumer; /** * Provides support for specializing the actions (openDocument etc.) to the host activity. */ public class ActionHandler<T extends BaseActivity> { public abstract class ActionHandler<T extends BaseActivity> { protected T mActivity; Loading Loading @@ -85,12 +86,22 @@ public class ActionHandler<T extends BaseActivity> { throw new UnsupportedOperationException("Can't show app details."); } public void open(RootInfo root) { public void openRoot(RootInfo root) { Metrics.logRootVisited(mActivity, root); mActivity.onRootPicked(root); } public void open(ResolveInfo app) { public void openRoot(ResolveInfo app) { throw new UnsupportedOperationException("Can't open an app."); } public boolean viewDocument(DocumentDetails doc) { throw new UnsupportedOperationException("Direct view not supported!"); } public boolean previewDocument(DocumentDetails doc) { throw new UnsupportedOperationException("Preview not supported!"); } public abstract boolean openDocument(DocumentDetails doc); } src/com/android/documentsui/BaseActivity.java +6 −3 Original line number Diff line number Diff line Loading @@ -140,8 +140,7 @@ public abstract class BaseActivity extends Activity implements NavigationViewMan * Provides Activity a means of injection into and specialization of * DirectoryFragment. */ public abstract FragmentTuner getFragmentTuner( Model model, MultiSelectManager selectionMgr, boolean mSearchMode); public abstract FragmentTuner getFragmentTuner(Model model, boolean mSearchMode); /** * Provides Activity a means of injection into and specialization of Loading @@ -158,8 +157,12 @@ public abstract class BaseActivity extends Activity implements NavigationViewMan /** * Provides Activity a means of injection into and specialization of * fragment actions. * * Args can be nullable when called from a contact without this information such as * RootsFragment. */ public abstract ActionHandler<? extends BaseActivity> getActionHandler(); public abstract ActionHandler<? extends BaseActivity> getActionHandler( @Nullable Model model, @Nullable MultiSelectManager selectionMgr); public abstract void onDocumentPicked(DocumentInfo doc, Model model); public abstract void onDocumentsPicked(List<DocumentInfo> docs); Loading src/com/android/documentsui/dirlist/DirectoryFragment.java +12 −11 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import com.android.documentsui.ActionHandler; import com.android.documentsui.BaseActivity; import com.android.documentsui.BaseActivity.RetainedState; import com.android.documentsui.DirectoryLoader; Loading Loading @@ -142,6 +143,12 @@ public class DirectoryFragment extends Fragment // This dependency is informally "injected" from the owning Activity in our onCreate method. private FragmentTuner mTuner; // This dependency is informally "injected" from the owning Activity in our onCreate method. private FocusManager mFocusManager; // This dependency is informally "injected" from the owning Activity in our onCreate method. private ActionHandler<?> mActionHandler; // This dependency is informally "injected" from the owning Activity in our onCreate method. private MenuManager mMenuManager; Loading @@ -149,7 +156,6 @@ public class DirectoryFragment extends Fragment private ActionModeController mActionModeController; private SelectionMetadata mSelectionMetadata; private UserInputHandler<InputEvent> mInputHandler; private FocusManager mFocusManager; private @Nullable BandController mBandController; private DragHoverListener mDragHoverListener; private IconHelper mIconHelper; Loading Loading @@ -292,13 +298,12 @@ public class DirectoryFragment extends Fragment final int edgeHeight = (int) getResources().getDimension(R.dimen.autoscroll_edge_height); GestureSelector gestureSel = GestureSelector.create( edgeHeight, mSelectionMgr, mRecView); edgeHeight, mSelectionMgr, mRecView); final BaseActivity activity = getBaseActivity(); mTuner = activity.getFragmentTuner(mModel, mSelectionMgr, mConfig.mSearchMode); mTuner = activity.getFragmentTuner(mModel, mConfig.mSearchMode); mFocusManager = activity.getFocusManager(mRecView, mModel); mActionHandler = activity.getActionHandler(mModel, mSelectionMgr); mMenuManager = activity.getMenuManager(); if (state.allowMultiple) { Loading @@ -322,16 +327,12 @@ public class DirectoryFragment extends Fragment ? gestureSel::start : EventHandler.createStub(false); mInputHandler = new UserInputHandler<>( mSelectionMgr, mActionHandler, mFocusManager, mSelectionMgr, (MotionEvent t) -> MotionInputEvent.obtain(t, mRecView), this::canSelect, this::onRightClick, // TODO: consider injecting the tuner directly into the handler for // less middle-man action. (DocumentDetails details) -> mTuner.openDocument(details.getModelId()), (DocumentDetails details) -> mTuner.viewDocument(details.getModelId()), (DocumentDetails details) -> mTuner.previewDocument(details.getModelId()), (DocumentDetails ignored) -> onDeleteSelectedDocuments(), // delete handler mDragStartListener::onTouchDragEvent, gestureHandler); Loading src/com/android/documentsui/dirlist/FragmentTuner.java +4 −10 Original line number Diff line number Diff line Loading @@ -51,21 +51,15 @@ public abstract class FragmentTuner { return false; } // TODO: Move to action handler. @Deprecated protected void showChooserForDoc(DocumentInfo doc) { throw new UnsupportedOperationException("Show chooser not supported!"); } // TODO: Move to action handler. @Deprecated protected void openInNewWindow(DocumentStack stack, DocumentInfo doc) { throw new UnsupportedOperationException("Open in new window not supported!"); } protected boolean viewDocument(String id) { throw new UnsupportedOperationException("Direct view not supported!"); } protected boolean previewDocument(String id) { throw new UnsupportedOperationException("Preview not supported!"); } protected abstract boolean openDocument(String id); } src/com/android/documentsui/dirlist/UserInputHandler.java +13 −28 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.view.GestureDetector; import android.view.KeyEvent; import android.view.MotionEvent; import com.android.documentsui.ActionHandler; import com.android.documentsui.base.EventHandler; import com.android.documentsui.base.Events; import com.android.documentsui.base.Events.InputEvent; Loading @@ -43,15 +44,15 @@ public final class UserInputHandler<T extends InputEvent> private static final String TAG = "UserInputHandler"; private final MultiSelectManager mSelectionMgr; private ActionHandler<?> mActionHandler; private final FocusHandler mFocusHandler; private final MultiSelectManager mSelectionMgr; private final Function<MotionEvent, T> mEventConverter; private final Predicate<DocumentDetails> mSelectable; private final EventHandler<InputEvent> mRightClickHandler; private final EventHandler<DocumentDetails> mOpenHandler; private final EventHandler<DocumentDetails> mViewHandler; private final EventHandler<DocumentDetails> mPreviewHandler; private final EventHandler<DocumentDetails> mDeleteHandler; private final EventHandler<InputEvent> mTouchDragListener; private final EventHandler<InputEvent> mGestureSelectHandler; Loading @@ -60,26 +61,22 @@ public final class UserInputHandler<T extends InputEvent> private final KeyInputHandler mKeyListener; public UserInputHandler( MultiSelectManager selectionMgr, ActionHandler<?> actionHandler, FocusHandler focusHandler, MultiSelectManager selectionMgr, Function<MotionEvent, T> eventConverter, Predicate<DocumentDetails> selectable, EventHandler<InputEvent> rightClickHandler, EventHandler<DocumentDetails> openHandler, EventHandler<DocumentDetails> viewHandler, EventHandler<DocumentDetails> previewHandler, EventHandler<DocumentDetails> deleteHandler, EventHandler<InputEvent> touchDragListener, EventHandler<InputEvent> gestureSelectHandler) { mSelectionMgr = selectionMgr; mActionHandler = actionHandler; mFocusHandler = focusHandler; mSelectionMgr = selectionMgr; mEventConverter = eventConverter; mSelectable = selectable; mRightClickHandler = rightClickHandler; mOpenHandler = openHandler; mViewHandler = viewHandler; mPreviewHandler = previewHandler; mDeleteHandler = deleteHandler; mTouchDragListener = touchDragListener; mGestureSelectHandler = gestureSelectHandler; Loading Loading @@ -190,18 +187,6 @@ public final class UserInputHandler<T extends InputEvent> return mKeyListener.onKey(doc, keyCode, event); } private boolean openDocument(DocumentDetails doc) { return mOpenHandler.accept(doc); } private boolean viewDocument(DocumentDetails doc) { return mViewHandler.accept(doc); } private boolean previewDocument(DocumentDetails doc) { return mPreviewHandler.accept(doc); } private boolean selectDocument(DocumentDetails doc) { assert(doc != null); assert(doc.hasModelId()); Loading Loading @@ -260,7 +245,7 @@ public final class UserInputHandler<T extends InputEvent> // otherwise they activate. return doc.isInSelectionHotspot(event) ? selectDocument(doc) : openDocument(doc); : mActionHandler.openDocument(doc); } boolean onSingleTapConfirmed(T event) { Loading Loading @@ -394,7 +379,7 @@ public final class UserInputHandler<T extends InputEvent> } DocumentDetails doc = event.getDocumentDetails(); return viewDocument(doc); return mActionHandler.viewDocument(doc); } final void onLongPress(T event) { Loading Loading @@ -460,9 +445,9 @@ public final class UserInputHandler<T extends InputEvent> // For non-shifted enter keypresses, fall through. case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_BUTTON_A: return viewDocument(doc); return mActionHandler.viewDocument(doc); case KeyEvent.KEYCODE_SPACE: return previewDocument(doc); return mActionHandler.previewDocument(doc); case KeyEvent.KEYCODE_FORWARD_DEL: // This has to be handled here instead of in a keyboard shortcut, because // keyboard shortcuts all have to be modified with the 'Ctrl' key. Loading Loading
src/com/android/documentsui/ActionHandler.java +14 −3 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.content.pm.ResolveInfo; import com.android.documentsui.base.DocumentInfo; import com.android.documentsui.base.RootInfo; import com.android.documentsui.clipping.DocumentClipper; import com.android.documentsui.dirlist.DocumentDetails; import com.android.documentsui.sidebar.EjectRootTask; import com.android.documentsui.sidebar.RootsFragment; Loading @@ -31,7 +32,7 @@ import java.util.function.Consumer; /** * Provides support for specializing the actions (openDocument etc.) to the host activity. */ public class ActionHandler<T extends BaseActivity> { public abstract class ActionHandler<T extends BaseActivity> { protected T mActivity; Loading Loading @@ -85,12 +86,22 @@ public class ActionHandler<T extends BaseActivity> { throw new UnsupportedOperationException("Can't show app details."); } public void open(RootInfo root) { public void openRoot(RootInfo root) { Metrics.logRootVisited(mActivity, root); mActivity.onRootPicked(root); } public void open(ResolveInfo app) { public void openRoot(ResolveInfo app) { throw new UnsupportedOperationException("Can't open an app."); } public boolean viewDocument(DocumentDetails doc) { throw new UnsupportedOperationException("Direct view not supported!"); } public boolean previewDocument(DocumentDetails doc) { throw new UnsupportedOperationException("Preview not supported!"); } public abstract boolean openDocument(DocumentDetails doc); }
src/com/android/documentsui/BaseActivity.java +6 −3 Original line number Diff line number Diff line Loading @@ -140,8 +140,7 @@ public abstract class BaseActivity extends Activity implements NavigationViewMan * Provides Activity a means of injection into and specialization of * DirectoryFragment. */ public abstract FragmentTuner getFragmentTuner( Model model, MultiSelectManager selectionMgr, boolean mSearchMode); public abstract FragmentTuner getFragmentTuner(Model model, boolean mSearchMode); /** * Provides Activity a means of injection into and specialization of Loading @@ -158,8 +157,12 @@ public abstract class BaseActivity extends Activity implements NavigationViewMan /** * Provides Activity a means of injection into and specialization of * fragment actions. * * Args can be nullable when called from a contact without this information such as * RootsFragment. */ public abstract ActionHandler<? extends BaseActivity> getActionHandler(); public abstract ActionHandler<? extends BaseActivity> getActionHandler( @Nullable Model model, @Nullable MultiSelectManager selectionMgr); public abstract void onDocumentPicked(DocumentInfo doc, Model model); public abstract void onDocumentsPicked(List<DocumentInfo> docs); Loading
src/com/android/documentsui/dirlist/DirectoryFragment.java +12 −11 Original line number Diff line number Diff line Loading @@ -63,6 +63,7 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import com.android.documentsui.ActionHandler; import com.android.documentsui.BaseActivity; import com.android.documentsui.BaseActivity.RetainedState; import com.android.documentsui.DirectoryLoader; Loading Loading @@ -142,6 +143,12 @@ public class DirectoryFragment extends Fragment // This dependency is informally "injected" from the owning Activity in our onCreate method. private FragmentTuner mTuner; // This dependency is informally "injected" from the owning Activity in our onCreate method. private FocusManager mFocusManager; // This dependency is informally "injected" from the owning Activity in our onCreate method. private ActionHandler<?> mActionHandler; // This dependency is informally "injected" from the owning Activity in our onCreate method. private MenuManager mMenuManager; Loading @@ -149,7 +156,6 @@ public class DirectoryFragment extends Fragment private ActionModeController mActionModeController; private SelectionMetadata mSelectionMetadata; private UserInputHandler<InputEvent> mInputHandler; private FocusManager mFocusManager; private @Nullable BandController mBandController; private DragHoverListener mDragHoverListener; private IconHelper mIconHelper; Loading Loading @@ -292,13 +298,12 @@ public class DirectoryFragment extends Fragment final int edgeHeight = (int) getResources().getDimension(R.dimen.autoscroll_edge_height); GestureSelector gestureSel = GestureSelector.create( edgeHeight, mSelectionMgr, mRecView); edgeHeight, mSelectionMgr, mRecView); final BaseActivity activity = getBaseActivity(); mTuner = activity.getFragmentTuner(mModel, mSelectionMgr, mConfig.mSearchMode); mTuner = activity.getFragmentTuner(mModel, mConfig.mSearchMode); mFocusManager = activity.getFocusManager(mRecView, mModel); mActionHandler = activity.getActionHandler(mModel, mSelectionMgr); mMenuManager = activity.getMenuManager(); if (state.allowMultiple) { Loading @@ -322,16 +327,12 @@ public class DirectoryFragment extends Fragment ? gestureSel::start : EventHandler.createStub(false); mInputHandler = new UserInputHandler<>( mSelectionMgr, mActionHandler, mFocusManager, mSelectionMgr, (MotionEvent t) -> MotionInputEvent.obtain(t, mRecView), this::canSelect, this::onRightClick, // TODO: consider injecting the tuner directly into the handler for // less middle-man action. (DocumentDetails details) -> mTuner.openDocument(details.getModelId()), (DocumentDetails details) -> mTuner.viewDocument(details.getModelId()), (DocumentDetails details) -> mTuner.previewDocument(details.getModelId()), (DocumentDetails ignored) -> onDeleteSelectedDocuments(), // delete handler mDragStartListener::onTouchDragEvent, gestureHandler); Loading
src/com/android/documentsui/dirlist/FragmentTuner.java +4 −10 Original line number Diff line number Diff line Loading @@ -51,21 +51,15 @@ public abstract class FragmentTuner { return false; } // TODO: Move to action handler. @Deprecated protected void showChooserForDoc(DocumentInfo doc) { throw new UnsupportedOperationException("Show chooser not supported!"); } // TODO: Move to action handler. @Deprecated protected void openInNewWindow(DocumentStack stack, DocumentInfo doc) { throw new UnsupportedOperationException("Open in new window not supported!"); } protected boolean viewDocument(String id) { throw new UnsupportedOperationException("Direct view not supported!"); } protected boolean previewDocument(String id) { throw new UnsupportedOperationException("Preview not supported!"); } protected abstract boolean openDocument(String id); }
src/com/android/documentsui/dirlist/UserInputHandler.java +13 −28 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import android.view.GestureDetector; import android.view.KeyEvent; import android.view.MotionEvent; import com.android.documentsui.ActionHandler; import com.android.documentsui.base.EventHandler; import com.android.documentsui.base.Events; import com.android.documentsui.base.Events.InputEvent; Loading @@ -43,15 +44,15 @@ public final class UserInputHandler<T extends InputEvent> private static final String TAG = "UserInputHandler"; private final MultiSelectManager mSelectionMgr; private ActionHandler<?> mActionHandler; private final FocusHandler mFocusHandler; private final MultiSelectManager mSelectionMgr; private final Function<MotionEvent, T> mEventConverter; private final Predicate<DocumentDetails> mSelectable; private final EventHandler<InputEvent> mRightClickHandler; private final EventHandler<DocumentDetails> mOpenHandler; private final EventHandler<DocumentDetails> mViewHandler; private final EventHandler<DocumentDetails> mPreviewHandler; private final EventHandler<DocumentDetails> mDeleteHandler; private final EventHandler<InputEvent> mTouchDragListener; private final EventHandler<InputEvent> mGestureSelectHandler; Loading @@ -60,26 +61,22 @@ public final class UserInputHandler<T extends InputEvent> private final KeyInputHandler mKeyListener; public UserInputHandler( MultiSelectManager selectionMgr, ActionHandler<?> actionHandler, FocusHandler focusHandler, MultiSelectManager selectionMgr, Function<MotionEvent, T> eventConverter, Predicate<DocumentDetails> selectable, EventHandler<InputEvent> rightClickHandler, EventHandler<DocumentDetails> openHandler, EventHandler<DocumentDetails> viewHandler, EventHandler<DocumentDetails> previewHandler, EventHandler<DocumentDetails> deleteHandler, EventHandler<InputEvent> touchDragListener, EventHandler<InputEvent> gestureSelectHandler) { mSelectionMgr = selectionMgr; mActionHandler = actionHandler; mFocusHandler = focusHandler; mSelectionMgr = selectionMgr; mEventConverter = eventConverter; mSelectable = selectable; mRightClickHandler = rightClickHandler; mOpenHandler = openHandler; mViewHandler = viewHandler; mPreviewHandler = previewHandler; mDeleteHandler = deleteHandler; mTouchDragListener = touchDragListener; mGestureSelectHandler = gestureSelectHandler; Loading Loading @@ -190,18 +187,6 @@ public final class UserInputHandler<T extends InputEvent> return mKeyListener.onKey(doc, keyCode, event); } private boolean openDocument(DocumentDetails doc) { return mOpenHandler.accept(doc); } private boolean viewDocument(DocumentDetails doc) { return mViewHandler.accept(doc); } private boolean previewDocument(DocumentDetails doc) { return mPreviewHandler.accept(doc); } private boolean selectDocument(DocumentDetails doc) { assert(doc != null); assert(doc.hasModelId()); Loading Loading @@ -260,7 +245,7 @@ public final class UserInputHandler<T extends InputEvent> // otherwise they activate. return doc.isInSelectionHotspot(event) ? selectDocument(doc) : openDocument(doc); : mActionHandler.openDocument(doc); } boolean onSingleTapConfirmed(T event) { Loading Loading @@ -394,7 +379,7 @@ public final class UserInputHandler<T extends InputEvent> } DocumentDetails doc = event.getDocumentDetails(); return viewDocument(doc); return mActionHandler.viewDocument(doc); } final void onLongPress(T event) { Loading Loading @@ -460,9 +445,9 @@ public final class UserInputHandler<T extends InputEvent> // For non-shifted enter keypresses, fall through. case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_BUTTON_A: return viewDocument(doc); return mActionHandler.viewDocument(doc); case KeyEvent.KEYCODE_SPACE: return previewDocument(doc); return mActionHandler.previewDocument(doc); case KeyEvent.KEYCODE_FORWARD_DEL: // This has to be handled here instead of in a keyboard shortcut, because // keyboard shortcuts all have to be modified with the 'Ctrl' key. Loading