Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 87949740 authored by Tomasz Mikolajewski's avatar Tomasz Mikolajewski Committed by android-build-merger
Browse files

Merge "Fix viewing files in archives by mouse." into arc-apps

am: 44be0b8b

Change-Id: I76623390deb1b46d36f8ea5de5513f1e821078df
parents 3e1fb92b 44be0b8b
Loading
Loading
Loading
Loading
+6 −11
Original line number Diff line number Diff line
@@ -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 {
@@ -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.");
@@ -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!");
+19 −6
Original line number Diff line number Diff line
@@ -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;
@@ -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);

    /**
@@ -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
@@ -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
+2 −1
Original line number Diff line number Diff line
@@ -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;
    }

+8 −4
Original line number Diff line number Diff line
@@ -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) {
@@ -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) {
@@ -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;
+55 −32
Original line number Diff line number Diff line
@@ -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;
@@ -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,
@@ -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;
        }
@@ -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()) {
@@ -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;
@@ -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());
@@ -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