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.MessagingLayout;
     20 import com.android.internal.widget.MessagingLinearLayout;
     21 import com.android.systemui.R;
     22 import com.android.systemui.statusbar.ExpandableNotificationRow;
     23 import com.android.systemui.statusbar.TransformableView;
     24 
     25 import android.content.Context;
     26 import android.text.TextUtils;
     27 import android.view.View;
     28 import android.widget.TextView;
     29 
     30 import java.util.ArrayList;
     31 
     32 /**
     33  * Wraps a notification containing a messaging template
     34  */
     35 public class NotificationMessagingTemplateViewWrapper extends NotificationTemplateViewWrapper {
     36 
     37     private final int mMinHeightWithActions;
     38     private MessagingLayout mMessagingLayout;
     39     private MessagingLinearLayout mMessagingLinearLayout;
     40 
     41     protected NotificationMessagingTemplateViewWrapper(Context ctx, View view,
     42             ExpandableNotificationRow row) {
     43         super(ctx, view, row);
     44         mMessagingLayout = (MessagingLayout) view;
     45         mMinHeightWithActions = NotificationUtils.getFontScaledHeight(ctx,
     46                 R.dimen.notification_messaging_actions_min_height);
     47     }
     48 
     49     private void resolveViews() {
     50         mMessagingLinearLayout = mMessagingLayout.getMessagingLinearLayout();
     51     }
     52 
     53     @Override
     54     public void onContentUpdated(ExpandableNotificationRow row) {
     55         // Reinspect the notification. Before the super call, because the super call also updates
     56         // the transformation types and we need to have our values set by then.
     57         resolveViews();
     58         super.onContentUpdated(row);
     59     }
     60 
     61     @Override
     62     protected void updateTransformedTypes() {
     63         // This also clears the existing types
     64         super.updateTransformedTypes();
     65         if (mMessagingLinearLayout != null) {
     66             mTransformationHelper.addTransformedView(mMessagingLinearLayout.getId(),
     67                     mMessagingLinearLayout);
     68         }
     69     }
     70 
     71     @Override
     72     public void setRemoteInputVisible(boolean visible) {
     73         mMessagingLayout.showHistoricMessages(visible);
     74     }
     75 
     76     @Override
     77     public int getMinLayoutHeight() {
     78         if (mActionsContainer != null && mActionsContainer.getVisibility() != View.GONE) {
     79             return mMinHeightWithActions;
     80         }
     81         return super.getMinLayoutHeight();
     82     }
     83 }
     84