• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.Point;
20 import android.os.SystemClock;
21 import android.view.MotionEvent;
22 import android.widget.TextView;
23 
24 import androidx.test.uiautomator.By;
25 import androidx.test.uiautomator.BySelector;
26 import androidx.test.uiautomator.UiObject2;
27 
28 /**
29  * App icon, whether in all apps or in workspace/
30  */
31 public final class AppIcon extends Launchable {
AppIcon(LauncherInstrumentation launcher, UiObject2 icon)32     AppIcon(LauncherInstrumentation launcher, UiObject2 icon) {
33         super(launcher, icon);
34     }
35 
getAppIconSelector(String appName, LauncherInstrumentation launcher)36     static BySelector getAppIconSelector(String appName, LauncherInstrumentation launcher) {
37         return By.clazz(TextView.class).text(appName).pkg(launcher.getLauncherPackageName());
38     }
39 
40     /**
41      * Long-clicks the icon to open its menu.
42      */
openMenu()43     public AppIconMenu openMenu() {
44         final Point iconCenter = mObject.getVisibleCenter();
45         final long downTime = SystemClock.uptimeMillis();
46         mLauncher.sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, iconCenter);
47         final UiObject2 deepShortcutsContainer = mLauncher.waitForLauncherObject(
48                 "deep_shortcuts_container");
49         mLauncher.sendPointer(
50                 downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, iconCenter);
51         return new AppIconMenu(mLauncher, deepShortcutsContainer);
52     }
53 
54     @Override
getLongPressIndicator()55     protected String getLongPressIndicator() {
56         return "deep_shortcuts_container";
57     }
58 }
59