Loading src/com/android/documentsui/AbstractActionHandler.java +6 −11 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ import java.util.function.Consumer; import javax.annotation.Nullable; /** * Provides support for specializing the actions (viewDocument etc.) to the host activity. * Provides support for specializing the actions (openDocument etc.) to the host activity. */ public abstract class AbstractActionHandler<T extends Activity & CommonAddons> implements ActionHandler { Loading Loading @@ -190,6 +190,11 @@ public abstract class AbstractActionHandler<T extends Activity & CommonAddons> mActivity.startActivity(intent); } @Override public boolean openDocument(DocumentDetails doc, @ViewType int type, @ViewType int fallback) { throw new UnsupportedOperationException("Can't open document."); } @Override public void springOpenDirectory(DocumentInfo doc) { throw new UnsupportedOperationException("Can't spring open directories."); Loading Loading @@ -254,16 +259,6 @@ public abstract class AbstractActionHandler<T extends Activity & CommonAddons> throw new UnsupportedOperationException("Can't rename documents."); } @Override public boolean viewDocument(DocumentDetails doc) { throw new UnsupportedOperationException("Direct view not supported!"); } @Override public boolean previewDocument(DocumentDetails doc) { throw new UnsupportedOperationException("Preview not supported!"); } @Override public void showChooserForDoc(DocumentInfo doc) { throw new UnsupportedOperationException("Show chooser for doc not supported!"); Loading src/com/android/documentsui/ActionHandler.java +19 −6 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.documentsui; import android.annotation.IntDef; import android.content.ContentProvider; import android.content.Intent; import android.content.pm.ResolveInfo; Loading @@ -28,12 +29,25 @@ import com.android.documentsui.base.DocumentStack; import com.android.documentsui.base.RootInfo; import com.android.documentsui.dirlist.DocumentDetails; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.function.Consumer; import javax.annotation.Nullable; public interface ActionHandler { @IntDef({ VIEW_TYPE_NONE, VIEW_TYPE_REGULAR, VIEW_TYPE_PREVIEW }) @Retention(RetentionPolicy.SOURCE) public @interface ViewType {} public static final int VIEW_TYPE_NONE = 0; public static final int VIEW_TYPE_REGULAR = 1; public static final int VIEW_TYPE_PREVIEW = 2; void openSettings(RootInfo root); /** Loading @@ -46,7 +60,6 @@ public interface ActionHandler { */ void ejectRoot(RootInfo root, BooleanConsumer listener); /** * Attempts to fetch the DocumentInfo for the supplied root. Returns the DocumentInfo to the * callback. If the task times out, callback will be called with null DocumentInfo. Supply Loading Loading @@ -78,11 +91,11 @@ public interface ActionHandler { @Nullable DocumentInfo renameDocument(String name, DocumentInfo document); boolean viewDocument(DocumentDetails doc); boolean previewDocument(DocumentDetails doc); boolean openDocument(DocumentDetails doc); /** * If container, then opens the container, otherwise views using the specified type of view. * If the primary view type is unavailable, then fallback to the alternative type of view. */ boolean openDocument(DocumentDetails doc, @ViewType int type, @ViewType int fallback); /** * This is called when user hovers over a doc for enough time during a drag n' drop, to open a Loading src/com/android/documentsui/dirlist/DirectoryFragment.java +2 −1 Original line number Diff line number Diff line Loading @@ -695,7 +695,8 @@ public class DirectoryFragment extends Fragment private boolean onAccessibilityClick(View child) { DocumentDetails doc = getDocumentHolder(child); mActions.openDocument(doc); mActions.openDocument(doc, ActionHandler.VIEW_TYPE_PREVIEW, ActionHandler.VIEW_TYPE_REGULAR); return true; } Loading src/com/android/documentsui/dirlist/UserInputHandler.java +8 −4 Original line number Diff line number Diff line Loading @@ -244,7 +244,8 @@ public final class UserInputHandler<T extends InputEvent> // otherwise they activate. return doc.isInSelectionHotspot(event) ? selectDocument(doc) : mActions.openDocument(doc); : mActions.openDocument(doc, ActionHandler.VIEW_TYPE_PREVIEW, ActionHandler.VIEW_TYPE_REGULAR); } boolean onSingleTapConfirmed(T event) { Loading Loading @@ -401,7 +402,8 @@ public final class UserInputHandler<T extends InputEvent> } DocumentDetails doc = event.getDocumentDetails(); return mActions.viewDocument(doc); return mActions.openDocument(doc, ActionHandler.VIEW_TYPE_REGULAR, ActionHandler.VIEW_TYPE_PREVIEW); } final void onLongPress(T event) { Loading Loading @@ -478,9 +480,11 @@ 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 mActions.viewDocument(doc); return mActions.openDocument(doc, ActionHandler.VIEW_TYPE_REGULAR, ActionHandler.VIEW_TYPE_PREVIEW); case KeyEvent.KEYCODE_SPACE: return mActions.previewDocument(doc); return mActions.openDocument(doc, ActionHandler.VIEW_TYPE_PREVIEW, ActionHandler.VIEW_TYPE_NONE); } return false; Loading src/com/android/documentsui/files/ActionHandler.java +55 −32 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ import com.android.documentsui.services.FileOperation; import com.android.documentsui.services.FileOperationService; import com.android.documentsui.services.FileOperations; import com.android.documentsui.ui.DialogController; import com.android.internal.annotations.VisibleForTesting; import java.io.IOException; import java.util.ArrayList; Loading Loading @@ -194,7 +195,8 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa } @Override public boolean openDocument(DocumentDetails details) { public boolean openDocument(DocumentDetails details, @ViewType int type, @ViewType int fallback) { DocumentInfo doc = mModel.getDocument(details.getModelId()); if (doc == null) { Log.w(TAG, Loading @@ -202,8 +204,14 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa return false; } return openDocument(doc, type, fallback); } // TODO: Make this private and make tests call openDocument(DocumentDetails, int, int) instead. @VisibleForTesting public boolean openDocument(DocumentInfo doc, @ViewType int type, @ViewType int fallback) { if (mConfig.isDocumentEnabled(doc.mimeType, doc.flags, mState)) { onDocumentPicked(doc); onDocumentPicked(doc, type, fallback); mSelectionMgr.clearSelection(); return true; } Loading @@ -217,21 +225,6 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa openContainerDocument(doc); } @Override public boolean viewDocument(DocumentDetails details) { DocumentInfo doc = mModel.getDocument(details.getModelId()); return viewDocument(doc); } @Override public boolean previewDocument(DocumentDetails details) { DocumentInfo doc = mModel.getDocument(details.getModelId()); if (doc.isContainer()) { return false; } return previewDocument(doc); } private Selection getSelectedOrFocused() { final Selection selection = this.getStableSelection(); if (selection.isEmpty()) { Loading Loading @@ -486,7 +479,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa } } public void onDocumentPicked(DocumentInfo doc) { private void onDocumentPicked(DocumentInfo doc, @ViewType int type, @ViewType int fallback) { if (doc.isContainer()) { openContainerDocument(doc); return; Loading @@ -496,35 +489,65 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa return; } switch (type) { case VIEW_TYPE_REGULAR: if (viewDocument(doc)) { return; } break; case VIEW_TYPE_PREVIEW: if (previewDocument(doc)) { return; } break; default: throw new IllegalArgumentException("Illegal view type."); } viewDocument(doc); switch (fallback) { case VIEW_TYPE_REGULAR: if (viewDocument(doc)) { return; } break; public boolean viewDocument(DocumentInfo doc) { case VIEW_TYPE_PREVIEW: if (previewDocument(doc)) { return; } break; case VIEW_TYPE_NONE: break; default: throw new IllegalArgumentException("Illegal fallback view type."); } // Failed to view including fallback, and it's in an archive. if (type != VIEW_TYPE_NONE && fallback != VIEW_TYPE_NONE && doc.isInArchive()) { mDialogs.showViewInArchivesUnsupported(); } } private boolean viewDocument(DocumentInfo doc) { if (doc.isPartial()) { Log.w(TAG, "Can't view partial file."); return false; } if (doc.isInArchive()) { mDialogs.showViewInArchivesUnsupported(); Log.w(TAG, "Can't view files in archives."); return false; } if (doc.isContainer()) { openContainerDocument(doc); return true; } // this is a redundant check. if (manageDocument(doc)) { if (doc.isDirectory()) { Log.w(TAG, "Can't view directories."); return true; } // Fall back to traditional VIEW action... Intent intent = buildViewIntent(doc); if (DEBUG && intent.getClipData() != null) { Log.d(TAG, "Starting intent w/ clip data: " + intent.getClipData()); Loading @@ -539,7 +562,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa return false; } public boolean previewDocument(DocumentInfo doc) { private boolean previewDocument(DocumentInfo doc) { if (doc.isPartial()) { Log.w(TAG, "Can't view partial file."); return false; Loading Loading
src/com/android/documentsui/AbstractActionHandler.java +6 −11 Original line number Diff line number Diff line Loading @@ -67,7 +67,7 @@ import java.util.function.Consumer; import javax.annotation.Nullable; /** * Provides support for specializing the actions (viewDocument etc.) to the host activity. * Provides support for specializing the actions (openDocument etc.) to the host activity. */ public abstract class AbstractActionHandler<T extends Activity & CommonAddons> implements ActionHandler { Loading Loading @@ -190,6 +190,11 @@ public abstract class AbstractActionHandler<T extends Activity & CommonAddons> mActivity.startActivity(intent); } @Override public boolean openDocument(DocumentDetails doc, @ViewType int type, @ViewType int fallback) { throw new UnsupportedOperationException("Can't open document."); } @Override public void springOpenDirectory(DocumentInfo doc) { throw new UnsupportedOperationException("Can't spring open directories."); Loading Loading @@ -254,16 +259,6 @@ public abstract class AbstractActionHandler<T extends Activity & CommonAddons> throw new UnsupportedOperationException("Can't rename documents."); } @Override public boolean viewDocument(DocumentDetails doc) { throw new UnsupportedOperationException("Direct view not supported!"); } @Override public boolean previewDocument(DocumentDetails doc) { throw new UnsupportedOperationException("Preview not supported!"); } @Override public void showChooserForDoc(DocumentInfo doc) { throw new UnsupportedOperationException("Show chooser for doc not supported!"); Loading
src/com/android/documentsui/ActionHandler.java +19 −6 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.documentsui; import android.annotation.IntDef; import android.content.ContentProvider; import android.content.Intent; import android.content.pm.ResolveInfo; Loading @@ -28,12 +29,25 @@ import com.android.documentsui.base.DocumentStack; import com.android.documentsui.base.RootInfo; import com.android.documentsui.dirlist.DocumentDetails; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.function.Consumer; import javax.annotation.Nullable; public interface ActionHandler { @IntDef({ VIEW_TYPE_NONE, VIEW_TYPE_REGULAR, VIEW_TYPE_PREVIEW }) @Retention(RetentionPolicy.SOURCE) public @interface ViewType {} public static final int VIEW_TYPE_NONE = 0; public static final int VIEW_TYPE_REGULAR = 1; public static final int VIEW_TYPE_PREVIEW = 2; void openSettings(RootInfo root); /** Loading @@ -46,7 +60,6 @@ public interface ActionHandler { */ void ejectRoot(RootInfo root, BooleanConsumer listener); /** * Attempts to fetch the DocumentInfo for the supplied root. Returns the DocumentInfo to the * callback. If the task times out, callback will be called with null DocumentInfo. Supply Loading Loading @@ -78,11 +91,11 @@ public interface ActionHandler { @Nullable DocumentInfo renameDocument(String name, DocumentInfo document); boolean viewDocument(DocumentDetails doc); boolean previewDocument(DocumentDetails doc); boolean openDocument(DocumentDetails doc); /** * If container, then opens the container, otherwise views using the specified type of view. * If the primary view type is unavailable, then fallback to the alternative type of view. */ boolean openDocument(DocumentDetails doc, @ViewType int type, @ViewType int fallback); /** * This is called when user hovers over a doc for enough time during a drag n' drop, to open a Loading
src/com/android/documentsui/dirlist/DirectoryFragment.java +2 −1 Original line number Diff line number Diff line Loading @@ -695,7 +695,8 @@ public class DirectoryFragment extends Fragment private boolean onAccessibilityClick(View child) { DocumentDetails doc = getDocumentHolder(child); mActions.openDocument(doc); mActions.openDocument(doc, ActionHandler.VIEW_TYPE_PREVIEW, ActionHandler.VIEW_TYPE_REGULAR); return true; } Loading
src/com/android/documentsui/dirlist/UserInputHandler.java +8 −4 Original line number Diff line number Diff line Loading @@ -244,7 +244,8 @@ public final class UserInputHandler<T extends InputEvent> // otherwise they activate. return doc.isInSelectionHotspot(event) ? selectDocument(doc) : mActions.openDocument(doc); : mActions.openDocument(doc, ActionHandler.VIEW_TYPE_PREVIEW, ActionHandler.VIEW_TYPE_REGULAR); } boolean onSingleTapConfirmed(T event) { Loading Loading @@ -401,7 +402,8 @@ public final class UserInputHandler<T extends InputEvent> } DocumentDetails doc = event.getDocumentDetails(); return mActions.viewDocument(doc); return mActions.openDocument(doc, ActionHandler.VIEW_TYPE_REGULAR, ActionHandler.VIEW_TYPE_PREVIEW); } final void onLongPress(T event) { Loading Loading @@ -478,9 +480,11 @@ 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 mActions.viewDocument(doc); return mActions.openDocument(doc, ActionHandler.VIEW_TYPE_REGULAR, ActionHandler.VIEW_TYPE_PREVIEW); case KeyEvent.KEYCODE_SPACE: return mActions.previewDocument(doc); return mActions.openDocument(doc, ActionHandler.VIEW_TYPE_PREVIEW, ActionHandler.VIEW_TYPE_NONE); } return false; Loading
src/com/android/documentsui/files/ActionHandler.java +55 −32 Original line number Diff line number Diff line Loading @@ -64,6 +64,7 @@ import com.android.documentsui.services.FileOperation; import com.android.documentsui.services.FileOperationService; import com.android.documentsui.services.FileOperations; import com.android.documentsui.ui.DialogController; import com.android.internal.annotations.VisibleForTesting; import java.io.IOException; import java.util.ArrayList; Loading Loading @@ -194,7 +195,8 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa } @Override public boolean openDocument(DocumentDetails details) { public boolean openDocument(DocumentDetails details, @ViewType int type, @ViewType int fallback) { DocumentInfo doc = mModel.getDocument(details.getModelId()); if (doc == null) { Log.w(TAG, Loading @@ -202,8 +204,14 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa return false; } return openDocument(doc, type, fallback); } // TODO: Make this private and make tests call openDocument(DocumentDetails, int, int) instead. @VisibleForTesting public boolean openDocument(DocumentInfo doc, @ViewType int type, @ViewType int fallback) { if (mConfig.isDocumentEnabled(doc.mimeType, doc.flags, mState)) { onDocumentPicked(doc); onDocumentPicked(doc, type, fallback); mSelectionMgr.clearSelection(); return true; } Loading @@ -217,21 +225,6 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa openContainerDocument(doc); } @Override public boolean viewDocument(DocumentDetails details) { DocumentInfo doc = mModel.getDocument(details.getModelId()); return viewDocument(doc); } @Override public boolean previewDocument(DocumentDetails details) { DocumentInfo doc = mModel.getDocument(details.getModelId()); if (doc.isContainer()) { return false; } return previewDocument(doc); } private Selection getSelectedOrFocused() { final Selection selection = this.getStableSelection(); if (selection.isEmpty()) { Loading Loading @@ -486,7 +479,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa } } public void onDocumentPicked(DocumentInfo doc) { private void onDocumentPicked(DocumentInfo doc, @ViewType int type, @ViewType int fallback) { if (doc.isContainer()) { openContainerDocument(doc); return; Loading @@ -496,35 +489,65 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa return; } switch (type) { case VIEW_TYPE_REGULAR: if (viewDocument(doc)) { return; } break; case VIEW_TYPE_PREVIEW: if (previewDocument(doc)) { return; } break; default: throw new IllegalArgumentException("Illegal view type."); } viewDocument(doc); switch (fallback) { case VIEW_TYPE_REGULAR: if (viewDocument(doc)) { return; } break; public boolean viewDocument(DocumentInfo doc) { case VIEW_TYPE_PREVIEW: if (previewDocument(doc)) { return; } break; case VIEW_TYPE_NONE: break; default: throw new IllegalArgumentException("Illegal fallback view type."); } // Failed to view including fallback, and it's in an archive. if (type != VIEW_TYPE_NONE && fallback != VIEW_TYPE_NONE && doc.isInArchive()) { mDialogs.showViewInArchivesUnsupported(); } } private boolean viewDocument(DocumentInfo doc) { if (doc.isPartial()) { Log.w(TAG, "Can't view partial file."); return false; } if (doc.isInArchive()) { mDialogs.showViewInArchivesUnsupported(); Log.w(TAG, "Can't view files in archives."); return false; } if (doc.isContainer()) { openContainerDocument(doc); return true; } // this is a redundant check. if (manageDocument(doc)) { if (doc.isDirectory()) { Log.w(TAG, "Can't view directories."); return true; } // Fall back to traditional VIEW action... Intent intent = buildViewIntent(doc); if (DEBUG && intent.getClipData() != null) { Log.d(TAG, "Starting intent w/ clip data: " + intent.getClipData()); Loading @@ -539,7 +562,7 @@ public class ActionHandler<T extends Activity & Addons> extends AbstractActionHa return false; } public boolean previewDocument(DocumentInfo doc) { private boolean previewDocument(DocumentInfo doc) { if (doc.isPartial()) { Log.w(TAG, "Can't view partial file."); return false; Loading