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

Commit d811b8fd authored by Ben Lin's avatar Ben Lin Committed by android-build-merger
Browse files

Add Drag and Drop states to RootList.

am: d020212f

Change-Id: Ib672a497b3f183b0bd15794ef2f4808d2879fb55
parents 557c5391 d020212f
Loading
Loading
Loading
Loading
+54 −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;

import static com.android.documentsui.base.Shared.DEBUG;

import android.util.Log;

import com.android.documentsui.base.DocumentInfo;

import java.util.List;

/**
 * A helper class for drag and drop operations
 */
public final class DragAndDropHelper {

    private static final String TAG = "DragAndDropHelper";

    private DragAndDropHelper() {}

    /**
     * Helper method to see whether an item can be dropped/copied into a particular destination.
     * Don't copy from the cwd into a provided list of prohibited directories. (ie. into cwd, into a
     * selected directory). Note: this currently doesn't work for multi-window drag, because
     * localState isn't carried over from one process to another.
     */
    public static boolean canCopyTo(Object dragLocalState, DocumentInfo dst) {
        if (dragLocalState == null || !(dragLocalState instanceof List<?>)) {
            if (DEBUG) Log.d(TAG, "Invalid local state object. Will allow copy.");
            return true;
        }
        List<?> src = (List<?>) dragLocalState;
        if (src.contains(dst)) {
            if (DEBUG) Log.d(TAG, "Drop target same as source. Ignoring.");
            return false;
        }
        return true;
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -166,6 +166,11 @@ public abstract class DrawerController implements DrawerListener {
            setOpen(true);
        }

        @Override
        public void onDragExited(View v, Object localState) {
            // do nothing
        }

        @Override
        public void onViewHovered(View v) {
        }
+5 −0
Original line number Diff line number Diff line
@@ -130,6 +130,11 @@ public final class HorizontalBreadcrumb extends RecyclerView
        // do nothing
    }

    @Override
    public void onDragExited(View v, Object localState) {
        // do nothing
    }

    @Override
    public void onViewHovered(View v) {
        int pos = getChildAdapterPosition(v);
+13 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.documentsui;

import static com.android.documentsui.base.Shared.DEBUG;

import android.content.ClipData;
import android.graphics.drawable.Drawable;
import android.util.Log;
@@ -24,8 +26,10 @@ import android.view.View;
import android.view.View.OnDragListener;

import com.android.documentsui.ItemDragListener.DragHost;
import com.android.documentsui.base.DocumentInfo;
import com.android.internal.annotations.VisibleForTesting;

import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

@@ -67,6 +71,8 @@ public class ItemDragListener<H extends DragHost> implements OnDragListener {
                handleLocationEvent(v, event.getX(), event.getY());
                return true;
            case DragEvent.ACTION_DRAG_EXITED:
                mDragHost.onDragExited(v, event.getLocalState());
                // fall through
            case DragEvent.ACTION_DRAG_ENDED:
                handleExitedEndedEvent(v, event);
                return true;
@@ -97,7 +103,6 @@ public class ItemDragListener<H extends DragHost> implements OnDragListener {

    private void handleExitedEndedEvent(View v, DragEvent event) {
        mDragHost.setDropTargetHighlight(v, event.getLocalState(), false);

        TimerTask task = (TimerTask) v.getTag(R.id.drag_hovering_tag);
        if (task != null) {
            task.cancel();
@@ -171,5 +176,12 @@ public class ItemDragListener<H extends DragHost> implements OnDragListener {
         * @param localState the Local state object given by DragEvent
         */
        void onDragEntered(View v, Object localState);

        /**
         * Notifies right away when drag shadow exits the view
         * @param v the view which drop shadow just exited
         * @param localState the Local state object given by DragEvent
         */
        void onDragExited(View v, Object localState);
    }
}
+3 −6
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.documentsui.dirlist;
import android.view.DragEvent;
import android.view.View;

import com.android.documentsui.DragAndDropHelper;
import com.android.documentsui.ItemDragListener;

import java.util.TimerTask;
@@ -36,10 +37,6 @@ class DirectoryDragListener extends ItemDragListener<DirectoryFragment> {
        final boolean result = super.onDrag(v, event);

        switch (event.getAction()) {
            case DragEvent.ACTION_DRAG_EXITED:
                // If drag exits, we want to update drag and drop status on the drop shadow
                mDragHost.dragExited(v);
                break;
            case DragEvent.ACTION_DRAG_ENDED:
                // getResult() is true if drag was accepted
                mDragHost.dragStopped(event.getResult());
@@ -58,7 +55,7 @@ class DirectoryDragListener extends ItemDragListener<DirectoryFragment> {

    @Override
    public @Nullable TimerTask createOpenTask(final View v, DragEvent event) {
        return mDragHost.canCopyTo(event.getLocalState(), v) ?
                super.createOpenTask(v, event) : null;
        return DragAndDropHelper.canCopyTo(event.getLocalState(), mDragHost.getDestination(v))
                ? super.createOpenTask(v, event) : null;
    }
}
 No newline at end of file
Loading