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