blob: 32c9b2a654da1d3dafa3d96b91bd908be507723f [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 Gruszczynski466f3212015-09-21 17:57:57 -070030
31/**
Jorim Jaggi61f39a72015-10-29 16:54:18 +010032 * Keeps information about the docked stack divider.
Filip Gruszczynski466f3212015-09-21 17:57:57 -070033 */
Jorim Jaggi61f39a72015-10-29 16:54:18 +010034public class DockedStackDividerController {
35
36 private static final String TAG = "DockedStackDividerController";
37
Filip Gruszczynski466f3212015-09-21 17:57:57 -070038 private final DisplayContent mDisplayContent;
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010039 private final int mDividerWindowWidth;
40 private final int mDividerInsets;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010041 private boolean mResizing;
42 private WindowState mWindow;
43 private final Rect mTmpRect = new Rect();
Filip Gruszczynski77049052015-11-09 14:01:21 -080044 private final Rect mLastRect = new Rect();
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080045 private IDockDividerVisibilityListener mListener;
46 private boolean mLastVisibility = false;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -080047 private boolean mForceVisibilityReevaluation;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070048
Filip Gruszczynski466f3212015-09-21 17:57:57 -070049 DockedStackDividerController(Context context, DisplayContent displayContent) {
Filip Gruszczynski466f3212015-09-21 17:57:57 -070050 mDisplayContent = displayContent;
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010051 mDividerWindowWidth = context.getResources().getDimensionPixelSize(
Filip Gruszczynski466f3212015-09-21 17:57:57 -070052 com.android.internal.R.dimen.docked_stack_divider_thickness);
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010053 mDividerInsets = context.getResources().getDimensionPixelSize(
54 com.android.internal.R.dimen.docked_stack_divider_insets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -070055 }
56
Jorim Jaggi61f39a72015-10-29 16:54:18 +010057 boolean isResizing() {
58 return mResizing;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070059 }
60
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010061 int getContentWidth() {
62 return mDividerWindowWidth - 2 * mDividerInsets;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070063 }
64
Jorim Jaggi61f39a72015-10-29 16:54:18 +010065 void setResizing(boolean resizing) {
66 mResizing = resizing;
67 }
68
69 void setWindow(WindowState window) {
70 mWindow = window;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -080071 reevaluateVisibility(false);
Jorim Jaggi61f39a72015-10-29 16:54:18 +010072 }
73
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -080074 void reevaluateVisibility(boolean force) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080075 if (mWindow == null) {
76 return;
77 }
Jorim Jaggie48f4282015-11-06 17:32:44 +010078 TaskStack stack = mDisplayContent.mService.mStackIdToStack.get(DOCKED_STACK_ID);
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080079 final boolean visible = stack != null && stack.isVisibleLocked();
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -080080 if (mLastVisibility == visible && !force) {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080081 return;
82 }
83 mLastVisibility = visible;
84 if (mListener != null) {
85 try {
86 mListener.onDockDividerVisibilityChanged(visible);
87 } catch (RemoteException e) {
88 Slog.e(TAG, "visibility call failed: " + e);
89 }
Jorim Jaggi61f39a72015-10-29 16:54:18 +010090 }
91 }
92
Filip Gruszczynski466f3212015-09-21 17:57:57 -070093 void positionDockedStackedDivider(Rect frame) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070094 TaskStack stack = mDisplayContent.getDockedStackLocked();
Filip Gruszczynski466f3212015-09-21 17:57:57 -070095 if (stack == null) {
96 // Unfortunately we might end up with still having a divider, even though the underlying
97 // stack was already removed. This is because we are on AM thread and the removal of the
Filip Gruszczynski77049052015-11-09 14:01:21 -080098 // divider was deferred to WM thread and hasn't happened yet. In that case let's just
99 // keep putting it in the same place it was before the stack was removed to have
100 // continuity and prevent it from jumping to the center. It will get hidden soon.
101 frame.set(mLastRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700102 return;
Filip Gruszczynski77049052015-11-09 14:01:21 -0800103 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800104 stack.getDimBounds(mTmpRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700105 }
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100106 int side = stack.getDockSide();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700107 switch (side) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700108 case DOCKED_LEFT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100109 frame.set(mTmpRect.right - mDividerInsets, frame.top,
110 mTmpRect.right + frame.width() - mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700111 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700112 case DOCKED_TOP:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100113 frame.set(frame.left, mTmpRect.bottom - mDividerInsets,
114 mTmpRect.right, mTmpRect.bottom + frame.height() - mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700115 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700116 case DOCKED_RIGHT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100117 frame.set(mTmpRect.left - frame.width() + mDividerInsets, frame.top,
118 mTmpRect.left + mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700119 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700120 case DOCKED_BOTTOM:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100121 frame.set(frame.left, mTmpRect.top - frame.height() + mDividerInsets,
122 frame.right, mTmpRect.top + mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700123 break;
124 }
Filip Gruszczynski77049052015-11-09 14:01:21 -0800125 mLastRect.set(frame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700126 }
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800127
128 public void registerDockDividerVisibilityListener(IDockDividerVisibilityListener listener) {
129 if (mListener != null && listener != null) {
130 throw new IllegalStateException("Dock divider visibility listener already set!");
131 }
132 mListener = listener;
Filip Gruszczynski85d5cc42015-12-04 09:21:37 -0800133 reevaluateVisibility(true);
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800134 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700135}