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

Commit 43a2f429 authored by Tony Wickham's avatar Tony Wickham Committed by Android (Google) Code Review
Browse files

Merge "Add NotificationListener to launcher." into ub-launcher3-master

parents 657bf0fc 010d2550
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -76,6 +76,13 @@
            android:process=":wallpaper_chooser">
        </service>

        <service android:name="com.android.launcher3.badging.NotificationListener"
                 android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
            <intent-filter>
                <action android:name="android.service.notification.NotificationListenerService" />
            </intent-filter>
        </service>

        <meta-data android:name="android.nfc.disable_beam_default"
                       android:value="true" />

+11 −3
Original line number Diff line number Diff line
@@ -39,14 +39,16 @@ import android.widget.TextView;

import com.android.launcher3.IconCache.IconLoadRequest;
import com.android.launcher3.IconCache.ItemInfoUpdateReceiver;
import com.android.launcher3.badge.BadgeRenderer;
import com.android.launcher3.badge.BadgeInfo;
import com.android.launcher3.badge.BadgeRenderer;
import com.android.launcher3.badging.NotificationInfo;
import com.android.launcher3.folder.FolderIcon;
import com.android.launcher3.graphics.DrawableFactory;
import com.android.launcher3.graphics.HolographicOutlineHelper;
import com.android.launcher3.model.PackageItemInfo;

import java.text.NumberFormat;
import java.util.List;

/**
 * TextView that draws a bubble behind the text. We cannot use a LineBackgroundSpan
@@ -168,6 +170,8 @@ public class BubbleTextView extends TextView
        if (promiseStateChanged || info.isPromise()) {
            applyPromiseState(promiseStateChanged);
        }

        applyBadgeState(info);
    }

    public void applyFromApplicationInfo(AppInfo info) {
@@ -178,6 +182,8 @@ public class BubbleTextView extends TextView

        // Verify high res immediately
        verifyHighRes();

        applyBadgeState(info);
    }

    public void applyFromPackageItemInfo(PackageItemInfo info) {
@@ -502,8 +508,9 @@ public class BubbleTextView extends TextView
        }
    }

    public void applyBadgeState(BadgeInfo badgeInfo) {
    public void applyBadgeState(ItemInfo itemInfo) {
        if (mIcon instanceof FastBitmapDrawable) {
            BadgeInfo badgeInfo = mLauncher.getPopupDataProvider().getBadgeInfoForItem(itemInfo);
            BadgeRenderer badgeRenderer = mLauncher.getDeviceProfile().mBadgeRenderer;
            ((FastBitmapDrawable) mIcon).applyIconBadge(badgeInfo, badgeRenderer);
        }
@@ -634,7 +641,8 @@ public class BubbleTextView extends TextView
     * Returns true if the view can show custom shortcuts.
     */
    public boolean hasDeepShortcuts() {
        return !mLauncher.getShortcutIdsForItem((ItemInfo) getTag()).isEmpty();
        return !mLauncher.getPopupDataProvider().getShortcutIdsForItem((ItemInfo) getTag())
                .isEmpty();
    }

    /**
+12 −7
Original line number Diff line number Diff line
@@ -30,12 +30,13 @@ import android.graphics.PixelFormat;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.util.SparseArray;
import android.view.animation.DecelerateInterpolator;

import com.android.launcher3.graphics.IconPalette;
import com.android.launcher3.badge.BadgeRenderer;
import com.android.launcher3.badge.BadgeInfo;
import com.android.launcher3.badge.BadgeRenderer;
import com.android.launcher3.graphics.IconPalette;

public class FastBitmapDrawable extends Drawable {
    private static final float DISABLED_DESATURATION = 1f;
@@ -123,14 +124,18 @@ public class FastBitmapDrawable extends Drawable {
    }

    public void applyIconBadge(BadgeInfo badgeInfo, BadgeRenderer badgeRenderer) {
        boolean wasBadged = mBadgeInfo != null;
        boolean isBadged = badgeInfo != null;
        mBadgeInfo = badgeInfo;
        mBadgeRenderer = badgeRenderer;
        if (mIconPalette == null) {
        if (wasBadged || isBadged) {
            if (mBadgeInfo != null && mIconPalette == null) {
                mIconPalette = IconPalette.fromDominantColor(Utilities
                        .findDominantColorByHue(mBitmap, 20));
            }
            invalidateSelf();
        }
    }

    @Override
    public void draw(Canvas canvas) {
@@ -157,7 +162,7 @@ public class FastBitmapDrawable extends Drawable {
    }

    private boolean hasBadge() {
        return mBadgeInfo != null && mBadgeInfo.getNotificationCount() != null;
        return mBadgeInfo != null && mBadgeInfo.getNotificationCount() != 0;
    }

    @Override
+33 −18
Original line number Diff line number Diff line
@@ -85,6 +85,8 @@ import com.android.launcher3.allapps.AllAppsContainerView;
import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.allapps.DefaultAppSearchController;
import com.android.launcher3.anim.AnimationLayerSet;
import com.android.launcher3.badging.NotificationListener;
import com.android.launcher3.popup.PopupDataProvider;
import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.PinItemRequestCompat;
@@ -119,6 +121,7 @@ import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.MultiHashMap;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.PendingRequestArgs;
import com.android.launcher3.util.TestingUtils;
import com.android.launcher3.util.Thunk;
@@ -133,10 +136,10 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Default launcher application.
@@ -263,8 +266,7 @@ public class Launcher extends BaseActivity
    private boolean mHasFocus = false;
    private boolean mAttached = false;

    /** Maps launcher activity components to their list of shortcut ids. */
    private MultiHashMap<ComponentKey, String> mDeepShortcutMap = new MultiHashMap<>();
    private PopupDataProvider mPopupDataProvider;

    private View.OnTouchListener mHapticFeedbackTouchListener;

@@ -397,6 +399,8 @@ public class Launcher extends BaseActivity
        mExtractedColors = new ExtractedColors();
        loadExtractedColorsAndColorItems();

        mPopupDataProvider = new PopupDataProvider(this);

        ((AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE))
                .addAccessibilityStateChangeListener(this);

@@ -655,6 +659,10 @@ public class Launcher extends BaseActivity
        return (int) info.id;
    }

    public PopupDataProvider getPopupDataProvider() {
        return mPopupDataProvider;
    }

    /**
     * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have
     * a configuration step, this allows the proper animations to run after other transitions.
@@ -930,6 +938,8 @@ public class Launcher extends BaseActivity
        if (Utilities.ATLEAST_NOUGAT_MR1) {
            mAppWidgetHost.stopListening();
        }

        NotificationListener.removeNotificationsChangedListener();
    }

    @Override
@@ -944,6 +954,10 @@ public class Launcher extends BaseActivity
        if (Utilities.ATLEAST_NOUGAT_MR1) {
            mAppWidgetHost.startListening();
        }

        if (!isWorkspaceLoading()) {
            NotificationListener.setNotificationsChangedListener(mPopupDataProvider);
        }
    }

    @Override
@@ -1568,6 +1582,19 @@ public class Launcher extends BaseActivity
        }
    };

    public void updateIconBadges(final Set<PackageUserKey> updatedBadges) {
        Runnable r = new Runnable() {
            @Override
            public void run() {
                mWorkspace.updateIconBadges(updatedBadges);
                mAppsView.updateIconBadges(updatedBadges);
            }
        };
        if (!waitUntilResume(r)) {
            r.run();
        }
    }

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
@@ -3656,6 +3683,8 @@ public class Launcher extends BaseActivity

        InstallShortcutReceiver.disableAndFlushInstallQueue(this);

        NotificationListener.setNotificationsChangedListener(mPopupDataProvider);

        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.finishBindingItems(false);
        }
@@ -3725,21 +3754,7 @@ public class Launcher extends BaseActivity
     */
    @Override
    public void bindDeepShortcutMap(MultiHashMap<ComponentKey, String> deepShortcutMapCopy) {
        mDeepShortcutMap = deepShortcutMapCopy;
        if (LOGD) Log.d(TAG, "bindDeepShortcutMap: " + mDeepShortcutMap);
    }

    public List<String> getShortcutIdsForItem(ItemInfo info) {
        if (!DeepShortcutManager.supportsShortcuts(info)) {
            return Collections.EMPTY_LIST;
        }
        ComponentName component = info.getTargetComponent();
        if (component == null) {
            return Collections.EMPTY_LIST;
        }

        List<String> ids = mDeepShortcutMap.get(new ComponentKey(component, info.user));
        return ids == null ? Collections.EMPTY_LIST : ids;
        mPopupDataProvider.setDeepShortcutMap(deepShortcutMapCopy);
    }

    /**
+19 −0
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.LongArrayMap;
import com.android.launcher3.util.MultiStateAlphaController;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.util.Thunk;
import com.android.launcher3.util.VerticalFlingDetector;
import com.android.launcher3.util.WallpaperOffsetInterpolator;
@@ -86,6 +87,7 @@ import com.android.launcher3.widget.PendingAddWidgetInfo;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
 * The workspace is a wide area with a wallpaper and a finite number of pages.
@@ -3957,6 +3959,23 @@ public class Workspace extends PagedView
        });
    }

    public void updateIconBadges(final Set<PackageUserKey> updatedBadges) {
        final PackageUserKey packageUserKey = new PackageUserKey(null, null);
        mapOverItems(MAP_RECURSE, new ItemOperator() {
            @Override
            public boolean evaluate(ItemInfo info, View v) {
                if (info instanceof ShortcutInfo && v instanceof BubbleTextView) {
                    packageUserKey.updateFromItemInfo(info);
                    if (updatedBadges.contains(packageUserKey)) {
                        ((BubbleTextView) v).applyBadgeState(info);
                    }
                }
                // process all the shortcuts
                return false;
            }
        });
    }

    public void removeAbandonedPromise(String packageName, UserHandle user) {
        HashSet<String> packages = new HashSet<>(1);
        packages.add(packageName);
Loading