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