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