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; |
| 22 | import android.util.ArrayMap; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 23 | import android.util.AttributeSet; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 24 | import android.view.View; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 25 | import android.widget.TextView; |
| 26 | |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 27 | import com.android.keyguard.AlphaOptimizedLinearLayout; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 28 | import com.android.systemui.R; |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 29 | import com.android.systemui.ViewInvertHelper; |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame^] | 30 | import com.android.systemui.statusbar.CrossFadeHelper; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 31 | import com.android.systemui.statusbar.TransformableView; |
| 32 | import com.android.systemui.statusbar.ViewTransformationHelper; |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 33 | import com.android.systemui.statusbar.phone.NotificationPanelView; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 34 | |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 35 | import java.util.ArrayList; |
| 36 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 37 | /** |
| 38 | * A hybrid view which may contain information about one ore more notifications. |
| 39 | */ |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 40 | public class HybridNotificationView extends AlphaOptimizedLinearLayout |
| 41 | implements TransformableView { |
| 42 | |
| 43 | private ViewTransformationHelper mTransformationHelper; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 44 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 45 | protected TextView mTitleView; |
| 46 | protected TextView mTextView; |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 47 | private ViewInvertHelper mInvertHelper; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 48 | |
| 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 Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 64 | } |
| 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 Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 71 | mInvertHelper = new ViewInvertHelper(this, NotificationPanelView.DOZE_ANIMATION_DURATION); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 72 | mTransformationHelper = new ViewTransformationHelper(); |
Selim Cinek | fd3e262 | 2016-01-12 16:02:42 -0800 | [diff] [blame^] | 73 | 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 Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 103 | mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TITLE, mTitleView); |
| 104 | mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TEXT, mTextView); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 105 | } |
| 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 Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 113 | if (TextUtils.isEmpty(title)) { |
| 114 | mTitleView.setVisibility(GONE); |
| 115 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 116 | mTextView.setText(text); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 117 | if (TextUtils.isEmpty(text)) { |
| 118 | mTextView.setVisibility(GONE); |
| 119 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 120 | requestLayout(); |
| 121 | } |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 122 | |
| 123 | public void setDark(boolean dark, boolean fade, long delay) { |
| 124 | mInvertHelper.setInverted(dark, fade, delay); |
| 125 | } |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 126 | |
| 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 Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 147 | } |