Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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.statusbar; |
| 18 | |
| 19 | import android.content.Context; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame^] | 20 | import android.graphics.Canvas; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 21 | import android.util.AttributeSet; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame^] | 22 | import android.util.Log; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 23 | import android.view.View; |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 24 | import android.view.accessibility.AccessibilityEvent; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 25 | |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 26 | import com.android.systemui.R; |
| 27 | |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 28 | public class ExpandableNotificationRow extends ActivatableNotificationView { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 29 | private int mRowMinHeight; |
| 30 | private int mRowMaxHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 31 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 32 | /** Does this row contain layouts that can adapt to row expansion */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 33 | private boolean mExpandable; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 34 | /** Has the user actively changed the expansion state of this row */ |
| 35 | private boolean mHasUserChangedExpansion; |
| 36 | /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 37 | private boolean mUserExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 38 | /** Is the user touching this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 39 | private boolean mUserLocked; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 40 | /** Are we showing the "public" version */ |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 41 | private boolean mShowingPublic; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 42 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 43 | /** |
| 44 | * Is this notification expanded by the system. The expansion state can be overridden by the |
| 45 | * user expansion. |
| 46 | */ |
| 47 | private boolean mIsSystemExpanded; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame^] | 48 | private NotificationContentView mPublicLayout; |
| 49 | private NotificationContentView mPrivateLayout; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 50 | private int mMaxExpandHeight; |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 51 | private NotificationActivator mActivator; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 52 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 53 | public ExpandableNotificationRow(Context context, AttributeSet attrs) { |
| 54 | super(context, attrs); |
| 55 | } |
| 56 | |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 57 | @Override |
| 58 | protected void onFinishInflate() { |
| 59 | super.onFinishInflate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame^] | 60 | mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic); |
| 61 | mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded); |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 62 | |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 63 | mActivator = new NotificationActivator(this); |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) { |
| 68 | if (super.onRequestSendAccessibilityEvent(child, event)) { |
| 69 | // Add a record for the entire layout since its content is somehow small. |
| 70 | // The event comes from a leaf view that is interacted with. |
| 71 | AccessibilityEvent record = AccessibilityEvent.obtain(); |
| 72 | onInitializeAccessibilityEvent(record); |
| 73 | dispatchPopulateAccessibilityEvent(record); |
| 74 | event.appendRecord(record); |
| 75 | return true; |
| 76 | } |
| 77 | return false; |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 78 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 79 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 80 | public void setHeightRange(int rowMinHeight, int rowMaxHeight) { |
| 81 | mRowMinHeight = rowMinHeight; |
| 82 | mRowMaxHeight = rowMaxHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | public boolean isExpandable() { |
| 86 | return mExpandable; |
| 87 | } |
| 88 | |
| 89 | public void setExpandable(boolean expandable) { |
| 90 | mExpandable = expandable; |
| 91 | } |
| 92 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 93 | /** |
| 94 | * @return whether the user has changed the expansion state |
| 95 | */ |
| 96 | public boolean hasUserChangedExpansion() { |
| 97 | return mHasUserChangedExpansion; |
| 98 | } |
| 99 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 100 | public boolean isUserExpanded() { |
| 101 | return mUserExpanded; |
| 102 | } |
| 103 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 104 | /** |
| 105 | * Set this notification to be expanded by the user |
| 106 | * |
| 107 | * @param userExpanded whether the user wants this notification to be expanded |
| 108 | */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 109 | public void setUserExpanded(boolean userExpanded) { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 110 | mHasUserChangedExpansion = true; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 111 | mUserExpanded = userExpanded; |
| 112 | } |
| 113 | |
| 114 | public boolean isUserLocked() { |
| 115 | return mUserLocked; |
| 116 | } |
| 117 | |
| 118 | public void setUserLocked(boolean userLocked) { |
| 119 | mUserLocked = userLocked; |
| 120 | } |
| 121 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 122 | /** |
| 123 | * @return has the system set this notification to be expanded |
| 124 | */ |
| 125 | public boolean isSystemExpanded() { |
| 126 | return mIsSystemExpanded; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Set this notification to be expanded by the system. |
| 131 | * |
| 132 | * @param expand whether the system wants this notification to be expanded. |
| 133 | */ |
| 134 | public void setSystemExpanded(boolean expand) { |
| 135 | mIsSystemExpanded = expand; |
| 136 | applyExpansionToLayout(expand); |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Apply an expansion state to the layout. |
| 141 | * |
| 142 | * @param expand should the layout be in the expanded state |
| 143 | */ |
| 144 | public void applyExpansionToLayout(boolean expand) { |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 145 | if (expand && mExpandable) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame^] | 146 | setActualHeight(mMaxExpandHeight); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 147 | } else { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame^] | 148 | setActualHeight(mRowMinHeight); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 149 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 150 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 151 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 152 | /** |
| 153 | * If {@link #isExpanded()} then this is the greatest possible height this view can |
| 154 | * get and otherwise it is {@link #mRowMinHeight}. |
| 155 | * |
| 156 | * @return the maximum allowed expansion height of this view. |
| 157 | */ |
| 158 | public int getMaximumAllowedExpandHeight() { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame^] | 159 | if (isUserLocked()) { |
| 160 | return getActualHeight(); |
| 161 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 162 | boolean inExpansionState = isExpanded(); |
| 163 | if (!inExpansionState) { |
| 164 | // not expanded, so we return the collapsed size |
| 165 | return mRowMinHeight; |
| 166 | } |
| 167 | |
| 168 | return mShowingPublic ? mRowMinHeight : getMaxExpandHeight(); |
| 169 | } |
| 170 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 171 | /** |
| 172 | * Check whether the view state is currently expanded. This is given by the system in {@link |
| 173 | * #setSystemExpanded(boolean)} and can be overridden by user expansion or |
| 174 | * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this |
| 175 | * view can differ from this state, if layout params are modified from outside. |
| 176 | * |
| 177 | * @return whether the view state is currently expanded. |
| 178 | */ |
| 179 | private boolean isExpanded() { |
| 180 | return !hasUserChangedExpansion() && isSystemExpanded() || isUserExpanded(); |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 185 | super.onLayout(changed, left, top, right, bottom); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame^] | 186 | boolean updateExpandHeight = mMaxExpandHeight == 0; |
| 187 | mMaxExpandHeight = mPrivateLayout.getMaxHeight(); |
| 188 | if (updateExpandHeight) { |
| 189 | applyExpansionToLayout(isExpanded()); |
| 190 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 191 | } |
| 192 | |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 193 | public void setShowingPublic(boolean show) { |
| 194 | mShowingPublic = show; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 195 | |
| 196 | // bail out if no public version |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 197 | if (mPublicLayout.getChildCount() == 0) return; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 198 | |
| 199 | // TODO: animation? |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 200 | mPublicLayout.setVisibility(show ? View.VISIBLE : View.GONE); |
| 201 | mPrivateLayout.setVisibility(show ? View.GONE : View.VISIBLE); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 202 | } |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 203 | |
| 204 | /** |
| 205 | * Sets the notification as dimmed, meaning that it will appear in a more gray variant. |
| 206 | */ |
| 207 | public void setDimmed(boolean dimmed) { |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 208 | super.setDimmed(dimmed); |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 209 | mActivator.setDimmed(dimmed); |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 210 | } |
| 211 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 212 | public int getMaxExpandHeight() { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 213 | return mMaxExpandHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 214 | } |
Jorim Jaggi | 584a7aa | 2014-04-10 23:26:13 +0200 | [diff] [blame] | 215 | |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 216 | public NotificationActivator getActivator() { |
| 217 | return mActivator; |
| 218 | } |
| 219 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 220 | /** |
| 221 | * @return the potential height this view could expand in addition. |
| 222 | */ |
| 223 | public int getExpandPotential() { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame^] | 224 | return getMaximumAllowedExpandHeight() - getActualHeight(); |
| 225 | } |
| 226 | |
| 227 | @Override |
| 228 | public void setActualHeight(int height) { |
| 229 | mPrivateLayout.setActualHeight(height); |
| 230 | invalidate(); |
| 231 | super.setActualHeight(height); |
| 232 | } |
| 233 | |
| 234 | @Override |
| 235 | public int getMaxHeight() { |
| 236 | return mPrivateLayout.getMaxHeight(); |
| 237 | } |
| 238 | |
| 239 | @Override |
| 240 | public void setClipTopAmount(int clipTopAmount) { |
| 241 | super.setClipTopAmount(clipTopAmount); |
| 242 | mPrivateLayout.setClipTopAmount(clipTopAmount); |
| 243 | } |
| 244 | |
| 245 | public void notifyContentUpdated() { |
| 246 | mPrivateLayout.notifyContentUpdated(); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 247 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 248 | } |