summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/dot
diff options
context:
space:
mode:
authorTony Wickham <twickham@google.com>2018-12-03 18:11:39 -0800
committerTony Wickham <twickham@google.com>2018-12-04 10:46:40 -0800
commitf34bee819c8fd88cfa0df8608e336b93aaf2e6ff (patch)
tree985ad9488b1f6b45bbbd3c8e539235f26bfb45f0 /src/com/android/launcher3/dot
parentde78d7ca78b457c057f91ba838ea5c7c0f14c2dd (diff)
downloadandroid_packages_apps_Trebuchet-f34bee819c8fd88cfa0df8608e336b93aaf2e6ff.tar.gz
android_packages_apps_Trebuchet-f34bee819c8fd88cfa0df8608e336b93aaf2e6ff.tar.bz2
android_packages_apps_Trebuchet-f34bee819c8fd88cfa0df8608e336b93aaf2e6ff.zip
Rename "badges" to "dots" where appropriate
This will reduce confusion with the other "badging" concept we use for, e.g. work profiles. It is also consistent with the external name "notification dots". Change-Id: I2a2c9d96dc0d6284eb0c48adc78a856271caad4d
Diffstat (limited to 'src/com/android/launcher3/dot')
-rw-r--r--src/com/android/launcher3/dot/DotInfo.java109
-rw-r--r--src/com/android/launcher3/dot/FolderDotInfo.java64
2 files changed, 173 insertions, 0 deletions
diff --git a/src/com/android/launcher3/dot/DotInfo.java b/src/com/android/launcher3/dot/DotInfo.java
new file mode 100644
index 000000000..9d0e5d38d
--- /dev/null
+++ b/src/com/android/launcher3/dot/DotInfo.java
@@ -0,0 +1,109 @@
+/*
+ * 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.dot;
+
+import com.android.launcher3.notification.NotificationInfo;
+import com.android.launcher3.notification.NotificationKeyData;
+import com.android.launcher3.util.PackageUserKey;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Contains data to be used for a notification dot.
+ */
+public class DotInfo {
+
+ public static final int MAX_COUNT = 999;
+
+ /** Used to link this DotInfo to icons on the workspace and all apps */
+ private PackageUserKey mPackageUserKey;
+
+ /**
+ * The keys of the notifications that this dot represents. These keys can later be
+ * used to retrieve {@link NotificationInfo}'s.
+ */
+ private List<NotificationKeyData> mNotificationKeys;
+
+ /**
+ * The current sum of the counts in {@link #mNotificationKeys},
+ * updated whenever a key is added or removed.
+ */
+ private int mTotalCount;
+
+ public DotInfo(PackageUserKey packageUserKey) {
+ mPackageUserKey = packageUserKey;
+ mNotificationKeys = new ArrayList<>();
+ }
+
+ /**
+ * Returns whether the notification was added or its count changed.
+ */
+ public boolean addOrUpdateNotificationKey(NotificationKeyData notificationKey) {
+ int indexOfPrevKey = mNotificationKeys.indexOf(notificationKey);
+ NotificationKeyData prevKey = indexOfPrevKey == -1 ? null
+ : mNotificationKeys.get(indexOfPrevKey);
+ if (prevKey != null) {
+ if (prevKey.count == notificationKey.count) {
+ return false;
+ }
+ // Notification was updated with a new count.
+ mTotalCount -= prevKey.count;
+ mTotalCount += notificationKey.count;
+ prevKey.count = notificationKey.count;
+ return true;
+ }
+ boolean added = mNotificationKeys.add(notificationKey);
+ if (added) {
+ mTotalCount += notificationKey.count;
+ }
+ return added;
+ }
+
+ /**
+ * Returns whether the notification was removed (false if it didn't exist).
+ */
+ public boolean removeNotificationKey(NotificationKeyData notificationKey) {
+ boolean removed = mNotificationKeys.remove(notificationKey);
+ if (removed) {
+ mTotalCount -= notificationKey.count;
+ }
+ return removed;
+ }
+
+ public List<NotificationKeyData> getNotificationKeys() {
+ return mNotificationKeys;
+ }
+
+ public int getNotificationCount() {
+ return Math.min(mTotalCount, MAX_COUNT);
+ }
+
+ /**
+ * TODO: this is outdated now that we only show dots instead of icons/numbers. can remove?
+ * Whether newDot represents the same PackageUserKey as this badge, and icons with
+ * this badge should be invalidated. So, for instance, if a badge has 3 notifications
+ * and one of those notifications is updated, this method should return false because
+ * the badge still says "3" and the contents of those notifications are only retrieved
+ * upon long-click. This method always returns true when adding or removing notifications,
+ * or if the badge has a notification icon to show.
+ */
+ public boolean shouldBeInvalidated(DotInfo newDot) {
+ return mPackageUserKey.equals(newDot.mPackageUserKey)
+ && (getNotificationCount() != newDot.getNotificationCount());
+ }
+}
diff --git a/src/com/android/launcher3/dot/FolderDotInfo.java b/src/com/android/launcher3/dot/FolderDotInfo.java
new file mode 100644
index 000000000..b5eb8cd58
--- /dev/null
+++ b/src/com/android/launcher3/dot/FolderDotInfo.java
@@ -0,0 +1,64 @@
+/*
+ * 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.dot;
+
+import android.view.ViewDebug;
+
+import com.android.launcher3.Utilities;
+
+/**
+ * Subclass of DotInfo that only contains the dot count, which is
+ * the sum of all the Folder's items' notifications (each counts as 1).
+ */
+public class FolderDotInfo extends DotInfo {
+
+ private static final int MIN_COUNT = 0;
+
+ private int mNumNotifications;
+
+ public FolderDotInfo() {
+ super(null);
+ }
+
+ public void addDotInfo(DotInfo dotToAdd) {
+ if (dotToAdd == null) {
+ return;
+ }
+ mNumNotifications += dotToAdd.getNotificationKeys().size();
+ mNumNotifications = Utilities.boundToRange(
+ mNumNotifications, MIN_COUNT, DotInfo.MAX_COUNT);
+ }
+
+ public void subtractDotInfo(DotInfo dotToSubtract) {
+ if (dotToSubtract == null) {
+ return;
+ }
+ mNumNotifications -= dotToSubtract.getNotificationKeys().size();
+ mNumNotifications = Utilities.boundToRange(
+ mNumNotifications, MIN_COUNT, DotInfo.MAX_COUNT);
+ }
+
+ @Override
+ public int getNotificationCount() {
+ return mNumNotifications;
+ }
+
+ @ViewDebug.ExportedProperty(category = "launcher")
+ public boolean hasDot() {
+ return mNumNotifications > 0;
+ }
+}