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

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

Merge "Add badges to folders" into ub-launcher3-master

parents 3cdda5fa 11ba507e
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -61,6 +61,7 @@ import com.android.launcher3.accessibility.OverviewAccessibilityDelegate;
import com.android.launcher3.accessibility.OverviewScreenAccessibilityDelegate;
import com.android.launcher3.accessibility.WorkspaceAccessibilityHelper;
import com.android.launcher3.anim.AnimationLayerSet;
import com.android.launcher3.badge.FolderBadgeInfo;
import com.android.launcher3.compat.AppWidgetManagerCompat;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.config.ProviderConfig;
@@ -3985,6 +3986,7 @@ public class Workspace extends PagedView

    public void updateIconBadges(final Set<PackageUserKey> updatedBadges) {
        final PackageUserKey packageUserKey = new PackageUserKey(null, null);
        final HashSet<Long> folderIds = new HashSet<>();
        mapOverItems(MAP_RECURSE, new ItemOperator() {
            @Override
            public boolean evaluate(ItemInfo info, View v) {
@@ -3992,7 +3994,26 @@ public class Workspace extends PagedView
                        && packageUserKey.updateFromItemInfo(info)) {
                    if (updatedBadges.contains(packageUserKey)) {
                        ((BubbleTextView) v).applyBadgeState(info);
                        folderIds.add(info.container);
                    }
                }
                // process all the shortcuts
                return false;
            }
        });

        // Update folder icons
        mapOverItems(MAP_NO_RECURSE, new ItemOperator() {
            @Override
            public boolean evaluate(ItemInfo info, View v) {
                if (info instanceof FolderInfo && folderIds.contains(info.id)
                        && v instanceof FolderIcon) {
                    FolderBadgeInfo folderBadgeInfo = new FolderBadgeInfo();
                    for (ShortcutInfo si : ((FolderInfo) info).contents) {
                        folderBadgeInfo.addBadgeInfo(mLauncher.getPopupDataProvider()
                                .getBadgeInfoForItem(si));
                    }
                    ((FolderIcon) v).setBadgeInfo(folderBadgeInfo);
                }
                // process all the shortcuts
                return false;
+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.badge;

import com.android.launcher3.Utilities;

import static com.android.launcher3.Utilities.boundToRange;

/**
 * Subclass of BadgeInfo that only contains the badge count,
 * which is the sum of all the Folder's items' counts.
 */
public class FolderBadgeInfo extends BadgeInfo {

    private static final int MIN_COUNT = 0;
    private static final int MAX_COUNT = 999;

    private int mTotalNotificationCount;

    public FolderBadgeInfo() {
        super(null);
    }

    public void addBadgeInfo(BadgeInfo badgeToAdd) {
        if (badgeToAdd == null) {
            return;
        }
        mTotalNotificationCount += badgeToAdd.getNotificationCount();
        mTotalNotificationCount = Utilities.boundToRange(
                mTotalNotificationCount, MIN_COUNT, MAX_COUNT);
    }

    public void subtractBadgeInfo(BadgeInfo badgeToSubtract) {
        if (badgeToSubtract == null) {
            return;
        }
        mTotalNotificationCount -= badgeToSubtract.getNotificationCount();
        mTotalNotificationCount = Utilities.boundToRange(
                mTotalNotificationCount, MIN_COUNT, MAX_COUNT);
    }

    @Override
    public int getNotificationCount() {
        return mTotalNotificationCount;
    }
}
+25 −0
Original line number Diff line number Diff line
@@ -64,9 +64,12 @@ import com.android.launcher3.SimpleOnStylusPressListener;
import com.android.launcher3.StylusEventHelper;
import com.android.launcher3.Utilities;
import com.android.launcher3.Workspace;
import com.android.launcher3.badge.BadgeRenderer;
import com.android.launcher3.badge.FolderBadgeInfo;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.graphics.IconPalette;
import com.android.launcher3.util.Thunk;

import java.util.ArrayList;
@@ -124,6 +127,9 @@ public class FolderIcon extends FrameLayout implements FolderListener {

    private Alarm mOpenAlarm = new Alarm();

    private FolderBadgeInfo mBadgeInfo = new FolderBadgeInfo();
    private BadgeRenderer mBadgeRenderer;

    public FolderIcon(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
@@ -172,6 +178,7 @@ public class FolderIcon extends FrameLayout implements FolderListener {
        icon.setOnClickListener(launcher);
        icon.mInfo = folderInfo;
        icon.mLauncher = launcher;
        icon.mBadgeRenderer = launcher.getDeviceProfile().mBadgeRenderer;
        icon.setContentDescription(launcher.getString(R.string.folder_name_format, folderInfo.title));
        Folder folder = Folder.fromXml(launcher);
        folder.setDragController(launcher.getDragController());
@@ -379,6 +386,11 @@ public class FolderIcon extends FrameLayout implements FolderListener {
        computePreviewDrawingParams(d.getIntrinsicWidth(), getMeasuredWidth());
    }

    public void setBadgeInfo(FolderBadgeInfo badgeInfo) {
        mBadgeInfo = badgeInfo;
        invalidate();
    }

    static class PreviewItemDrawingParams {
        PreviewItemDrawingParams(float transX, float transY, float scale, float overlayAlpha) {
            this.transX = transX;
@@ -767,6 +779,14 @@ public class FolderIcon extends FrameLayout implements FolderListener {
        if (mPreviewLayoutRule.clipToBackground() && !mBackground.drawingDelegated()) {
            mBackground.drawBackgroundStroke(canvas, mBgPaint);
        }

        int offsetX = mBackground.getOffsetX();
        int offsetY = mBackground.getOffsetY();
        int previewSize = (int) (mBackground.previewSize * mBackground.mScale);
        Rect bounds = new Rect(offsetX, offsetY, offsetX + previewSize, offsetY + previewSize);
        if (mBadgeInfo != null && mBadgeInfo.getNotificationCount() > 0) {
            mBadgeRenderer.draw(canvas, IconPalette.FOLDER_ICON_PALETTE, mBadgeInfo, bounds);
        }
    }

    class FolderPreviewItemAnim {
@@ -916,16 +936,21 @@ public class FolderIcon extends FrameLayout implements FolderListener {
        requestLayout();
    }

    @Override
    public void onAdd(ShortcutInfo item) {
        mBadgeInfo.addBadgeInfo(mLauncher.getPopupDataProvider().getBadgeInfoForItem(item));
        invalidate();
        requestLayout();
    }

    @Override
    public void onRemove(ShortcutInfo item) {
        mBadgeInfo.subtractBadgeInfo(mLauncher.getPopupDataProvider().getBadgeInfoForItem(item));
        invalidate();
        requestLayout();
    }

    @Override
    public void onTitleChanged(CharSequence title) {
        mFolderName.setText(title);
        setContentDescription(getContext().getString(R.string.folder_name_format, title));
+2 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ public class IconPalette {
    private static final boolean DEBUG = false;
    private static final String TAG = "IconPalette";

    public static final IconPalette FOLDER_ICON_PALETTE = new IconPalette(Color.WHITE);

    private static final float MIN_PRELOAD_COLOR_SATURATION = 0.2f;
    private static final float MIN_PRELOAD_COLOR_LIGHTNESS = 0.6f;
    private static final int DEFAULT_PRELOAD_COLOR = 0xFF009688;