1 /*
2  * Copyright (C) 2024 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.taskbar;
18 
19 import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_ALLAPPS_BUTTON_LONG_PRESS;
20 import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASKBAR_ALLAPPS_BUTTON_TAP;
21 
22 import android.view.InputDevice;
23 import android.view.MotionEvent;
24 import android.view.View;
25 
26 import com.android.internal.jank.Cuj;
27 import com.android.systemui.shared.system.InteractionJankMonitorWrapper;
28 
29 /**
30  * Callbacks for {@link TaskbarView} to interact with its controller.
31  */
32 public class TaskbarViewCallbacks {
33 
34     private final TaskbarActivityContext mActivity;
35     private final TaskbarControllers mControllers;
36     private final TaskbarView mTaskbarView;
37 
TaskbarViewCallbacks(TaskbarActivityContext activity, TaskbarControllers controllers, TaskbarView taskbarView)38     public TaskbarViewCallbacks(TaskbarActivityContext activity, TaskbarControllers controllers,
39             TaskbarView taskbarView) {
40         mActivity = activity;
41         mControllers = controllers;
42         mTaskbarView = taskbarView;
43     }
44 
getIconOnClickListener()45     public View.OnClickListener getIconOnClickListener() {
46         return mActivity.getItemOnClickListener();
47     }
48 
49     /** Trigger All Apps button click action. */
triggerAllAppsButtonClick(View v)50     protected void triggerAllAppsButtonClick(View v) {
51         InteractionJankMonitorWrapper.begin(v, Cuj.CUJ_LAUNCHER_OPEN_ALL_APPS,
52                 /* tag= */ "TASKBAR_BUTTON");
53         mActivity.getStatsLogManager().logger().log(LAUNCHER_TASKBAR_ALLAPPS_BUTTON_TAP);
54         mControllers.taskbarAllAppsController.toggle();
55     }
56 
57     /** Trigger All Apps button long click action. */
triggerAllAppsButtonLongClick()58     protected void triggerAllAppsButtonLongClick() {
59         mActivity.getStatsLogManager().logger().log(LAUNCHER_TASKBAR_ALLAPPS_BUTTON_LONG_PRESS);
60     }
61 
isAllAppsButtonHapticFeedbackEnabled()62     public boolean isAllAppsButtonHapticFeedbackEnabled() {
63         return false;
64     }
65 
getTaskbarDividerLongClickListener()66     public View.OnLongClickListener getTaskbarDividerLongClickListener() {
67         return v -> {
68             mControllers.taskbarPinningController.showPinningView(v);
69             return true;
70         };
71     }
72 
getTaskbarDividerRightClickListener()73     public View.OnTouchListener getTaskbarDividerRightClickListener() {
74         return (v, event) -> {
75             if (event.isFromSource(InputDevice.SOURCE_MOUSE)
76                     && event.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
77                 mControllers.taskbarPinningController.showPinningView(v);
78                 return true;
79             }
80             return false;
81         };
82     }
83 
84     public View.OnLongClickListener getIconOnLongClickListener() {
85         return mControllers.taskbarDragController::startDragOnLongClick;
86     }
87 
88     /** Gets the hover listener for the provided icon view. */
89     public View.OnHoverListener getIconOnHoverListener(View icon) {
90         return new TaskbarHoverToolTipController(mActivity, mTaskbarView, icon);
91     }
92 
93     /**
94      * Notifies launcher to update icon alignment.
95      */
96     public void notifyIconLayoutBoundsChanged() {
97         mControllers.uiController.onIconLayoutBoundsChanged();
98     }
99 
100     /**
101      * Notifies the taskbar scrim when the visibility of taskbar changes.
102      */
103     public void notifyVisibilityChanged() {
104         mControllers.taskbarScrimViewController.onTaskbarVisibilityChanged(
105                 mTaskbarView.getVisibility());
106     }
107 }
108