Home | History | Annotate | Download | only in notification
      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.service.notification.StatusBarNotification;
     25 import android.view.View;
     26 
     27 /**
     28  * Wraps a notification containing a messaging template
     29  */
     30 public class NotificationMessagingTemplateViewWrapper extends NotificationTemplateViewWrapper {
     31 
     32     private View mContractedMessage;
     33 
     34     protected NotificationMessagingTemplateViewWrapper(Context ctx, View view,
     35             ExpandableNotificationRow row) {
     36         super(ctx, view, row);
     37     }
     38 
     39     private void resolveViews() {
     40         mContractedMessage = null;
     41 
     42         View container = mView.findViewById(com.android.internal.R.id.notification_messaging);
     43         if (container instanceof MessagingLinearLayout
     44                 && ((MessagingLinearLayout) container).getChildCount() > 0) {
     45             MessagingLinearLayout messagingContainer = (MessagingLinearLayout) container;
     46 
     47             // Only consider the first child - transforming to a position other than the first
     48             // looks bad because we have to move across other messages that are fading in.
     49             View child = messagingContainer.getChildAt(0);
     50             if (child.getId() == messagingContainer.getContractedChildId()) {
     51                 mContractedMessage = child;
     52             }
     53         }
     54     }
     55 
     56     @Override
     57     public void notifyContentUpdated(StatusBarNotification notification) {
     58         // Reinspect the notification. Before the super call, because the super call also updates
     59         // the transformation types and we need to have our values set by then.
     60         resolveViews();
     61         super.notifyContentUpdated(notification);
     62     }
     63 
     64     @Override
     65     protected void updateTransformedTypes() {
     66         // This also clears the existing types
     67         super.updateTransformedTypes();
     68         if (mContractedMessage != null) {
     69             mTransformationHelper.addTransformedView(TransformableView.TRANSFORMING_VIEW_TEXT,
     70                     mContractedMessage);
     71         }
     72     }
     73 }
     74