Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 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; |
| 18 | |
| 19 | import android.annotation.Nullable; |
| 20 | import android.content.Context; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 21 | import android.text.TextUtils; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 22 | import android.util.AttributeSet; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 23 | import android.view.View; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 24 | import android.widget.TextView; |
| 25 | |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 26 | import com.android.keyguard.AlphaOptimizedLinearLayout; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 27 | import com.android.systemui.R; |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 28 | import com.android.systemui.ViewInvertHelper; |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 29 | import com.android.systemui.statusbar.CrossFadeHelper; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 30 | import com.android.systemui.statusbar.TransformableView; |
| 31 | import com.android.systemui.statusbar.ViewTransformationHelper; |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 32 | import com.android.systemui.statusbar.phone.NotificationPanelView; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * A hybrid view which may contain information about one ore more notifications. |
| 36 | */ |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 37 | public class HybridNotificationView extends AlphaOptimizedLinearLayout |
| 38 | implements TransformableView { |
| 39 | |
| 40 | private ViewTransformationHelper mTransformationHelper; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 41 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 42 | protected TextView mTitleView; |
| 43 | protected TextView mTextView; |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 44 | private ViewInvertHelper mInvertHelper; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 45 | |
| 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 Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 61 | } |
| 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 Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 68 | mInvertHelper = new ViewInvertHelper(this, NotificationPanelView.DOZE_ANIMATION_DURATION); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 69 | mTransformationHelper = new ViewTransformationHelper(); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 70 | mTransformationHelper.setCustomTransformation( |
| 71 | new ViewTransformationHelper.CustomTransformation() { |
| 72 | @Override |
| 73 | public boolean transformTo(TransformState ownState, TransformableView notification, |
| 74 | Runnable endRunnable) { |
| 75 | // We want to transform to the same y location as the title |
| 76 | TransformState otherState = notification.getCurrentState( |
| 77 | TRANSFORMING_VIEW_TITLE); |
| 78 | CrossFadeHelper.fadeOut(mTextView, endRunnable); |
| 79 | if (otherState != null) { |
| 80 | ownState.animateViewVerticalTo(otherState, endRunnable); |
| 81 | otherState.recycle(); |
| 82 | } |
| 83 | return true; |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public boolean transformFrom(TransformState ownState, |
| 88 | TransformableView notification) { |
| 89 | // We want to transform from the same y location as the title |
| 90 | TransformState otherState = notification.getCurrentState( |
| 91 | TRANSFORMING_VIEW_TITLE); |
| 92 | CrossFadeHelper.fadeIn(mTextView); |
| 93 | if (otherState != null) { |
| 94 | ownState.animateViewVerticalFrom(otherState); |
| 95 | otherState.recycle(); |
| 96 | } |
| 97 | return true; |
| 98 | } |
| 99 | }, TRANSFORMING_VIEW_TEXT); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 100 | mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TITLE, mTitleView); |
| 101 | mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TEXT, mTextView); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 102 | } |
| 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 Cinek | a3d3b91 | 2016-02-02 11:22:06 -0800 | [diff] [blame^] | 110 | mTitleView.setVisibility(TextUtils.isEmpty(title) ? GONE : VISIBLE); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 111 | if (TextUtils.isEmpty(text)) { |
| 112 | mTextView.setVisibility(GONE); |
Selim Cinek | a3d3b91 | 2016-02-02 11:22:06 -0800 | [diff] [blame^] | 113 | mTextView.setText(null); |
| 114 | } else { |
| 115 | mTextView.setVisibility(VISIBLE); |
| 116 | mTextView.setText(text.toString()); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 117 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 118 | requestLayout(); |
| 119 | } |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 120 | |
| 121 | public void setDark(boolean dark, boolean fade, long delay) { |
| 122 | mInvertHelper.setInverted(dark, fade, delay); |
| 123 | } |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 124 | |
| 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 |
| 136 | public void transformFrom(TransformableView notification) { |
| 137 | mTransformationHelper.transformFrom(notification); |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public void setVisible(boolean visible) { |
| 142 | setVisibility(visible ? View.VISIBLE : View.INVISIBLE); |
| 143 | mTransformationHelper.setVisible(visible); |
| 144 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 145 | } |