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 androidx.annotation.IntDef; 20 21 import com.android.launcher3.LauncherSettings; 22 23 import java.lang.annotation.Retention; 24 import java.lang.annotation.RetentionPolicy; 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 @Retention(RetentionPolicy.SOURCE) 32 @IntDef({NO_CATEGORY, CONVERSATIONS}) 33 public @interface Category{} 34 /** The package is not categorized in the widget tray. */ 35 public static final int NO_CATEGORY = 0; 36 /** The package is categorized to conversations widget in the widget tray. */ 37 public static final int CONVERSATIONS = 1; 38 39 /** 40 * Package name of the {@link PackageItemInfo}. 41 */ 42 public final String packageName; 43 44 /** Represents a widget category shown in the widget tray section. */ 45 @Category public final int category; 46 PackageItemInfo(String packageName)47 public PackageItemInfo(String packageName) { 48 this(packageName, NO_CATEGORY); 49 } 50 PackageItemInfo(String packageName, @Category int category)51 public PackageItemInfo(String packageName, @Category int category) { 52 this.packageName = packageName; 53 this.category = category; 54 this.itemType = LauncherSettings.Favorites.ITEM_TYPE_NON_ACTIONABLE; 55 } 56 PackageItemInfo(PackageItemInfo copy)57 public PackageItemInfo(PackageItemInfo copy) { 58 this.packageName = copy.packageName; 59 this.category = copy.category; 60 this.itemType = LauncherSettings.Favorites.ITEM_TYPE_NON_ACTIONABLE; 61 } 62 63 @Override dumpProperties()64 protected String dumpProperties() { 65 return super.dumpProperties() + " packageName=" + packageName; 66 } 67 68 @Override clone()69 public PackageItemInfo clone() { 70 return new PackageItemInfo(this); 71 } 72 73 @Override equals(Object o)74 public boolean equals(Object o) { 75 if (this == o) return true; 76 if (o == null || getClass() != o.getClass()) return false; 77 PackageItemInfo that = (PackageItemInfo) o; 78 return Objects.equals(packageName, that.packageName); 79 } 80 81 @Override hashCode()82 public int hashCode() { 83 return Objects.hash(packageName, user); 84 } 85 } 86