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.graphics.drawable.Icon;
21 import android.os.Bundle;
22 import android.view.View;
23 
24 import androidx.cardview.widget.CardView;
25 
26 import com.android.car.notification.AlertEntry;
27 import com.android.car.notification.NotificationClickHandlerFactory;
28 import com.android.car.notification.R;
29 
30 /**
31  * Notification view template that displays a car emergency notification.
32  */
33 public class EmergencyNotificationViewHolder extends CarNotificationBaseViewHolder {
34     private final CardView mCardView;
35     private final CarNotificationHeaderView mHeaderView;
36     private final CarNotificationActionsView mActionsView;
37     private final CarNotificationBodyView mBodyView;
38     @ColorInt
39     private final int mEmergencyBackgroundColor;
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         Icon icon = notification.getLargeIcon();
76         mBodyView.bind(title, text, icon);
77     }
78 }
79