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; |
| 20 | import android.util.AttributeSet; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 21 | import android.view.View; |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 22 | import android.view.accessibility.AccessibilityEvent; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 23 | |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 24 | import com.android.systemui.R; |
| 25 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 26 | public class ExpandableNotificationRow extends ActivatableNotificationView { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 27 | private int mRowMinHeight; |
| 28 | private int mRowMaxHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 29 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 30 | /** Does this row contain layouts that can adapt to row expansion */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 31 | private boolean mExpandable; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 32 | /** Has the user actively changed the expansion state of this row */ |
| 33 | private boolean mHasUserChangedExpansion; |
| 34 | /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 35 | private boolean mUserExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 36 | /** Is the user touching this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 37 | private boolean mUserLocked; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 38 | /** Are we showing the "public" version */ |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 39 | private boolean mShowingPublic; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 40 | private boolean mSensitive; |
| 41 | private boolean mShowingPublicInitialized; |
| 42 | private boolean mShowingPublicForIntrinsicHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 43 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 44 | /** |
| 45 | * Is this notification expanded by the system. The expansion state can be overridden by the |
| 46 | * user expansion. |
| 47 | */ |
| 48 | private boolean mIsSystemExpanded; |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * Whether the notification expansion is disabled. This is the case on Keyguard. |
| 52 | */ |
| 53 | private boolean mExpansionDisabled; |
| 54 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 55 | private NotificationContentView mPublicLayout; |
| 56 | private NotificationContentView mPrivateLayout; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 57 | private int mMaxExpandHeight; |
Selim Cinek | 863834b | 2014-05-20 04:20:25 +0200 | [diff] [blame] | 58 | private View mVetoButton; |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 59 | private boolean mClearable; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 60 | private ExpansionLogger mLogger; |
| 61 | private String mLoggingKey; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 62 | private boolean mWasReset; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 63 | |
| 64 | public interface ExpansionLogger { |
| 65 | public void logNotificationExpansion(String key, boolean userAction, boolean expanded); |
| 66 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 67 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 68 | public ExpandableNotificationRow(Context context, AttributeSet attrs) { |
| 69 | super(context, attrs); |
| 70 | } |
| 71 | |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 72 | /** |
| 73 | * Resets this view so it can be re-used for an updated notification. |
| 74 | */ |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 75 | @Override |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 76 | public void reset() { |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 77 | super.reset(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 78 | mRowMinHeight = 0; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 79 | final boolean wasExpanded = isExpanded(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 80 | mRowMaxHeight = 0; |
| 81 | mExpandable = false; |
| 82 | mHasUserChangedExpansion = false; |
| 83 | mUserLocked = false; |
| 84 | mShowingPublic = false; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 85 | mSensitive = false; |
| 86 | mShowingPublicInitialized = false; |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 87 | mIsSystemExpanded = false; |
| 88 | mExpansionDisabled = false; |
| 89 | mPublicLayout.reset(); |
| 90 | mPrivateLayout.reset(); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 91 | resetHeight(); |
| 92 | logExpansionEvent(false, wasExpanded); |
| 93 | } |
| 94 | |
| 95 | public void resetHeight() { |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 96 | mMaxExpandHeight = 0; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 97 | mWasReset = true; |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 98 | onHeightReset(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 99 | } |
| 100 | |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 101 | @Override |
| 102 | protected void onFinishInflate() { |
| 103 | super.onFinishInflate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 104 | mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic); |
| 105 | mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded); |
Selim Cinek | 863834b | 2014-05-20 04:20:25 +0200 | [diff] [blame] | 106 | mVetoButton = findViewById(R.id.veto); |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) { |
| 111 | if (super.onRequestSendAccessibilityEvent(child, event)) { |
| 112 | // Add a record for the entire layout since its content is somehow small. |
| 113 | // The event comes from a leaf view that is interacted with. |
| 114 | AccessibilityEvent record = AccessibilityEvent.obtain(); |
| 115 | onInitializeAccessibilityEvent(record); |
| 116 | dispatchPopulateAccessibilityEvent(record); |
| 117 | event.appendRecord(record); |
| 118 | return true; |
| 119 | } |
| 120 | return false; |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 121 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 122 | |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 123 | @Override |
| 124 | public void setDark(boolean dark, boolean fade) { |
| 125 | super.setDark(dark, fade); |
| 126 | final NotificationContentView showing = getShowingLayout(); |
| 127 | if (showing != null) { |
| 128 | showing.setDark(dark, fade); |
| 129 | } |
| 130 | } |
| 131 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 132 | public void setHeightRange(int rowMinHeight, int rowMaxHeight) { |
| 133 | mRowMinHeight = rowMinHeight; |
| 134 | mRowMaxHeight = rowMaxHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | public boolean isExpandable() { |
| 138 | return mExpandable; |
| 139 | } |
| 140 | |
| 141 | public void setExpandable(boolean expandable) { |
| 142 | mExpandable = expandable; |
| 143 | } |
| 144 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 145 | /** |
| 146 | * @return whether the user has changed the expansion state |
| 147 | */ |
| 148 | public boolean hasUserChangedExpansion() { |
| 149 | return mHasUserChangedExpansion; |
| 150 | } |
| 151 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 152 | public boolean isUserExpanded() { |
| 153 | return mUserExpanded; |
| 154 | } |
| 155 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 156 | /** |
| 157 | * Set this notification to be expanded by the user |
| 158 | * |
| 159 | * @param userExpanded whether the user wants this notification to be expanded |
| 160 | */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 161 | public void setUserExpanded(boolean userExpanded) { |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 162 | if (userExpanded && !mExpandable) return; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 163 | final boolean wasExpanded = isExpanded(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 164 | mHasUserChangedExpansion = true; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 165 | mUserExpanded = userExpanded; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 166 | logExpansionEvent(true, wasExpanded); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 167 | } |
| 168 | |
Selim Cinek | ccd14fb | 2014-08-12 18:53:24 +0200 | [diff] [blame] | 169 | public void resetUserExpansion() { |
| 170 | mHasUserChangedExpansion = false; |
| 171 | mUserExpanded = false; |
| 172 | } |
| 173 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 174 | public boolean isUserLocked() { |
| 175 | return mUserLocked; |
| 176 | } |
| 177 | |
| 178 | public void setUserLocked(boolean userLocked) { |
| 179 | mUserLocked = userLocked; |
| 180 | } |
| 181 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 182 | /** |
| 183 | * @return has the system set this notification to be expanded |
| 184 | */ |
| 185 | public boolean isSystemExpanded() { |
| 186 | return mIsSystemExpanded; |
| 187 | } |
| 188 | |
| 189 | /** |
| 190 | * Set this notification to be expanded by the system. |
| 191 | * |
| 192 | * @param expand whether the system wants this notification to be expanded. |
| 193 | */ |
| 194 | public void setSystemExpanded(boolean expand) { |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 195 | if (expand != mIsSystemExpanded) { |
| 196 | final boolean wasExpanded = isExpanded(); |
| 197 | mIsSystemExpanded = expand; |
| 198 | notifyHeightChanged(); |
| 199 | logExpansionEvent(false, wasExpanded); |
| 200 | } |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /** |
| 204 | * @param expansionDisabled whether to prevent notification expansion |
| 205 | */ |
| 206 | public void setExpansionDisabled(boolean expansionDisabled) { |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 207 | if (expansionDisabled != mExpansionDisabled) { |
| 208 | final boolean wasExpanded = isExpanded(); |
| 209 | mExpansionDisabled = expansionDisabled; |
| 210 | logExpansionEvent(false, wasExpanded); |
| 211 | if (wasExpanded != isExpanded()) { |
| 212 | notifyHeightChanged(); |
| 213 | } |
| 214 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | /** |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 218 | * @return Can the underlying notification be cleared? |
| 219 | */ |
| 220 | public boolean isClearable() { |
| 221 | return mClearable; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Set whether the notification can be cleared. |
| 226 | * |
| 227 | * @param clearable |
| 228 | */ |
| 229 | public void setClearable(boolean clearable) { |
| 230 | mClearable = clearable; |
| 231 | updateVetoButton(); |
| 232 | } |
| 233 | |
| 234 | /** |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 235 | * Apply an expansion state to the layout. |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 236 | */ |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 237 | public void applyExpansionToLayout() { |
| 238 | boolean expand = isExpanded(); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 239 | if (expand && mExpandable) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 240 | setActualHeight(mMaxExpandHeight); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 241 | } else { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 242 | setActualHeight(mRowMinHeight); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 243 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 244 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 245 | |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 246 | @Override |
| 247 | public int getIntrinsicHeight() { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 248 | if (isUserLocked()) { |
| 249 | return getActualHeight(); |
| 250 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 251 | boolean inExpansionState = isExpanded(); |
| 252 | if (!inExpansionState) { |
| 253 | // not expanded, so we return the collapsed size |
| 254 | return mRowMinHeight; |
| 255 | } |
| 256 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 257 | return mShowingPublicForIntrinsicHeight ? mRowMinHeight : getMaxExpandHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 258 | } |
| 259 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 260 | /** |
| 261 | * Check whether the view state is currently expanded. This is given by the system in {@link |
| 262 | * #setSystemExpanded(boolean)} and can be overridden by user expansion or |
| 263 | * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this |
| 264 | * view can differ from this state, if layout params are modified from outside. |
| 265 | * |
| 266 | * @return whether the view state is currently expanded. |
| 267 | */ |
| 268 | private boolean isExpanded() { |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 269 | return !mExpansionDisabled |
| 270 | && (!hasUserChangedExpansion() && isSystemExpanded() || isUserExpanded()); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | @Override |
| 274 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 275 | super.onLayout(changed, left, top, right, bottom); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 276 | boolean updateExpandHeight = mMaxExpandHeight == 0 && !mWasReset; |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame^] | 277 | updateMaxExpandHeight(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 278 | if (updateExpandHeight) { |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 279 | applyExpansionToLayout(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 280 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 281 | mWasReset = false; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 282 | } |
| 283 | |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame^] | 284 | private void updateMaxExpandHeight() { |
| 285 | int intrinsicBefore = getIntrinsicHeight(); |
| 286 | mMaxExpandHeight = mPrivateLayout.getMaxHeight(); |
| 287 | if (intrinsicBefore != getIntrinsicHeight()) { |
| 288 | notifyHeightChanged(); |
| 289 | } |
| 290 | } |
| 291 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 292 | public void setSensitive(boolean sensitive) { |
| 293 | mSensitive = sensitive; |
| 294 | } |
| 295 | |
| 296 | public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) { |
| 297 | mShowingPublicForIntrinsicHeight = mSensitive && hideSensitive; |
| 298 | } |
| 299 | |
| 300 | public void setHideSensitive(boolean hideSensitive, boolean animated, long delay, |
| 301 | long duration) { |
| 302 | boolean oldShowingPublic = mShowingPublic; |
| 303 | mShowingPublic = mSensitive && hideSensitive; |
| 304 | if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) { |
| 305 | return; |
| 306 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 307 | |
| 308 | // bail out if no public version |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 309 | if (mPublicLayout.getChildCount() == 0) return; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 310 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 311 | if (!animated) { |
| 312 | mPublicLayout.animate().cancel(); |
| 313 | mPrivateLayout.animate().cancel(); |
| 314 | mPublicLayout.setAlpha(1f); |
| 315 | mPrivateLayout.setAlpha(1f); |
| 316 | mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE); |
| 317 | mPrivateLayout.setVisibility(mShowingPublic ? View.INVISIBLE : View.VISIBLE); |
| 318 | } else { |
| 319 | animateShowingPublic(delay, duration); |
| 320 | } |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 321 | |
| 322 | updateVetoButton(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 323 | mShowingPublicInitialized = true; |
| 324 | } |
| 325 | |
| 326 | private void animateShowingPublic(long delay, long duration) { |
| 327 | final View source = mShowingPublic ? mPrivateLayout : mPublicLayout; |
| 328 | View target = mShowingPublic ? mPublicLayout : mPrivateLayout; |
| 329 | source.setVisibility(View.VISIBLE); |
| 330 | target.setVisibility(View.VISIBLE); |
| 331 | target.setAlpha(0f); |
| 332 | source.animate().cancel(); |
| 333 | target.animate().cancel(); |
| 334 | source.animate() |
| 335 | .alpha(0f) |
| 336 | .withLayer() |
| 337 | .setStartDelay(delay) |
| 338 | .setDuration(duration) |
| 339 | .withEndAction(new Runnable() { |
| 340 | @Override |
| 341 | public void run() { |
| 342 | source.setVisibility(View.INVISIBLE); |
| 343 | } |
| 344 | }); |
| 345 | target.animate() |
| 346 | .alpha(1f) |
| 347 | .withLayer() |
| 348 | .setStartDelay(delay) |
| 349 | .setDuration(duration); |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | private void updateVetoButton() { |
| 353 | // public versions cannot be dismissed |
| 354 | mVetoButton.setVisibility(isClearable() && !mShowingPublic ? View.VISIBLE : View.GONE); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 355 | } |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 356 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 357 | public int getMaxExpandHeight() { |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 358 | return mShowingPublicForIntrinsicHeight ? mRowMinHeight : mMaxExpandHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 359 | } |
Jorim Jaggi | 584a7aa | 2014-04-10 23:26:13 +0200 | [diff] [blame] | 360 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 361 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 362 | public boolean isContentExpandable() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 363 | NotificationContentView showingLayout = getShowingLayout(); |
| 364 | return showingLayout.isContentExpandable(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | @Override |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 368 | public void setActualHeight(int height, boolean notifyListeners) { |
Selim Cinek | c9c00ae | 2014-05-20 03:33:40 +0200 | [diff] [blame] | 369 | mPrivateLayout.setActualHeight(height); |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 370 | mPublicLayout.setActualHeight(height); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 371 | invalidate(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 372 | super.setActualHeight(height, notifyListeners); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | @Override |
| 376 | public int getMaxHeight() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 377 | NotificationContentView showingLayout = getShowingLayout(); |
| 378 | return showingLayout.getMaxHeight(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 382 | public int getMinHeight() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 383 | NotificationContentView showingLayout = getShowingLayout(); |
| 384 | return showingLayout.getMinHeight(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | @Override |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 388 | public void setClipTopAmount(int clipTopAmount) { |
| 389 | super.setClipTopAmount(clipTopAmount); |
| 390 | mPrivateLayout.setClipTopAmount(clipTopAmount); |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 391 | mPublicLayout.setClipTopAmount(clipTopAmount); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | public void notifyContentUpdated() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 395 | mPublicLayout.notifyContentUpdated(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 396 | mPrivateLayout.notifyContentUpdated(); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 397 | } |
Selim Cinek | 7d44772 | 2014-06-10 15:51:59 +0200 | [diff] [blame] | 398 | |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 399 | public boolean isMaxExpandHeightInitialized() { |
| 400 | return mMaxExpandHeight != 0; |
Selim Cinek | 7d44772 | 2014-06-10 15:51:59 +0200 | [diff] [blame] | 401 | } |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 402 | |
| 403 | private NotificationContentView getShowingLayout() { |
| 404 | return mShowingPublic ? mPublicLayout : mPrivateLayout; |
| 405 | } |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 406 | |
| 407 | public void setExpansionLogger(ExpansionLogger logger, String key) { |
| 408 | mLogger = logger; |
| 409 | mLoggingKey = key; |
| 410 | } |
| 411 | |
| 412 | |
| 413 | private void logExpansionEvent(boolean userAction, boolean wasExpanded) { |
| 414 | final boolean nowExpanded = isExpanded(); |
| 415 | if (wasExpanded != nowExpanded && mLogger != null) { |
| 416 | mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded) ; |
| 417 | } |
| 418 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 419 | } |