blob: 8f3d3e30ad1a4050b9805bc4f7f6c913212c11f1 [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 Gruszczynski64cdc142015-11-29 21:10:07 -080021import android.os.RemoteException;
Filip Gruszczynski77049052015-11-09 14:01:21 -080022import android.util.Slog;
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080023import android.view.IDockDividerVisibilityListener;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010024
Jorim Jaggie48f4282015-11-06 17:32:44 +010025import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010026import static android.view.WindowManager.DOCKED_BOTTOM;
27import static android.view.WindowManager.DOCKED_LEFT;
28import static android.view.WindowManager.DOCKED_RIGHT;
29import static android.view.WindowManager.DOCKED_TOP;
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080030import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
31import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070032
33/**
Jorim Jaggi61f39a72015-10-29 16:54:18 +010034 * Keeps information about the docked stack divider.
Filip Gruszczynski466f3212015-09-21 17:57:57 -070035 */
Jorim Jaggi61f39a72015-10-29 16:54:18 +010036public class DockedStackDividerController {
37
Filip Gruszczynski0bd180d2015-12-07 15:43:52 -080038 private static final String TAG = TAG_WITH_CLASS_NAME ? "DockedStackDividerController" : TAG_WM;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010039
Filip Gruszczynski466f3212015-09-21 17:57:57 -070040 private final DisplayContent mDisplayContent;
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010041 private final int mDividerWindowWidth;
42 private final int mDividerInsets;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010043 private boolean mResizing;
44 private WindowState mWindow;
45 private final Rect mTmpRect = new Rect();
Filip Gruszczynski77049052015-11-09 14:01:21 -080046 private final Rect mLastRect = new Rect();
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080047 private IDockDividerVisibilityListener mListener;
48 private boolean mLastVisibility = false;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -080049 private boolean mForceVisibilityReevaluation;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070050
Filip Gruszczynski466f3212015-09-21 17:57:57 -070051 DockedStackDividerController(Context context, DisplayContent displayContent) {
Filip Gruszczynski466f3212015-09-21 17:57:57 -070052 mDisplayContent = displayContent;
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010053 mDividerWindowWidth = context.getResources().getDimensionPixelSize(
Filip Gruszczynski466f3212015-09-21 17:57:57 -070054 com.android.internal.R.dimen.docked_stack_divider_thickness);
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010055 mDividerInsets = context.getResources().getDimensionPixelSize(
56 com.android.internal.R.dimen.docked_stack_divider_insets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -070057 }
58
Jorim Jaggi61f39a72015-10-29 16:54:18 +010059 boolean isResizing() {
60 return mResizing;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070061 }
62
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010063 int getContentWidth() {
64 return mDividerWindowWidth - 2 * mDividerInsets;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070065 }
66
Jorim Jaggi61f39a72015-10-29 16:54:18 +010067 void setResizing(boolean resizing) {
68 mResizing = resizing;
69 }
70
71 void setWindow(WindowState window) {
72 mWindow = window;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -080073 reevaluateVisibility(false);
Jorim Jaggi61f39a72015-10-29 16:54:18 +010074 }
75
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -080076 void reevaluateVisibility(boolean force) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080077 if (mWindow == null) {
78 return;
79 }
Jorim Jaggie48f4282015-11-06 17:32:44 +010080 TaskStack stack = mDisplayContent.mService.mStackIdToStack.get(DOCKED_STACK_ID);
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080081 final boolean visible = stack != null && stack.isVisibleLocked();
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -080082 if (mLastVisibility == visible && !force) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080083 return;
84 }
85 mLastVisibility = visible;
86 if (mListener != null) {
87 try {
88 mListener.onDockDividerVisibilityChanged(visible);
89 } catch (RemoteException e) {
90 Slog.e(TAG, "visibility call failed: " + e);
91 }
Jorim Jaggi61f39a72015-10-29 16:54:18 +010092 }
93 }
94
Filip Gruszczynski466f3212015-09-21 17:57:57 -070095 void positionDockedStackedDivider(Rect frame) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070096 TaskStack stack = mDisplayContent.getDockedStackLocked();
Filip Gruszczynski466f3212015-09-21 17:57:57 -070097 if (stack == null) {
98 // Unfortunately we might end up with still having a divider, even though the underlying
99 // stack was already removed. This is because we are on AM thread and the removal of the
Filip Gruszczynski77049052015-11-09 14:01:21 -0800100 // divider was deferred to WM thread and hasn't happened yet. In that case let's just
101 // keep putting it in the same place it was before the stack was removed to have
102 // continuity and prevent it from jumping to the center. It will get hidden soon.
103 frame.set(mLastRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700104 return;
Filip Gruszczynski77049052015-11-09 14:01:21 -0800105 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800106 stack.getDimBounds(mTmpRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700107 }
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100108 int side = stack.getDockSide();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700109 switch (side) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700110 case DOCKED_LEFT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100111 frame.set(mTmpRect.right - mDividerInsets, frame.top,
112 mTmpRect.right + frame.width() - mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700113 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700114 case DOCKED_TOP:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100115 frame.set(frame.left, mTmpRect.bottom - mDividerInsets,
116 mTmpRect.right, mTmpRect.bottom + frame.height() - mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700117 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700118 case DOCKED_RIGHT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100119 frame.set(mTmpRect.left - frame.width() + mDividerInsets, frame.top,
120 mTmpRect.left + mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700121 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700122 case DOCKED_BOTTOM:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100123 frame.set(frame.left, mTmpRect.top - frame.height() + mDividerInsets,
124 frame.right, mTmpRect.top + mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700125 break;
126 }
Filip Gruszczynski77049052015-11-09 14:01:21 -0800127 mLastRect.set(frame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700128 }
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800129
130 public void registerDockDividerVisibilityListener(IDockDividerVisibilityListener listener) {
131 if (mListener != null && listener != null) {
132 throw new IllegalStateException("Dock divider visibility listener already set!");
133 }
134 mListener = listener;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800135 reevaluateVisibility(true);
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800136 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700137}