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.quickstep.views; 18 19 import android.app.Activity; 20 import android.content.Context; 21 import android.content.ContextWrapper; 22 import android.content.LocusId; 23 import android.os.Bundle; 24 import android.view.KeyEvent; 25 import android.view.MotionEvent; 26 import android.view.View; 27 import android.view.Window; 28 29 import com.android.launcher3.BaseActivity; 30 import com.android.launcher3.logger.LauncherAtom; 31 import com.android.launcher3.util.SystemUiController; 32 import com.android.launcher3.views.ActivityContext; 33 import com.android.launcher3.views.ScrimView; 34 35 /** 36 * Interface to be implemented by the parent view of RecentsView 37 */ 38 public interface RecentsViewContainer extends ActivityContext { 39 40 /** 41 * Returns an instance of an implementation of RecentsViewContainer 42 * @param context will find instance of recentsViewContainer from given context. 43 */ containerFromContext(Context context)44 static <T extends RecentsViewContainer> T containerFromContext(Context context) { 45 if (context instanceof RecentsViewContainer) { 46 return (T) context; 47 } else if (context instanceof ContextWrapper) { 48 return containerFromContext(((ContextWrapper) context).getBaseContext()); 49 } else { 50 throw new IllegalArgumentException("Cannot find RecentsViewContainer in parent tree"); 51 } 52 } 53 54 /** 55 * Returns {@link SystemUiController} to manage various window flags to control system UI. 56 */ getSystemUiController()57 SystemUiController getSystemUiController(); 58 59 /** 60 * Returns {@link ScrimView} 61 */ getScrimView()62 ScrimView getScrimView(); 63 64 /** 65 * Returns the Overview Panel as a View 66 */ getOverviewPanel()67 <T extends View> T getOverviewPanel(); 68 69 /** 70 * Returns the RootView 71 */ getRootView()72 View getRootView(); 73 74 /** 75 * Dispatches a generic motion event to the view hierarchy. 76 * Returns the current RecentsViewContainer as context 77 */ asContext()78 default Context asContext() { 79 return (Context) this; 80 } 81 82 /** 83 * @see Window.Callback#dispatchGenericMotionEvent(MotionEvent) 84 */ dispatchGenericMotionEvent(MotionEvent ev)85 boolean dispatchGenericMotionEvent(MotionEvent ev); 86 87 /** 88 * @see Window.Callback#dispatchKeyEvent(KeyEvent) 89 */ dispatchKeyEvent(KeyEvent ev)90 boolean dispatchKeyEvent(KeyEvent ev); 91 92 /** 93 * Returns overview actions view as a view 94 */ getActionsView()95 View getActionsView(); 96 97 /** 98 * @see BaseActivity#addForceInvisibleFlag(int) 99 * @param flag {@link BaseActivity.InvisibilityFlags} 100 */ addForceInvisibleFlag(@aseActivity.InvisibilityFlags int flag)101 void addForceInvisibleFlag(@BaseActivity.InvisibilityFlags int flag); 102 103 /** 104 * @see BaseActivity#clearForceInvisibleFlag(int) 105 * @param flag {@link BaseActivity.InvisibilityFlags} 106 */ clearForceInvisibleFlag(@aseActivity.InvisibilityFlags int flag)107 void clearForceInvisibleFlag(@BaseActivity.InvisibilityFlags int flag); 108 109 /** 110 * @see android.app.Activity#setLocusContext(LocusId, Bundle) 111 * @param id {@link LocusId} 112 * @param bundle {@link Bundle} 113 */ setLocusContext(LocusId id, Bundle bundle)114 void setLocusContext(LocusId id, Bundle bundle); 115 116 /** 117 * @see BaseActivity#isStarted() 118 * @return boolean 119 */ isStarted()120 boolean isStarted(); 121 122 /** 123 * @see BaseActivity#addEventCallback(int, Runnable) 124 * @param event {@link BaseActivity.ActivityEvent} 125 * @param callback runnable to be executed upon event 126 */ addEventCallback(@aseActivity.ActivityEvent int event, Runnable callback)127 void addEventCallback(@BaseActivity.ActivityEvent int event, Runnable callback); 128 129 /** 130 * @see BaseActivity#removeEventCallback(int, Runnable) 131 * @param event {@link BaseActivity.ActivityEvent} 132 * @param callback runnable to be executed upon event 133 */ removeEventCallback(@aseActivity.ActivityEvent int event, Runnable callback)134 void removeEventCallback(@BaseActivity.ActivityEvent int event, Runnable callback); 135 136 /** 137 * @see com.android.quickstep.util.TISBindHelper#runOnBindToTouchInteractionService(Runnable) 138 * @param r runnable to be executed upon event 139 */ runOnBindToTouchInteractionService(Runnable r)140 void runOnBindToTouchInteractionService(Runnable r); 141 142 /** 143 * @see Activity#getWindow() 144 * @return Window 145 */ getWindow()146 Window getWindow(); 147 148 /** 149 * @see 150 * BaseActivity#addMultiWindowModeChangedListener(BaseActivity.MultiWindowModeChangedListener) 151 * @param listener {@link BaseActivity.MultiWindowModeChangedListener} 152 */ addMultiWindowModeChangedListener( BaseActivity.MultiWindowModeChangedListener listener)153 void addMultiWindowModeChangedListener( 154 BaseActivity.MultiWindowModeChangedListener listener); 155 156 /** 157 * @see 158 * BaseActivity#removeMultiWindowModeChangedListener( 159 * BaseActivity.MultiWindowModeChangedListener) 160 * @param listener {@link BaseActivity.MultiWindowModeChangedListener} 161 */ removeMultiWindowModeChangedListener( BaseActivity.MultiWindowModeChangedListener listener)162 void removeMultiWindowModeChangedListener( 163 BaseActivity.MultiWindowModeChangedListener listener); 164 165 /** 166 * Begins transition from overview back to homescreen 167 */ returnToHomescreen()168 void returnToHomescreen(); 169 170 /** 171 * True if the overview panel is visible. 172 * @return Boolean 173 */ isRecentsViewVisible()174 boolean isRecentsViewVisible(); 175 176 /** 177 * Overwrites any logged item in Launcher that doesn't have a container with the 178 * {@link com.android.launcher3.touch.PagedOrientationHandler} in use for Overview. 179 * 180 * @param itemInfoBuilder {@link LauncherAtom.ItemInfo.Builder} 181 */ applyOverwritesToLogItem(LauncherAtom.ItemInfo.Builder itemInfoBuilder)182 default void applyOverwritesToLogItem(LauncherAtom.ItemInfo.Builder itemInfoBuilder) { 183 if (!itemInfoBuilder.getContainerInfo().hasTaskSwitcherContainer()) { 184 return; 185 } 186 187 if (!isRecentsViewVisible()) { 188 return; 189 } 190 191 RecentsView<?, ?> recentsView = getOverviewPanel(); 192 var orientationForLogging = 193 recentsView.getPagedOrientationHandler().getHandlerTypeForLogging(); 194 itemInfoBuilder.setContainerInfo( 195 LauncherAtom.ContainerInfo.newBuilder() 196 .setTaskSwitcherContainer( 197 LauncherAtom.TaskSwitcherContainer.newBuilder() 198 .setOrientationHandler(orientationForLogging)) 199 .build()); 200 } 201 } 202