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