blob: df8d5d6f6e9b96c5617de9d029251c9490024678 [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.util.SparseArray;
24import android.util.SparseIntArray;
25import android.view.IDockDividerVisibilityListener;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010026
Jorim Jaggie48f4282015-11-06 17:32:44 +010027import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
Jorim Jaggi61f39a72015-10-29 16:54:18 +010028import static android.view.WindowManager.DOCKED_BOTTOM;
29import static android.view.WindowManager.DOCKED_LEFT;
30import static android.view.WindowManager.DOCKED_RIGHT;
31import static android.view.WindowManager.DOCKED_TOP;
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
38 private static final String TAG = "DockedStackDividerController";
39
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 Gruszczynski3ddc5d62015-09-23 15:01:30 -070049
Filip Gruszczynski466f3212015-09-21 17:57:57 -070050 DockedStackDividerController(Context context, DisplayContent displayContent) {
Filip Gruszczynski466f3212015-09-21 17:57:57 -070051 mDisplayContent = displayContent;
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010052 mDividerWindowWidth = context.getResources().getDimensionPixelSize(
Filip Gruszczynski466f3212015-09-21 17:57:57 -070053 com.android.internal.R.dimen.docked_stack_divider_thickness);
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010054 mDividerInsets = context.getResources().getDimensionPixelSize(
55 com.android.internal.R.dimen.docked_stack_divider_insets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -070056 }
57
Jorim Jaggi61f39a72015-10-29 16:54:18 +010058 boolean isResizing() {
59 return mResizing;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070060 }
61
Jorim Jaggi1fcbab62015-11-04 16:39:50 +010062 int getContentWidth() {
63 return mDividerWindowWidth - 2 * mDividerInsets;
Filip Gruszczynski466f3212015-09-21 17:57:57 -070064 }
65
Jorim Jaggi61f39a72015-10-29 16:54:18 +010066 void setResizing(boolean resizing) {
67 mResizing = resizing;
68 }
69
70 void setWindow(WindowState window) {
71 mWindow = window;
72 reevaluateVisibility();
73 }
74
75 void reevaluateVisibility() {
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080076 if (mWindow == null) {
77 return;
78 }
Jorim Jaggie48f4282015-11-06 17:32:44 +010079 TaskStack stack = mDisplayContent.mService.mStackIdToStack.get(DOCKED_STACK_ID);
Filip Gruszczynski64cdc142015-11-29 21:10:07 -080080 final boolean visible = stack != null && stack.isVisibleLocked();
81 if (mLastVisibility == visible) {
82 return;
83 }
84 mLastVisibility = visible;
85 if (mListener != null) {
86 try {
87 mListener.onDockDividerVisibilityChanged(visible);
88 } catch (RemoteException e) {
89 Slog.e(TAG, "visibility call failed: " + e);
90 }
Jorim Jaggi61f39a72015-10-29 16:54:18 +010091 }
92 }
93
Filip Gruszczynski466f3212015-09-21 17:57:57 -070094 void positionDockedStackedDivider(Rect frame) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -070095 TaskStack stack = mDisplayContent.getDockedStackLocked();
Filip Gruszczynski466f3212015-09-21 17:57:57 -070096 if (stack == null) {
97 // Unfortunately we might end up with still having a divider, even though the underlying
98 // stack was already removed. This is because we are on AM thread and the removal of the
Filip Gruszczynski77049052015-11-09 14:01:21 -080099 // divider was deferred to WM thread and hasn't happened yet. In that case let's just
100 // keep putting it in the same place it was before the stack was removed to have
101 // continuity and prevent it from jumping to the center. It will get hidden soon.
102 frame.set(mLastRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700103 return;
Filip Gruszczynski77049052015-11-09 14:01:21 -0800104 } else {
Chong Zhang4c9ba52a2015-11-10 18:36:33 -0800105 stack.getDimBounds(mTmpRect);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700106 }
Jorim Jaggi61f39a72015-10-29 16:54:18 +0100107 int side = stack.getDockSide();
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700108 switch (side) {
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700109 case DOCKED_LEFT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100110 frame.set(mTmpRect.right - mDividerInsets, frame.top,
111 mTmpRect.right + frame.width() - mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700112 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700113 case DOCKED_TOP:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100114 frame.set(frame.left, mTmpRect.bottom - mDividerInsets,
115 mTmpRect.right, mTmpRect.bottom + frame.height() - mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700116 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700117 case DOCKED_RIGHT:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100118 frame.set(mTmpRect.left - frame.width() + mDividerInsets, frame.top,
119 mTmpRect.left + mDividerInsets, frame.bottom);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700120 break;
Filip Gruszczynski3ddc5d62015-09-23 15:01:30 -0700121 case DOCKED_BOTTOM:
Jorim Jaggi1fcbab62015-11-04 16:39:50 +0100122 frame.set(frame.left, mTmpRect.top - frame.height() + mDividerInsets,
123 frame.right, mTmpRect.top + mDividerInsets);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700124 break;
125 }
Filip Gruszczynski77049052015-11-09 14:01:21 -0800126 mLastRect.set(frame);
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700127 }
Filip Gruszczynski64cdc142015-11-29 21:10:07 -0800128
129 public void registerDockDividerVisibilityListener(IDockDividerVisibilityListener listener) {
130 if (mListener != null && listener != null) {
131 throw new IllegalStateException("Dock divider visibility listener already set!");
132 }
133 mListener = listener;
134 }
Filip Gruszczynski466f3212015-09-21 17:57:57 -0700135}