blob: c80cad836f48ce7f5a335f6b2a0918c067e6b575 [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
63 @Override
64 protected void onFinishInflate() {
65 super.onFinishInflate();
66 mTitleView = (TextView) findViewById(R.id.notification_title);
67 mTextView = (TextView) findViewById(R.id.notification_text);
Selim Cinek9c7712d2015-12-08 19:19:48 -080068 mInvertHelper = new ViewInvertHelper(this, NotificationPanelView.DOZE_ANIMATION_DURATION);
Selim Cinek4ffd6362015-12-29 15:12:23 +010069 mTransformationHelper = new ViewTransformationHelper();
Selim Cinekfd3e2622016-01-12 16:02:42 -080070 mTransformationHelper.setCustomTransformation(
71 new ViewTransformationHelper.CustomTransformation() {
72 @Override
73 public boolean transformTo(TransformState ownState, TransformableView notification,
Selim Cinek8f2f6a62016-02-23 19:56:31 -080074 float transformationAmount) {
Selim Cinekfd3e2622016-01-12 16:02:42 -080075 // We want to transform to the same y location as the title
76 TransformState otherState = notification.getCurrentState(
77 TRANSFORMING_VIEW_TITLE);
Selim Cinek8f2f6a62016-02-23 19:56:31 -080078 CrossFadeHelper.fadeOut(mTextView, transformationAmount);
Selim Cinekfd3e2622016-01-12 16:02:42 -080079 if (otherState != null) {
Selim Cinek8f2f6a62016-02-23 19:56:31 -080080 ownState.transformViewVerticalTo(otherState, transformationAmount);
Selim Cinekfd3e2622016-01-12 16:02:42 -080081 otherState.recycle();
82 }
83 return true;
84 }
85
86 @Override
87 public boolean transformFrom(TransformState ownState,
Selim Cinek8f2f6a62016-02-23 19:56:31 -080088 TransformableView notification, float transformationAmount) {
Selim Cinekfd3e2622016-01-12 16:02:42 -080089 // We want to transform from the same y location as the title
90 TransformState otherState = notification.getCurrentState(
91 TRANSFORMING_VIEW_TITLE);
Selim Cinek8f2f6a62016-02-23 19:56:31 -080092 CrossFadeHelper.fadeIn(mTextView, transformationAmount);
Selim Cinekfd3e2622016-01-12 16:02:42 -080093 if (otherState != null) {
Selim Cinek8f2f6a62016-02-23 19:56:31 -080094 ownState.transformViewVerticalFrom(otherState, transformationAmount);
Selim Cinekfd3e2622016-01-12 16:02:42 -080095 otherState.recycle();
96 }
97 return true;
98 }
99 }, TRANSFORMING_VIEW_TEXT);
Selim Cinek4ffd6362015-12-29 15:12:23 +0100100 mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TITLE, mTitleView);
101 mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TEXT, mTextView);
Selim Cinek83bc7832015-10-22 13:26:54 -0700102 }
103
104 public void bind(CharSequence title) {
105 bind(title, null);
106 }
107
108 public void bind(CharSequence title, CharSequence text) {
109 mTitleView.setText(title);
Selim Cineka3d3b912016-02-02 11:22:06 -0800110 mTitleView.setVisibility(TextUtils.isEmpty(title) ? GONE : VISIBLE);
Selim Cinek4ffd6362015-12-29 15:12:23 +0100111 if (TextUtils.isEmpty(text)) {
112 mTextView.setVisibility(GONE);
Selim Cineka3d3b912016-02-02 11:22:06 -0800113 mTextView.setText(null);
114 } else {
115 mTextView.setVisibility(VISIBLE);
116 mTextView.setText(text.toString());
Selim Cinek4ffd6362015-12-29 15:12:23 +0100117 }
Selim Cinek83bc7832015-10-22 13:26:54 -0700118 requestLayout();
119 }
Selim Cinek9c7712d2015-12-08 19:19:48 -0800120
121 public void setDark(boolean dark, boolean fade, long delay) {
122 mInvertHelper.setInverted(dark, fade, delay);
123 }
Selim Cinek4ffd6362015-12-29 15:12:23 +0100124
125 @Override
126 public TransformState getCurrentState(int fadingView) {
127 return mTransformationHelper.getCurrentState(fadingView);
128 }
129
130 @Override
131 public void transformTo(TransformableView notification, Runnable endRunnable) {
132 mTransformationHelper.transformTo(notification, endRunnable);
133 }
134
135 @Override
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800136 public void transformTo(TransformableView notification, float transformationAmount) {
137 mTransformationHelper.transformTo(notification, transformationAmount);
138 }
139
140 @Override
Selim Cinek4ffd6362015-12-29 15:12:23 +0100141 public void transformFrom(TransformableView notification) {
142 mTransformationHelper.transformFrom(notification);
143 }
144
145 @Override
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800146 public void transformFrom(TransformableView notification, float transformationAmount) {
147 mTransformationHelper.transformFrom(notification, transformationAmount);
148 }
149
150 @Override
Selim Cinek4ffd6362015-12-29 15:12:23 +0100151 public void setVisible(boolean visible) {
152 setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
153 mTransformationHelper.setVisible(visible);
154 }
Selim Cinek83bc7832015-10-22 13:26:54 -0700155}