1 /* 2 * Copyright (C) 2022 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 package com.android.launcher3.taskbar.overlay; 17 18 import android.content.Context; 19 import android.view.View; 20 21 import androidx.annotation.Nullable; 22 23 import com.android.launcher3.DeviceProfile; 24 import com.android.launcher3.R; 25 import com.android.launcher3.dot.DotInfo; 26 import com.android.launcher3.model.data.ItemInfo; 27 import com.android.launcher3.popup.PopupDataProvider; 28 import com.android.launcher3.taskbar.BaseTaskbarContext; 29 import com.android.launcher3.taskbar.TaskbarActivityContext; 30 import com.android.launcher3.taskbar.TaskbarControllers; 31 import com.android.launcher3.taskbar.TaskbarDragController; 32 import com.android.launcher3.taskbar.TaskbarUIController; 33 import com.android.launcher3.taskbar.allapps.TaskbarAllAppsContainerView; 34 import com.android.launcher3.taskbar.allapps.TaskbarSearchSessionController; 35 import com.android.launcher3.util.SplitConfigurationOptions.SplitSelectSource; 36 37 /** 38 * Window context for the taskbar overlays such as All Apps and EDU. 39 * <p> 40 * Overlays have their own window and need a window context. Some properties are delegated to the 41 * {@link TaskbarActivityContext} such as {@link PopupDataProvider}. 42 */ 43 public class TaskbarOverlayContext extends BaseTaskbarContext { 44 private final TaskbarActivityContext mTaskbarContext; 45 46 private final TaskbarOverlayController mOverlayController; 47 private final TaskbarDragController mDragController; 48 private final TaskbarOverlayDragLayer mDragLayer; 49 50 private final int mStashedTaskbarHeight; 51 private final TaskbarUIController mUiController; 52 53 private @Nullable TaskbarSearchSessionController mSearchSessionController; 54 TaskbarOverlayContext( Context windowContext, TaskbarActivityContext taskbarContext, TaskbarControllers controllers)55 public TaskbarOverlayContext( 56 Context windowContext, 57 TaskbarActivityContext taskbarContext, 58 TaskbarControllers controllers) { 59 super(windowContext); 60 mTaskbarContext = taskbarContext; 61 mOverlayController = controllers.taskbarOverlayController; 62 mDragController = new TaskbarDragController(this); 63 mDragController.init(controllers); 64 mDragLayer = new TaskbarOverlayDragLayer(this); 65 mStashedTaskbarHeight = controllers.taskbarStashController.getStashedHeight(); 66 67 mUiController = controllers.uiController; 68 } 69 getSearchSessionController()70 public @Nullable TaskbarSearchSessionController getSearchSessionController() { 71 return mSearchSessionController; 72 } 73 setSearchSessionController( @ullable TaskbarSearchSessionController searchSessionController)74 public void setSearchSessionController( 75 @Nullable TaskbarSearchSessionController searchSessionController) { 76 mSearchSessionController = searchSessionController; 77 } 78 getStashedTaskbarHeight()79 int getStashedTaskbarHeight() { 80 return mStashedTaskbarHeight; 81 } 82 getOverlayController()83 public TaskbarOverlayController getOverlayController() { 84 return mOverlayController; 85 } 86 87 /** Returns {@code true} if overlay or Taskbar windows are handling a system drag. */ isAnySystemDragInProgress()88 boolean isAnySystemDragInProgress() { 89 return mDragController.isSystemDragInProgress() 90 || mTaskbarContext.getDragController().isSystemDragInProgress(); 91 } 92 93 @Override getDeviceProfile()94 public DeviceProfile getDeviceProfile() { 95 return mOverlayController.getLauncherDeviceProfile(); 96 } 97 98 @Override getAccessibilityDelegate()99 public View.AccessibilityDelegate getAccessibilityDelegate() { 100 return mTaskbarContext.getAccessibilityDelegate(); 101 } 102 103 @Override getDragController()104 public TaskbarDragController getDragController() { 105 return mDragController; 106 } 107 108 @Override getDragLayer()109 public TaskbarOverlayDragLayer getDragLayer() { 110 return mDragLayer; 111 } 112 113 @Override getAppsView()114 public TaskbarAllAppsContainerView getAppsView() { 115 return mDragLayer.findViewById(R.id.apps_view); 116 } 117 118 @Override isBindingItems()119 public boolean isBindingItems() { 120 return mTaskbarContext.isBindingItems(); 121 } 122 123 @Override getItemOnClickListener()124 public View.OnClickListener getItemOnClickListener() { 125 return mTaskbarContext.getItemOnClickListener(); 126 } 127 128 @Override getAllAppsItemLongClickListener()129 public View.OnLongClickListener getAllAppsItemLongClickListener() { 130 return mDragController::startDragOnLongClick; 131 } 132 133 @Override getPopupDataProvider()134 public PopupDataProvider getPopupDataProvider() { 135 return mTaskbarContext.getPopupDataProvider(); 136 } 137 138 @Override startSplitSelection(SplitSelectSource splitSelectSource)139 public void startSplitSelection(SplitSelectSource splitSelectSource) { 140 mUiController.startSplitSelection(splitSelectSource); 141 } 142 143 @Override getDotInfoForItem(ItemInfo info)144 public DotInfo getDotInfoForItem(ItemInfo info) { 145 return mTaskbarContext.getDotInfoForItem(info); 146 } 147 148 @Override onDragStart()149 public void onDragStart() {} 150 151 @Override onDragEnd()152 public void onDragEnd() { 153 mOverlayController.maybeCloseWindow(); 154 } 155 156 @Override onPopupVisibilityChanged(boolean isVisible)157 public void onPopupVisibilityChanged(boolean isVisible) {} 158 159 @Override onSplitScreenMenuButtonClicked()160 public void onSplitScreenMenuButtonClicked() { 161 } 162 } 163