1 /* 2 * Copyright (C) 2018 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 package com.android.car.notification.template; 17 18 import android.app.Notification; 19 import android.os.Bundle; 20 import android.view.View; 21 22 import com.android.car.notification.AlertEntry; 23 import com.android.car.notification.NotificationClickHandlerFactory; 24 import com.android.car.notification.R; 25 26 /** 27 * Inbox notification view template that 28 * displays a {@link android.app.Notification.InboxStyle} notification. 29 */ 30 public class InboxNotificationViewHolder extends CarNotificationBaseViewHolder { 31 private final CarNotificationHeaderView mHeaderView; 32 private final CarNotificationBodyView mBodyView; 33 private final CarNotificationActionsView mActionsView; 34 private NotificationClickHandlerFactory mClickHandlerFactory; 35 InboxNotificationViewHolder( View view, NotificationClickHandlerFactory clickHandlerFactory)36 public InboxNotificationViewHolder( 37 View view, NotificationClickHandlerFactory clickHandlerFactory) { 38 super(view, clickHandlerFactory); 39 mHeaderView = view.findViewById(R.id.notification_header); 40 mBodyView = view.findViewById(R.id.notification_body); 41 mActionsView = view.findViewById(R.id.notification_actions); 42 mClickHandlerFactory = clickHandlerFactory; 43 } 44 45 /** 46 * Binds a {@link AlertEntry} to an inbox style car notification template. 47 */ 48 @Override bind(AlertEntry alertEntry, boolean isInGroup, boolean isHeadsUp, boolean isSeen)49 public void bind(AlertEntry alertEntry, boolean isInGroup, 50 boolean isHeadsUp, boolean isSeen) { 51 super.bind(alertEntry, isInGroup, isHeadsUp, isSeen); 52 bindBody(alertEntry); 53 mHeaderView.bind(alertEntry, isInGroup); 54 mActionsView.bind(mClickHandlerFactory, alertEntry); 55 } 56 57 /** 58 * Private method that binds the data to the view. 59 */ bindBody(AlertEntry alertEntry)60 private void bindBody(AlertEntry alertEntry) { 61 Notification notification = alertEntry.getNotification(); 62 Bundle extraData = notification.extras; 63 CharSequence title = extraData.getCharSequence(Notification.EXTRA_TITLE_BIG); 64 CharSequence text = extraData.getCharSequence(Notification.EXTRA_SUMMARY_TEXT); 65 66 mBodyView.bind(title, text, 67 alertEntry.getStatusBarNotification(), 68 notification.getLargeIcon(), /* titleIcon= */ null, /* countText= */ null, 69 notification.showsTime() ? notification.when : null); 70 } 71 } 72