2017-03-24 11:31:12 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2017 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.android.launcher3.notification;
|
|
|
|
|
|
2017-02-24 18:06:14 -08:00
|
|
|
import android.app.Notification;
|
2019-07-26 12:28:38 -07:00
|
|
|
import android.app.Person;
|
2017-03-24 11:31:12 -07:00
|
|
|
import android.service.notification.StatusBarNotification;
|
|
|
|
|
|
2019-08-14 14:26:05 -07:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
2019-07-26 12:28:38 -07:00
|
|
|
import com.android.launcher3.Utilities;
|
2019-08-14 14:26:05 -07:00
|
|
|
|
2017-03-24 11:31:12 -07:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
2018-08-14 15:21:45 -07:00
|
|
|
|
2017-03-24 11:31:12 -07:00
|
|
|
/**
|
|
|
|
|
* The key data associated with the notification, used to determine what to include
|
2018-12-03 18:11:39 -08:00
|
|
|
* in dots and dummy popup views before they are populated.
|
2017-03-24 11:31:12 -07:00
|
|
|
*
|
|
|
|
|
* @see NotificationInfo for the full data used when populating the dummy views.
|
|
|
|
|
*/
|
|
|
|
|
public class NotificationKeyData {
|
|
|
|
|
public final String notificationKey;
|
|
|
|
|
public final String shortcutId;
|
2019-08-14 14:26:05 -07:00
|
|
|
@NonNull
|
|
|
|
|
public final String[] personKeysFromNotification;
|
2017-02-24 18:06:14 -08:00
|
|
|
public int count;
|
2017-03-24 11:31:12 -07:00
|
|
|
|
2019-07-26 12:28:38 -07:00
|
|
|
private NotificationKeyData(String notificationKey, String shortcutId, int count,
|
|
|
|
|
String[] personKeysFromNotification) {
|
2017-03-24 11:31:12 -07:00
|
|
|
this.notificationKey = notificationKey;
|
|
|
|
|
this.shortcutId = shortcutId;
|
2017-04-27 12:07:34 -07:00
|
|
|
this.count = Math.max(1, count);
|
2019-07-26 12:28:38 -07:00
|
|
|
this.personKeysFromNotification = personKeysFromNotification;
|
2017-03-24 11:31:12 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static NotificationKeyData fromNotification(StatusBarNotification sbn) {
|
2017-02-24 18:06:14 -08:00
|
|
|
Notification notif = sbn.getNotification();
|
2019-07-26 12:28:38 -07:00
|
|
|
return new NotificationKeyData(sbn.getKey(), notif.getShortcutId(), notif.number,
|
|
|
|
|
extractPersonKeyOnly(notif.extras.getParcelableArrayList(
|
|
|
|
|
Notification.EXTRA_PEOPLE_LIST)));
|
2017-03-24 11:31:12 -07:00
|
|
|
}
|
|
|
|
|
|
2019-07-26 12:28:38 -07:00
|
|
|
public static List<String> extractKeysOnly(
|
|
|
|
|
@NonNull List<NotificationKeyData> notificationKeys) {
|
2017-03-24 11:31:12 -07:00
|
|
|
List<String> keysOnly = new ArrayList<>(notificationKeys.size());
|
|
|
|
|
for (NotificationKeyData notificationKeyData : notificationKeys) {
|
|
|
|
|
keysOnly.add(notificationKeyData.notificationKey);
|
|
|
|
|
}
|
|
|
|
|
return keysOnly;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-26 12:28:38 -07:00
|
|
|
private static String[] extractPersonKeyOnly(@Nullable ArrayList<Person> people) {
|
|
|
|
|
if (people == null || people.isEmpty()) {
|
|
|
|
|
return Utilities.EMPTY_STRING_ARRAY;
|
|
|
|
|
}
|
2019-08-14 14:26:05 -07:00
|
|
|
return people.stream().filter(person -> person.getKey() != null)
|
|
|
|
|
.map(Person::getKey).sorted().toArray(String[]::new);
|
2019-07-26 12:28:38 -07:00
|
|
|
}
|
|
|
|
|
|
2017-03-24 11:31:12 -07:00
|
|
|
@Override
|
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
|
if (!(obj instanceof NotificationKeyData)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// Only compare the keys.
|
|
|
|
|
return ((NotificationKeyData) obj).notificationKey.equals(notificationKey);
|
|
|
|
|
}
|
|
|
|
|
}
|