1 /* 2 * Copyright (C) 2015 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.model.data; 18 19 import static com.android.launcher3.widget.WidgetSections.NO_CATEGORY; 20 21 import android.os.UserHandle; 22 23 import com.android.launcher3.LauncherSettings; 24 25 import java.util.Objects; 26 27 /** 28 * Represents a {@link Package} in the widget tray section. 29 */ 30 public class PackageItemInfo extends ItemInfoWithIcon { 31 /** 32 * Package name of the {@link PackageItemInfo}. 33 */ 34 public final String packageName; 35 36 /** Represents a widget category shown in the widget tray section. */ 37 public final int widgetCategory; 38 PackageItemInfo(String packageName, UserHandle user)39 public PackageItemInfo(String packageName, UserHandle user) { 40 this(packageName, NO_CATEGORY, user); 41 } 42 PackageItemInfo(String packageName, int widgetCategory, UserHandle user)43 public PackageItemInfo(String packageName, int widgetCategory, UserHandle user) { 44 this.packageName = packageName; 45 this.widgetCategory = widgetCategory; 46 this.user = user; 47 this.itemType = LauncherSettings.Favorites.ITEM_TYPE_NON_ACTIONABLE; 48 } 49 PackageItemInfo(PackageItemInfo copy)50 public PackageItemInfo(PackageItemInfo copy) { 51 this.packageName = copy.packageName; 52 this.widgetCategory = copy.widgetCategory; 53 this.user = copy.user; 54 this.itemType = LauncherSettings.Favorites.ITEM_TYPE_NON_ACTIONABLE; 55 } 56 57 @Override dumpProperties()58 protected String dumpProperties() { 59 return super.dumpProperties() + " packageName=" + packageName; 60 } 61 62 @Override clone()63 public PackageItemInfo clone() { 64 return new PackageItemInfo(this); 65 } 66 67 @Override equals(Object o)68 public boolean equals(Object o) { 69 if (this == o) return true; 70 if (o == null || getClass() != o.getClass()) return false; 71 PackageItemInfo that = (PackageItemInfo) o; 72 return Objects.equals(packageName, that.packageName) 73 && Objects.equals(user, that.user) 74 && widgetCategory == that.widgetCategory; 75 } 76 77 @Override hashCode()78 public int hashCode() { 79 return Objects.hash(packageName, user, widgetCategory); 80 } 81 } 82