diff options
author | Tony Wickham <twickham@google.com> | 2017-02-02 12:42:50 -0800 |
---|---|---|
committer | Tony Wickham <twickham@google.com> | 2017-02-07 10:09:10 -0800 |
commit | 11ba507eab83f591b924ae42d42fa47073b78917 (patch) | |
tree | da2d6a2c9ee62264c20c514ae8989aafed0c3f3c /src | |
parent | db7b82960a54b85510aaeba2f543b37b4dc59fc8 (diff) | |
download | android_packages_apps_Trebuchet-11ba507eab83f591b924ae42d42fa47073b78917.tar.gz android_packages_apps_Trebuchet-11ba507eab83f591b924ae42d42fa47073b78917.tar.bz2 android_packages_apps_Trebuchet-11ba507eab83f591b924ae42d42fa47073b78917.zip |
Add badges to folders
- The folder badge contains the sum of the badge counts within.
- This is represented by FolderBadgeInfo, a subclass of BadgeInfo.
Bug: 34828806
Bug: 32410600
Change-Id: I977a69cc7baf80a7207af9adf98dddb0a3509c47
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 21 | ||||
-rw-r--r-- | src/com/android/launcher3/badge/FolderBadgeInfo.java | 60 | ||||
-rw-r--r-- | src/com/android/launcher3/folder/FolderIcon.java | 25 | ||||
-rw-r--r-- | src/com/android/launcher3/graphics/IconPalette.java | 2 |
4 files changed, 108 insertions, 0 deletions
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index c80d4a883..cd74ed96f 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -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; diff --git a/src/com/android/launcher3/badge/FolderBadgeInfo.java b/src/com/android/launcher3/badge/FolderBadgeInfo.java new file mode 100644 index 000000000..4d1e5c203 --- /dev/null +++ b/src/com/android/launcher3/badge/FolderBadgeInfo.java @@ -0,0 +1,60 @@ +/* + * 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; + } +} diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java index 7f5569cb9..74dc48c06 100644 --- a/src/com/android/launcher3/folder/FolderIcon.java +++ b/src/com/android/launcher3/folder/FolderIcon.java @@ -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)); diff --git a/src/com/android/launcher3/graphics/IconPalette.java b/src/com/android/launcher3/graphics/IconPalette.java index 991038cca..7cb69b316 100644 --- a/src/com/android/launcher3/graphics/IconPalette.java +++ b/src/com/android/launcher3/graphics/IconPalette.java @@ -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; |