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 | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 20 | import android.service.notification.StatusBarNotification; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 21 | import android.view.NotificationHeaderView; |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 22 | import android.view.View; |
| 23 | |
Selim Cinek | 0ffbda6 | 2016-01-01 20:29:12 +0100 | [diff] [blame] | 24 | import com.android.systemui.statusbar.CrossFadeHelper; |
| 25 | import com.android.systemui.statusbar.TransformableView; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 26 | |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 27 | /** |
| 28 | * Wraps the actual notification content view; used to implement behaviors which are different for |
| 29 | * the individual templates and custom views. |
| 30 | */ |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 31 | public abstract class NotificationViewWrapper implements TransformableView { |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 32 | |
| 33 | protected final View mView; |
Selim Cinek | 19ba705 | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 34 | protected boolean mDark; |
Selim Cinek | b88b984 | 2016-02-26 09:25:33 -0800 | [diff] [blame] | 35 | protected boolean mDarkInitialized = false; |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 36 | |
| 37 | public static NotificationViewWrapper wrap(Context ctx, View v) { |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 38 | 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] | 39 | if ("bigPicture".equals(v.getTag())) { |
| 40 | return new NotificationBigPictureTemplateViewWrapper(ctx, v); |
Selim Cinek | d634d06 | 2016-02-02 15:47:14 -0800 | [diff] [blame] | 41 | } else if ("bigText".equals(v.getTag())) { |
| 42 | return new NotificationBigTextTemplateViewWrapper(ctx, v); |
Selim Cinek | df5bf61 | 2016-02-26 09:56:31 -0800 | [diff] [blame] | 43 | } else if ("media".equals(v.getTag()) || "bigMediaNarrow".equals(v.getTag())) { |
| 44 | return new NotificationMediaTemplateViewWrapper(ctx, v); |
Selim Cinek | 0ffbda6 | 2016-01-01 20:29:12 +0100 | [diff] [blame] | 45 | } |
Selim Cinek | 75fe38c | 2015-11-20 12:47:59 -0800 | [diff] [blame] | 46 | return new NotificationTemplateViewWrapper(ctx, v); |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 47 | } else if (v instanceof NotificationHeaderView) { |
| 48 | return new NotificationHeaderViewWrapper(ctx, v); |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 49 | } 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 Cinek | 19ba705 | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 65 | public void setDark(boolean dark, boolean fade, long delay) { |
| 66 | mDark = dark; |
Selim Cinek | b88b984 | 2016-02-26 09:25:33 -0800 | [diff] [blame] | 67 | mDarkInitialized = true; |
Selim Cinek | 19ba705 | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 68 | } |
Jorim Jaggi | dacc924 | 2014-12-08 19:21:26 +0100 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * Notifies this wrapper that the content of the view might have changed. |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 72 | * @param notification |
Jorim Jaggi | dacc924 | 2014-12-08 19:21:26 +0100 | [diff] [blame] | 73 | */ |
Selim Cinek | 19ba705 | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 74 | public void notifyContentUpdated(StatusBarNotification notification) { |
Selim Cinek | b88b984 | 2016-02-26 09:25:33 -0800 | [diff] [blame] | 75 | mDarkInitialized = false; |
Selim Cinek | 19ba705 | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 76 | }; |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 77 | |
| 78 | /** |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 79 | * 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 Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * @return the notification header if it exists |
| 88 | */ |
| 89 | public NotificationHeaderView getNotificationHeader() { |
| 90 | return null; |
| 91 | } |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 92 | |
| 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 Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 105 | public void transformTo(TransformableView notification, float transformationAmount) { |
| 106 | CrossFadeHelper.fadeOut(mView, transformationAmount); |
| 107 | } |
| 108 | |
| 109 | @Override |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 110 | public void transformFrom(TransformableView notification) { |
| 111 | // By default we are fading in completely |
| 112 | CrossFadeHelper.fadeIn(mView); |
| 113 | } |
| 114 | |
| 115 | @Override |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 116 | public void transformFrom(TransformableView notification, float transformationAmount) { |
| 117 | CrossFadeHelper.fadeIn(mView, transformationAmount); |
| 118 | } |
| 119 | |
| 120 | @Override |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 121 | public void setVisible(boolean visible) { |
Selim Cinek | f64044c | 2016-02-11 18:18:08 -0800 | [diff] [blame] | 122 | mView.animate().cancel(); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 123 | mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); |
| 124 | } |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 125 | } |