Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.server.wm; |
| 18 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 20 | import android.graphics.Rect; |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 21 | |
| 22 | import static android.view.WindowManager.DOCKED_BOTTOM; |
| 23 | import static android.view.WindowManager.DOCKED_LEFT; |
| 24 | import static android.view.WindowManager.DOCKED_RIGHT; |
| 25 | import static android.view.WindowManager.DOCKED_TOP; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 28 | * Keeps information about the docked stack divider. |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 29 | */ |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 30 | public class DockedStackDividerController { |
| 31 | |
| 32 | private static final String TAG = "DockedStackDividerController"; |
| 33 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 34 | private final DisplayContent mDisplayContent; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame^] | 35 | private final int mDividerWindowWidth; |
| 36 | private final int mDividerInsets; |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 37 | private boolean mResizing; |
| 38 | private WindowState mWindow; |
| 39 | private final Rect mTmpRect = new Rect(); |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 40 | |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 41 | DockedStackDividerController(Context context, DisplayContent displayContent) { |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 42 | mDisplayContent = displayContent; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame^] | 43 | mDividerWindowWidth = context.getResources().getDimensionPixelSize( |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 44 | com.android.internal.R.dimen.docked_stack_divider_thickness); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame^] | 45 | mDividerInsets = context.getResources().getDimensionPixelSize( |
| 46 | com.android.internal.R.dimen.docked_stack_divider_insets); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 49 | boolean isResizing() { |
| 50 | return mResizing; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame^] | 53 | int getContentWidth() { |
| 54 | return mDividerWindowWidth - 2 * mDividerInsets; |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Jorim Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 57 | 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 Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 76 | void positionDockedStackedDivider(Rect frame) { |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 77 | TaskStack stack = mDisplayContent.getDockedStackLocked(); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 78 | 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 Jaggi | 61f39a7 | 2015-10-29 16:54:18 +0100 | [diff] [blame] | 84 | int side = stack.getDockSide(); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 85 | stack.getBounds(mTmpRect); |
| 86 | switch (side) { |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 87 | case DOCKED_LEFT: |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame^] | 88 | frame.set(mTmpRect.right - mDividerInsets, frame.top, |
| 89 | mTmpRect.right + frame.width() - mDividerInsets, frame.bottom); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 90 | break; |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 91 | case DOCKED_TOP: |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame^] | 92 | frame.set(frame.left, mTmpRect.bottom - mDividerInsets, |
| 93 | mTmpRect.right, mTmpRect.bottom + frame.height() - mDividerInsets); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 94 | break; |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 95 | case DOCKED_RIGHT: |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame^] | 96 | frame.set(mTmpRect.left - frame.width() + mDividerInsets, frame.top, |
| 97 | mTmpRect.left + mDividerInsets, frame.bottom); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 98 | break; |
Filip Gruszczynski | 3ddc5d6 | 2015-09-23 15:01:30 -0700 | [diff] [blame] | 99 | case DOCKED_BOTTOM: |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame^] | 100 | frame.set(frame.left, mTmpRect.top - frame.height() + mDividerInsets, |
| 101 | frame.right, mTmpRect.top + mDividerInsets); |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 102 | break; |
| 103 | } |
| 104 | } |
Filip Gruszczynski | 466f321 | 2015-09-21 17:57:57 -0700 | [diff] [blame] | 105 | } |