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 public class Folder { 25 26 protected static final String FOLDER_CONTENT_RES_ID = "folder_content"; 27 28 private final UiObject2 mContainer; 29 private final LauncherInstrumentation mLauncher; 30 Folder(LauncherInstrumentation launcher)31 Folder(LauncherInstrumentation launcher) { 32 this.mLauncher = launcher; 33 this.mContainer = launcher.waitForLauncherObject(FOLDER_CONTENT_RES_ID); 34 } 35 36 /** 37 * Find an app icon with given name or raise assertion error. 38 */ 39 @NonNull getAppIcon(String appName)40 public HomeAppIcon getAppIcon(String appName) { 41 try (LauncherInstrumentation.Closable ignored = mLauncher.addContextLayer( 42 "Want to get app icon in folder")) { 43 return new WorkspaceAppIcon(mLauncher, 44 mLauncher.waitForObjectInContainer( 45 mContainer, 46 AppIcon.getAppIconSelector(appName, mLauncher))); 47 } 48 } 49 50 /** 51 * Close opened folder if possible. It throws assertion error if the folder is already closed. 52 */ close()53 public Workspace close() { 54 try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); 55 LauncherInstrumentation.Closable c = mLauncher.addContextLayer( 56 "Want to close opened folder")) { 57 mLauncher.waitForLauncherObject(FOLDER_CONTENT_RES_ID); 58 mLauncher.touchOutsideContainer(this.mContainer, false /* tapRight */); 59 mLauncher.waitUntilLauncherObjectGone(FOLDER_CONTENT_RES_ID); 60 return mLauncher.getWorkspace(); 61 } 62 } getDropLocationBounds()63 Rect getDropLocationBounds() { 64 return mLauncher.getVisibleBounds(mContainer); 65 } 66 } 67