1 /* 2 * Copyright (C) 2020 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.wm.shell.pip; 18 19 import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; 20 import static android.view.WindowManager.LayoutParams.FLAG_SLIPPERY; 21 import static android.view.WindowManager.LayoutParams.FLAG_SPLIT_TOUCH; 22 import static android.view.WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; 23 import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY; 24 import static android.view.WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; 25 26 import android.annotation.Nullable; 27 import android.app.ActivityManager.RunningTaskInfo; 28 import android.app.RemoteAction; 29 import android.content.pm.ParceledListSlice; 30 import android.graphics.PixelFormat; 31 import android.graphics.Rect; 32 import android.view.SurfaceControl; 33 import android.view.WindowManager; 34 35 /** 36 * Interface to allow {@link com.android.wm.shell.pip.PipTaskOrganizer} to call into 37 * PiP menu when certain events happen (task appear/vanish, PiP move, etc.) 38 */ 39 public interface PipMenuController { 40 41 String MENU_WINDOW_TITLE = "PipMenuView"; 42 43 /** 44 * Called when 45 * {@link PipTaskOrganizer#onTaskAppeared(RunningTaskInfo, SurfaceControl)} 46 * is called. 47 */ attach(SurfaceControl leash)48 void attach(SurfaceControl leash); 49 50 /** 51 * Called when 52 * {@link PipTaskOrganizer#onTaskVanished(RunningTaskInfo)} is called. 53 */ detach()54 void detach(); 55 56 /** 57 * Check if menu is visible or not. 58 */ isMenuVisible()59 boolean isMenuVisible(); 60 61 /** 62 * Show the PIP menu. 63 */ showMenu()64 void showMenu(); 65 66 /** 67 * Given a set of actions, update the menu. 68 */ setAppActions(ParceledListSlice<RemoteAction> appActions)69 void setAppActions(ParceledListSlice<RemoteAction> appActions); 70 71 /** 72 * Resize the PiP menu with the given bounds. The PiP SurfaceControl is given if there is a 73 * need to synchronize the movements on the same frame as PiP. 74 */ resizePipMenu(@ullable SurfaceControl pipLeash, @Nullable SurfaceControl.Transaction t, Rect destinationBounds)75 default void resizePipMenu(@Nullable SurfaceControl pipLeash, 76 @Nullable SurfaceControl.Transaction t, 77 Rect destinationBounds) {} 78 79 /** 80 * Move the PiP menu with the given bounds. The PiP SurfaceControl is given if there is a 81 * need to synchronize the movements on the same frame as PiP. 82 */ movePipMenu(@ullable SurfaceControl pipLeash, @Nullable SurfaceControl.Transaction t, Rect destinationBounds)83 default void movePipMenu(@Nullable SurfaceControl pipLeash, 84 @Nullable SurfaceControl.Transaction t, 85 Rect destinationBounds) {} 86 87 /** 88 * Update the PiP menu with the given bounds for re-layout purposes. 89 */ updateMenuBounds(Rect destinationBounds)90 default void updateMenuBounds(Rect destinationBounds) {} 91 92 /** 93 * Update when the current focused task changes. 94 */ onFocusTaskChanged(RunningTaskInfo taskInfo)95 default void onFocusTaskChanged(RunningTaskInfo taskInfo) {} 96 97 /** 98 * Returns a default LayoutParams for the PIP Menu. 99 * @param width the PIP stack width. 100 * @param height the PIP stack height. 101 */ getPipMenuLayoutParams(String title, int width, int height)102 default WindowManager.LayoutParams getPipMenuLayoutParams(String title, int width, int height) { 103 final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(width, height, 104 TYPE_APPLICATION_OVERLAY, 105 FLAG_WATCH_OUTSIDE_TOUCH | FLAG_SPLIT_TOUCH | FLAG_SLIPPERY | FLAG_NOT_TOUCHABLE, 106 PixelFormat.TRANSLUCENT); 107 lp.privateFlags |= PRIVATE_FLAG_TRUSTED_OVERLAY; 108 lp.setTitle(title); 109 return lp; 110 } 111 } 112