NotificationViewWrapper.java revision 4ffd63611a0d516c9988b37e9c06e6f8390c2a2f
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 17package com.android.systemui.statusbar; 18 19import android.content.Context; 20import android.service.notification.StatusBarNotification; 21import android.view.NotificationHeaderView; 22import android.view.View; 23 24import com.android.systemui.statusbar.notification.TransformState; 25 26/** 27 * Wraps the actual notification content view; used to implement behaviors which are different for 28 * the individual templates and custom views. 29 */ 30public abstract class NotificationViewWrapper implements TransformableView { 31 32 protected final View mView; 33 34 public static NotificationViewWrapper wrap(Context ctx, View v) { 35 if (v.getId() == com.android.internal.R.id.status_bar_latest_event_content) { 36 return new NotificationTemplateViewWrapper(ctx, v); 37 } else if (v instanceof NotificationHeaderView) { 38 return new NotificationHeaderViewWrapper(ctx, v); 39 } else { 40 return new NotificationCustomViewWrapper(v); 41 } 42 } 43 44 protected NotificationViewWrapper(View view) { 45 mView = view; 46 } 47 48 /** 49 * In dark mode, we draw as little as possible, assuming a black background. 50 * 51 * @param dark whether we should display ourselves in dark mode 52 * @param fade whether to animate the transition if the mode changes 53 * @param delay if fading, the delay of the animation 54 */ 55 public abstract void setDark(boolean dark, boolean fade, long delay); 56 57 /** 58 * Notifies this wrapper that the content of the view might have changed. 59 * @param notification 60 */ 61 public void notifyContentUpdated(StatusBarNotification notification) {}; 62 63 /** 64 * @return true if this template might need to be clipped with a round rect to make it look 65 * nice, false otherwise 66 */ 67 public boolean needsRoundRectClipping() { 68 return false; 69 } 70 71 /** 72 * Update the appearance of the expand button. 73 * 74 * @param expandable should this view be expandable 75 * @param onClickListener the listener to invoke when the expand affordance is clicked on 76 */ 77 public void updateExpandability(boolean expandable, View.OnClickListener onClickListener) {} 78 79 /** 80 * @return the notification header if it exists 81 */ 82 public NotificationHeaderView getNotificationHeader() { 83 return null; 84 } 85 86 @Override 87 public TransformState getCurrentState(int fadingView) { 88 return null; 89 } 90 91 @Override 92 public void transformTo(TransformableView notification, Runnable endRunnable) { 93 // By default we are fading out completely 94 CrossFadeHelper.fadeOut(mView, endRunnable); 95 } 96 97 @Override 98 public void transformFrom(TransformableView notification) { 99 // By default we are fading in completely 100 CrossFadeHelper.fadeIn(mView); 101 } 102 103 @Override 104 public void setVisible(boolean visible) { 105 mView.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); 106 } 107} 108