blob: 5eed5ed71bcc6daf9d324e1dec8009edba2ca3bb [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;
22import android.util.ArrayMap;
Selim Cinek83bc7832015-10-22 13:26:54 -070023import android.util.AttributeSet;
Selim Cinek4ffd6362015-12-29 15:12:23 +010024import android.view.View;
Selim Cinek83bc7832015-10-22 13:26:54 -070025import android.widget.TextView;
26
Selim Cinek7b836392015-12-04 20:02:59 -080027import com.android.keyguard.AlphaOptimizedLinearLayout;
Selim Cinek83bc7832015-10-22 13:26:54 -070028import com.android.systemui.R;
Selim Cinek9c7712d2015-12-08 19:19:48 -080029import com.android.systemui.ViewInvertHelper;
Selim Cinekfd3e2622016-01-12 16:02:42 -080030import com.android.systemui.statusbar.CrossFadeHelper;
Selim Cinek4ffd6362015-12-29 15:12:23 +010031import com.android.systemui.statusbar.TransformableView;
32import com.android.systemui.statusbar.ViewTransformationHelper;
Selim Cinek9c7712d2015-12-08 19:19:48 -080033import com.android.systemui.statusbar.phone.NotificationPanelView;
Selim Cinek83bc7832015-10-22 13:26:54 -070034
Selim Cinek4ffd6362015-12-29 15:12:23 +010035import java.util.ArrayList;
36
Selim Cinek83bc7832015-10-22 13:26:54 -070037/**
38 * A hybrid view which may contain information about one ore more notifications.
39 */
Selim Cinek4ffd6362015-12-29 15:12:23 +010040public class HybridNotificationView extends AlphaOptimizedLinearLayout
41 implements TransformableView {
42
43 private ViewTransformationHelper mTransformationHelper;
Selim Cinek83bc7832015-10-22 13:26:54 -070044
Selim Cinek83bc7832015-10-22 13:26:54 -070045 protected TextView mTitleView;
46 protected TextView mTextView;
Selim Cinek9c7712d2015-12-08 19:19:48 -080047 private ViewInvertHelper mInvertHelper;
Selim Cinek83bc7832015-10-22 13:26:54 -070048
49 public HybridNotificationView(Context context) {
50 this(context, null);
51 }
52
53 public HybridNotificationView(Context context, @Nullable AttributeSet attrs) {
54 this(context, attrs, 0);
55 }
56
57 public HybridNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
58 this(context, attrs, defStyleAttr, 0);
59 }
60
61 public HybridNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
62 int defStyleRes) {
63 super(context, attrs, defStyleAttr, defStyleRes);
Selim Cinek83bc7832015-10-22 13:26:54 -070064 }
65
66 @Override
67 protected void onFinishInflate() {
68 super.onFinishInflate();
69 mTitleView = (TextView) findViewById(R.id.notification_title);
70 mTextView = (TextView) findViewById(R.id.notification_text);
Selim Cinek9c7712d2015-12-08 19:19:48 -080071 mInvertHelper = new ViewInvertHelper(this, NotificationPanelView.DOZE_ANIMATION_DURATION);
Selim Cinek4ffd6362015-12-29 15:12:23 +010072 mTransformationHelper = new ViewTransformationHelper();
Selim Cinekfd3e2622016-01-12 16:02:42 -080073 mTransformationHelper.setCustomTransformation(
74 new ViewTransformationHelper.CustomTransformation() {
75 @Override
76 public boolean transformTo(TransformState ownState, TransformableView notification,
77 Runnable endRunnable) {
78 // We want to transform to the same y location as the title
79 TransformState otherState = notification.getCurrentState(
80 TRANSFORMING_VIEW_TITLE);
81 CrossFadeHelper.fadeOut(mTextView, endRunnable);
82 if (otherState != null) {
83 ownState.animateViewVerticalTo(otherState, endRunnable);
84 otherState.recycle();
85 }
86 return true;
87 }
88
89 @Override
90 public boolean transformFrom(TransformState ownState,
91 TransformableView notification) {
92 // We want to transform from the same y location as the title
93 TransformState otherState = notification.getCurrentState(
94 TRANSFORMING_VIEW_TITLE);
95 CrossFadeHelper.fadeIn(mTextView);
96 if (otherState != null) {
97 ownState.animateViewVerticalFrom(otherState);
98 otherState.recycle();
99 }
100 return true;
101 }
102 }, TRANSFORMING_VIEW_TEXT);
Selim Cinek4ffd6362015-12-29 15:12:23 +0100103 mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TITLE, mTitleView);
104 mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TEXT, mTextView);
Selim Cinek83bc7832015-10-22 13:26:54 -0700105 }
106
107 public void bind(CharSequence title) {
108 bind(title, null);
109 }
110
111 public void bind(CharSequence title, CharSequence text) {
112 mTitleView.setText(title);
Selim Cinek4ffd6362015-12-29 15:12:23 +0100113 if (TextUtils.isEmpty(title)) {
114 mTitleView.setVisibility(GONE);
115 }
Selim Cinek83bc7832015-10-22 13:26:54 -0700116 mTextView.setText(text);
Selim Cinek4ffd6362015-12-29 15:12:23 +0100117 if (TextUtils.isEmpty(text)) {
118 mTextView.setVisibility(GONE);
119 }
Selim Cinek83bc7832015-10-22 13:26:54 -0700120 requestLayout();
121 }
Selim Cinek9c7712d2015-12-08 19:19:48 -0800122
123 public void setDark(boolean dark, boolean fade, long delay) {
124 mInvertHelper.setInverted(dark, fade, delay);
125 }
Selim Cinek4ffd6362015-12-29 15:12:23 +0100126
127 @Override
128 public TransformState getCurrentState(int fadingView) {
129 return mTransformationHelper.getCurrentState(fadingView);
130 }
131
132 @Override
133 public void transformTo(TransformableView notification, Runnable endRunnable) {
134 mTransformationHelper.transformTo(notification, endRunnable);
135 }
136
137 @Override
138 public void transformFrom(TransformableView notification) {
139 mTransformationHelper.transformFrom(notification);
140 }
141
142 @Override
143 public void setVisible(boolean visible) {
144 setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
145 mTransformationHelper.setVisible(visible);
146 }
Selim Cinek83bc7832015-10-22 13:26:54 -0700147}