blob: c1e04811c38ac37388642fb7eb9ca4c7aad25e7d [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;
Filip Gruszczynski77049052015-11-09 14:01:21 -080021import android.util.Slog;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010022
Jorim Jaggie48f4282015-11-06 17:32:44 +010023import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010024import static android.view.WindowManager.DOCKED_BOTTOM;
25import static android.view.WindowManager.DOCKED_LEFT;
26import static android.view.WindowManager.DOCKED_RIGHT;
27import static android.view.WindowManager.DOCKED_TOP;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070028
29/**
Jorim Jaggi61f39a72015-10-29 16:54:18 +010030 * Keeps information about the docked stack divider.
Filip Gruszczynski466f3212015-09-21 17:57:57 -070031 */
Jorim Jaggi61f39a72015-10-29 16:54:18 +010032public class DockedStackDividerController {
33
34 private static final String TAG = "DockedStackDividerController";
35
Filip Gruszczynski466f3212015-09-21 17:57:57 -070036 private final DisplayContent mDisplayContent;
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010037 private final int mDividerWindowWidth;
38 private final int mDividerInsets;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010039 private boolean mResizing;
40 private WindowState mWindow;
41 private final Rect mTmpRect = new Rect();
Filip Gruszczynski77049052015-11-09 14:01:21 -080042 private final Rect mLastRect = new Rect();
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070043
Filip Gruszczynski466f3212015-09-21 17:57:57 -070044 DockedStackDividerController(Context context, DisplayContent displayContent) {
Filip Gruszczynski466f3212015-09-21 17:57:57 -070045 mDisplayContent = displayContent;
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010046 mDividerWindowWidth = context.getResources().getDimensionPixelSize(
Filip Gruszczynski466f3212015-09-21 17:57:57 -070047 com.android.internal.R.dimen.docked_stack_divider_thickness);
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010048 mDividerInsets = context.getResources().getDimensionPixelSize(
49 com.android.internal.R.dimen.docked_stack_divider_insets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -070050 }
51
Jorim Jaggi61f39a72015-10-29 16:54:18 +010052 boolean isResizing() {
53 return mResizing;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070054 }
55
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010056 int getContentWidth() {
57 return mDividerWindowWidth - 2 * mDividerInsets;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070058 }
59
Jorim Jaggi61f39a72015-10-29 16:54:18 +010060 void setResizing(boolean resizing) {
61 mResizing = resizing;
62 }
63
64 void setWindow(WindowState window) {
65 mWindow = window;
66 reevaluateVisibility();
67 }
68
69 void reevaluateVisibility() {
70 if (mWindow == null) return;
Jorim Jaggie48f4282015-11-06 17:32:44 +010071 TaskStack stack = mDisplayContent.mService.mStackIdToStack.get(DOCKED_STACK_ID);
72 if (stack != null && stack.isVisibleLocked()) {
Jorim Jaggi61f39a72015-10-29 16:54:18 +010073 mWindow.showLw(true /* doAnimation */);
74 } else {
75 mWindow.hideLw(true /* doAnimation */);
76 }
77 }
78
Filip Gruszczynski466f3212015-09-21 17:57:57 -070079 void positionDockedStackedDivider(Rect frame) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070080 TaskStack stack = mDisplayContent.getDockedStackLocked();
Filip Gruszczynski466f3212015-09-21 17:57:57 -070081 if (stack == null) {
82 // Unfortunately we might end up with still having a divider, even though the underlying
83 // stack was already removed. This is because we are on AM thread and the removal of the
Filip Gruszczynski77049052015-11-09 14:01:21 -080084 // divider was deferred to WM thread and hasn't happened yet. In that case let's just
85 // keep putting it in the same place it was before the stack was removed to have
86 // continuity and prevent it from jumping to the center. It will get hidden soon.
87 frame.set(mLastRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -070088 return;
Filip Gruszczynski77049052015-11-09 14:01:21 -080089 } else {
90 stack.getBounds(mTmpRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -070091 }
Jorim Jaggi61f39a72015-10-29 16:54:18 +010092 int side = stack.getDockSide();
Filip Gruszczynski466f3212015-09-21 17:57:57 -070093 switch (side) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070094 case DOCKED_LEFT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010095 frame.set(mTmpRect.right - mDividerInsets, frame.top,
96 mTmpRect.right + frame.width() - mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -070097 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070098 case DOCKED_TOP:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010099 frame.set(frame.left, mTmpRect.bottom - mDividerInsets,
100 mTmpRect.right, mTmpRect.bottom + frame.height() - mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700101 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700102 case DOCKED_RIGHT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100103 frame.set(mTmpRect.left - frame.width() + mDividerInsets, frame.top,
104 mTmpRect.left + mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700105 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700106 case DOCKED_BOTTOM:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100107 frame.set(frame.left, mTmpRect.top - frame.height() + mDividerInsets,
108 frame.right, mTmpRect.top + mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700109 break;
110 }
Filip Gruszczynski77049052015-11-09 14:01:21 -0800111 mLastRect.set(frame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700112 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700113}