• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.car.notification;
18 
19 import android.content.Context;
20 import android.os.Handler;
21 import android.service.notification.StatusBarNotification;
22 import android.view.View;
23 import android.view.ViewGroup;
24 import android.widget.FrameLayout;
25 
26 import com.android.car.notification.template.CarNotificationBaseViewHolder;
27 
28 /**
29  * Class to store the state for Heads Up Notifications. Each notification will have its own post
30  * time, handler, and Layout. This class ensures to store it as a separate state so that each Heads
31  * up notification can be controlled independently.
32  */
33 public class HeadsUpEntry {
34 
35     private final StatusBarNotification mStatusBarNotification;
36     private long mPostTime;
37     private final Handler mHandler;
38     protected boolean isAlertAgain;
39     protected boolean isNewHeadsUp;
40     private View mNotificationView;
41     private NotificationClickHandlerFactory mClickHandlerFactory;
42     private CarNotificationBaseViewHolder mCarNotificationBaseViewHolder;
43 
HeadsUpEntry(StatusBarNotification statusBarNotification)44     HeadsUpEntry(StatusBarNotification statusBarNotification) {
45         mStatusBarNotification = statusBarNotification;
46         mPostTime = calculatePostTime();
47         mHandler = new Handler();
48     }
49 
50     /**
51      * Calculate what the post time of a notification is at some current time.
52      *
53      * @return the post time
54      */
calculatePostTime()55     private long calculatePostTime() {
56         return System.currentTimeMillis();
57     }
58 
59     /**
60      * Updates the current post time for the Heads up notification.
61      */
updatePostTime()62     protected void updatePostTime() {
63         mPostTime = calculatePostTime();
64     }
65 
getStatusBarNotification()66     protected StatusBarNotification getStatusBarNotification() {
67         return mStatusBarNotification;
68     }
69 
70     /**
71      * Handler will used the method {@link Handler#postDelayed(Runnable, long)} which will control
72      * he dismiss time for the Heads Up notification. All the notifications should have their own
73      * handler o control this time.
74      */
getHandler()75     protected Handler getHandler() {
76         return mHandler;
77     }
78 
79 
getPostTime()80     protected long getPostTime() {
81         return mPostTime;
82     }
83 
84     /**
85      * View that holds the actual card for heads up notification.
86      */
setNotificationView(View notificationView)87     protected void setNotificationView(View notificationView) {
88         mNotificationView = notificationView;
89     }
90 
getNotificationView()91     protected View getNotificationView() {
92         return mNotificationView;
93     }
94 
getClickHandlerFactory()95     protected NotificationClickHandlerFactory getClickHandlerFactory() {
96         return mClickHandlerFactory;
97     }
98 
setClickHandlerFactory( NotificationClickHandlerFactory clickHandlerFactory)99     protected void setClickHandlerFactory(
100             NotificationClickHandlerFactory clickHandlerFactory) {
101         mClickHandlerFactory = clickHandlerFactory;
102     }
103 
setViewHolder(CarNotificationBaseViewHolder viewHolder)104     protected void setViewHolder(CarNotificationBaseViewHolder viewHolder) {
105         mCarNotificationBaseViewHolder = viewHolder;
106     }
107 
getViewHolder()108     protected CarNotificationBaseViewHolder getViewHolder() {
109         return mCarNotificationBaseViewHolder;
110     }
111 }
112