1 /* 2 * Copyright (C) 2017 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.launcher3.notification; 18 19 import android.app.Notification; 20 import android.service.notification.StatusBarNotification; 21 22 import java.util.ArrayList; 23 import java.util.List; 24 25 import androidx.annotation.NonNull; 26 27 /** 28 * The key data associated with the notification, used to determine what to include 29 * in dots and dummy popup views before they are populated. 30 * 31 * @see NotificationInfo for the full data used when populating the dummy views. 32 */ 33 public class NotificationKeyData { 34 public final String notificationKey; 35 public final String shortcutId; 36 public int count; 37 NotificationKeyData(String notificationKey, String shortcutId, int count)38 private NotificationKeyData(String notificationKey, String shortcutId, int count) { 39 this.notificationKey = notificationKey; 40 this.shortcutId = shortcutId; 41 this.count = Math.max(1, count); 42 } 43 fromNotification(StatusBarNotification sbn)44 public static NotificationKeyData fromNotification(StatusBarNotification sbn) { 45 Notification notif = sbn.getNotification(); 46 return new NotificationKeyData(sbn.getKey(), notif.getShortcutId(), notif.number); 47 } 48 extractKeysOnly(@onNull List<NotificationKeyData> notificationKeys)49 public static List<String> extractKeysOnly(@NonNull List<NotificationKeyData> notificationKeys) { 50 List<String> keysOnly = new ArrayList<>(notificationKeys.size()); 51 for (NotificationKeyData notificationKeyData : notificationKeys) { 52 keysOnly.add(notificationKeyData.notificationKey); 53 } 54 return keysOnly; 55 } 56 57 @Override equals(Object obj)58 public boolean equals(Object obj) { 59 if (!(obj instanceof NotificationKeyData)) { 60 return false; 61 } 62 // Only compare the keys. 63 return ((NotificationKeyData) obj).notificationKey.equals(notificationKey); 64 } 65 } 66