• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 com.android.internal.widget.MessagingLinearLayout;
20 import com.android.systemui.statusbar.ExpandableNotificationRow;
21 import com.android.systemui.statusbar.TransformableView;
22 
23 import android.content.Context;
24 import android.text.TextUtils;
25 import android.view.View;
26 import android.widget.TextView;
27 
28 import java.util.ArrayList;
29 
30 /**
31  * Wraps a notification containing a messaging template
32  */
33 public class NotificationMessagingTemplateViewWrapper extends NotificationTemplateViewWrapper {
34 
35     private View mContractedMessage;
36     private ArrayList<View> mHistoricMessages = new ArrayList<View>();
37 
NotificationMessagingTemplateViewWrapper(Context ctx, View view, ExpandableNotificationRow row)38     protected NotificationMessagingTemplateViewWrapper(Context ctx, View view,
39             ExpandableNotificationRow row) {
40         super(ctx, view, row);
41     }
42 
resolveViews()43     private void resolveViews() {
44         mContractedMessage = null;
45 
46         View container = mView.findViewById(com.android.internal.R.id.notification_messaging);
47         if (container instanceof MessagingLinearLayout
48                 && ((MessagingLinearLayout) container).getChildCount() > 0) {
49             MessagingLinearLayout messagingContainer = (MessagingLinearLayout) container;
50 
51             int childCount = messagingContainer.getChildCount();
52             for (int i = 0; i < childCount; i++) {
53                 View child = messagingContainer.getChildAt(i);
54 
55                 if (child.getVisibility() == View.GONE
56                         && child instanceof TextView
57                         && !TextUtils.isEmpty(((TextView) child).getText())) {
58                     mHistoricMessages.add(child);
59                 }
60 
61                 // Only consider the first visible child - transforming to a position other than the
62                 // first looks bad because we have to move across other messages that are fading in.
63                 if (child.getId() == messagingContainer.getContractedChildId()) {
64                     mContractedMessage = child;
65                 } else if (child.getVisibility() == View.VISIBLE) {
66                     break;
67                 }
68             }
69         }
70     }
71 
72     @Override
onContentUpdated(ExpandableNotificationRow row)73     public void onContentUpdated(ExpandableNotificationRow row) {
74         // Reinspect the notification. Before the super call, because the super call also updates
75         // the transformation types and we need to have our values set by then.
76         resolveViews();
77         super.onContentUpdated(row);
78     }
79 
80     @Override
updateTransformedTypes()81     protected void updateTransformedTypes() {
82         // This also clears the existing types
83         super.updateTransformedTypes();
84         if (mContractedMessage != null) {
85             mTransformationHelper.addTransformedView(TransformableView.TRANSFORMING_VIEW_TEXT,
86                     mContractedMessage);
87         }
88     }
89 
90     @Override
setRemoteInputVisible(boolean visible)91     public void setRemoteInputVisible(boolean visible) {
92         for (int i = 0; i < mHistoricMessages.size(); i++) {
93             mHistoricMessages.get(i).setVisibility(visible ? View.VISIBLE : View.GONE);
94         }
95     }
96 }
97