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 | |
| 136 | @Override |
| 137 | public TransformState getCurrentState(int fadingView) { |
| 138 | return null; |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public void transformTo(TransformableView notification, Runnable endRunnable) { |
| 143 | // By default we are fading out completely |
| 144 | CrossFadeHelper.fadeOut(mView, endRunnable); |
| 145 | } |
| 146 | |
| 147 | @Override |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 148 | public void transformTo(TransformableView notification, float transformationAmount) { |
| 149 | CrossFadeHelper.fadeOut(mView, transformationAmount); |
| 150 | } |
| 151 | |
| 152 | @Override |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 153 | public void transformFrom(TransformableView notification) { |
| 154 | // By default we are fading in completely |
| 155 | CrossFadeHelper.fadeIn(mView); |
| 156 | } |
| 157 | |
| 158 | @Override |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 159 | public void transformFrom(TransformableView notification, float transformationAmount) { |
| 160 | CrossFadeHelper.fadeIn(mView, transformationAmount); |
| 161 | } |
| 162 | |
| 163 | @Override |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 164 | public void setVisible(boolean visible) { |
Selim Cinek | f64044c | 2016-02-11 18:18:08 -0800 | [diff] [blame] | 165 | mView.animate().cancel(); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 166 | mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); |
| 167 | } |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 168 | |
| 169 | public int getCustomBackgroundColor() { |
Selim Cinek | 7b9605b | 2017-01-19 17:36:00 -0800 | [diff] [blame] | 170 | // Parent notifications should always use the normal background color |
| 171 | return mRow.isSummaryWithChildren() ? 0 : mBackgroundColor; |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 172 | } |
| 173 | |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 174 | public void setLegacy(boolean legacy) { |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 175 | } |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 176 | |
| 177 | public void setContentHeight(int contentHeight, int minHeightHint) { |
| 178 | } |
Adrian Roos | 7b9ed0d | 2017-01-24 15:55:18 -0800 | [diff] [blame] | 179 | |
| 180 | public void setRemoteInputVisible(boolean visible) { |
| 181 | } |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 182 | |
| 183 | public void setIsChildInGroup(boolean isChildInGroup) { |
| 184 | } |
Selim Cinek | 63edaf2 | 2017-04-24 22:18:48 -0700 | [diff] [blame] | 185 | |
| 186 | public boolean isDimmable() { |
| 187 | return true; |
| 188 | } |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 189 | } |