1 /*
2  * Copyright (C) 2023 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.systemui.car.userpicker;
18 
19 import android.annotation.IntDef;
20 
21 import androidx.annotation.NonNull;
22 
23 import com.android.systemui.car.userpicker.UserPickerController.Callbacks;
24 
25 import java.lang.annotation.Retention;
26 import java.lang.annotation.RetentionPolicy;
27 
28 final class HeaderState {
29     static final int HEADER_STATE_LOGOUT = 1;
30     static final int HEADER_STATE_CHANGE_USER = 2;
31 
32     @IntDef(prefix = { "HEADER_STATE_" }, value = {
33             HEADER_STATE_LOGOUT,
34             HEADER_STATE_CHANGE_USER,
35     })
36     @Retention(RetentionPolicy.SOURCE)
37     public @interface HeaderStateType {}
38 
39     private Callbacks mCallbacks;
40 
41     private int mState;
42 
HeaderState(Callbacks callbacks)43     HeaderState(Callbacks callbacks) {
44         mCallbacks = callbacks;
45     }
46 
setState(@eaderStateType int state)47     void setState(@HeaderStateType int state) {
48         if (mState != state) {
49             mState = state;
50             mCallbacks.onHeaderStateChanged(this);
51         }
52     }
53 
getState()54     @HeaderStateType int getState() {
55         return mState;
56     }
57 
58     @NonNull
59     @Override
toString()60     public String toString() {
61         StringBuilder sb = new StringBuilder();
62         sb.append(getClass().getSimpleName()).append("@").append(Integer.toHexString(hashCode()));
63         sb.append(" [").append("mState=").append(stateToString(mState)).append(" mCallbacks=")
64                 .append(mCallbacks).append("]");
65         return sb.toString();
66     }
67 
stateToString(int state)68     private String stateToString(int state) {
69         switch (state) {
70             case HEADER_STATE_CHANGE_USER:
71                 return "HEADER_STATE_CHANGE_USER";
72             case HEADER_STATE_LOGOUT:
73                 return "HEADER_STATE_LOGOUT";
74             default:
75                 return null;
76         }
77     }
78 }
79