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.annotation.ColorInt; 19 import android.app.Notification; 20 import android.os.Bundle; 21 import android.view.View; 22 23 import androidx.cardview.widget.CardView; 24 25 import com.android.car.notification.AlertEntry; 26 import com.android.car.notification.NotificationClickHandlerFactory; 27 import com.android.car.notification.R; 28 29 /** 30 * Notification view template that displays a car emergency notification. 31 */ 32 public class EmergencyNotificationViewHolder extends CarNotificationBaseViewHolder { 33 private final CardView mCardView; 34 private final CarNotificationHeaderView mHeaderView; 35 private final CarNotificationActionsView mActionsView; 36 private final CarNotificationBodyView mBodyView; 37 @ColorInt 38 private final int mEmergencyBackgroundColor; 39 40 private NotificationClickHandlerFactory mClickHandlerFactory; 41 EmergencyNotificationViewHolder(View view, NotificationClickHandlerFactory clickHandlerFactory)42 public EmergencyNotificationViewHolder(View view, 43 NotificationClickHandlerFactory clickHandlerFactory) { 44 super(view, clickHandlerFactory); 45 mCardView = view.findViewById(R.id.card_view); 46 mHeaderView = view.findViewById(R.id.notification_header); 47 mBodyView = view.findViewById(R.id.notification_body); 48 mActionsView = view.findViewById(R.id.notification_actions); 49 mEmergencyBackgroundColor = view.getContext().getColor(R.color.emergency_background_color); 50 mClickHandlerFactory = clickHandlerFactory; 51 } 52 53 @Override hasCustomBackgroundColor()54 boolean hasCustomBackgroundColor() { 55 return true; 56 } 57 58 /** 59 * Binds a {@link AlertEntry} to a car emergency notification template. 60 */ 61 @Override bind(AlertEntry alertEntry, boolean isInGroup, boolean isHeadsUp)62 public void bind(AlertEntry alertEntry, boolean isInGroup, 63 boolean isHeadsUp) { 64 super.bind(alertEntry, isInGroup, isHeadsUp); 65 66 Notification notification = alertEntry.getNotification(); 67 68 mCardView.setCardBackgroundColor(mEmergencyBackgroundColor); 69 mHeaderView.bind(alertEntry, isInGroup); 70 mActionsView.bind(mClickHandlerFactory, alertEntry); 71 72 Bundle extraData = notification.extras; 73 CharSequence title = extraData.getCharSequence(Notification.EXTRA_TITLE); 74 CharSequence text = extraData.getCharSequence(Notification.EXTRA_TEXT); 75 76 mBodyView.bind(title, text, loadAppLauncherIcon(alertEntry.getStatusBarNotification()), 77 notification.getLargeIcon(), /* titleIcon= */ null, /* countText= */ null, 78 notification.showsTime() ? notification.when : null); 79 } 80 } 81