blob: 0a1795f21234f518382588928319cca9c7421a83 [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
17package com.android.systemui.statusbar.notification;
18
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 Cinek9c7712d2015-12-08 19:19:48 -080028import com.android.systemui.ViewInvertHelper;
Selim Cinekfd3e2622016-01-12 16:02:42 -080029import com.android.systemui.statusbar.CrossFadeHelper;
Selim Cinek4ffd6362015-12-29 15:12:23 +010030import com.android.systemui.statusbar.TransformableView;
31import com.android.systemui.statusbar.ViewTransformationHelper;
Selim Cinek9c7712d2015-12-08 19:19:48 -080032import com.android.systemui.statusbar.phone.NotificationPanelView;
Selim Cinek83bc7832015-10-22 13:26:54 -070033
34/**
35 * A hybrid view which may contain information about one ore more notifications.
36 */
Selim Cinek4ffd6362015-12-29 15:12:23 +010037public class HybridNotificationView extends AlphaOptimizedLinearLayout
38 implements TransformableView {
39
40 private ViewTransformationHelper mTransformationHelper;
Selim Cinek83bc7832015-10-22 13:26:54 -070041
Selim Cinek83bc7832015-10-22 13:26:54 -070042 protected TextView mTitleView;
43 protected TextView mTextView;
Selim Cinek9c7712d2015-12-08 19:19:48 -080044 private ViewInvertHelper mInvertHelper;
Selim Cinek83bc7832015-10-22 13:26:54 -070045
46 public HybridNotificationView(Context context) {
47 this(context, null);
48 }
49
50 public HybridNotificationView(Context context, @Nullable AttributeSet attrs) {
51 this(context, attrs, 0);
52 }
53
54 public HybridNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
55 this(context, attrs, defStyleAttr, 0);
56 }
57
58 public HybridNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
59 int defStyleRes) {
60 super(context, attrs, defStyleAttr, defStyleRes);
Selim Cinek83bc7832015-10-22 13:26:54 -070061 }
62
Selim Cinekc897bd32016-03-18 17:32:31 -070063 public TextView getTitleView() {
64 return mTitleView;
65 }
66
67 public TextView getTextView() {
68 return mTextView;
69 }
70
Selim Cinek83bc7832015-10-22 13:26:54 -070071 @Override
72 protected void onFinishInflate() {
73 super.onFinishInflate();
74 mTitleView = (TextView) findViewById(R.id.notification_title);
75 mTextView = (TextView) findViewById(R.id.notification_text);
Selim Cinek9c7712d2015-12-08 19:19:48 -080076 mInvertHelper = new ViewInvertHelper(this, NotificationPanelView.DOZE_ANIMATION_DURATION);
Selim Cinek4ffd6362015-12-29 15:12:23 +010077 mTransformationHelper = new ViewTransformationHelper();
Selim Cinekfd3e2622016-01-12 16:02:42 -080078 mTransformationHelper.setCustomTransformation(
79 new ViewTransformationHelper.CustomTransformation() {
80 @Override
81 public boolean transformTo(TransformState ownState, TransformableView notification,
Selim Cinek8f2f6a62016-02-23 19:56:31 -080082 float transformationAmount) {
Selim Cinekfd3e2622016-01-12 16:02:42 -080083 // We want to transform to the same y location as the title
84 TransformState otherState = notification.getCurrentState(
85 TRANSFORMING_VIEW_TITLE);
Selim Cinek8f2f6a62016-02-23 19:56:31 -080086 CrossFadeHelper.fadeOut(mTextView, transformationAmount);
Selim Cinekfd3e2622016-01-12 16:02:42 -080087 if (otherState != null) {
Selim Cinek8f2f6a62016-02-23 19:56:31 -080088 ownState.transformViewVerticalTo(otherState, transformationAmount);
Selim Cinekfd3e2622016-01-12 16:02:42 -080089 otherState.recycle();
90 }
91 return true;
92 }
93
94 @Override
95 public boolean transformFrom(TransformState ownState,
Selim Cinek8f2f6a62016-02-23 19:56:31 -080096 TransformableView notification, float transformationAmount) {
Selim Cinekfd3e2622016-01-12 16:02:42 -080097 // We want to transform from the same y location as the title
98 TransformState otherState = notification.getCurrentState(
99 TRANSFORMING_VIEW_TITLE);
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800100 CrossFadeHelper.fadeIn(mTextView, transformationAmount);
Selim Cinekfd3e2622016-01-12 16:02:42 -0800101 if (otherState != null) {
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800102 ownState.transformViewVerticalFrom(otherState, transformationAmount);
Selim Cinekfd3e2622016-01-12 16:02:42 -0800103 otherState.recycle();
104 }
105 return true;
106 }
107 }, TRANSFORMING_VIEW_TEXT);
Selim Cinek4ffd6362015-12-29 15:12:23 +0100108 mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TITLE, mTitleView);
109 mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TEXT, mTextView);
Selim Cinek83bc7832015-10-22 13:26:54 -0700110 }
111
112 public void bind(CharSequence title) {
113 bind(title, null);
114 }
115
116 public void bind(CharSequence title, CharSequence text) {
117 mTitleView.setText(title);
Selim Cineka3d3b912016-02-02 11:22:06 -0800118 mTitleView.setVisibility(TextUtils.isEmpty(title) ? GONE : VISIBLE);
Selim Cinek4ffd6362015-12-29 15:12:23 +0100119 if (TextUtils.isEmpty(text)) {
120 mTextView.setVisibility(GONE);
Selim Cineka3d3b912016-02-02 11:22:06 -0800121 mTextView.setText(null);
122 } else {
123 mTextView.setVisibility(VISIBLE);
124 mTextView.setText(text.toString());
Selim Cinek4ffd6362015-12-29 15:12:23 +0100125 }
Selim Cinek83bc7832015-10-22 13:26:54 -0700126 requestLayout();
127 }
Selim Cinek9c7712d2015-12-08 19:19:48 -0800128
129 public void setDark(boolean dark, boolean fade, long delay) {
130 mInvertHelper.setInverted(dark, fade, delay);
131 }
Selim Cinek4ffd6362015-12-29 15:12:23 +0100132
133 @Override
134 public TransformState getCurrentState(int fadingView) {
135 return mTransformationHelper.getCurrentState(fadingView);
136 }
137
138 @Override
139 public void transformTo(TransformableView notification, Runnable endRunnable) {
140 mTransformationHelper.transformTo(notification, endRunnable);
141 }
142
143 @Override
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800144 public void transformTo(TransformableView notification, float transformationAmount) {
145 mTransformationHelper.transformTo(notification, transformationAmount);
146 }
147
148 @Override
Selim Cinek4ffd6362015-12-29 15:12:23 +0100149 public void transformFrom(TransformableView notification) {
150 mTransformationHelper.transformFrom(notification);
151 }
152
153 @Override
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800154 public void transformFrom(TransformableView notification, float transformationAmount) {
155 mTransformationHelper.transformFrom(notification, transformationAmount);
156 }
157
158 @Override
Selim Cinek4ffd6362015-12-29 15:12:23 +0100159 public void setVisible(boolean visible) {
160 setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
161 mTransformationHelper.setVisible(visible);
162 }
Selim Cinek83bc7832015-10-22 13:26:54 -0700163}