Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Selim Cinek | 0ffbda6 | 2016-01-01 20:29:12 +0100 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification; |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 18 | |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.graphics.Color; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 21 | import android.graphics.Rect; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 22 | import android.service.notification.StatusBarNotification; |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 23 | import android.view.View; |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 24 | import android.widget.ImageView; |
Selim Cinek | 75fe38c | 2015-11-20 12:47:59 -0800 | [diff] [blame] | 25 | import android.widget.ProgressBar; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 26 | import android.widget.TextView; |
| 27 | |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 28 | import com.android.systemui.statusbar.CrossFadeHelper; |
Selim Cinek | 7d1c63e | 2016-04-21 15:26:10 -0700 | [diff] [blame] | 29 | import com.android.systemui.statusbar.ExpandableNotificationRow; |
Selim Cinek | 0ffbda6 | 2016-01-01 20:29:12 +0100 | [diff] [blame] | 30 | import com.android.systemui.statusbar.TransformableView; |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 31 | import com.android.systemui.statusbar.ViewTransformationHelper; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 32 | |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 33 | /** |
| 34 | * Wraps a notification view inflated from a template. |
| 35 | */ |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 36 | public class NotificationTemplateViewWrapper extends NotificationHeaderViewWrapper { |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 37 | |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 38 | private static final int mDarkProgressTint = 0xffffffff; |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 39 | |
Jorim Jaggi | dacc924 | 2014-12-08 19:21:26 +0100 | [diff] [blame] | 40 | protected ImageView mPicture; |
Selim Cinek | 75fe38c | 2015-11-20 12:47:59 -0800 | [diff] [blame] | 41 | private ProgressBar mProgressBar; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 42 | private TextView mTitle; |
| 43 | private TextView mText; |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 44 | protected View mActionsContainer; |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 45 | private View mReplyAction; |
| 46 | private Rect mTmpRect = new Rect(); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 47 | |
| 48 | private int mContentHeight; |
| 49 | private int mMinHeightHint; |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 50 | |
Adrian Roos | 7bcf6d3 | 2017-04-04 16:44:25 -0700 | [diff] [blame] | 51 | protected NotificationTemplateViewWrapper(Context ctx, View view, |
| 52 | ExpandableNotificationRow row) { |
Selim Cinek | 7d1c63e | 2016-04-21 15:26:10 -0700 | [diff] [blame] | 53 | super(ctx, view, row); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 54 | mTransformationHelper.setCustomTransformation( |
| 55 | new ViewTransformationHelper.CustomTransformation() { |
| 56 | @Override |
| 57 | public boolean transformTo(TransformState ownState, |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 58 | TransformableView notification, final float transformationAmount) { |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 59 | if (!(notification instanceof HybridNotificationView)) { |
| 60 | return false; |
| 61 | } |
| 62 | TransformState otherState = notification.getCurrentState( |
| 63 | TRANSFORMING_VIEW_TITLE); |
Selim Cinek | b66685b | 2016-02-02 17:16:08 -0800 | [diff] [blame] | 64 | final View text = ownState.getTransformedView(); |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 65 | CrossFadeHelper.fadeOut(text, transformationAmount); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 66 | if (otherState != null) { |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 67 | ownState.transformViewVerticalTo(otherState, this, |
| 68 | transformationAmount); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 69 | otherState.recycle(); |
| 70 | } |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | @Override |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 75 | public boolean customTransformTarget(TransformState ownState, |
| 76 | TransformState otherState) { |
| 77 | float endY = getTransformationY(ownState, otherState); |
| 78 | ownState.setTransformationEndY(endY); |
| 79 | return true; |
| 80 | } |
| 81 | |
| 82 | @Override |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 83 | public boolean transformFrom(TransformState ownState, |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 84 | TransformableView notification, float transformationAmount) { |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 85 | if (!(notification instanceof HybridNotificationView)) { |
| 86 | return false; |
| 87 | } |
| 88 | TransformState otherState = notification.getCurrentState( |
| 89 | TRANSFORMING_VIEW_TITLE); |
Selim Cinek | b66685b | 2016-02-02 17:16:08 -0800 | [diff] [blame] | 90 | final View text = ownState.getTransformedView(); |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 91 | CrossFadeHelper.fadeIn(text, transformationAmount); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 92 | if (otherState != null) { |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 93 | ownState.transformViewVerticalFrom(otherState, this, |
| 94 | transformationAmount); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 95 | otherState.recycle(); |
| 96 | } |
| 97 | return true; |
| 98 | } |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 99 | |
| 100 | @Override |
| 101 | public boolean initTransformation(TransformState ownState, |
| 102 | TransformState otherState) { |
| 103 | float startY = getTransformationY(ownState, otherState); |
| 104 | ownState.setTransformationStartY(startY); |
| 105 | return true; |
| 106 | } |
| 107 | |
| 108 | private float getTransformationY(TransformState ownState, |
| 109 | TransformState otherState) { |
| 110 | int[] otherStablePosition = otherState.getLaidOutLocationOnScreen(); |
| 111 | int[] ownStablePosition = ownState.getLaidOutLocationOnScreen(); |
| 112 | return (otherStablePosition[1] |
| 113 | + otherState.getTransformedView().getHeight() |
| 114 | - ownStablePosition[1]) * 0.33f; |
| 115 | } |
| 116 | |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 117 | }, TRANSFORMING_VIEW_TEXT); |
Jorim Jaggi | dacc924 | 2014-12-08 19:21:26 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 120 | private void resolveTemplateViews(StatusBarNotification notification) { |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 121 | mPicture = (ImageView) mView.findViewById(com.android.internal.R.id.right_icon); |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 122 | if (mPicture != null) { |
| 123 | mPicture.setTag(ImageTransformState.ICON_TAG, |
| 124 | notification.getNotification().getLargeIcon()); |
| 125 | } |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 126 | mTitle = (TextView) mView.findViewById(com.android.internal.R.id.title); |
| 127 | mText = (TextView) mView.findViewById(com.android.internal.R.id.text); |
Selim Cinek | 75fe38c | 2015-11-20 12:47:59 -0800 | [diff] [blame] | 128 | final View progress = mView.findViewById(com.android.internal.R.id.progress); |
| 129 | if (progress instanceof ProgressBar) { |
| 130 | mProgressBar = (ProgressBar) progress; |
| 131 | } else { |
| 132 | // It's still a viewstub |
| 133 | mProgressBar = null; |
| 134 | } |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 135 | mActionsContainer = mView.findViewById(com.android.internal.R.id.actions_container); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 136 | mReplyAction = mView.findViewById(com.android.internal.R.id.reply_icon_action); |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public boolean disallowSingleClick(float x, float y) { |
| 141 | if (mReplyAction != null && mReplyAction.getVisibility() == View.VISIBLE) { |
| 142 | if (isOnView(mReplyAction, x, y) || isOnView(mPicture, x, y)) { |
| 143 | return true; |
| 144 | } |
| 145 | } |
| 146 | return super.disallowSingleClick(x, y); |
| 147 | } |
| 148 | |
| 149 | private boolean isOnView(View view, float x, float y) { |
| 150 | View searchView = (View) view.getParent(); |
| 151 | while (searchView != null && !(searchView instanceof ExpandableNotificationRow)) { |
| 152 | searchView.getHitRect(mTmpRect); |
| 153 | x -= mTmpRect.left; |
| 154 | y -= mTmpRect.top; |
| 155 | searchView = (View) searchView.getParent(); |
| 156 | } |
| 157 | view.getHitRect(mTmpRect); |
| 158 | return mTmpRect.contains((int) x,(int) y); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | @Override |
Selim Cinek | 131f1a4 | 2017-06-05 17:50:19 -0700 | [diff] [blame] | 162 | public void onContentUpdated(ExpandableNotificationRow row) { |
Selim Cinek | 646d205 | 2016-01-03 14:42:02 +0800 | [diff] [blame] | 163 | // Reinspect the notification. Before the super call, because the super call also updates |
| 164 | // the transformation types and we need to have our values set by then. |
Selim Cinek | a6ee4bd | 2017-09-20 22:52:29 +0000 | [diff] [blame] | 165 | resolveTemplateViews(row.getStatusBarNotification()); |
Selim Cinek | 131f1a4 | 2017-06-05 17:50:19 -0700 | [diff] [blame] | 166 | super.onContentUpdated(row); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | @Override |
| 170 | protected void updateInvertHelper() { |
| 171 | super.updateInvertHelper(); |
| 172 | View mainColumn = mView.findViewById(com.android.internal.R.id.notification_main_column); |
Selim Cinek | 75fe38c | 2015-11-20 12:47:59 -0800 | [diff] [blame] | 173 | if (mainColumn != null) { |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 174 | mInvertHelper.addTarget(mainColumn); |
Selim Cinek | 75fe38c | 2015-11-20 12:47:59 -0800 | [diff] [blame] | 175 | } |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | @Override |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 179 | protected void updateTransformedTypes() { |
| 180 | // This also clears the existing types |
| 181 | super.updateTransformedTypes(); |
| 182 | if (mTitle != null) { |
Adrian Roos | 7bcf6d3 | 2017-04-04 16:44:25 -0700 | [diff] [blame] | 183 | mTransformationHelper.addTransformedView(TransformableView.TRANSFORMING_VIEW_TITLE, |
| 184 | mTitle); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 185 | } |
| 186 | if (mText != null) { |
Adrian Roos | 7bcf6d3 | 2017-04-04 16:44:25 -0700 | [diff] [blame] | 187 | mTransformationHelper.addTransformedView(TransformableView.TRANSFORMING_VIEW_TEXT, |
| 188 | mText); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 189 | } |
| 190 | if (mPicture != null) { |
Adrian Roos | 7bcf6d3 | 2017-04-04 16:44:25 -0700 | [diff] [blame] | 191 | mTransformationHelper.addTransformedView(TransformableView.TRANSFORMING_VIEW_IMAGE, |
| 192 | mPicture); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 193 | } |
| 194 | if (mProgressBar != null) { |
Adrian Roos | 7bcf6d3 | 2017-04-04 16:44:25 -0700 | [diff] [blame] | 195 | mTransformationHelper.addTransformedView(TransformableView.TRANSFORMING_VIEW_PROGRESS, |
| 196 | mProgressBar); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 197 | } |
Jorim Jaggi | dacc924 | 2014-12-08 19:21:26 +0100 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | @Override |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 201 | public void setDark(boolean dark, boolean fade, long delay) { |
Selim Cinek | b88b984 | 2016-02-26 09:25:33 -0800 | [diff] [blame] | 202 | if (dark == mDark && mDarkInitialized) { |
Selim Cinek | 19ba705 | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 203 | return; |
| 204 | } |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 205 | super.setDark(dark, fade, delay); |
Adrian Roos | 7bcf6d3 | 2017-04-04 16:44:25 -0700 | [diff] [blame] | 206 | setPictureDark(dark, fade, delay); |
Selim Cinek | 75fe38c | 2015-11-20 12:47:59 -0800 | [diff] [blame] | 207 | setProgressBarDark(dark, fade, delay); |
| 208 | } |
| 209 | |
| 210 | private void setProgressBarDark(boolean dark, boolean fade, long delay) { |
| 211 | if (mProgressBar != null) { |
| 212 | if (fade) { |
| 213 | fadeProgressDark(mProgressBar, dark, delay); |
| 214 | } else { |
| 215 | updateProgressDark(mProgressBar, dark); |
| 216 | } |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | private void fadeProgressDark(final ProgressBar target, final boolean dark, long delay) { |
Adrian Roos | 7bcf6d3 | 2017-04-04 16:44:25 -0700 | [diff] [blame] | 221 | getDozer().startIntensityAnimation(animation -> { |
| 222 | float t = (float) animation.getAnimatedValue(); |
| 223 | updateProgressDark(target, t); |
Selim Cinek | 75fe38c | 2015-11-20 12:47:59 -0800 | [diff] [blame] | 224 | }, dark, delay, null /* listener */); |
| 225 | } |
| 226 | |
| 227 | private void updateProgressDark(ProgressBar target, float intensity) { |
| 228 | int color = interpolateColor(mColor, mDarkProgressTint, intensity); |
| 229 | target.getIndeterminateDrawable().mutate().setTint(color); |
| 230 | target.getProgressDrawable().mutate().setTint(color); |
| 231 | } |
| 232 | |
| 233 | private void updateProgressDark(ProgressBar target, boolean dark) { |
| 234 | updateProgressDark(target, dark ? 1f : 0f); |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 235 | } |
| 236 | |
Adrian Roos | 7bcf6d3 | 2017-04-04 16:44:25 -0700 | [diff] [blame] | 237 | private void setPictureDark(boolean dark, boolean fade, long delay) { |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 238 | if (mPicture != null) { |
Adrian Roos | 7bcf6d3 | 2017-04-04 16:44:25 -0700 | [diff] [blame] | 239 | getDozer().setImageDark(mPicture, dark, fade, delay, true /* useGrayscale */); |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 240 | } |
| 241 | } |
| 242 | |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 243 | private static int interpolateColor(int source, int target, float t) { |
| 244 | int aSource = Color.alpha(source); |
| 245 | int rSource = Color.red(source); |
| 246 | int gSource = Color.green(source); |
| 247 | int bSource = Color.blue(source); |
| 248 | int aTarget = Color.alpha(target); |
| 249 | int rTarget = Color.red(target); |
| 250 | int gTarget = Color.green(target); |
| 251 | int bTarget = Color.blue(target); |
| 252 | return Color.argb( |
| 253 | (int) (aSource * (1f - t) + aTarget * t), |
| 254 | (int) (rSource * (1f - t) + rTarget * t), |
| 255 | (int) (gSource * (1f - t) + gTarget * t), |
| 256 | (int) (bSource * (1f - t) + bTarget * t)); |
| 257 | } |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 258 | |
| 259 | @Override |
| 260 | public void setContentHeight(int contentHeight, int minHeightHint) { |
| 261 | super.setContentHeight(contentHeight, minHeightHint); |
| 262 | |
| 263 | mContentHeight = contentHeight; |
| 264 | mMinHeightHint = minHeightHint; |
| 265 | updateActionOffset(); |
| 266 | } |
| 267 | |
Selim Cinek | 86bfcee | 2018-01-17 11:00:47 -0800 | [diff] [blame] | 268 | @Override |
| 269 | public boolean shouldClipToRounding(boolean topRounded, boolean bottomRounded) { |
| 270 | if (super.shouldClipToRounding(topRounded, bottomRounded)) { |
| 271 | return true; |
| 272 | } |
| 273 | return bottomRounded && mActionsContainer != null |
| 274 | && mActionsContainer.getVisibility() != View.GONE; |
| 275 | } |
| 276 | |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 277 | private void updateActionOffset() { |
| 278 | if (mActionsContainer != null) { |
| 279 | // We should never push the actions higher than they are in the headsup view. |
| 280 | int constrainedContentHeight = Math.max(mContentHeight, mMinHeightHint); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 281 | |
| 282 | // We also need to compensate for any header translation, since we're always at the end. |
| 283 | mActionsContainer.setTranslationY(constrainedContentHeight - mView.getHeight() |
| 284 | - getHeaderTranslation()); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 285 | } |
| 286 | } |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 287 | } |