1 /* 2 * Copyright (C) 2017 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.testing; 18 19 import android.annotation.Nullable; 20 import android.content.ClipData; 21 import android.net.Uri; 22 import android.util.Pair; 23 import android.view.KeyEvent; 24 import android.view.View; 25 26 import com.android.documentsui.ActionHandler; 27 import com.android.documentsui.DragAndDropManager; 28 import com.android.documentsui.MenuManager; 29 import com.android.documentsui.MenuManager.SelectionDetails; 30 import com.android.documentsui.base.DocumentInfo; 31 import com.android.documentsui.base.DocumentStack; 32 import com.android.documentsui.base.RootInfo; 33 import com.android.documentsui.dirlist.IconHelper; 34 import com.android.documentsui.services.FileOperations; 35 36 import java.util.List; 37 38 public class TestDragAndDropManager implements DragAndDropManager { 39 40 public final TestEventListener<List<DocumentInfo>> startDragHandler = new TestEventListener<>(); 41 public final TestEventHandler<Pair<ClipData, RootInfo>> dropOnRootHandler = 42 new TestEventHandler<>(); 43 public final TestEventHandler<Pair<ClipData, DocumentStack>> dropOnDocumentHandler = 44 new TestEventHandler<>(); 45 46 @Override 47 public void onKeyEvent(KeyEvent event) {} 48 49 @Override 50 public void startDrag(View v, List<DocumentInfo> srcs, RootInfo root, List<Uri> invalidDest, 51 SelectionDetails details, IconHelper iconHelper, @Nullable DocumentInfo parent) { 52 startDragHandler.accept(srcs); 53 } 54 55 @Override 56 public boolean canSpringOpen(RootInfo root, DocumentInfo doc) { 57 return false; 58 } 59 60 @Override 61 public void updateStateToNotAllowed(View v) {} 62 63 @Override 64 public int updateState(View v, RootInfo destRoot, @Nullable DocumentInfo destDoc) { 65 return 0; 66 } 67 68 @Override 69 public void resetState(View v) {} 70 71 @Override 72 public boolean drop(ClipData clipData, Object localState, RootInfo root, ActionHandler actions, 73 FileOperations.Callback callback) { 74 return dropOnRootHandler.accept(Pair.create(clipData, root)); 75 } 76 77 @Override 78 public boolean drop(ClipData clipData, Object localState, DocumentStack dstStack, 79 FileOperations.Callback callback) { 80 return dropOnDocumentHandler.accept(Pair.create(clipData, dstStack)); 81 } 82 83 @Override 84 public void dragEnded() {} 85 } 86