blob: d3503e7516dffb2946c82fc257dbd3fdfa683506 [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;
Jorim Jaggi4e857f42014-11-17 19:14:04 +010035
36 public static NotificationViewWrapper wrap(Context ctx, View v) {
Jorim Jaggibe4116a2015-05-20 20:04:08 -070037 if (v.getId() == com.android.internal.R.id.status_bar_latest_event_content) {
Selim Cinek0ffbda62016-01-01 20:29:12 +010038 if ("bigPicture".equals(v.getTag())) {
39 return new NotificationBigPictureTemplateViewWrapper(ctx, v);
Selim Cinekd634d062016-02-02 15:47:14 -080040 } else if ("bigText".equals(v.getTag())) {
41 return new NotificationBigTextTemplateViewWrapper(ctx, v);
Selim Cinek0ffbda62016-01-01 20:29:12 +010042 }
Selim Cinek75fe38c2015-11-20 12:47:59 -080043 return new NotificationTemplateViewWrapper(ctx, v);
Selim Cinek9c7712d2015-12-08 19:19:48 -080044 } else if (v instanceof NotificationHeaderView) {
45 return new NotificationHeaderViewWrapper(ctx, v);
Jorim Jaggi4e857f42014-11-17 19:14:04 +010046 } else {
47 return new NotificationCustomViewWrapper(v);
48 }
49 }
50
51 protected NotificationViewWrapper(View view) {
52 mView = view;
53 }
54
55 /**
56 * In dark mode, we draw as little as possible, assuming a black background.
57 *
58 * @param dark whether we should display ourselves in dark mode
59 * @param fade whether to animate the transition if the mode changes
60 * @param delay if fading, the delay of the animation
61 */
Selim Cinek19ba7052016-01-27 20:04:27 -080062 public void setDark(boolean dark, boolean fade, long delay) {
63 mDark = dark;
64 }
Jorim Jaggidacc9242014-12-08 19:21:26 +010065
66 /**
67 * Notifies this wrapper that the content of the view might have changed.
Selim Cinek4ffd6362015-12-29 15:12:23 +010068 * @param notification
Jorim Jaggidacc9242014-12-08 19:21:26 +010069 */
Selim Cinek19ba7052016-01-27 20:04:27 -080070 public void notifyContentUpdated(StatusBarNotification notification) {
71 mDark = false;
72 };
Jorim Jaggibe4116a2015-05-20 20:04:08 -070073
74 /**
Selim Cinek65b2e7c2015-10-26 14:11:31 -070075 * Update the appearance of the expand button.
76 *
77 * @param expandable should this view be expandable
78 * @param onClickListener the listener to invoke when the expand affordance is clicked on
79 */
80 public void updateExpandability(boolean expandable, View.OnClickListener onClickListener) {}
Selim Cinekea4bef72015-12-02 15:51:10 -080081
82 /**
83 * @return the notification header if it exists
84 */
85 public NotificationHeaderView getNotificationHeader() {
86 return null;
87 }
Selim Cinek4ffd6362015-12-29 15:12:23 +010088
89 @Override
90 public TransformState getCurrentState(int fadingView) {
91 return null;
92 }
93
94 @Override
95 public void transformTo(TransformableView notification, Runnable endRunnable) {
96 // By default we are fading out completely
97 CrossFadeHelper.fadeOut(mView, endRunnable);
98 }
99
100 @Override
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800101 public void transformTo(TransformableView notification, float transformationAmount) {
102 CrossFadeHelper.fadeOut(mView, transformationAmount);
103 }
104
105 @Override
Selim Cinek4ffd6362015-12-29 15:12:23 +0100106 public void transformFrom(TransformableView notification) {
107 // By default we are fading in completely
108 CrossFadeHelper.fadeIn(mView);
109 }
110
111 @Override
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800112 public void transformFrom(TransformableView notification, float transformationAmount) {
113 CrossFadeHelper.fadeIn(mView, transformationAmount);
114 }
115
116 @Override
Selim Cinek4ffd6362015-12-29 15:12:23 +0100117 public void setVisible(boolean visible) {
Selim Cinekf64044c2016-02-11 18:18:08 -0800118 mView.animate().cancel();
Selim Cinek4ffd6362015-12-29 15:12:23 +0100119 mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
120 }
Jorim Jaggi4e857f42014-11-17 19:14:04 +0100121}