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 mEnterSplitButton;
36     protected View mSettingsButton;
37     protected View mDismissButton;
38 
PipMenuIconsAlgorithm(Context context)39     protected PipMenuIconsAlgorithm(Context context) {
40     }
41 
42     /**
43      * Bind the necessary views.
44      */
bindViews(ViewGroup viewRoot, ViewGroup topEndContainer, View dragHandle, View enterSplitButton, View settingsButton, View dismissButton)45     public void bindViews(ViewGroup viewRoot, ViewGroup topEndContainer, View dragHandle,
46             View enterSplitButton, View settingsButton, View dismissButton) {
47         mViewRoot = viewRoot;
48         mTopEndContainer = topEndContainer;
49         mDragHandle = dragHandle;
50         mEnterSplitButton = enterSplitButton;
51         mSettingsButton = settingsButton;
52         mDismissButton = dismissButton;
53     }
54 
55     /**
56      * Updates the position of the drag handle based on where the PIP window is on the screen.
57      */
onBoundsChanged(Rect bounds)58     public void onBoundsChanged(Rect bounds) {
59         // On phones, the menu icons are always static and will never move based on the PIP window
60         // position. No need to do anything here.
61     }
62 
63     /**
64      * Set the gravity on the given view.
65      */
setLayoutGravity(View v, int gravity)66     protected static void setLayoutGravity(View v, int gravity) {
67         if (v.getLayoutParams() instanceof FrameLayout.LayoutParams) {
68             FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) v.getLayoutParams();
69             params.gravity = gravity;
70             v.setLayoutParams(params);
71         }
72     }
73 }
74