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 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.row; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 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 | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 28 | import com.android.systemui.statusbar.CrossFadeHelper; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 29 | import com.android.systemui.statusbar.TransformableView; |
| 30 | import com.android.systemui.statusbar.ViewTransformationHelper; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 31 | import com.android.systemui.statusbar.notification.TransformState; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * A hybrid view which may contain information about one ore more notifications. |
| 35 | */ |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 36 | public class HybridNotificationView extends AlphaOptimizedLinearLayout |
| 37 | implements TransformableView { |
| 38 | |
| 39 | private ViewTransformationHelper mTransformationHelper; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 40 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 41 | protected TextView mTitleView; |
| 42 | protected TextView mTextView; |
| 43 | |
| 44 | public HybridNotificationView(Context context) { |
| 45 | this(context, null); |
| 46 | } |
| 47 | |
| 48 | public HybridNotificationView(Context context, @Nullable AttributeSet attrs) { |
| 49 | this(context, attrs, 0); |
| 50 | } |
| 51 | |
| 52 | public HybridNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { |
| 53 | this(context, attrs, defStyleAttr, 0); |
| 54 | } |
| 55 | |
| 56 | public HybridNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, |
| 57 | int defStyleRes) { |
| 58 | super(context, attrs, defStyleAttr, defStyleRes); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 61 | public TextView getTitleView() { |
| 62 | return mTitleView; |
| 63 | } |
| 64 | |
| 65 | public TextView getTextView() { |
| 66 | return mTextView; |
| 67 | } |
| 68 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 69 | @Override |
| 70 | protected void onFinishInflate() { |
| 71 | super.onFinishInflate(); |
| 72 | mTitleView = (TextView) findViewById(R.id.notification_title); |
| 73 | mTextView = (TextView) findViewById(R.id.notification_text); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 74 | mTransformationHelper = new ViewTransformationHelper(); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 75 | mTransformationHelper.setCustomTransformation( |
| 76 | new ViewTransformationHelper.CustomTransformation() { |
| 77 | @Override |
| 78 | public boolean transformTo(TransformState ownState, TransformableView notification, |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 79 | float transformationAmount) { |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 80 | // We want to transform to the same y location as the title |
| 81 | TransformState otherState = notification.getCurrentState( |
| 82 | TRANSFORMING_VIEW_TITLE); |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 83 | CrossFadeHelper.fadeOut(mTextView, transformationAmount); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 84 | if (otherState != null) { |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 85 | ownState.transformViewVerticalTo(otherState, transformationAmount); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 86 | otherState.recycle(); |
| 87 | } |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public boolean transformFrom(TransformState ownState, |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 93 | TransformableView notification, float transformationAmount) { |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 94 | // We want to transform from the same y location as the title |
| 95 | TransformState otherState = notification.getCurrentState( |
| 96 | TRANSFORMING_VIEW_TITLE); |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 97 | CrossFadeHelper.fadeIn(mTextView, transformationAmount); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 98 | if (otherState != null) { |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 99 | ownState.transformViewVerticalFrom(otherState, transformationAmount); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame] | 100 | otherState.recycle(); |
| 101 | } |
| 102 | return true; |
| 103 | } |
| 104 | }, TRANSFORMING_VIEW_TEXT); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 105 | mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TITLE, mTitleView); |
| 106 | mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TEXT, mTextView); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | public void bind(CharSequence title) { |
| 110 | bind(title, null); |
| 111 | } |
| 112 | |
| 113 | public void bind(CharSequence title, CharSequence text) { |
| 114 | mTitleView.setText(title); |
Selim Cinek | a3d3b91 | 2016-02-02 11:22:06 -0800 | [diff] [blame] | 115 | mTitleView.setVisibility(TextUtils.isEmpty(title) ? GONE : VISIBLE); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 116 | if (TextUtils.isEmpty(text)) { |
| 117 | mTextView.setVisibility(GONE); |
Selim Cinek | a3d3b91 | 2016-02-02 11:22:06 -0800 | [diff] [blame] | 118 | mTextView.setText(null); |
| 119 | } else { |
| 120 | mTextView.setVisibility(VISIBLE); |
| 121 | mTextView.setText(text.toString()); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 122 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 123 | requestLayout(); |
| 124 | } |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 125 | |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 126 | @Override |
| 127 | public TransformState getCurrentState(int fadingView) { |
| 128 | return mTransformationHelper.getCurrentState(fadingView); |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public void transformTo(TransformableView notification, Runnable endRunnable) { |
| 133 | mTransformationHelper.transformTo(notification, endRunnable); |
| 134 | } |
| 135 | |
| 136 | @Override |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 137 | public void transformTo(TransformableView notification, float transformationAmount) { |
| 138 | mTransformationHelper.transformTo(notification, transformationAmount); |
| 139 | } |
| 140 | |
| 141 | @Override |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 142 | public void transformFrom(TransformableView notification) { |
| 143 | mTransformationHelper.transformFrom(notification); |
| 144 | } |
| 145 | |
| 146 | @Override |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 147 | public void transformFrom(TransformableView notification, float transformationAmount) { |
| 148 | mTransformationHelper.transformFrom(notification, transformationAmount); |
| 149 | } |
| 150 | |
| 151 | @Override |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 152 | public void setVisible(boolean visible) { |
| 153 | setVisibility(visible ? View.VISIBLE : View.INVISIBLE); |
| 154 | mTransformationHelper.setVisible(visible); |
| 155 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 156 | } |