blob: 6eb0646afaea327fa223589e4d9f0b4c4970cc0d [file] [log] [blame]
Jason Monkabe19742015-09-29 09:47:06 -04001/*
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 */
16package com.android.systemui.qs.tiles;
17
18import android.content.Context;
19import android.graphics.drawable.Drawable;
20import android.util.Pair;
Chris Wrenf6e9228b2016-01-26 18:04:35 -050021import com.android.internal.logging.MetricsProto.MetricsEvent;
Jason Monkabe19742015-09-29 09:47:06 -040022import com.android.systemui.qs.QSTile;
23import com.android.systemui.statusbar.policy.UserInfoController;
24import com.android.systemui.statusbar.policy.UserSwitcherController;
25
26public class UserTile extends QSTile<QSTile.State> implements UserInfoController.OnUserInfoChangedListener {
27
28 private final UserSwitcherController mUserSwitcherController;
29 private final UserInfoController mUserInfoController;
30 private Pair<String, Drawable> mLastUpdate;
31
32 public UserTile(Host host) {
33 super(host);
34 mUserSwitcherController = host.getUserSwitcherController();
35 mUserInfoController = host.getUserInfoController();
36 }
37
38 @Override
39 protected State newTileState() {
40 return new QSTile.State();
41 }
42
43 @Override
44 protected void handleClick() {
45 showDetail(true);
46 }
47
48 @Override
49 public DetailAdapter getDetailAdapter() {
50 return mUserSwitcherController.userDetailAdapter;
51 }
52
53 @Override
54 public int getMetricsCategory() {
Chris Wrenf6e9228b2016-01-26 18:04:35 -050055 return MetricsEvent.QS_USER_TILE;
Jason Monkabe19742015-09-29 09:47:06 -040056 }
57
58 @Override
59 public void setListening(boolean listening) {
60 if (listening) {
61 mUserInfoController.addListener(this);
62 } else {
63 mUserInfoController.remListener(this);
64 }
65 }
66
67 @Override
68 protected void handleUpdateState(State state, Object arg) {
69 final Pair<String, Drawable> p = arg != null ? (Pair<String, Drawable>) arg : mLastUpdate;
Jason Monkba2318e2015-12-08 09:04:23 -050070 if (p != null) {
71 state.label = p.first;
72 // TODO: Better content description.
73 state.contentDescription = p.first;
74 state.icon = new Icon() {
75 @Override
76 public Drawable getDrawable(Context context) {
77 return p.second;
78 }
79 };
80 } else {
81 // TODO: Default state.
82 }
Jason Monkabe19742015-09-29 09:47:06 -040083 }
84
85 @Override
86 public void onUserInfoChanged(String name, Drawable picture) {
87 mLastUpdate = new Pair<>(name, picture);
88 refreshState(mLastUpdate);
89 }
90}