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 22 import com.android.documentsui.DragAndDropHelper; 23 import com.android.documentsui.ItemDragListener; 24 25 import java.util.TimerTask; 26 27 import javax.annotation.Nullable; 28 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 39 switch (event.getAction()) { 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; 46 } 47 48 return result; 49 } 50 51 @Override 52 public boolean handleDropEventChecked(View v, DragEvent event) { 53 return mDragHost.handleDropEvent(v, event); 54 } 55 56 @Override 57 public @Nullable TimerTask createOpenTask(final View v, DragEvent event) { 58 return DragAndDropHelper.canCopyTo(event.getLocalState(), mDragHost.getDestination(v)) 59 ? super.createOpenTask(v, event) : null; 60 } 61 }