1 /*
2  * Copyright (C) 2013 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.util;
18 
19 import static com.android.launcher3.icons.BitmapInfo.FLAG_CLONE;
20 import static com.android.launcher3.icons.BitmapInfo.FLAG_PRIVATE;
21 import static com.android.launcher3.icons.BitmapInfo.FLAG_WORK;
22 
23 import android.os.UserHandle;
24 
25 import androidx.annotation.IntDef;
26 import androidx.annotation.NonNull;
27 
28 /**
29  * Data class which stores various properties of a {@link android.os.UserHandle}
30  * which affects rendering
31  */
32 public class UserIconInfo {
33 
34     public static final int TYPE_MAIN = 0;
35     public static final int TYPE_WORK = 1;
36     public static final int TYPE_CLONED = 2;
37 
38     public static final int TYPE_PRIVATE = 3;
39 
40     @IntDef({TYPE_MAIN, TYPE_WORK, TYPE_CLONED, TYPE_PRIVATE})
41     public @interface UserType { }
42 
43     public final UserHandle user;
44     @UserType
45     public final int type;
46 
47     public final long userSerial;
48 
UserIconInfo(UserHandle user, @UserType int type)49     public UserIconInfo(UserHandle user, @UserType int type) {
50         this(user, type, user != null ? user.hashCode() : 0);
51     }
52 
UserIconInfo(UserHandle user, @UserType int type, long userSerial)53     public UserIconInfo(UserHandle user, @UserType int type, long userSerial) {
54         this.user = user;
55         this.type = type;
56         this.userSerial = userSerial;
57     }
58 
isMain()59     public boolean isMain() {
60         return type == TYPE_MAIN;
61     }
62 
isWork()63     public boolean isWork() {
64         return type == TYPE_WORK;
65     }
66 
isCloned()67     public boolean isCloned() {
68         return type == TYPE_CLONED;
69     }
70 
isPrivate()71     public boolean isPrivate() {
72         return type == TYPE_PRIVATE;
73     }
74 
75     @NonNull
applyBitmapInfoFlags(@onNull FlagOp op)76     public FlagOp applyBitmapInfoFlags(@NonNull FlagOp op) {
77         return op.setFlag(FLAG_WORK, isWork())
78                 .setFlag(FLAG_CLONE, isCloned())
79                 .setFlag(FLAG_PRIVATE, isPrivate());
80     }
81 }
82