blob: b09df158072c4e49fa711cf636582f6b5a0dbe92 [file] [log] [blame]
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001/*
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 Cinek0ffbda62016-01-01 20:29:12 +010017package com.android.systemui.statusbar.notification;
Jorim Jaggi4e857f42014-11-17 19:14:04 +010018
19import android.content.Context;
Selim Cinek7b9605b2017-01-19 17:36:00 -080020import android.graphics.Color;
Selim Cinek7b9605b2017-01-19 17:36:00 -080021import android.graphics.drawable.ColorDrawable;
22import android.graphics.drawable.Drawable;
Selim Cinek7b9605b2017-01-19 17:36:00 -080023import android.support.v4.graphics.ColorUtils;
Selim Cinekea4bef72015-12-02 15:51:10 -080024import android.view.NotificationHeaderView;
Jorim Jaggi4e857f42014-11-17 19:14:04 +010025import android.view.View;
26
Selim Cinek0ffbda62016-01-01 20:29:12 +010027import com.android.systemui.statusbar.CrossFadeHelper;
Selim Cinek7d1c63e2016-04-21 15:26:10 -070028import com.android.systemui.statusbar.ExpandableNotificationRow;
Selim Cinek0ffbda62016-01-01 20:29:12 +010029import com.android.systemui.statusbar.TransformableView;
Selim Cinek4ffd6362015-12-29 15:12:23 +010030
Jorim Jaggi4e857f42014-11-17 19:14:04 +010031/**
32 * Wraps the actual notification content view; used to implement behaviors which are different for
33 * the individual templates and custom views.
34 */
Selim Cinek4ffd6362015-12-29 15:12:23 +010035public abstract class NotificationViewWrapper implements TransformableView {
Jorim Jaggi4e857f42014-11-17 19:14:04 +010036
37 protected final View mView;
Selim Cinek7d1c63e2016-04-21 15:26:10 -070038 protected final ExpandableNotificationRow mRow;
Adrian Roos7bcf6d32017-04-04 16:44:25 -070039 private final NotificationDozeHelper mDozer;
40
Selim Cinek19ba7052016-01-27 20:04:27 -080041 protected boolean mDark;
Selim Cinek7b9605b2017-01-19 17:36:00 -080042 private int mBackgroundColor = 0;
43 protected boolean mShouldInvertDark;
Selim Cinekb88b9842016-02-26 09:25:33 -080044 protected boolean mDarkInitialized = false;
Jorim Jaggi4e857f42014-11-17 19:14:04 +010045
Selim Cinek7d1c63e2016-04-21 15:26:10 -070046 public static NotificationViewWrapper wrap(Context ctx, View v, ExpandableNotificationRow row) {
Jorim Jaggibe4116a2015-05-20 20:04:08 -070047 if (v.getId() == com.android.internal.R.id.status_bar_latest_event_content) {
Selim Cinek0ffbda62016-01-01 20:29:12 +010048 if ("bigPicture".equals(v.getTag())) {
Selim Cinek7d1c63e2016-04-21 15:26:10 -070049 return new NotificationBigPictureTemplateViewWrapper(ctx, v, row);
Selim Cinekd634d062016-02-02 15:47:14 -080050 } else if ("bigText".equals(v.getTag())) {
Selim Cinek7d1c63e2016-04-21 15:26:10 -070051 return new NotificationBigTextTemplateViewWrapper(ctx, v, row);
Selim Cinekdf5bf612016-02-26 09:56:31 -080052 } else if ("media".equals(v.getTag()) || "bigMediaNarrow".equals(v.getTag())) {
Selim Cinek7d1c63e2016-04-21 15:26:10 -070053 return new NotificationMediaTemplateViewWrapper(ctx, v, row);
Adrian Roosfeafa052016-06-01 17:09:45 -070054 } else if ("messaging".equals(v.getTag())) {
55 return new NotificationMessagingTemplateViewWrapper(ctx, v, row);
Selim Cinek0ffbda62016-01-01 20:29:12 +010056 }
Selim Cinek7d1c63e2016-04-21 15:26:10 -070057 return new NotificationTemplateViewWrapper(ctx, v, row);
Selim Cinek9c7712d2015-12-08 19:19:48 -080058 } else if (v instanceof NotificationHeaderView) {
Selim Cinek7d1c63e2016-04-21 15:26:10 -070059 return new NotificationHeaderViewWrapper(ctx, v, row);
Jorim Jaggi4e857f42014-11-17 19:14:04 +010060 } else {
Adrian Roos7bcf6d32017-04-04 16:44:25 -070061 return new NotificationCustomViewWrapper(ctx, v, row);
Jorim Jaggi4e857f42014-11-17 19:14:04 +010062 }
63 }
64
Adrian Roos7bcf6d32017-04-04 16:44:25 -070065 protected NotificationViewWrapper(Context ctx, View view, ExpandableNotificationRow row) {
Jorim Jaggi4e857f42014-11-17 19:14:04 +010066 mView = view;
Selim Cinek7d1c63e2016-04-21 15:26:10 -070067 mRow = row;
Adrian Roos7bcf6d32017-04-04 16:44:25 -070068 mDozer = createDozer(ctx);
Selim Cinek131f1a42017-06-05 17:50:19 -070069 onReinflated();
Adrian Roos7bcf6d32017-04-04 16:44:25 -070070 }
71
72 protected NotificationDozeHelper createDozer(Context ctx) {
Adrian Roos7c68e292017-04-04 17:22:03 -070073 return new NotificationDozeHelper();
Adrian Roos7bcf6d32017-04-04 16:44:25 -070074 }
75
76 protected NotificationDozeHelper getDozer() {
77 return mDozer;
Jorim Jaggi4e857f42014-11-17 19:14:04 +010078 }
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 Cinek19ba7052016-01-27 20:04:27 -080087 public void setDark(boolean dark, boolean fade, long delay) {
88 mDark = dark;
Selim Cinekb88b9842016-02-26 09:25:33 -080089 mDarkInitialized = true;
Selim Cinek19ba7052016-01-27 20:04:27 -080090 }
Jorim Jaggidacc9242014-12-08 19:21:26 +010091
92 /**
93 * Notifies this wrapper that the content of the view might have changed.
Selim Cinek414ad332017-02-24 19:06:12 -080094 * @param row the row this wrapper is attached to
Jorim Jaggidacc9242014-12-08 19:21:26 +010095 */
Selim Cinek131f1a42017-06-05 17:50:19 -070096 public void onContentUpdated(ExpandableNotificationRow row) {
Selim Cinekb88b9842016-02-26 09:25:33 -080097 mDarkInitialized = false;
Selim Cinek131f1a42017-06-05 17:50:19 -070098 }
99
100 public void onReinflated() {
Selim Cinek245090f2017-02-02 10:36:02 -0800101 if (shouldClearBackgroundOnReapply()) {
102 mBackgroundColor = 0;
103 }
Selim Cinek131f1a42017-06-05 17:50:19 -0700104 Drawable background = mView.getBackground();
Selim Cinek7b9605b2017-01-19 17:36:00 -0800105 if (background instanceof ColorDrawable) {
106 mBackgroundColor = ((ColorDrawable) background).getColor();
107 mView.setBackground(null);
108 }
109 mShouldInvertDark = mBackgroundColor == 0 || isColorLight(mBackgroundColor);
110 }
111
Selim Cinek245090f2017-02-02 10:36:02 -0800112 protected boolean shouldClearBackgroundOnReapply() {
113 return true;
114 }
115
Selim Cinek7b9605b2017-01-19 17:36:00 -0800116 private boolean isColorLight(int backgroundColor) {
117 return Color.alpha(backgroundColor) == 0
118 || ColorUtils.calculateLuminance(backgroundColor) > 0.5;
119 }
Jorim Jaggibe4116a2015-05-20 20:04:08 -0700120
121 /**
Selim Cinek65b2e7c2015-10-26 14:11:31 -0700122 * 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 Cinekea4bef72015-12-02 15:51:10 -0800128
129 /**
130 * @return the notification header if it exists
131 */
132 public NotificationHeaderView getNotificationHeader() {
133 return null;
134 }
Selim Cinek4ffd6362015-12-29 15:12:23 +0100135
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800136 public int getHeaderTranslation() {
137 return 0;
138 }
139
Selim Cinek4ffd6362015-12-29 15:12:23 +0100140 @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 Cinek8f2f6a62016-02-23 19:56:31 -0800152 public void transformTo(TransformableView notification, float transformationAmount) {
153 CrossFadeHelper.fadeOut(mView, transformationAmount);
154 }
155
156 @Override
Selim Cinek4ffd6362015-12-29 15:12:23 +0100157 public void transformFrom(TransformableView notification) {
158 // By default we are fading in completely
159 CrossFadeHelper.fadeIn(mView);
160 }
161
162 @Override
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800163 public void transformFrom(TransformableView notification, float transformationAmount) {
164 CrossFadeHelper.fadeIn(mView, transformationAmount);
165 }
166
167 @Override
Selim Cinek4ffd6362015-12-29 15:12:23 +0100168 public void setVisible(boolean visible) {
Selim Cinekf64044c2016-02-11 18:18:08 -0800169 mView.animate().cancel();
Selim Cinek4ffd6362015-12-29 15:12:23 +0100170 mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
171 }
Selim Cinekc3179332016-03-04 14:44:56 -0800172
173 public int getCustomBackgroundColor() {
Selim Cinek7b9605b2017-01-19 17:36:00 -0800174 // Parent notifications should always use the normal background color
175 return mRow.isSummaryWithChildren() ? 0 : mBackgroundColor;
Selim Cinekc3179332016-03-04 14:44:56 -0800176 }
177
Selim Cinek1a48bab2017-02-17 19:38:40 -0800178 public void setLegacy(boolean legacy) {
Selim Cinekc3179332016-03-04 14:44:56 -0800179 }
Adrian Roos181385c2016-05-05 17:45:44 -0400180
181 public void setContentHeight(int contentHeight, int minHeightHint) {
182 }
Adrian Roos7b9ed0d2017-01-24 15:55:18 -0800183
184 public void setRemoteInputVisible(boolean visible) {
185 }
Selim Cinek414ad332017-02-24 19:06:12 -0800186
187 public void setIsChildInGroup(boolean isChildInGroup) {
188 }
Selim Cinek4705f292017-04-24 22:18:48 -0700189
190 public boolean isDimmable() {
191 return true;
192 }
Selim Cinek5d6ef8d2017-05-18 22:16:00 -0700193
194 public boolean disallowSingleClick(float x, float y) {
195 return false;
196 }
Selim Cineke62255c2017-09-28 18:23:23 -0700197
198 public int getMinLayoutHeight() {
199 return 0;
200 }
Selim Cinek515b2032017-11-15 10:20:19 -0800201
Selim Cinek86bfcee2018-01-17 11:00:47 -0800202 public boolean shouldClipToRounding(boolean topRounded, boolean bottomRounded) {
Selim Cinek515b2032017-11-15 10:20:19 -0800203 return false;
204 }
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800205
206 public void setHeaderVisibleAmount(float headerVisibleAmount) {
207 }
Selim Cinek396caca2018-04-10 17:46:46 -0700208
209 /**
210 * Get the extra height that needs to be added to this view, such that it can be measured
211 * normally.
212 */
213 public int getExtraMeasureHeight() {
214 return 0;
215 }
Jorim Jaggi4e857f42014-11-17 19:14:04 +0100216}