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.phone; 18 19 import android.content.Context; 20 import android.graphics.Rect; 21 import android.view.View; 22 import android.view.ViewGroup; 23 import android.widget.FrameLayout; 24 25 /** 26 * Helper class to calculate and place the menu icons on the PIP Menu. 27 */ 28 public class PipMenuIconsAlgorithm { 29 30 private static final String TAG = "PipMenuIconsAlgorithm"; 31 32 protected ViewGroup mViewRoot; 33 protected ViewGroup mTopEndContainer; 34 protected View mDragHandle; 35 protected View mSettingsButton; 36 protected View mDismissButton; 37 PipMenuIconsAlgorithm(Context context)38 protected PipMenuIconsAlgorithm(Context context) { 39 } 40 41 /** 42 * Bind the necessary views. 43 */ bindViews(ViewGroup viewRoot, ViewGroup topEndContainer, View dragHandle, View settingsButton, View dismissButton)44 public void bindViews(ViewGroup viewRoot, ViewGroup topEndContainer, View dragHandle, 45 View settingsButton, View dismissButton) { 46 mViewRoot = viewRoot; 47 mTopEndContainer = topEndContainer; 48 mDragHandle = dragHandle; 49 mSettingsButton = settingsButton; 50 mDismissButton = dismissButton; 51 } 52 53 /** 54 * Updates the position of the drag handle based on where the PIP window is on the screen. 55 */ onBoundsChanged(Rect bounds)56 public void onBoundsChanged(Rect bounds) { 57 // On phones, the menu icons are always static and will never move based on the PIP window 58 // position. No need to do anything here. 59 } 60 61 /** 62 * Set the gravity on the given view. 63 */ setLayoutGravity(View v, int gravity)64 protected static void setLayoutGravity(View v, int gravity) { 65 if (v.getLayoutParams() instanceof FrameLayout.LayoutParams) { 66 FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) v.getLayoutParams(); 67 params.gravity = gravity; 68 v.setLayoutParams(params); 69 } 70 } 71 } 72