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 | |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 63 | public TextView getTitleView() { |
| 64 | return mTitleView; |
| 65 | } |
| 66 | |
| 67 | public TextView getTextView() { |
| 68 | return mTextView; |
| 69 | } |
| 70 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 71 | @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 Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 76 | mInvertHelper = new ViewInvertHelper(this, NotificationPanelView.DOZE_ANIMATION_DURATION); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 77 | mTransformationHelper = new ViewTransformationHelper(); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 78 | mTransformationHelper.setCustomTransformation( |
| 79 | new ViewTransformationHelper.CustomTransformation() { |
| 80 | @Override |
| 81 | public boolean transformTo(TransformState ownState, TransformableView notification, |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 82 | float transformationAmount) { |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 83 | // We want to transform to the same y location as the title |
| 84 | TransformState otherState = notification.getCurrentState( |
| 85 | TRANSFORMING_VIEW_TITLE); |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 86 | CrossFadeHelper.fadeOut(mTextView, transformationAmount); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 87 | if (otherState != null) { |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 88 | ownState.transformViewVerticalTo(otherState, transformationAmount); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 89 | otherState.recycle(); |
| 90 | } |
| 91 | return true; |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public boolean transformFrom(TransformState ownState, |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 96 | TransformableView notification, float transformationAmount) { |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 97 | // We want to transform from the same y location as the title |
| 98 | TransformState otherState = notification.getCurrentState( |
| 99 | TRANSFORMING_VIEW_TITLE); |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 100 | CrossFadeHelper.fadeIn(mTextView, transformationAmount); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 101 | if (otherState != null) { |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 102 | ownState.transformViewVerticalFrom(otherState, transformationAmount); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 103 | otherState.recycle(); |
| 104 | } |
| 105 | return true; |
| 106 | } |
| 107 | }, TRANSFORMING_VIEW_TEXT); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 108 | mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TITLE, mTitleView); |
| 109 | mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TEXT, mTextView); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 110 | } |
| 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 Cinek | a3d3b91 | 2016-02-02 11:22:06 -0800 | [diff] [blame] | 118 | mTitleView.setVisibility(TextUtils.isEmpty(title) ? GONE : VISIBLE); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 119 | if (TextUtils.isEmpty(text)) { |
| 120 | mTextView.setVisibility(GONE); |
Selim Cinek | a3d3b91 | 2016-02-02 11:22:06 -0800 | [diff] [blame] | 121 | mTextView.setText(null); |
| 122 | } else { |
| 123 | mTextView.setVisibility(VISIBLE); |
| 124 | mTextView.setText(text.toString()); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 125 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 126 | requestLayout(); |
| 127 | } |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 128 | |
| 129 | public void setDark(boolean dark, boolean fade, long delay) { |
| 130 | mInvertHelper.setInverted(dark, fade, delay); |
| 131 | } |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 132 | |
| 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 Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 144 | public void transformTo(TransformableView notification, float transformationAmount) { |
| 145 | mTransformationHelper.transformTo(notification, transformationAmount); |
| 146 | } |
| 147 | |
| 148 | @Override |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 149 | public void transformFrom(TransformableView notification) { |
| 150 | mTransformationHelper.transformFrom(notification); |
| 151 | } |
| 152 | |
| 153 | @Override |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 154 | public void transformFrom(TransformableView notification, float transformationAmount) { |
| 155 | mTransformationHelper.transformFrom(notification, transformationAmount); |
| 156 | } |
| 157 | |
| 158 | @Override |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 159 | public void setVisible(boolean visible) { |
| 160 | setVisibility(visible ? View.VISIBLE : View.INVISIBLE); |
| 161 | mTransformationHelper.setVisible(visible); |
| 162 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 163 | } |