blob: e7340a11cbcbd7e53f58de0d503ec11898629aa3 [file] [log] [blame]
Garfield, Tan804133e2016-04-20 15:13:56 -07001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.documentsui.dirlist;
18
19import android.view.DragEvent;
20import android.view.View;
21
Ben Lind0202122016-11-10 18:00:12 -080022import com.android.documentsui.DragAndDropHelper;
Garfield, Tan804133e2016-04-20 15:13:56 -070023import com.android.documentsui.ItemDragListener;
24
Ben Lin5a305b42016-09-08 11:33:07 -070025import java.util.TimerTask;
26
27import javax.annotation.Nullable;
28
Garfield, Tan804133e2016-04-20 15:13:56 -070029class DirectoryDragListener extends ItemDragListener<DirectoryFragment> {
30
31 DirectoryDragListener(DirectoryFragment fragment) {
32 super(fragment);
33 }
34
35 @Override
36 public boolean onDrag(View v, DragEvent event) {
37 final boolean result = super.onDrag(v, event);
38
Ben Lin1c456292016-10-07 16:43:18 -070039 switch (event.getAction()) {
Ben Lin1c456292016-10-07 16:43:18 -070040 case DragEvent.ACTION_DRAG_ENDED:
41 // getResult() is true if drag was accepted
42 mDragHost.dragStopped(event.getResult());
43 break;
44 default:
45 break;
Garfield, Tan804133e2016-04-20 15:13:56 -070046 }
47
48 return result;
49 }
50
51 @Override
52 public boolean handleDropEventChecked(View v, DragEvent event) {
53 return mDragHost.handleDropEvent(v, event);
54 }
Ben Lin5a305b42016-09-08 11:33:07 -070055
56 @Override
57 public @Nullable TimerTask createOpenTask(final View v, DragEvent event) {
Ben Lind0202122016-11-10 18:00:12 -080058 return DragAndDropHelper.canCopyTo(event.getLocalState(), mDragHost.getDestination(v))
59 ? super.createOpenTask(v, event) : null;
Ben Lin5a305b42016-09-08 11:33:07 -070060 }
Ben Linc5e3e8e2016-07-13 18:16:36 -070061}