• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.row.wrapper
18 
19 import android.app.Flags.notificationsRedesignTemplates
20 import android.content.Context
21 import android.view.View
22 import com.android.internal.widget.CachingIconView
23 import com.android.internal.widget.CallLayout
24 import com.android.systemui.res.R
25 import com.android.systemui.statusbar.notification.NotificationFadeAware
26 import com.android.systemui.statusbar.notification.NotificationUtils
27 import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
28 
29 /** Wraps a notification containing a call template */
30 class NotificationCallTemplateViewWrapper
31 constructor(ctx: Context, view: View, row: ExpandableNotificationRow) :
32     NotificationTemplateViewWrapper(ctx, view, row) {
33 
34     private val minHeightWithActions: Int =
35         NotificationUtils.getFontScaledHeight(ctx, R.dimen.notification_max_height)
36     private val callLayout: CallLayout = view as CallLayout
37 
38     private lateinit var conversationIconContainer: View
39     private lateinit var conversationIconView: CachingIconView
40     private lateinit var conversationBadgeBg: View
41     private lateinit var expandBtn: View
42     private lateinit var appName: View
43     private lateinit var conversationTitleView: View
44 
resolveViewsnull45     private fun resolveViews() {
46         with(callLayout) {
47             conversationIconContainer =
48                 requireViewById(com.android.internal.R.id.conversation_icon_container)
49             conversationIconView = requireViewById(com.android.internal.R.id.conversation_icon)
50             conversationBadgeBg =
51                 requireViewById(com.android.internal.R.id.conversation_icon_badge_bg)
52             expandBtn = requireViewById(com.android.internal.R.id.expand_button)
53             appName = requireViewById(com.android.internal.R.id.app_name_text)
54             conversationTitleView =
55                 requireViewById(
56                     if (notificationsRedesignTemplates()) com.android.internal.R.id.title
57                     else com.android.internal.R.id.conversation_text
58                 )
59         }
60     }
61 
onContentUpdatednull62     override fun onContentUpdated(row: ExpandableNotificationRow) {
63         // Reinspect the notification. Before the super call, because the super call also updates
64         // the transformation types and we need to have our values set by then.
65         resolveViews()
66         super.onContentUpdated(row)
67     }
68 
updateTransformedTypesnull69     override fun updateTransformedTypes() {
70         // This also clears the existing types
71         super.updateTransformedTypes()
72         addTransformedViews(appName, conversationTitleView)
73         addViewsTransformingToSimilar(conversationIconView, conversationBadgeBg, expandBtn)
74     }
75 
disallowSingleClicknull76     override fun disallowSingleClick(x: Float, y: Float): Boolean {
77         val isOnExpandButton = expandBtn.visibility == View.VISIBLE && isOnView(expandBtn, x, y)
78         return isOnExpandButton || super.disallowSingleClick(x, y)
79     }
80 
getMinLayoutHeightnull81     override fun getMinLayoutHeight(): Int = minHeightWithActions
82 
83     /**
84      * Apply the faded state as a layer type change to the face pile view which needs to have
85      * overlapping contents render precisely.
86      */
87     override fun setNotificationFaded(faded: Boolean) {
88         // Do not call super
89         NotificationFadeAware.setLayerTypeForFaded(expandBtn, faded)
90         NotificationFadeAware.setLayerTypeForFaded(conversationIconContainer, faded)
91     }
92 }
93