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 | 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 | |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame^] | 34 | import java.util.ArrayList; |
| 35 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 36 | /** |
| 37 | * A hybrid view which may contain information about one ore more notifications. |
| 38 | */ |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame^] | 39 | public class HybridNotificationView extends AlphaOptimizedLinearLayout |
| 40 | implements TransformableView { |
| 41 | |
| 42 | private ViewTransformationHelper mTransformationHelper; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 43 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 44 | protected TextView mTitleView; |
| 45 | protected TextView mTextView; |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 46 | private ViewInvertHelper mInvertHelper; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 47 | |
| 48 | public HybridNotificationView(Context context) { |
| 49 | this(context, null); |
| 50 | } |
| 51 | |
| 52 | public HybridNotificationView(Context context, @Nullable AttributeSet attrs) { |
| 53 | this(context, attrs, 0); |
| 54 | } |
| 55 | |
| 56 | public HybridNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { |
| 57 | this(context, attrs, defStyleAttr, 0); |
| 58 | } |
| 59 | |
| 60 | public HybridNotificationView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, |
| 61 | int defStyleRes) { |
| 62 | super(context, attrs, defStyleAttr, defStyleRes); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Override |
| 66 | protected void onFinishInflate() { |
| 67 | super.onFinishInflate(); |
| 68 | mTitleView = (TextView) findViewById(R.id.notification_title); |
| 69 | mTextView = (TextView) findViewById(R.id.notification_text); |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 70 | mInvertHelper = new ViewInvertHelper(this, NotificationPanelView.DOZE_ANIMATION_DURATION); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame^] | 71 | mTransformationHelper = new ViewTransformationHelper(); |
| 72 | mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TITLE, mTitleView); |
| 73 | mTransformationHelper.addTransformedView(TRANSFORMING_VIEW_TEXT, mTextView); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | public void bind(CharSequence title) { |
| 77 | bind(title, null); |
| 78 | } |
| 79 | |
| 80 | public void bind(CharSequence title, CharSequence text) { |
| 81 | mTitleView.setText(title); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame^] | 82 | if (TextUtils.isEmpty(title)) { |
| 83 | mTitleView.setVisibility(GONE); |
| 84 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 85 | mTextView.setText(text); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame^] | 86 | if (TextUtils.isEmpty(text)) { |
| 87 | mTextView.setVisibility(GONE); |
| 88 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 89 | requestLayout(); |
| 90 | } |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 91 | |
| 92 | public void setDark(boolean dark, boolean fade, long delay) { |
| 93 | mInvertHelper.setInverted(dark, fade, delay); |
| 94 | } |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame^] | 95 | |
| 96 | @Override |
| 97 | public TransformState getCurrentState(int fadingView) { |
| 98 | return mTransformationHelper.getCurrentState(fadingView); |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public void transformTo(TransformableView notification, Runnable endRunnable) { |
| 103 | mTransformationHelper.transformTo(notification, endRunnable); |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public void transformFrom(TransformableView notification) { |
| 108 | mTransformationHelper.transformFrom(notification); |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public void setVisible(boolean visible) { |
| 113 | setVisibility(visible ? View.VISIBLE : View.INVISIBLE); |
| 114 | mTransformationHelper.setVisible(visible); |
| 115 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 116 | } |