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