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 | |
| 19 | import android.content.Context; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 20 | import android.graphics.Color; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 21 | import android.graphics.drawable.ColorDrawable; |
| 22 | import android.graphics.drawable.Drawable; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 23 | import android.support.v4.graphics.ColorUtils; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 24 | import android.view.NotificationHeaderView; |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 25 | import android.view.View; |
| 26 | |
Selim Cinek | 0ffbda6 | 2016-01-01 20:29:12 +0100 | [diff] [blame] | 27 | import com.android.systemui.statusbar.CrossFadeHelper; |
Selim Cinek | 7d1c63e | 2016-04-21 15:26:10 -0700 | [diff] [blame] | 28 | import com.android.systemui.statusbar.ExpandableNotificationRow; |
Selim Cinek | 0ffbda6 | 2016-01-01 20:29:12 +0100 | [diff] [blame] | 29 | import com.android.systemui.statusbar.TransformableView; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 30 | |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 31 | /** |
| 32 | * Wraps the actual notification content view; used to implement behaviors which are different for |
| 33 | * the individual templates and custom views. |
| 34 | */ |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 35 | public abstract class NotificationViewWrapper implements TransformableView { |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 36 | |
| 37 | protected final View mView; |
Selim Cinek | 7d1c63e | 2016-04-21 15:26:10 -0700 | [diff] [blame] | 38 | protected final ExpandableNotificationRow mRow; |
Adrian Roos | 7bcf6d3 | 2017-04-04 16:44:25 -0700 | [diff] [blame] | 39 | private final NotificationDozeHelper mDozer; |
| 40 | |
Selim Cinek | 19ba705 | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 41 | protected boolean mDark; |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 42 | private int mBackgroundColor = 0; |
| 43 | protected boolean mShouldInvertDark; |
Selim Cinek | b88b984 | 2016-02-26 09:25:33 -0800 | [diff] [blame] | 44 | protected boolean mDarkInitialized = false; |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 45 | |
Selim Cinek | 7d1c63e | 2016-04-21 15:26:10 -0700 | [diff] [blame] | 46 | public static NotificationViewWrapper wrap(Context ctx, View v, ExpandableNotificationRow row) { |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 47 | if (v.getId() == com.android.internal.R.id.status_bar_latest_event_content) { |
Selim Cinek | 0ffbda6 | 2016-01-01 20:29:12 +0100 | [diff] [blame] | 48 | if ("bigPicture".equals(v.getTag())) { |
Selim Cinek | 7d1c63e | 2016-04-21 15:26:10 -0700 | [diff] [blame] | 49 | return new NotificationBigPictureTemplateViewWrapper(ctx, v, row); |
Selim Cinek | d634d06 | 2016-02-02 15:47:14 -0800 | [diff] [blame] | 50 | } else if ("bigText".equals(v.getTag())) { |
Selim Cinek | 7d1c63e | 2016-04-21 15:26:10 -0700 | [diff] [blame] | 51 | return new NotificationBigTextTemplateViewWrapper(ctx, v, row); |
Selim Cinek | df5bf61 | 2016-02-26 09:56:31 -0800 | [diff] [blame] | 52 | } else if ("media".equals(v.getTag()) || "bigMediaNarrow".equals(v.getTag())) { |
Selim Cinek | 7d1c63e | 2016-04-21 15:26:10 -0700 | [diff] [blame] | 53 | return new NotificationMediaTemplateViewWrapper(ctx, v, row); |
Adrian Roos | feafa05 | 2016-06-01 17:09:45 -0700 | [diff] [blame] | 54 | } else if ("messaging".equals(v.getTag())) { |
| 55 | return new NotificationMessagingTemplateViewWrapper(ctx, v, row); |
Selim Cinek | 0ffbda6 | 2016-01-01 20:29:12 +0100 | [diff] [blame] | 56 | } |
Selim Cinek | 7d1c63e | 2016-04-21 15:26:10 -0700 | [diff] [blame] | 57 | return new NotificationTemplateViewWrapper(ctx, v, row); |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 58 | } else if (v instanceof NotificationHeaderView) { |
Selim Cinek | 7d1c63e | 2016-04-21 15:26:10 -0700 | [diff] [blame] | 59 | return new NotificationHeaderViewWrapper(ctx, v, row); |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 60 | } else { |
Adrian Roos | 7bcf6d3 | 2017-04-04 16:44:25 -0700 | [diff] [blame] | 61 | return new NotificationCustomViewWrapper(ctx, v, row); |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
Adrian Roos | 7bcf6d3 | 2017-04-04 16:44:25 -0700 | [diff] [blame] | 65 | protected NotificationViewWrapper(Context ctx, View view, ExpandableNotificationRow row) { |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 66 | mView = view; |
Selim Cinek | 7d1c63e | 2016-04-21 15:26:10 -0700 | [diff] [blame] | 67 | mRow = row; |
Adrian Roos | 7bcf6d3 | 2017-04-04 16:44:25 -0700 | [diff] [blame] | 68 | mDozer = createDozer(ctx); |
Selim Cinek | 131f1a4 | 2017-06-05 17:50:19 -0700 | [diff] [blame] | 69 | onReinflated(); |
Adrian Roos | 7bcf6d3 | 2017-04-04 16:44:25 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | protected NotificationDozeHelper createDozer(Context ctx) { |
Adrian Roos | 7c68e29 | 2017-04-04 17:22:03 -0700 | [diff] [blame] | 73 | return new NotificationDozeHelper(); |
Adrian Roos | 7bcf6d3 | 2017-04-04 16:44:25 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | protected NotificationDozeHelper getDozer() { |
| 77 | return mDozer; |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /** |
| 81 | * In dark mode, we draw as little as possible, assuming a black background. |
| 82 | * |
| 83 | * @param dark whether we should display ourselves in dark mode |
| 84 | * @param fade whether to animate the transition if the mode changes |
| 85 | * @param delay if fading, the delay of the animation |
| 86 | */ |
Selim Cinek | 19ba705 | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 87 | public void setDark(boolean dark, boolean fade, long delay) { |
| 88 | mDark = dark; |
Selim Cinek | b88b984 | 2016-02-26 09:25:33 -0800 | [diff] [blame] | 89 | mDarkInitialized = true; |
Selim Cinek | 19ba705 | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 90 | } |
Jorim Jaggi | dacc924 | 2014-12-08 19:21:26 +0100 | [diff] [blame] | 91 | |
| 92 | /** |
| 93 | * Notifies this wrapper that the content of the view might have changed. |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 94 | * @param row the row this wrapper is attached to |
Jorim Jaggi | dacc924 | 2014-12-08 19:21:26 +0100 | [diff] [blame] | 95 | */ |
Selim Cinek | 131f1a4 | 2017-06-05 17:50:19 -0700 | [diff] [blame] | 96 | public void onContentUpdated(ExpandableNotificationRow row) { |
Selim Cinek | b88b984 | 2016-02-26 09:25:33 -0800 | [diff] [blame] | 97 | mDarkInitialized = false; |
Selim Cinek | 131f1a4 | 2017-06-05 17:50:19 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | public void onReinflated() { |
Selim Cinek | 245090f | 2017-02-02 10:36:02 -0800 | [diff] [blame] | 101 | if (shouldClearBackgroundOnReapply()) { |
| 102 | mBackgroundColor = 0; |
| 103 | } |
Selim Cinek | 131f1a4 | 2017-06-05 17:50:19 -0700 | [diff] [blame] | 104 | Drawable background = mView.getBackground(); |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 105 | if (background instanceof ColorDrawable) { |
| 106 | mBackgroundColor = ((ColorDrawable) background).getColor(); |
| 107 | mView.setBackground(null); |
| 108 | } |
| 109 | mShouldInvertDark = mBackgroundColor == 0 || isColorLight(mBackgroundColor); |
| 110 | } |
| 111 | |
Selim Cinek | 245090f | 2017-02-02 10:36:02 -0800 | [diff] [blame] | 112 | protected boolean shouldClearBackgroundOnReapply() { |
| 113 | return true; |
| 114 | } |
| 115 | |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 116 | private boolean isColorLight(int backgroundColor) { |
| 117 | return Color.alpha(backgroundColor) == 0 |
| 118 | || ColorUtils.calculateLuminance(backgroundColor) > 0.5; |
| 119 | } |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 120 | |
| 121 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 122 | * Update the appearance of the expand button. |
| 123 | * |
| 124 | * @param expandable should this view be expandable |
| 125 | * @param onClickListener the listener to invoke when the expand affordance is clicked on |
| 126 | */ |
| 127 | public void updateExpandability(boolean expandable, View.OnClickListener onClickListener) {} |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 128 | |
| 129 | /** |
| 130 | * @return the notification header if it exists |
| 131 | */ |
| 132 | public NotificationHeaderView getNotificationHeader() { |
| 133 | return null; |
| 134 | } |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 135 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 136 | public int getHeaderTranslation() { |
| 137 | return 0; |
| 138 | } |
| 139 | |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 140 | @Override |
| 141 | public TransformState getCurrentState(int fadingView) { |
| 142 | return null; |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void transformTo(TransformableView notification, Runnable endRunnable) { |
| 147 | // By default we are fading out completely |
| 148 | CrossFadeHelper.fadeOut(mView, endRunnable); |
| 149 | } |
| 150 | |
| 151 | @Override |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 152 | public void transformTo(TransformableView notification, float transformationAmount) { |
| 153 | CrossFadeHelper.fadeOut(mView, transformationAmount); |
| 154 | } |
| 155 | |
| 156 | @Override |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 157 | public void transformFrom(TransformableView notification) { |
| 158 | // By default we are fading in completely |
| 159 | CrossFadeHelper.fadeIn(mView); |
| 160 | } |
| 161 | |
| 162 | @Override |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 163 | public void transformFrom(TransformableView notification, float transformationAmount) { |
| 164 | CrossFadeHelper.fadeIn(mView, transformationAmount); |
| 165 | } |
| 166 | |
| 167 | @Override |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 168 | public void setVisible(boolean visible) { |
Selim Cinek | f64044c | 2016-02-11 18:18:08 -0800 | [diff] [blame] | 169 | mView.animate().cancel(); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 170 | mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); |
| 171 | } |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 172 | |
| 173 | public int getCustomBackgroundColor() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 174 | // Parent notifications should always use the normal background color |
| 175 | return mRow.isSummaryWithChildren() ? 0 : mBackgroundColor; |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 176 | } |
| 177 | |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 178 | public void setLegacy(boolean legacy) { |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 179 | } |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 180 | |
| 181 | public void setContentHeight(int contentHeight, int minHeightHint) { |
| 182 | } |
Adrian Roos | 7b9ed0d | 2017-01-24 15:55:18 -0800 | [diff] [blame] | 183 | |
| 184 | public void setRemoteInputVisible(boolean visible) { |
| 185 | } |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 186 | |
| 187 | public void setIsChildInGroup(boolean isChildInGroup) { |
| 188 | } |
Selim Cinek | 4705f29 | 2017-04-24 22:18:48 -0700 | [diff] [blame] | 189 | |
| 190 | public boolean isDimmable() { |
| 191 | return true; |
| 192 | } |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 193 | |
| 194 | public boolean disallowSingleClick(float x, float y) { |
| 195 | return false; |
| 196 | } |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 197 | |
| 198 | public int getMinLayoutHeight() { |
| 199 | return 0; |
| 200 | } |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 201 | |
Selim Cinek | 86bfcee | 2018-01-17 11:00:47 -0800 | [diff] [blame] | 202 | public boolean shouldClipToRounding(boolean topRounded, boolean bottomRounded) { |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 203 | return false; |
| 204 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 205 | |
| 206 | public void setHeaderVisibleAmount(float headerVisibleAmount) { |
| 207 | } |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 208 | } |