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.testing; 18 19 import android.content.Intent; 20 21 import com.android.documentsui.AbstractActionHandler; 22 import com.android.documentsui.TestActivity; 23 import com.android.documentsui.base.DocumentInfo; 24 import com.android.documentsui.base.RootInfo; 25 import com.android.documentsui.dirlist.DocumentDetails; 26 27 import java.util.function.Consumer; 28 29 public class TestActionHandler extends AbstractActionHandler<TestActivity> { 30 31 private final TestEnv mEnv; 32 33 public final TestEventHandler<DocumentDetails> open = new TestEventHandler<>(); 34 public boolean mDeleteHappened; 35 36 public DocumentInfo nextRootDocument; 37 TestActionHandler()38 public TestActionHandler() { 39 this(TestEnv.create()); 40 } 41 TestActionHandler(TestEnv env)42 public TestActionHandler(TestEnv env) { 43 super( 44 TestActivity.create(env), 45 env.state, 46 env.providers, 47 env.docs, 48 env.searchViewManager, 49 (String authority) -> null, 50 env.injector); 51 52 mEnv = env; 53 } 54 55 @Override openDocument(DocumentDetails doc, @ViewType int type, @ViewType int fallback)56 public boolean openDocument(DocumentDetails doc, @ViewType int type, @ViewType int fallback) { 57 return open.accept(doc); 58 } 59 60 @Override deleteSelectedDocuments()61 public void deleteSelectedDocuments() { 62 mDeleteHappened = true; 63 } 64 65 @Override openRoot(RootInfo root)66 public void openRoot(RootInfo root) { 67 throw new UnsupportedOperationException(); 68 } 69 70 @Override initLocation(Intent intent)71 public void initLocation(Intent intent) { 72 throw new UnsupportedOperationException(); 73 } 74 75 @Override launchToDefaultLocation()76 protected void launchToDefaultLocation() { 77 throw new UnsupportedOperationException(); 78 } 79 80 @Override getRootDocument(RootInfo root, int timeout, Consumer<DocumentInfo> callback)81 public void getRootDocument(RootInfo root, int timeout, Consumer<DocumentInfo> callback) { 82 mEnv.mExecutor.submit(() -> { 83 callback.accept(nextRootDocument); 84 }); 85 } 86 } 87