1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.launcher3.badge; 18 19 import com.android.launcher3.Utilities; 20 21 /** 22 * Subclass of BadgeInfo that only contains the badge count, which is 23 * the sum of all the Folder's items' notifications (each counts as 1). 24 */ 25 public class FolderBadgeInfo extends BadgeInfo { 26 27 private static final int MIN_COUNT = 0; 28 29 private int mNumNotifications; 30 FolderBadgeInfo()31 public FolderBadgeInfo() { 32 super(null); 33 } 34 addBadgeInfo(BadgeInfo badgeToAdd)35 public void addBadgeInfo(BadgeInfo badgeToAdd) { 36 if (badgeToAdd == null) { 37 return; 38 } 39 mNumNotifications += badgeToAdd.getNotificationKeys().size(); 40 mNumNotifications = Utilities.boundToRange( 41 mNumNotifications, MIN_COUNT, BadgeInfo.MAX_COUNT); 42 } 43 subtractBadgeInfo(BadgeInfo badgeToSubtract)44 public void subtractBadgeInfo(BadgeInfo badgeToSubtract) { 45 if (badgeToSubtract == null) { 46 return; 47 } 48 mNumNotifications -= badgeToSubtract.getNotificationKeys().size(); 49 mNumNotifications = Utilities.boundToRange( 50 mNumNotifications, MIN_COUNT, BadgeInfo.MAX_COUNT); 51 } 52 53 @Override getNotificationCount()54 public int getNotificationCount() { 55 // This forces the folder badge to always show up as a dot. 56 return 0; 57 } 58 hasBadge()59 public boolean hasBadge() { 60 return mNumNotifications > 0; 61 } 62 } 63