Garfield, Tan | 804133e | 2016-04-20 15:13:56 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.documentsui.dirlist; |
| 18 | |
| 19 | import android.view.DragEvent; |
| 20 | import android.view.View; |
| 21 | |
Ben Lin | d020212 | 2016-11-10 18:00:12 -0800 | [diff] [blame] | 22 | import com.android.documentsui.DragAndDropHelper; |
Garfield, Tan | 804133e | 2016-04-20 15:13:56 -0700 | [diff] [blame] | 23 | import com.android.documentsui.ItemDragListener; |
| 24 | |
Ben Lin | 5a305b4 | 2016-09-08 11:33:07 -0700 | [diff] [blame] | 25 | import java.util.TimerTask; |
| 26 | |
| 27 | import javax.annotation.Nullable; |
| 28 | |
Garfield, Tan | 804133e | 2016-04-20 15:13:56 -0700 | [diff] [blame] | 29 | class 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 Lin | 1c45629 | 2016-10-07 16:43:18 -0700 | [diff] [blame] | 39 | switch (event.getAction()) { |
Ben Lin | 1c45629 | 2016-10-07 16:43:18 -0700 | [diff] [blame] | 40 | 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, Tan | 804133e | 2016-04-20 15:13:56 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | return result; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public boolean handleDropEventChecked(View v, DragEvent event) { |
| 53 | return mDragHost.handleDropEvent(v, event); |
| 54 | } |
Ben Lin | 5a305b4 | 2016-09-08 11:33:07 -0700 | [diff] [blame] | 55 | |
| 56 | @Override |
| 57 | public @Nullable TimerTask createOpenTask(final View v, DragEvent event) { |
Ben Lin | d020212 | 2016-11-10 18:00:12 -0800 | [diff] [blame] | 58 | return DragAndDropHelper.canCopyTo(event.getLocalState(), mDragHost.getDestination(v)) |
| 59 | ? super.createOpenTask(v, event) : null; |
Ben Lin | 5a305b4 | 2016-09-08 11:33:07 -0700 | [diff] [blame] | 60 | } |
Ben Lin | c5e3e8e | 2016-07-13 18:16:36 -0700 | [diff] [blame] | 61 | } |