Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c3dfed43 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "De-dupe shortcuts with the same id as the main notification." into ub-launcher3-dorval

parents 40dfa3bf 2f5bb169
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;

import com.android.launcher3.notification.NotificationInfo;
import com.android.launcher3.notification.NotificationKeyData;
import com.android.launcher3.util.PackageUserKey;

import java.util.ArrayList;
@@ -42,7 +43,7 @@ public class BadgeInfo {
     * The keys of the notifications that this badge represents. These keys can later be
     * used to retrieve {@link NotificationInfo}'s.
     */
    private List<String> mNotificationKeys;
    private List<NotificationKeyData> mNotificationKeys;

    /** This will only be initialized if the badge should display the notification icon. */
    private NotificationInfo mNotificationInfo;
@@ -61,7 +62,7 @@ public class BadgeInfo {
    /**
     * Returns whether the notification was added (false if it already existed).
     */
    public boolean addNotificationKeyIfNotExists(String notificationKey) {
    public boolean addNotificationKeyIfNotExists(NotificationKeyData notificationKey) {
        if (mNotificationKeys.contains(notificationKey)) {
            return false;
        }
@@ -71,11 +72,11 @@ public class BadgeInfo {
    /**
     * Returns whether the notification was removed (false if it didn't exist).
     */
    public boolean removeNotificationKey(String notificationKey) {
    public boolean removeNotificationKey(NotificationKeyData notificationKey) {
        return mNotificationKeys.remove(notificationKey);
    }

    public List<String> getNotificationKeys() {
    public List<NotificationKeyData> getNotificationKeys() {
        return mNotificationKeys;
    }

+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ import com.android.launcher3.util.PackageUserKey;
 * only be created when we need to show the notification contents on the UI; until then, a
 * {@link com.android.launcher3.badge.BadgeInfo} with only the notification key should
 * be passed around, and then this can be constructed using the StatusBarNotification from
 * {@link NotificationListener#getNotificationsForKeys(String[])}.
 * {@link NotificationListener#getNotificationsForKeys(java.util.List)}.
 */
public class NotificationInfo implements View.OnClickListener {

+60 −0
Original line number Diff line number Diff line
/*
 * 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;

import android.service.notification.StatusBarNotification;
import android.support.annotation.NonNull;

import java.util.ArrayList;
import java.util.List;

/**
 * The key data associated with the notification, used to determine what to include
 * in badges and dummy popup views before they are populated.
 *
 * @see NotificationInfo for the full data used when populating the dummy views.
 */
public class NotificationKeyData {
    public final String notificationKey;
    public final String shortcutId;

    private NotificationKeyData(String notificationKey, String shortcutId) {
        this.notificationKey = notificationKey;
        this.shortcutId = shortcutId;
    }

    public static NotificationKeyData fromNotification(StatusBarNotification sbn) {
        return new NotificationKeyData(sbn.getKey(), sbn.getNotification().getShortcutId());
    }

    public static List<String> extractKeysOnly(@NonNull List<NotificationKeyData> notificationKeys) {
        List<String> keysOnly = new ArrayList<>(notificationKeys.size());
        for (NotificationKeyData notificationKeyData : notificationKeys) {
            keysOnly.add(notificationKeyData.notificationKey);
        }
        return keysOnly;
    }

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof NotificationKeyData)) {
            return false;
        }
        // Only compare the keys.
        return ((NotificationKeyData) obj).notificationKey.equals(notificationKey);
    }
}
+14 −11
Original line number Diff line number Diff line
@@ -94,8 +94,8 @@ public class NotificationListener extends NotificationListenerService {
                    break;
                case MSG_NOTIFICATION_REMOVED:
                    if (sNotificationsChangedListener != null) {
                        Pair<PackageUserKey, String> pair
                                = (Pair<PackageUserKey, String>) message.obj;
                        Pair<PackageUserKey, NotificationKeyData> pair
                                = (Pair<PackageUserKey, NotificationKeyData>) message.obj;
                        sNotificationsChangedListener.onNotificationRemoved(pair.first, pair.second);
                    }
                    break;
@@ -165,12 +165,12 @@ public class NotificationListener extends NotificationListenerService {
     */
    private class NotificationPostedMsg {
        PackageUserKey packageUserKey;
        String notificationKey;
        NotificationKeyData notificationKey;
        boolean shouldBeFilteredOut;

        NotificationPostedMsg(StatusBarNotification sbn) {
            packageUserKey = PackageUserKey.fromNotification(sbn);
            notificationKey = sbn.getKey();
            notificationKey = NotificationKeyData.fromNotification(sbn);
            shouldBeFilteredOut = shouldBeFilteredOut(sbn);
        }
    }
@@ -178,16 +178,18 @@ public class NotificationListener extends NotificationListenerService {
    @Override
    public void onNotificationRemoved(final StatusBarNotification sbn) {
        super.onNotificationRemoved(sbn);
        Pair<PackageUserKey, String> packageUserKeyAndNotificationKey
                = new Pair<>(PackageUserKey.fromNotification(sbn), sbn.getKey());
        Pair<PackageUserKey, NotificationKeyData> packageUserKeyAndNotificationKey
                = new Pair<>(PackageUserKey.fromNotification(sbn),
                        NotificationKeyData.fromNotification(sbn));
        mWorkerHandler.obtainMessage(MSG_NOTIFICATION_REMOVED, packageUserKeyAndNotificationKey)
                .sendToTarget();
    }

    /** This makes a potentially expensive binder call and should be run on a background thread. */
    public List<StatusBarNotification> getNotificationsForKeys(String[] keys) {
    public List<StatusBarNotification> getNotificationsForKeys(List<NotificationKeyData> keys) {
        StatusBarNotification[] notifications = NotificationListener.this
                .getActiveNotifications(keys);
                .getActiveNotifications(NotificationKeyData.extractKeysOnly(keys)
                        .toArray(new String[keys.size()]));
        return notifications == null ? Collections.EMPTY_LIST : Arrays.asList(notifications);
    }

@@ -238,9 +240,10 @@ public class NotificationListener extends NotificationListenerService {
    }

    public interface NotificationsChangedListener {
        void onNotificationPosted(PackageUserKey postedPackageUserKey, String notificationKey,
                boolean shouldBeFilteredOut);
        void onNotificationRemoved(PackageUserKey removedPackageUserKey, String notificationKey);
        void onNotificationPosted(PackageUserKey postedPackageUserKey,
                NotificationKeyData notificationKey, boolean shouldBeFilteredOut);
        void onNotificationRemoved(PackageUserKey removedPackageUserKey,
                NotificationKeyData notificationKey);
        void onNotificationFullRefresh(List<StatusBarNotification> activeNotifications);
    }
}
+8 −6
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.graphics.TriangleShape;
import com.android.launcher3.notification.NotificationItemView;
import com.android.launcher3.notification.NotificationKeyData;
import com.android.launcher3.shortcuts.DeepShortcutView;
import com.android.launcher3.shortcuts.ShortcutsItemView;
import com.android.launcher3.util.PackageUserKey;
@@ -138,9 +139,9 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
        }
        ItemInfo itemInfo = (ItemInfo) icon.getTag();
        List<String> shortcutIds = launcher.getPopupDataProvider().getShortcutIdsForItem(itemInfo);
        String[] notificationKeys = launcher.getPopupDataProvider()
        List<NotificationKeyData> notificationKeys = launcher.getPopupDataProvider()
                .getNotificationKeysForItem(itemInfo);
        if (shortcutIds.size() > 0 || notificationKeys.length > 0) {
        if (shortcutIds.size() > 0 || notificationKeys.size() > 0) {
            final PopupContainerWithArrow container =
                    (PopupContainerWithArrow) launcher.getLayoutInflater().inflate(
                            R.layout.popup_container, launcher.getDragLayer(), false);
@@ -153,7 +154,7 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
    }

    public void populateAndShow(final BubbleTextView originalIcon, final List<String> shortcutIds,
            final String[] notificationKeys) {
            final List<NotificationKeyData> notificationKeys) {
        final Resources resources = getResources();
        final int arrowWidth = resources.getDimensionPixelSize(R.dimen.deep_shortcuts_arrow_width);
        final int arrowHeight = resources.getDimensionPixelSize(R.dimen.deep_shortcuts_arrow_height);
@@ -165,7 +166,7 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
        // Add dummy views first, and populate with real info when ready.
        PopupPopulator.Item[] itemsToPopulate = PopupPopulator
                .getItemsToPopulate(shortcutIds, notificationKeys);
        addDummyViews(originalIcon, itemsToPopulate, notificationKeys.length > 1);
        addDummyViews(originalIcon, itemsToPopulate, notificationKeys.size() > 1);

        measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
        orientAboutIcon(originalIcon, arrowHeight + arrowVerticalOffset);
@@ -176,7 +177,7 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
            mNotificationItemView = null;
            mShortcutsItemView = null;
            itemsToPopulate = PopupPopulator.reverseItems(itemsToPopulate);
            addDummyViews(originalIcon, itemsToPopulate, notificationKeys.length > 1);
            addDummyViews(originalIcon, itemsToPopulate, notificationKeys.size() > 1);

            measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
            orientAboutIcon(originalIcon, arrowHeight + arrowVerticalOffset);
@@ -606,7 +607,8 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
            removeNotification.start();
            return;
        }
        mNotificationItemView.trimNotifications(badgeInfo.getNotificationKeys());
        mNotificationItemView.trimNotifications(NotificationKeyData.extractKeysOnly(
                badgeInfo.getNotificationKeys()));
    }

    private ObjectAnimator createArrowScaleAnim(float scale) {
Loading