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.Context; 30 import android.graphics.PixelFormat; 31 import android.graphics.Rect; 32 import android.view.SurfaceControl; 33 import android.view.WindowManager; 34 35 import com.android.wm.shell.R; 36 37 import java.util.List; 38 39 /** 40 * Interface to allow {@link com.android.wm.shell.pip.PipTaskOrganizer} to call into 41 * PiP menu when certain events happen (task appear/vanish, PiP move, etc.) 42 */ 43 public interface PipMenuController { 44 45 String MENU_WINDOW_TITLE = "PipMenuView"; 46 47 /** 48 * Used with 49 * {@link PipMenuController#movePipMenu(SurfaceControl, SurfaceControl.Transaction, Rect, 50 * float)} to indicate that we don't want to affect the alpha value of the menu surfaces. 51 */ 52 float ALPHA_NO_CHANGE = -1f; 53 54 /** 55 * Called when 56 * {@link PipTaskOrganizer#onTaskAppeared(RunningTaskInfo, SurfaceControl)} 57 * is called. 58 */ attach(SurfaceControl leash)59 void attach(SurfaceControl leash); 60 61 /** 62 * Called when 63 * {@link PipTaskOrganizer#onTaskVanished(RunningTaskInfo)} is called. 64 */ detach()65 void detach(); 66 67 /** 68 * Check if menu is visible or not. 69 */ isMenuVisible()70 boolean isMenuVisible(); 71 72 /** 73 * Show the PIP menu. 74 */ showMenu()75 void showMenu(); 76 77 /** 78 * Given a set of actions, update the menu. 79 */ setAppActions(List<RemoteAction> appActions, RemoteAction closeAction)80 void setAppActions(List<RemoteAction> appActions, RemoteAction closeAction); 81 82 /** 83 * Resize the PiP menu with the given bounds. The PiP SurfaceControl is given if there is a 84 * need to synchronize the movements on the same frame as PiP. 85 */ resizePipMenu(@ullable SurfaceControl pipLeash, @Nullable SurfaceControl.Transaction t, Rect destinationBounds)86 default void resizePipMenu(@Nullable SurfaceControl pipLeash, 87 @Nullable SurfaceControl.Transaction t, 88 Rect destinationBounds) {} 89 90 /** 91 * Move the PiP menu with the given bounds. The PiP SurfaceControl is given if there is a 92 * need to synchronize the movements on the same frame as PiP. 93 */ movePipMenu(@ullable SurfaceControl pipLeash, @Nullable SurfaceControl.Transaction t, Rect destinationBounds, float alpha)94 default void movePipMenu(@Nullable SurfaceControl pipLeash, 95 @Nullable SurfaceControl.Transaction t, Rect destinationBounds, float alpha) { 96 } 97 98 /** 99 * Update the PiP menu with the given bounds for re-layout purposes. 100 */ updateMenuBounds(Rect destinationBounds)101 default void updateMenuBounds(Rect destinationBounds) {} 102 103 /** 104 * Update when the current focused task changes. 105 */ onFocusTaskChanged(RunningTaskInfo taskInfo)106 default void onFocusTaskChanged(RunningTaskInfo taskInfo) {} 107 108 /** 109 * Returns a default LayoutParams for the PIP Menu. 110 * @param context the context. 111 * @param width the PIP stack width. 112 * @param height the PIP stack height. 113 */ getPipMenuLayoutParams(Context context, String title, int width, int height)114 default WindowManager.LayoutParams getPipMenuLayoutParams(Context context, String title, 115 int width, int height) { 116 final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(width, height, 117 TYPE_APPLICATION_OVERLAY, 118 FLAG_WATCH_OUTSIDE_TOUCH | FLAG_SPLIT_TOUCH | FLAG_SLIPPERY | FLAG_NOT_TOUCHABLE, 119 PixelFormat.TRANSLUCENT); 120 lp.privateFlags |= PRIVATE_FLAG_TRUSTED_OVERLAY; 121 lp.setTitle(title); 122 lp.accessibilityTitle = context.getResources().getString( 123 R.string.pip_menu_accessibility_title); 124 return lp; 125 } 126 } 127