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; |
Winson Chung | 60fa647 | 2017-06-12 15:30:14 -0700 | [diff] [blame^] | 28 | import com.android.systemui.recents.events.EventBus; |
| 29 | import com.android.systemui.recents.events.ui.RecentsDrawnEvent; |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 30 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 31 | |
| 32 | import static android.content.res.Configuration.ORIENTATION_LANDSCAPE; |
| 33 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
| 34 | |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 35 | import java.io.FileDescriptor; |
| 36 | import java.io.PrintWriter; |
| 37 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 38 | /** |
| 39 | * Controls the docked stack divider. |
| 40 | */ |
| 41 | public class Divider extends SystemUI { |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 42 | private DividerWindowManager mWindowManager; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 43 | private DividerView mView; |
Jorim Jaggi | a6c05d5 | 2016-05-27 00:31:21 -0700 | [diff] [blame] | 44 | private final DividerState mDividerState = new DividerState(); |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 45 | private DockDividerVisibilityListener mDockDividerVisibilityListener; |
| 46 | private boolean mVisible = false; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 47 | private boolean mMinimized = false; |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 48 | private boolean mAdjustedForIme = false; |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 49 | private boolean mHomeStackResizable = false; |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 50 | private ForcedResizableInfoActivityController mForcedResizableController; |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 51 | |
| 52 | @Override |
| 53 | public void start() { |
| 54 | mWindowManager = new DividerWindowManager(mContext); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 55 | update(mContext.getResources().getConfiguration()); |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 56 | putComponent(Divider.class, this); |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 57 | mDockDividerVisibilityListener = new DockDividerVisibilityListener(); |
| 58 | SystemServicesProxy ssp = Recents.getSystemServices(); |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 59 | ssp.registerDockedStackListener(mDockDividerVisibilityListener); |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 60 | mForcedResizableController = new ForcedResizableInfoActivityController(mContext); |
Winson Chung | 60fa647 | 2017-06-12 15:30:14 -0700 | [diff] [blame^] | 61 | EventBus.getDefault().register(this); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | @Override |
| 65 | protected void onConfigurationChanged(Configuration newConfig) { |
| 66 | super.onConfigurationChanged(newConfig); |
| 67 | update(newConfig); |
| 68 | } |
| 69 | |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 70 | public DividerView getView() { |
| 71 | return mView; |
| 72 | } |
| 73 | |
Matthew Ng | 8d37288 | 2016-12-20 11:06:49 -0800 | [diff] [blame] | 74 | public boolean isMinimized() { |
| 75 | return mMinimized; |
| 76 | } |
| 77 | |
Matthew Ng | fb692ac | 2017-02-02 14:02:56 -0800 | [diff] [blame] | 78 | public boolean isHomeStackResizable() { |
| 79 | return mHomeStackResizable; |
| 80 | } |
| 81 | |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 82 | private void addDivider(Configuration configuration) { |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 83 | mView = (DividerView) |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 84 | LayoutInflater.from(mContext).inflate(R.layout.docked_stack_divider, null); |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 85 | mView.setVisibility(mVisible ? View.VISIBLE : View.INVISIBLE); |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 86 | mView.setMinimizedDockStack(mMinimized, mHomeStackResizable); |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 87 | final int size = mContext.getResources().getDimensionPixelSize( |
| 88 | com.android.internal.R.dimen.docked_stack_divider_thickness); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 89 | final boolean landscape = configuration.orientation == ORIENTATION_LANDSCAPE; |
Jorim Jaggi | 11c62e1 | 2016-04-05 20:41:21 -0700 | [diff] [blame] | 90 | final int width = landscape ? size : MATCH_PARENT; |
| 91 | final int height = landscape ? MATCH_PARENT : size; |
Jorim Jaggi | dd98d41 | 2015-11-18 15:57:38 -0800 | [diff] [blame] | 92 | mWindowManager.add(mView, width, height); |
Jorim Jaggi | a6c05d5 | 2016-05-27 00:31:21 -0700 | [diff] [blame] | 93 | mView.injectDependencies(mWindowManager, mDividerState); |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | private void removeDivider() { |
Wale Ogunwale | 15ba151 | 2017-06-06 08:31:17 -0700 | [diff] [blame] | 97 | if (mView != null) { |
| 98 | mView.onDividerRemoved(); |
| 99 | } |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 100 | mWindowManager.remove(); |
| 101 | } |
| 102 | |
| 103 | private void update(Configuration configuration) { |
| 104 | removeDivider(); |
| 105 | addDivider(configuration); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 106 | if (mMinimized) { |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 107 | mView.setMinimizedDockStack(true, mHomeStackResizable); |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 108 | updateTouchable(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 109 | } |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 110 | } |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 111 | |
| 112 | private void updateVisibility(final boolean visible) { |
| 113 | mView.post(new Runnable() { |
| 114 | @Override |
| 115 | public void run() { |
| 116 | if (mVisible != visible) { |
| 117 | mVisible = visible; |
| 118 | mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); |
Jorim Jaggi | ef92d6f | 2016-03-25 22:07:16 -0700 | [diff] [blame] | 119 | |
| 120 | // Update state because animations won't finish. |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 121 | mView.setMinimizedDockStack(mMinimized, mHomeStackResizable); |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | }); |
| 125 | } |
| 126 | |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 127 | private void updateMinimizedDockedStack(final boolean minimized, final long animDuration, |
| 128 | final boolean isHomeStackResizable) { |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 129 | mView.post(new Runnable() { |
| 130 | @Override |
| 131 | public void run() { |
Matthew Ng | fb692ac | 2017-02-02 14:02:56 -0800 | [diff] [blame] | 132 | mHomeStackResizable = isHomeStackResizable; |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 133 | if (mMinimized != minimized) { |
| 134 | mMinimized = minimized; |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 135 | updateTouchable(); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 136 | if (animDuration > 0) { |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 137 | mView.setMinimizedDockStack(minimized, animDuration, isHomeStackResizable); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 138 | } else { |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 139 | mView.setMinimizedDockStack(minimized, isHomeStackResizable); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 140 | } |
| 141 | } |
| 142 | } |
| 143 | }); |
| 144 | } |
| 145 | |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 146 | private void notifyDockedStackExistsChanged(final boolean exists) { |
| 147 | mView.post(new Runnable() { |
| 148 | @Override |
| 149 | public void run() { |
| 150 | mForcedResizableController.notifyDockedStackExistsChanged(exists); |
| 151 | } |
| 152 | }); |
| 153 | } |
| 154 | |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 155 | private void updateTouchable() { |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 156 | mWindowManager.setTouchable((mHomeStackResizable || !mMinimized) && !mAdjustedForIme); |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Winson Chung | 60fa647 | 2017-06-12 15:30:14 -0700 | [diff] [blame^] | 159 | /** |
| 160 | * Workaround for b/62528361, at the time RecentsDrawnEvent is sent, it may happen before a |
| 161 | * configuration change to the Divider, and internally, the event will be posted to the |
| 162 | * subscriber, or DividerView, which has been removed and prevented from resizing. Instead, |
| 163 | * register the event handler here and proxy the event to the current DividerView. |
| 164 | */ |
| 165 | public final void onBusEvent(RecentsDrawnEvent drawnEvent) { |
| 166 | if (mView != null) { |
| 167 | mView.onRecentsDrawn(); |
| 168 | } |
| 169 | } |
| 170 | |
Jorim Jaggi | 31f7170 | 2016-05-04 16:43:04 -0700 | [diff] [blame] | 171 | @Override |
| 172 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 173 | pw.print(" mVisible="); pw.println(mVisible); |
| 174 | pw.print(" mMinimized="); pw.println(mMinimized); |
| 175 | pw.print(" mAdjustedForIme="); pw.println(mAdjustedForIme); |
| 176 | } |
| 177 | |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 178 | class DockDividerVisibilityListener extends IDockedStackListener.Stub { |
| 179 | |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 180 | @Override |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 181 | public void onDividerVisibilityChanged(boolean visible) throws RemoteException { |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 182 | updateVisibility(visible); |
| 183 | } |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 184 | |
| 185 | @Override |
| 186 | public void onDockedStackExistsChanged(boolean exists) throws RemoteException { |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame] | 187 | notifyDockedStackExistsChanged(exists); |
Jorim Jaggi | a6c934e | 2015-12-21 13:22:31 +0100 | [diff] [blame] | 188 | } |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 189 | |
| 190 | @Override |
Matthew Ng | e15352e | 2016-12-20 15:36:29 -0800 | [diff] [blame] | 191 | public void onDockedStackMinimizedChanged(boolean minimized, long animDuration, |
| 192 | boolean isHomeStackResizable) throws RemoteException { |
| 193 | mHomeStackResizable = isHomeStackResizable; |
| 194 | updateMinimizedDockedStack(minimized, animDuration, isHomeStackResizable); |
Jorim Jaggi | 42625d1b | 2016-02-11 20:11:07 -0800 | [diff] [blame] | 195 | } |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 196 | |
| 197 | @Override |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 198 | public void onAdjustedForImeChanged(boolean adjustedForIme, long animDuration) |
| 199 | throws RemoteException { |
| 200 | mView.post(() -> { |
| 201 | if (mAdjustedForIme != adjustedForIme) { |
| 202 | mAdjustedForIme = adjustedForIme; |
| 203 | updateTouchable(); |
Jorim Jaggi | 3070e77 | 2016-05-17 16:41:32 -0700 | [diff] [blame] | 204 | if (!mMinimized) { |
| 205 | if (animDuration > 0) { |
| 206 | mView.setAdjustedForIme(adjustedForIme, animDuration); |
| 207 | } else { |
| 208 | mView.setAdjustedForIme(adjustedForIme); |
| 209 | } |
Jorim Jaggi | 698e763 | 2016-04-13 21:02:22 -0700 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | }); |
| 213 | } |
| 214 | |
| 215 | @Override |
Jorim Jaggi | 2917dc4 | 2016-04-11 11:39:13 -0700 | [diff] [blame] | 216 | public void onDockSideChanged(final int newDockSide) throws RemoteException { |
| 217 | mView.post(() -> mView.notifyDockSideChanged(newDockSide)); |
| 218 | } |
Filip Gruszczynski | 64cdc14 | 2015-11-29 21:10:07 -0800 | [diff] [blame] | 219 | } |
Jorim Jaggi | 1fcbab6 | 2015-11-04 16:39:50 +0100 | [diff] [blame] | 220 | } |