blob: be25d6377912893425375b36d2be14901a6e4028 [file] [log] [blame]
Selim Cinek83bc7832015-10-22 13:26:54 -07001/*
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
Rohan Shah20790b82018-07-02 17:21:04 -070017package com.android.systemui.statusbar.notification.row;
Selim Cinek83bc7832015-10-22 13:26:54 -070018
19import android.annotation.Nullable;
20import android.content.Context;
Selim Cinek4ffd6362015-12-29 15:12:23 +010021import android.text.TextUtils;
Selim Cinek83bc7832015-10-22 13:26:54 -070022import android.util.AttributeSet;
Selim Cinek4ffd6362015-12-29 15:12:23 +010023import android.view.View;
Selim Cinek83bc7832015-10-22 13:26:54 -070024import android.widget.TextView;
25
Selim Cinek7b836392015-12-04 20:02:59 -080026import com.android.keyguard.AlphaOptimizedLinearLayout;
Selim Cinek83bc7832015-10-22 13:26:54 -070027import com.android.systemui.R;
Selim Cinekfd3e2622016-01-12 16:02:42 -080028import com.android.systemui.statusbar.CrossFadeHelper;
Selim Cinek4ffd6362015-12-29 15:12:23 +010029import com.android.systemui.statusbar.TransformableView;
30import com.android.systemui.statusbar.ViewTransformationHelper;
Rohan Shah20790b82018-07-02 17:21:04 -070031import com.android.systemui.statusbar.notification.TransformState;
Selim Cinek83bc7832015-10-22 13:26:54 -070032
33/**
34 * A hybrid view which may contain information about one ore more notifications.
35 */
Selim Cinek4ffd6362015-12-29 15:12:23 +010036public class HybridNotificationView extends AlphaOptimizedLinearLayout
37 implements TransformableView {
38
39 private ViewTransformationHelper mTransformationHelper;
Selim Cinek83bc7832015-10-22 13:26:54 -070040
Selim Cinek83bc7832015-10-22 13:26:54 -070041 protected TextView mTitleView;
42 protected TextView mTextView;
43
44 public HybridNotificationView(Context context) {
45 this(context, null);
46 }
47
48 public HybridNotificationView(Context context, @Nullable AttributeSet attrs) {
49 this(context, attrs, 0);
50 }
51
52 public HybridNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
53 this(context, attrs, defStyleAttr, 0);
54 }
55
56 public HybridNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
57 int defStyleRes) {
58 super(context, attrs, defStyleAttr, defStyleRes);
Selim Cinek83bc7832015-10-22 13:26:54 -070059 }
60
Selim Cinekc897bd32016-03-18 17:32:31 -070061 public TextView getTitleView() {
62 return mTitleView;
63 }
64
65 public TextView getTextView() {
66 return mTextView;
67 }
68
Selim Cinek83bc7832015-10-22 13:26:54 -070069 @Override
70 protected void onFinishInflate() {
71 super.onFinishInflate();
72 mTitleView = (TextView) findViewById(R.id.notification_title);
73 mTextView = (TextView) findViewById(R.id.notification_text);
Selim Cinek4ffd6362015-12-29 15:12:23 +010074 mTransformationHelper = new ViewTransformationHelper();
Selim Cinekfd3e2622016-01-12 16:02:42 -080075 mTransformationHelper.setCustomTransformation(
76 new ViewTransformationHelper.CustomTransformation() {
77 @Override
78 public boolean transformTo(TransformState ownState, TransformableView notification,
Selim Cinek8f2f6a62016-02-23 19:56:31 -080079 float transformationAmount) {
Selim Cinekfd3e2622016-01-12 16:02:42 -080080 // We want to transform to the same y location as the title
81 TransformState otherState = notification.getCurrentState(
82 TRANSFORMING_VIEW_TITLE);
Selim Cinek8f2f6a62016-02-23 19:56:31 -080083 CrossFadeHelper.fadeOut(mTextView, transformationAmount);
Selim Cinekfd3e2622016-01-12 16:02:42 -080084 if (otherState != null) {
Selim Cinek8f2f6a62016-02-23 19:56:31 -080085 ownState.transformViewVerticalTo(otherState, transformationAmount);
Selim Cinekfd3e2622016-01-12 16:02:42 -080086 otherState.recycle();
87 }
88 return true;
89 }
90
91 @Override
92 public boolean transformFrom(TransformState ownState,
Selim Cinek8f2f6a62016-02-23 19:56:31 -080093 TransformableView notification, float transformationAmount) {
Selim Cinekfd3e2622016-01-12 16:02:42 -080094 // We want to transform from the same y location as the title
95 TransformState otherState = notification.getCurrentState(
96 TRANSFORMING_VIEW_TITLE);
Selim Cinek8f2f6a62016-02-23 19:56:31 -080097 CrossFadeHelper.fadeIn(mTextView, transformationAmount);
Selim Cinekfd3e2622016-01-12 16:02:42 -080098 if (otherState != null) {
Selim Cinek8f2f6a62016-02-23 19:56:31 -080099 ownState.transformViewVerticalFrom(otherState, transformationAmount);
Selim Cinekfd3e2622016-01-12 16:02:42 -0800100 otherState.recycle();
101 }
102 return true;
103 }
104 }, TRANSFORMING_VIEW_TEXT);
Selim Cinek4ffd6362015-12-29 15:12:23 +0100105 mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TITLE, mTitleView);
106 mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TEXT, mTextView);
Selim Cinek83bc7832015-10-22 13:26:54 -0700107 }
108
109 public void bind(CharSequence title) {
110 bind(title, null);
111 }
112
113 public void bind(CharSequence title, CharSequence text) {
114 mTitleView.setText(title);
Selim Cineka3d3b912016-02-02 11:22:06 -0800115 mTitleView.setVisibility(TextUtils.isEmpty(title) ? GONE : VISIBLE);
Selim Cinek4ffd6362015-12-29 15:12:23 +0100116 if (TextUtils.isEmpty(text)) {
117 mTextView.setVisibility(GONE);
Selim Cineka3d3b912016-02-02 11:22:06 -0800118 mTextView.setText(null);
119 } else {
120 mTextView.setVisibility(VISIBLE);
121 mTextView.setText(text.toString());
Selim Cinek4ffd6362015-12-29 15:12:23 +0100122 }
Selim Cinek83bc7832015-10-22 13:26:54 -0700123 requestLayout();
124 }
Selim Cinek9c7712d2015-12-08 19:19:48 -0800125
Selim Cinek4ffd6362015-12-29 15:12:23 +0100126 @Override
127 public TransformState getCurrentState(int fadingView) {
128 return mTransformationHelper.getCurrentState(fadingView);
129 }
130
131 @Override
132 public void transformTo(TransformableView notification, Runnable endRunnable) {
133 mTransformationHelper.transformTo(notification, endRunnable);
134 }
135
136 @Override
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800137 public void transformTo(TransformableView notification, float transformationAmount) {
138 mTransformationHelper.transformTo(notification, transformationAmount);
139 }
140
141 @Override
Selim Cinek4ffd6362015-12-29 15:12:23 +0100142 public void transformFrom(TransformableView notification) {
143 mTransformationHelper.transformFrom(notification);
144 }
145
146 @Override
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800147 public void transformFrom(TransformableView notification, float transformationAmount) {
148 mTransformationHelper.transformFrom(notification, transformationAmount);
149 }
150
151 @Override
Selim Cinek4ffd6362015-12-29 15:12:23 +0100152 public void setVisible(boolean visible) {
153 setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
154 mTransformationHelper.setVisible(visible);
155 }
Selim Cinek83bc7832015-10-22 13:26:54 -0700156}