1 /* 2 * Copyright (C) 2019 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 package com.android.launcher3.model; 17 18 import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP; 19 import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_HOTSEAT; 20 import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET; 21 import static com.android.launcher3.LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET; 22 23 import com.android.launcher3.model.data.ItemInfo; 24 import com.android.launcher3.util.IntSet; 25 26 import java.util.function.Predicate; 27 28 /** 29 * Utils class for {@link com.android.launcher3.LauncherModel}. 30 */ 31 public class ModelUtils { 32 33 /** 34 * Returns a filter for items on hotseat or current screens 35 */ currentScreenContentFilter(IntSet currentScreenIds)36 public static Predicate<ItemInfo> currentScreenContentFilter(IntSet currentScreenIds) { 37 return item -> item.container == CONTAINER_HOTSEAT 38 || (item.container == CONTAINER_DESKTOP 39 && currentScreenIds.contains(item.screenId)); 40 } 41 42 /** 43 * Returns a filter for widget items 44 */ 45 public static final Predicate<ItemInfo> WIDGET_FILTER = item -> 46 item.itemType == ITEM_TYPE_APPWIDGET || item.itemType == ITEM_TYPE_CUSTOM_APPWIDGET; 47 } 48