1 /*
2  * Copyright (C) 2019 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.graphics.drawable.Icon;
20 import android.os.Bundle;
21 import android.view.View;
22 
23 import com.android.car.notification.AlertEntry;
24 import com.android.car.notification.NotificationClickHandlerFactory;
25 import com.android.car.notification.R;
26 
27 /**
28  * Basic notification view template that displays a minimal notification.
29  */
30 public class NavigationNotificationViewHolder extends CarNotificationBaseViewHolder {
31 
32     private final CarNotificationBodyView mBodyView;
33     private final CarNotificationActionsView mActionsView;
34     private final CarNotificationHeaderView mHeaderView;
35     private final NotificationClickHandlerFactory mClickHandlerFactory;
36 
NavigationNotificationViewHolder( View view, NotificationClickHandlerFactory clickHandlerFactory)37     public NavigationNotificationViewHolder(
38             View view, NotificationClickHandlerFactory clickHandlerFactory) {
39         super(view, clickHandlerFactory);
40         mBodyView = view.findViewById(R.id.notification_body);
41         mHeaderView = view.findViewById(R.id.notification_header);
42         mActionsView = view.findViewById(R.id.notification_actions);
43         mClickHandlerFactory = clickHandlerFactory;
44     }
45 
46     /**
47      * Binds a {@link AlertEntry} to a basic car notification template.
48      */
49     @Override
bind(AlertEntry alertEntry, boolean isInGroup, boolean isHeadsUp)50     public void bind(AlertEntry alertEntry, boolean isInGroup,
51             boolean isHeadsUp) {
52         super.bind(alertEntry, isInGroup, isHeadsUp);
53         bindBody(alertEntry);
54         mHeaderView.bind(alertEntry, isInGroup);
55         mActionsView.bind(mClickHandlerFactory, alertEntry);
56     }
57 
58     /**
59      * Private method that binds the data to the view.
60      */
bindBody(AlertEntry alertEntry)61     private void bindBody(AlertEntry alertEntry) {
62         Notification notification = alertEntry.getNotification();
63         Bundle extraData = notification.extras;
64         CharSequence title = extraData.getCharSequence(Notification.EXTRA_TITLE);
65         CharSequence text = extraData.getCharSequence(Notification.EXTRA_TEXT);
66         Icon icon = notification.getLargeIcon();
67         mBodyView.bind(title, text, icon);
68     }
69 }
70