blob: 0df0d26aea108824dec7fa33b7de279d01f5681a [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 Cinek4ffd6362015-12-29 15:12:23 +010020import android.service.notification.StatusBarNotification;
Selim Cinekea4bef72015-12-02 15:51:10 -080021import android.view.NotificationHeaderView;
Jorim Jaggi4e857f42014-11-17 19:14:04 +010022import android.view.View;
23
Selim Cinek0ffbda62016-01-01 20:29:12 +010024import com.android.systemui.statusbar.CrossFadeHelper;
25import com.android.systemui.statusbar.TransformableView;
Selim Cinek4ffd6362015-12-29 15:12:23 +010026
Jorim Jaggi4e857f42014-11-17 19:14:04 +010027/**
28 * Wraps the actual notification content view; used to implement behaviors which are different for
29 * the individual templates and custom views.
30 */
Selim Cinek4ffd6362015-12-29 15:12:23 +010031public abstract class NotificationViewWrapper implements TransformableView {
Jorim Jaggi4e857f42014-11-17 19:14:04 +010032
33 protected final View mView;
Selim Cinek19ba7052016-01-27 20:04:27 -080034 protected boolean mDark;
Selim Cinekb88b9842016-02-26 09:25:33 -080035 protected boolean mDarkInitialized = false;
Jorim Jaggi4e857f42014-11-17 19:14:04 +010036
37 public static NotificationViewWrapper wrap(Context ctx, View v) {
Jorim Jaggibe4116a2015-05-20 20:04:08 -070038 if (v.getId() == com.android.internal.R.id.status_bar_latest_event_content) {
Selim Cinek0ffbda62016-01-01 20:29:12 +010039 if ("bigPicture".equals(v.getTag())) {
40 return new NotificationBigPictureTemplateViewWrapper(ctx, v);
Selim Cinekd634d062016-02-02 15:47:14 -080041 } else if ("bigText".equals(v.getTag())) {
42 return new NotificationBigTextTemplateViewWrapper(ctx, v);
Selim Cinekdf5bf612016-02-26 09:56:31 -080043 } else if ("media".equals(v.getTag()) || "bigMediaNarrow".equals(v.getTag())) {
44 return new NotificationMediaTemplateViewWrapper(ctx, v);
Selim Cinek0ffbda62016-01-01 20:29:12 +010045 }
Selim Cinek75fe38c2015-11-20 12:47:59 -080046 return new NotificationTemplateViewWrapper(ctx, v);
Selim Cinek9c7712d2015-12-08 19:19:48 -080047 } else if (v instanceof NotificationHeaderView) {
48 return new NotificationHeaderViewWrapper(ctx, v);
Jorim Jaggi4e857f42014-11-17 19:14:04 +010049 } else {
50 return new NotificationCustomViewWrapper(v);
51 }
52 }
53
54 protected NotificationViewWrapper(View view) {
55 mView = view;
56 }
57
58 /**
59 * In dark mode, we draw as little as possible, assuming a black background.
60 *
61 * @param dark whether we should display ourselves in dark mode
62 * @param fade whether to animate the transition if the mode changes
63 * @param delay if fading, the delay of the animation
64 */
Selim Cinek19ba7052016-01-27 20:04:27 -080065 public void setDark(boolean dark, boolean fade, long delay) {
66 mDark = dark;
Selim Cinekb88b9842016-02-26 09:25:33 -080067 mDarkInitialized = true;
Selim Cinek19ba7052016-01-27 20:04:27 -080068 }
Jorim Jaggidacc9242014-12-08 19:21:26 +010069
70 /**
71 * Notifies this wrapper that the content of the view might have changed.
Selim Cinek4ffd6362015-12-29 15:12:23 +010072 * @param notification
Jorim Jaggidacc9242014-12-08 19:21:26 +010073 */
Selim Cinek19ba7052016-01-27 20:04:27 -080074 public void notifyContentUpdated(StatusBarNotification notification) {
Selim Cinekb88b9842016-02-26 09:25:33 -080075 mDarkInitialized = false;
Selim Cinek19ba7052016-01-27 20:04:27 -080076 };
Jorim Jaggibe4116a2015-05-20 20:04:08 -070077
78 /**
Selim Cinek65b2e7c2015-10-26 14:11:31 -070079 * Update the appearance of the expand button.
80 *
81 * @param expandable should this view be expandable
82 * @param onClickListener the listener to invoke when the expand affordance is clicked on
83 */
84 public void updateExpandability(boolean expandable, View.OnClickListener onClickListener) {}
Selim Cinekea4bef72015-12-02 15:51:10 -080085
86 /**
87 * @return the notification header if it exists
88 */
89 public NotificationHeaderView getNotificationHeader() {
90 return null;
91 }
Selim Cinek4ffd6362015-12-29 15:12:23 +010092
93 @Override
94 public TransformState getCurrentState(int fadingView) {
95 return null;
96 }
97
98 @Override
99 public void transformTo(TransformableView notification, Runnable endRunnable) {
100 // By default we are fading out completely
101 CrossFadeHelper.fadeOut(mView, endRunnable);
102 }
103
104 @Override
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800105 public void transformTo(TransformableView notification, float transformationAmount) {
106 CrossFadeHelper.fadeOut(mView, transformationAmount);
107 }
108
109 @Override
Selim Cinek4ffd6362015-12-29 15:12:23 +0100110 public void transformFrom(TransformableView notification) {
111 // By default we are fading in completely
112 CrossFadeHelper.fadeIn(mView);
113 }
114
115 @Override
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800116 public void transformFrom(TransformableView notification, float transformationAmount) {
117 CrossFadeHelper.fadeIn(mView, transformationAmount);
118 }
119
120 @Override
Selim Cinek4ffd6362015-12-29 15:12:23 +0100121 public void setVisible(boolean visible) {
Selim Cinekf64044c2016-02-11 18:18:08 -0800122 mView.animate().cancel();
Selim Cinek4ffd6362015-12-29 15:12:23 +0100123 mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
124 }
Jorim Jaggi4e857f42014-11-17 19:14:04 +0100125}