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 17 package com.android.systemui.statusbar.notification; 18 19 import android.animation.Animator; 20 import android.animation.ValueAnimator; 21 import android.content.Context; 22 import android.graphics.ColorMatrix; 23 import android.service.notification.StatusBarNotification; 24 import android.view.NotificationHeaderView; 25 import android.view.View; 26 27 import com.android.systemui.Interpolators; 28 import com.android.systemui.statusbar.CrossFadeHelper; 29 import com.android.systemui.statusbar.ExpandableNotificationRow; 30 import com.android.systemui.statusbar.TransformableView; 31 import com.android.systemui.statusbar.phone.NotificationPanelView; 32 33 /** 34 * Wraps the actual notification content view; used to implement behaviors which are different for 35 * the individual templates and custom views. 36 */ 37 public abstract class NotificationViewWrapper implements TransformableView { 38 39 protected final ColorMatrix mGrayscaleColorMatrix = new ColorMatrix(); 40 protected final View mView; 41 protected final ExpandableNotificationRow mRow; 42 protected boolean mDark; 43 protected boolean mDarkInitialized = false; 44 45 public static NotificationViewWrapper wrap(Context ctx, View v, ExpandableNotificationRow row) { 46 if (v.getId() == com.android.internal.R.id.status_bar_latest_event_content) { 47 if ("bigPicture".equals(v.getTag())) { 48 return new NotificationBigPictureTemplateViewWrapper(ctx, v, row); 49 } else if ("bigText".equals(v.getTag())) { 50 return new NotificationBigTextTemplateViewWrapper(ctx, v, row); 51 } else if ("media".equals(v.getTag()) || "bigMediaNarrow".equals(v.getTag())) { 52 return new NotificationMediaTemplateViewWrapper(ctx, v, row); 53 } else if ("messaging".equals(v.getTag())) { 54 return new NotificationMessagingTemplateViewWrapper(ctx, v, row); 55 } 56 return new NotificationTemplateViewWrapper(ctx, v, row); 57 } else if (v instanceof NotificationHeaderView) { 58 return new NotificationHeaderViewWrapper(ctx, v, row); 59 } else { 60 return new NotificationCustomViewWrapper(v, row); 61 } 62 } 63 64 protected NotificationViewWrapper(View view, ExpandableNotificationRow row) { 65 mView = view; 66 mRow = row; 67 } 68 69 /** 70 * In dark mode, we draw as little as possible, assuming a black background. 71 * 72 * @param dark whether we should display ourselves in dark mode 73 * @param fade whether to animate the transition if the mode changes 74 * @param delay if fading, the delay of the animation 75 */ 76 public void setDark(boolean dark, boolean fade, long delay) { 77 mDark = dark; 78 mDarkInitialized = true; 79 } 80 81 /** 82 * Notifies this wrapper that the content of the view might have changed. 83 * @param notification 84 */ 85 public void notifyContentUpdated(StatusBarNotification notification) { 86 mDarkInitialized = false; 87 }; 88 89 90 protected void startIntensityAnimation(ValueAnimator.AnimatorUpdateListener updateListener, 91 boolean dark, long delay, Animator.AnimatorListener listener) { 92 float startIntensity = dark ? 0f : 1f; 93 float endIntensity = dark ? 1f : 0f; 94 ValueAnimator animator = ValueAnimator.ofFloat(startIntensity, endIntensity); 95 animator.addUpdateListener(updateListener); 96 animator.setDuration(NotificationPanelView.DOZE_ANIMATION_DURATION); 97 animator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN); 98 animator.setStartDelay(delay); 99 if (listener != null) { 100 animator.addListener(listener); 101 } 102 animator.start(); 103 } 104 105 protected void updateGrayscaleMatrix(float intensity) { 106 mGrayscaleColorMatrix.setSaturation(1 - intensity); 107 } 108 109 /** 110 * Update the appearance of the expand button. 111 * 112 * @param expandable should this view be expandable 113 * @param onClickListener the listener to invoke when the expand affordance is clicked on 114 */ 115 public void updateExpandability(boolean expandable, View.OnClickListener onClickListener) {} 116 117 /** 118 * @return the notification header if it exists 119 */ 120 public NotificationHeaderView getNotificationHeader() { 121 return null; 122 } 123 124 @Override 125 public TransformState getCurrentState(int fadingView) { 126 return null; 127 } 128 129 @Override 130 public void transformTo(TransformableView notification, Runnable endRunnable) { 131 // By default we are fading out completely 132 CrossFadeHelper.fadeOut(mView, endRunnable); 133 } 134 135 @Override 136 public void transformTo(TransformableView notification, float transformationAmount) { 137 CrossFadeHelper.fadeOut(mView, transformationAmount); 138 } 139 140 @Override 141 public void transformFrom(TransformableView notification) { 142 // By default we are fading in completely 143 CrossFadeHelper.fadeIn(mView); 144 } 145 146 @Override 147 public void transformFrom(TransformableView notification, float transformationAmount) { 148 CrossFadeHelper.fadeIn(mView, transformationAmount); 149 } 150 151 @Override 152 public void setVisible(boolean visible) { 153 mView.animate().cancel(); 154 mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); 155 } 156 157 public int getCustomBackgroundColor() { 158 return 0; 159 } 160 161 public void setShowingLegacyBackground(boolean showing) { 162 } 163 164 public void setContentHeight(int contentHeight, int minHeightHint) { 165 } 166 } 167