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