1 /* 2 * Copyright (C) 2021 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.launcher3.tapl; 18 19 import android.graphics.Rect; 20 21 import androidx.annotation.NonNull; 22 import androidx.test.uiautomator.UiObject2; 23 24 import com.android.launcher3.testing.TestProtocol; 25 26 /** 27 * Folder Icon, an app folder in workspace. 28 */ 29 public class FolderIcon implements FolderDragTarget { 30 31 protected final UiObject2 mObject; 32 protected final LauncherInstrumentation mLauncher; 33 FolderIcon(LauncherInstrumentation launcher, UiObject2 icon)34 FolderIcon(LauncherInstrumentation launcher, UiObject2 icon) { 35 mObject = icon; 36 mLauncher = launcher; 37 } 38 39 /** 40 * Open and return a folder or raise assertion error. 41 */ 42 @NonNull open()43 public Folder open() { 44 try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); 45 LauncherInstrumentation.Closable c = mLauncher.addContextLayer("open folder")) { 46 mLauncher.executeAndWaitForLauncherEvent(() -> mLauncher.clickLauncherObject(mObject), 47 event -> TestProtocol.FOLDER_OPENED_MESSAGE.equals( 48 event.getClassName().toString()), 49 () -> "Fail to open folder.", 50 "open folder"); 51 } 52 return new Folder(mLauncher); 53 } 54 55 @Override getDropLocationBounds()56 public Rect getDropLocationBounds() { 57 return mLauncher.getVisibleBounds(mObject.getParent()); 58 } 59 60 @Override getTargetFolder(Rect bounds)61 public FolderIcon getTargetFolder(Rect bounds) { 62 return this; 63 } 64 } 65