blob: 6bdff1ec022a10b00e9a18ffb50df811451fb0ed [file] [log] [blame]
Filip Gruszczynski466f3212015-09-21 17:57:57 -07001/*
2 * Copyright (C) 2012 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
17package com.android.server.wm;
18
Filip Gruszczynski466f3212015-09-21 17:57:57 -070019import android.content.Context;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070020import android.graphics.Rect;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010021
22import static android.view.WindowManager.DOCKED_BOTTOM;
23import static android.view.WindowManager.DOCKED_LEFT;
24import static android.view.WindowManager.DOCKED_RIGHT;
25import static android.view.WindowManager.DOCKED_TOP;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070026
27/**
Jorim Jaggi61f39a72015-10-29 16:54:18 +010028 * Keeps information about the docked stack divider.
Filip Gruszczynski466f3212015-09-21 17:57:57 -070029 */
Jorim Jaggi61f39a72015-10-29 16:54:18 +010030public class DockedStackDividerController {
31
32 private static final String TAG = "DockedStackDividerController";
33
Filip Gruszczynski466f3212015-09-21 17:57:57 -070034 private final DisplayContent mDisplayContent;
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010035 private final int mDividerWindowWidth;
36 private final int mDividerInsets;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010037 private boolean mResizing;
38 private WindowState mWindow;
39 private final Rect mTmpRect = new Rect();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070040
Filip Gruszczynski466f3212015-09-21 17:57:57 -070041 DockedStackDividerController(Context context, DisplayContent displayContent) {
Filip Gruszczynski466f3212015-09-21 17:57:57 -070042 mDisplayContent = displayContent;
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010043 mDividerWindowWidth = context.getResources().getDimensionPixelSize(
Filip Gruszczynski466f3212015-09-21 17:57:57 -070044 com.android.internal.R.dimen.docked_stack_divider_thickness);
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010045 mDividerInsets = context.getResources().getDimensionPixelSize(
46 com.android.internal.R.dimen.docked_stack_divider_insets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -070047 }
48
Jorim Jaggi61f39a72015-10-29 16:54:18 +010049 boolean isResizing() {
50 return mResizing;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070051 }
52
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010053 int getContentWidth() {
54 return mDividerWindowWidth - 2 * mDividerInsets;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070055 }
56
Jorim Jaggi61f39a72015-10-29 16:54:18 +010057 void setResizing(boolean resizing) {
58 mResizing = resizing;
59 }
60
61 void setWindow(WindowState window) {
62 mWindow = window;
63 reevaluateVisibility();
64 }
65
66 void reevaluateVisibility() {
67 if (mWindow == null) return;
68 boolean visible = mDisplayContent.getDockedStackLocked() != null;
69 if (visible) {
70 mWindow.showLw(true /* doAnimation */);
71 } else {
72 mWindow.hideLw(true /* doAnimation */);
73 }
74 }
75
Filip Gruszczynski466f3212015-09-21 17:57:57 -070076 void positionDockedStackedDivider(Rect frame) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070077 TaskStack stack = mDisplayContent.getDockedStackLocked();
Filip Gruszczynski466f3212015-09-21 17:57:57 -070078 if (stack == null) {
79 // Unfortunately we might end up with still having a divider, even though the underlying
80 // stack was already removed. This is because we are on AM thread and the removal of the
81 // divider was deferred to WM thread and hasn't happened yet.
82 return;
83 }
Jorim Jaggi61f39a72015-10-29 16:54:18 +010084 int side = stack.getDockSide();
Filip Gruszczynski466f3212015-09-21 17:57:57 -070085 stack.getBounds(mTmpRect);
86 switch (side) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070087 case DOCKED_LEFT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010088 frame.set(mTmpRect.right - mDividerInsets, frame.top,
89 mTmpRect.right + frame.width() - mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -070090 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070091 case DOCKED_TOP:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010092 frame.set(frame.left, mTmpRect.bottom - mDividerInsets,
93 mTmpRect.right, mTmpRect.bottom + frame.height() - mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -070094 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070095 case DOCKED_RIGHT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010096 frame.set(mTmpRect.left - frame.width() + mDividerInsets, frame.top,
97 mTmpRect.left + mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -070098 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070099 case DOCKED_BOTTOM:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100100 frame.set(frame.left, mTmpRect.top - frame.height() + mDividerInsets,
101 frame.right, mTmpRect.top + mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700102 break;
103 }
104 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700105}