1 /* 2 * Copyright (C) 2015 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.row; 18 19 import android.annotation.Nullable; 20 import android.content.Context; 21 import android.text.TextUtils; 22 import android.util.AttributeSet; 23 import android.view.View; 24 import android.widget.TextView; 25 26 import com.android.keyguard.AlphaOptimizedLinearLayout; 27 import com.android.systemui.R; 28 import com.android.systemui.statusbar.CrossFadeHelper; 29 import com.android.systemui.statusbar.TransformableView; 30 import com.android.systemui.statusbar.ViewTransformationHelper; 31 import com.android.systemui.statusbar.notification.NotificationFadeAware; 32 import com.android.systemui.statusbar.notification.TransformState; 33 34 /** 35 * A hybrid view which may contain information about one ore more notifications. 36 */ 37 public class HybridNotificationView extends AlphaOptimizedLinearLayout 38 implements TransformableView, NotificationFadeAware { 39 40 protected final ViewTransformationHelper mTransformationHelper = new ViewTransformationHelper(); 41 protected TextView mTitleView; 42 protected TextView mTextView; 43 HybridNotificationView(Context context)44 public HybridNotificationView(Context context) { 45 this(context, null); 46 } 47 HybridNotificationView(Context context, @Nullable AttributeSet attrs)48 public HybridNotificationView(Context context, @Nullable AttributeSet attrs) { 49 this(context, attrs, 0); 50 } 51 HybridNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr)52 public HybridNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 53 this(context, attrs, defStyleAttr, 0); 54 } 55 HybridNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes)56 public HybridNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, 57 int defStyleRes) { 58 super(context, attrs, defStyleAttr, defStyleRes); 59 } 60 getTitleView()61 public TextView getTitleView() { 62 return mTitleView; 63 } 64 getTextView()65 public TextView getTextView() { 66 return mTextView; 67 } 68 69 @Override onFinishInflate()70 protected void onFinishInflate() { 71 super.onFinishInflate(); 72 mTitleView = findViewById(R.id.notification_title); 73 mTextView = findViewById(R.id.notification_text); 74 mTransformationHelper.setCustomTransformation( 75 new ViewTransformationHelper.CustomTransformation() { 76 @Override 77 public boolean transformTo(TransformState ownState, TransformableView notification, 78 float transformationAmount) { 79 // We want to transform to the same y location as the title 80 TransformState otherState = notification.getCurrentState( 81 TRANSFORMING_VIEW_TITLE); 82 CrossFadeHelper.fadeOut(mTextView, transformationAmount); 83 if (otherState != null) { 84 ownState.transformViewVerticalTo(otherState, transformationAmount); 85 otherState.recycle(); 86 } 87 return true; 88 } 89 90 @Override 91 public boolean transformFrom(TransformState ownState, 92 TransformableView notification, float transformationAmount) { 93 // We want to transform from the same y location as the title 94 TransformState otherState = notification.getCurrentState( 95 TRANSFORMING_VIEW_TITLE); 96 CrossFadeHelper.fadeIn(mTextView, transformationAmount, true /* remap */); 97 if (otherState != null) { 98 ownState.transformViewVerticalFrom(otherState, transformationAmount); 99 otherState.recycle(); 100 } 101 return true; 102 } 103 }, TRANSFORMING_VIEW_TEXT); 104 mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TITLE, mTitleView); 105 mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TEXT, mTextView); 106 } 107 bind(@ullable CharSequence title, @Nullable CharSequence text, @Nullable View contentView)108 public void bind(@Nullable CharSequence title, @Nullable CharSequence text, 109 @Nullable View contentView) { 110 mTitleView.setText(title); 111 mTitleView.setVisibility(TextUtils.isEmpty(title) ? GONE : VISIBLE); 112 if (TextUtils.isEmpty(text)) { 113 mTextView.setVisibility(GONE); 114 mTextView.setText(null); 115 } else { 116 mTextView.setVisibility(VISIBLE); 117 mTextView.setText(text.toString()); 118 } 119 requestLayout(); 120 } 121 122 @Override getCurrentState(int fadingView)123 public TransformState getCurrentState(int fadingView) { 124 return mTransformationHelper.getCurrentState(fadingView); 125 } 126 127 @Override transformTo(TransformableView notification, Runnable endRunnable)128 public void transformTo(TransformableView notification, Runnable endRunnable) { 129 mTransformationHelper.transformTo(notification, endRunnable); 130 } 131 132 @Override transformTo(TransformableView notification, float transformationAmount)133 public void transformTo(TransformableView notification, float transformationAmount) { 134 mTransformationHelper.transformTo(notification, transformationAmount); 135 } 136 137 @Override transformFrom(TransformableView notification)138 public void transformFrom(TransformableView notification) { 139 mTransformationHelper.transformFrom(notification); 140 } 141 142 @Override transformFrom(TransformableView notification, float transformationAmount)143 public void transformFrom(TransformableView notification, float transformationAmount) { 144 mTransformationHelper.transformFrom(notification, transformationAmount); 145 } 146 147 @Override setVisible(boolean visible)148 public void setVisible(boolean visible) { 149 setVisibility(visible ? View.VISIBLE : View.INVISIBLE); 150 mTransformationHelper.setVisible(visible); 151 } 152 153 @Override setNotificationFaded(boolean faded)154 public void setNotificationFaded(boolean faded) {} 155 } 156