Sunny Goyal | 3fe4a14 | 2016-12-15 17:40:07 -0800 | [diff] [blame] | 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; |
| 18 | |
Hyunyoung Song | 48cb7bc | 2018-09-25 17:03:34 -0700 | [diff] [blame] | 19 | import static com.android.launcher3.icons.BitmapInfo.LOW_RES_ICON; |
Sunny Goyal | 2b787e5 | 2018-08-20 15:01:03 -0700 | [diff] [blame] | 20 | |
Sunny Goyal | 3fe4a14 | 2016-12-15 17:40:07 -0800 | [diff] [blame] | 21 | import android.graphics.Bitmap; |
| 22 | |
Hyunyoung Song | cda96a5 | 2018-10-18 15:05:45 -0700 | [diff] [blame] | 23 | import com.android.launcher3.icons.BitmapInfo; |
| 24 | |
Sunny Goyal | 3fe4a14 | 2016-12-15 17:40:07 -0800 | [diff] [blame] | 25 | /** |
| 26 | * Represents an ItemInfo which also holds an icon. |
| 27 | */ |
| 28 | public abstract class ItemInfoWithIcon extends ItemInfo { |
| 29 | |
| 30 | /** |
| 31 | * A bitmap version of the application icon. |
| 32 | */ |
| 33 | public Bitmap iconBitmap; |
| 34 | |
| 35 | /** |
Sunny Goyal | 179249d | 2017-12-19 16:49:24 -0800 | [diff] [blame] | 36 | * Dominant color in the {@link #iconBitmap}. |
| 37 | */ |
| 38 | public int iconColor; |
| 39 | |
| 40 | /** |
Sunny Goyal | 076839c | 2017-10-30 13:52:20 -0700 | [diff] [blame] | 41 | * Indicates that the icon is disabled due to safe mode restrictions. |
| 42 | */ |
| 43 | public static final int FLAG_DISABLED_SAFEMODE = 1 << 0; |
| 44 | |
| 45 | /** |
| 46 | * Indicates that the icon is disabled as the app is not available. |
| 47 | */ |
| 48 | public static final int FLAG_DISABLED_NOT_AVAILABLE = 1 << 1; |
| 49 | |
| 50 | /** |
| 51 | * Indicates that the icon is disabled as the app is suspended |
| 52 | */ |
| 53 | public static final int FLAG_DISABLED_SUSPENDED = 1 << 2; |
| 54 | |
| 55 | /** |
| 56 | * Indicates that the icon is disabled as the user is in quiet mode. |
| 57 | */ |
| 58 | public static final int FLAG_DISABLED_QUIET_USER = 1 << 3; |
| 59 | |
| 60 | /** |
| 61 | * Indicates that the icon is disabled as the publisher has disabled the actual shortcut. |
| 62 | */ |
| 63 | public static final int FLAG_DISABLED_BY_PUBLISHER = 1 << 4; |
| 64 | |
| 65 | /** |
| 66 | * Indicates that the icon is disabled as the user partition is currently locked. |
| 67 | */ |
| 68 | public static final int FLAG_DISABLED_LOCKED_USER = 1 << 5; |
| 69 | |
| 70 | public static final int FLAG_DISABLED_MASK = FLAG_DISABLED_SAFEMODE | |
| 71 | FLAG_DISABLED_NOT_AVAILABLE | FLAG_DISABLED_SUSPENDED | |
| 72 | FLAG_DISABLED_QUIET_USER | FLAG_DISABLED_BY_PUBLISHER | FLAG_DISABLED_LOCKED_USER; |
| 73 | |
Sunny Goyal | 076839c | 2017-10-30 13:52:20 -0700 | [diff] [blame] | 74 | /** |
| 75 | * The item points to a system app. |
| 76 | */ |
| 77 | public static final int FLAG_SYSTEM_YES = 1 << 6; |
| 78 | |
| 79 | /** |
| 80 | * The item points to a non system app. |
| 81 | */ |
| 82 | public static final int FLAG_SYSTEM_NO = 1 << 7; |
| 83 | |
| 84 | public static final int FLAG_SYSTEM_MASK = FLAG_SYSTEM_YES | FLAG_SYSTEM_NO; |
| 85 | |
| 86 | /** |
Sunny Goyal | ea52908 | 2017-10-31 13:33:03 -0700 | [diff] [blame] | 87 | * Flag indicating that the icon is an {@link android.graphics.drawable.AdaptiveIconDrawable} |
| 88 | * that can be optimized in various way. |
| 89 | */ |
| 90 | public static final int FLAG_ADAPTIVE_ICON = 1 << 8; |
| 91 | |
| 92 | /** |
Mario Bertschler | d39148a | 2018-04-05 22:44:42 +0200 | [diff] [blame] | 93 | * Flag indicating that the icon is badged. |
| 94 | */ |
| 95 | public static final int FLAG_ICON_BADGED = 1 << 9; |
| 96 | |
| 97 | /** |
Sunny Goyal | 076839c | 2017-10-30 13:52:20 -0700 | [diff] [blame] | 98 | * Status associated with the system state of the underlying item. This is calculated every |
| 99 | * time a new info is created and not persisted on the disk. |
| 100 | */ |
| 101 | public int runtimeStatusFlags = 0; |
| 102 | |
Sunny Goyal | 3fe4a14 | 2016-12-15 17:40:07 -0800 | [diff] [blame] | 103 | protected ItemInfoWithIcon() { } |
| 104 | |
Mario Bertschler | 0fc6f68 | 2017-02-17 12:16:13 -0800 | [diff] [blame] | 105 | protected ItemInfoWithIcon(ItemInfoWithIcon info) { |
Sunny Goyal | 3fe4a14 | 2016-12-15 17:40:07 -0800 | [diff] [blame] | 106 | super(info); |
Mario Bertschler | 0fc6f68 | 2017-02-17 12:16:13 -0800 | [diff] [blame] | 107 | iconBitmap = info.iconBitmap; |
Sunny Goyal | 179249d | 2017-12-19 16:49:24 -0800 | [diff] [blame] | 108 | iconColor = info.iconColor; |
Sunny Goyal | 076839c | 2017-10-30 13:52:20 -0700 | [diff] [blame] | 109 | runtimeStatusFlags = info.runtimeStatusFlags; |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public boolean isDisabled() { |
| 114 | return (runtimeStatusFlags & FLAG_DISABLED_MASK) != 0; |
Sunny Goyal | 3fe4a14 | 2016-12-15 17:40:07 -0800 | [diff] [blame] | 115 | } |
Sunny Goyal | 2b787e5 | 2018-08-20 15:01:03 -0700 | [diff] [blame] | 116 | |
| 117 | /** |
| 118 | * Indicates whether we're using a low res icon |
| 119 | */ |
| 120 | public boolean usingLowResIcon() { |
| 121 | return iconBitmap == LOW_RES_ICON; |
| 122 | } |
Hyunyoung Song | cda96a5 | 2018-10-18 15:05:45 -0700 | [diff] [blame] | 123 | |
| 124 | public void applyFrom(BitmapInfo info) { |
| 125 | iconBitmap = info.icon; |
| 126 | iconColor = info.color; |
| 127 | } |
| 128 | |
Sunny Goyal | 3fe4a14 | 2016-12-15 17:40:07 -0800 | [diff] [blame] | 129 | } |