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 17package com.android.documentsui.dirlist; 18 19import android.view.DragEvent; 20import android.view.View; 21 22import com.android.documentsui.DragAndDropManager; 23import com.android.documentsui.ItemDragListener; 24 25import java.util.TimerTask; 26 27import javax.annotation.Nullable; 28 29class DirectoryDragListener extends ItemDragListener<DragHost<?>> { 30 31 32 DirectoryDragListener(com.android.documentsui.dirlist.DragHost<?> host) { 33 super(host); 34 } 35 36 @Override 37 public boolean onDrag(View v, DragEvent event) { 38 final boolean result = super.onDrag(v, event); 39 40 switch (event.getAction()) { 41 case DragEvent.ACTION_DRAG_ENDED: 42 // getResult() is true if drag was accepted 43 mDragHost.dragStopped(event.getResult()); 44 break; 45 default: 46 break; 47 } 48 49 return result; 50 } 51 52 @Override 53 public boolean handleDropEventChecked(View v, DragEvent event) { 54 return mDragHost.handleDropEvent(v, event); 55 } 56 57 @Override 58 public @Nullable TimerTask createOpenTask(final View v, DragEvent event) { 59 return mDragHost.canSpringOpen(v) 60 ? super.createOpenTask(v, event) : null; 61 } 62}