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

Commit da2c0f0b authored by Garfield Tan's avatar Garfield Tan
Browse files

Allow user control move/copy during drag and drop.

* Refactor some shared drag and drop logic into one single place.
* Add a workaround for updating badges across windows.
* Add unit tests for DragAndDropManager

Bug: 29581353
Change-Id: I2fcf950194457501e35e1bbc2e00ab68d7962666
parent aa3d615c
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -16,15 +16,21 @@

<selector xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <!-- state when we can't drop -->
    <item
        app:state_droppable="true"
        app:state_drop_hovered="true"
        android:drawable="@drawable/ic_drop_ok_badge" />
        app:state_reject_drop="true"
        android:drawable="@drawable/ic_reject_drop_badge"/>

    <!-- state when we can drop, and it will be a copy -->
    <item
        app:state_droppable="false"
        app:state_drop_hovered="true"
        android:drawable="@drawable/ic_drop_not_ok_badge" />
        app:state_reject_drop="false"
        app:state_copy="true"
        android:drawable="@drawable/ic_drop_copy_badge"/>

    <!-- default state. Also used to show state when we can drop, and it will be a move -->
    <item
        app:state_drop_hovered="false"
        app:state_reject_drop="false"
        app:state_copy="false"
        android:drawable="@android:color/transparent" />
</selector>
 No newline at end of file
+3 −3
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@
    <declare-styleable name="HighlightedItemView">
        <attr name="state_highlighted" format="boolean"/>
    </declare-styleable>
    <declare-styleable name="DroppableItemView">
        <attr name="state_droppable" format="boolean"/>
        <attr name="state_drop_hovered" format="boolean"/>
    <declare-styleable name="DropBadgeView">
        <attr name="state_reject_drop" format="boolean"/>
        <attr name="state_copy" format="boolean"/>
    </declare-styleable>
</resources>
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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 android.annotation.CallSuper;
import android.view.View;

import com.android.documentsui.services.FileOperationService;

/**
 * Provides common functionality for a {@link ItemDragListener.DragHost}.
 */
public abstract class AbstractDragHost implements ItemDragListener.DragHost {

    protected DragAndDropManager mDragAndDropManager;

    public AbstractDragHost(DragAndDropManager dragAndDropManager) {
        mDragAndDropManager = dragAndDropManager;
    }

    @CallSuper
    @Override
    public void onDragExited(View v) {
        mDragAndDropManager.resetState(v);
    }

    @CallSuper
    @Override
    public void onDragEnded() {
        mDragAndDropManager.dragEnded();
    }
}
Loading