Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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.systemui.stackdivider; |
| 18 | |
| 19 | import android.content.res.Configuration; |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 20 | import android.os.RemoteException; |
| 21 | import android.view.IDockedStackListener; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 22 | import android.view.LayoutInflater; |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 23 | import android.view.View; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 24 | |
| 25 | import com.android.systemui.R; |
| 26 | import com.android.systemui.SystemUI; |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 27 | import com.android.systemui.recents.Recents; |
| 28 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 29 | |
| 30 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
| 31 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
| 32 | |
| 33 | /** |
| 34 | * Controls the docked stack divider. |
| 35 | */ |
| 36 | public class Divider extends SystemUI { |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 37 | private DividerWindowManager mWindowManager; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 38 | private DividerView mView; |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 39 | private DockDividerVisibilityListener mDockDividerVisibilityListener; |
| 40 | private boolean mVisible = false; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 41 | private boolean mMinimized = false; |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame^] | 42 | private boolean mAdjustedForIme = false; |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 43 | private ForcedResizableInfoActivityController mForcedResizableController; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 44 | |
| 45 | @Override |
| 46 | public void start() { |
| 47 | mWindowManager = new DividerWindowManager(mContext); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 48 | update(mContext.getResources().getConfiguration()); |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 49 | putComponent(Divider.class, this); |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 50 | mDockDividerVisibilityListener = new DockDividerVisibilityListener(); |
| 51 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 52 | ssp.registerDockedStackListener(mDockDividerVisibilityListener); |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 53 | mForcedResizableController = new ForcedResizableInfoActivityController(mContext); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | @Override |
| 57 | protected void onConfigurationChanged(Configuration newConfig) { |
| 58 | super.onConfigurationChanged(newConfig); |
| 59 | update(newConfig); |
| 60 | } |
| 61 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 62 | public DividerView getView() { |
| 63 | return mView; |
| 64 | } |
| 65 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 66 | private void addDivider(Configuration configuration) { |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 67 | mView = (DividerView) |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 68 | LayoutInflater.from(mContext).inflate(R.layout.docked_stack_divider, null); |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 69 | mView.setVisibility(mVisible ? View.VISIBLE : View.INVISIBLE); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 70 | final int size = mContext.getResources().getDimensionPixelSize( |
| 71 | com.android.internal.R.dimen.docked_stack_divider_thickness); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 72 | final boolean landscape = configuration.orientation == ORIENTATION_LANDSCAPE; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 73 | final int width = landscape ? size : MATCH_PARENT; |
| 74 | final int height = landscape ? MATCH_PARENT : size; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 75 | mWindowManager.add(mView, width, height); |
| 76 | mView.setWindowManager(mWindowManager); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | private void removeDivider() { |
| 80 | mWindowManager.remove(); |
| 81 | } |
| 82 | |
| 83 | private void update(Configuration configuration) { |
| 84 | removeDivider(); |
| 85 | addDivider(configuration); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 86 | if (mMinimized) { |
| 87 | mView.setMinimizedDockStack(true); |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame^] | 88 | updateTouchable(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 89 | } |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 90 | } |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 91 | |
| 92 | private void updateVisibility(final boolean visible) { |
| 93 | mView.post(new Runnable() { |
| 94 | @Override |
| 95 | public void run() { |
| 96 | if (mVisible != visible) { |
| 97 | mVisible = visible; |
| 98 | mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); |
Jorim Jaggi | ef92d6f | 2016-03-25 22:07:16 -0700 | [diff] [blame] | 99 | |
| 100 | // Update state because animations won't finish. |
| 101 | mView.setMinimizedDockStack(mMinimized); |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | }); |
| 105 | } |
| 106 | |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 107 | private void updateMinimizedDockedStack(final boolean minimized, final long animDuration) { |
| 108 | mView.post(new Runnable() { |
| 109 | @Override |
| 110 | public void run() { |
| 111 | if (mMinimized != minimized) { |
| 112 | mMinimized = minimized; |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame^] | 113 | updateTouchable(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 114 | if (animDuration > 0) { |
| 115 | mView.setMinimizedDockStack(minimized, animDuration); |
| 116 | } else { |
| 117 | mView.setMinimizedDockStack(minimized); |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | }); |
| 122 | } |
| 123 | |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 124 | private void notifyDockedStackExistsChanged(final boolean exists) { |
| 125 | mView.post(new Runnable() { |
| 126 | @Override |
| 127 | public void run() { |
| 128 | mForcedResizableController.notifyDockedStackExistsChanged(exists); |
| 129 | } |
| 130 | }); |
| 131 | } |
| 132 | |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame^] | 133 | private void updateTouchable() { |
| 134 | mWindowManager.setTouchable(!mMinimized && !mAdjustedForIme); |
| 135 | } |
| 136 | |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 137 | class DockDividerVisibilityListener extends IDockedStackListener.Stub { |
| 138 | |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 139 | @Override |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 140 | public void onDividerVisibilityChanged(boolean visible) throws RemoteException { |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 141 | updateVisibility(visible); |
| 142 | } |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 143 | |
| 144 | @Override |
| 145 | public void onDockedStackExistsChanged(boolean exists) throws RemoteException { |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 146 | notifyDockedStackExistsChanged(exists); |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 147 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 148 | |
| 149 | @Override |
| 150 | public void onDockedStackMinimizedChanged(boolean minimized, long animDuration) |
| 151 | throws RemoteException { |
| 152 | updateMinimizedDockedStack(minimized, animDuration); |
| 153 | } |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 154 | |
| 155 | @Override |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame^] | 156 | public void onAdjustedForImeChanged(boolean adjustedForIme, long animDuration) |
| 157 | throws RemoteException { |
| 158 | mView.post(() -> { |
| 159 | if (mAdjustedForIme != adjustedForIme) { |
| 160 | mAdjustedForIme = adjustedForIme; |
| 161 | updateTouchable(); |
| 162 | if (animDuration > 0) { |
| 163 | mView.setAdjustedForIme(adjustedForIme, animDuration); |
| 164 | } else { |
| 165 | mView.setAdjustedForIme(adjustedForIme); |
| 166 | } |
| 167 | } |
| 168 | }); |
| 169 | } |
| 170 | |
| 171 | @Override |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 172 | public void onDockSideChanged(final int newDockSide) throws RemoteException { |
| 173 | mView.post(() -> mView.notifyDockSideChanged(newDockSide)); |
| 174 | } |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 175 | } |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 176 | } |