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.content.ClipData; 20 import android.net.Uri; 21 import android.util.Pair; 22 import android.view.KeyEvent; 23 import android.view.View; 24 25 import androidx.annotation.Nullable; 26 27 import com.android.documentsui.ActionHandler; 28 import com.android.documentsui.DragAndDropManager; 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 onKeyEvent(KeyEvent event)47 public void onKeyEvent(KeyEvent event) {} 48 49 @Override startDrag(View v, List<DocumentInfo> srcs, RootInfo root, List<Uri> invalidDest, SelectionDetails details, IconHelper iconHelper, @Nullable DocumentInfo parent)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 canSpringOpen(RootInfo root, DocumentInfo doc)56 public boolean canSpringOpen(RootInfo root, DocumentInfo doc) { 57 return false; 58 } 59 60 @Override updateStateToNotAllowed(View v)61 public void updateStateToNotAllowed(View v) {} 62 63 @Override updateState(View v, RootInfo destRoot, @Nullable DocumentInfo destDoc)64 public int updateState(View v, RootInfo destRoot, @Nullable DocumentInfo destDoc) { 65 return 0; 66 } 67 68 @Override resetState(View v)69 public void resetState(View v) {} 70 71 @Override isDragFromSameApp()72 public boolean isDragFromSameApp() { 73 return true; 74 } 75 76 @Override drop(ClipData clipData, Object localState, RootInfo root, ActionHandler actions, FileOperations.Callback callback)77 public boolean drop(ClipData clipData, Object localState, RootInfo root, ActionHandler actions, 78 FileOperations.Callback callback) { 79 return dropOnRootHandler.accept(Pair.create(clipData, root)); 80 } 81 82 @Override drop(ClipData clipData, Object localState, DocumentStack dstStack, FileOperations.Callback callback)83 public boolean drop(ClipData clipData, Object localState, DocumentStack dstStack, 84 FileOperations.Callback callback) { 85 return dropOnDocumentHandler.accept(Pair.create(clipData, dstStack)); 86 } 87 88 @Override dragEnded()89 public void dragEnded() {} 90 } 91