blob: 246c23e20f48f39fb3a9debf163af945bbfe39f1 [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;
Jason Monk76c67aa2016-02-19 14:49:42 -050019import android.content.Intent;
Jason Monkabe19742015-09-29 09:47:06 -040020import android.graphics.drawable.Drawable;
Jason Monk76c67aa2016-02-19 14:49:42 -050021import android.provider.Settings;
Jason Monkabe19742015-09-29 09:47:06 -040022import android.util.Pair;
Winsonc0d70582016-01-29 10:24:39 -080023
Tamas Berghammer383db5eb2016-06-22 15:21:38 +010024import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Jason Monk0ceef212016-11-02 14:05:23 -040025import com.android.systemui.plugins.qs.QS.DetailAdapter;
Jason Monkabe19742015-09-29 09:47:06 -040026import com.android.systemui.qs.QSTile;
27import com.android.systemui.statusbar.policy.UserInfoController;
28import com.android.systemui.statusbar.policy.UserSwitcherController;
29
30public class UserTile extends QSTile<QSTile.State> implements UserInfoController.OnUserInfoChangedListener {
31
32 private final UserSwitcherController mUserSwitcherController;
33 private final UserInfoController mUserInfoController;
34 private Pair<String, Drawable> mLastUpdate;
35
36 public UserTile(Host host) {
37 super(host);
38 mUserSwitcherController = host.getUserSwitcherController();
39 mUserInfoController = host.getUserInfoController();
40 }
41
42 @Override
Jason Monk62b63a02016-02-02 15:15:31 -050043 public State newTileState() {
Jason Monkabe19742015-09-29 09:47:06 -040044 return new QSTile.State();
45 }
46
47 @Override
Jason Monk76c67aa2016-02-19 14:49:42 -050048 public Intent getLongClickIntent() {
49 return new Intent(Settings.ACTION_USER_SETTINGS);
50 }
51
52 @Override
Jason Monkabe19742015-09-29 09:47:06 -040053 protected void handleClick() {
54 showDetail(true);
55 }
56
57 @Override
58 public DetailAdapter getDetailAdapter() {
59 return mUserSwitcherController.userDetailAdapter;
60 }
61
62 @Override
63 public int getMetricsCategory() {
Chris Wrenf6e9228b2016-01-26 18:04:35 -050064 return MetricsEvent.QS_USER_TILE;
Jason Monkabe19742015-09-29 09:47:06 -040065 }
66
67 @Override
68 public void setListening(boolean listening) {
69 if (listening) {
Jason Monk88529052016-11-04 13:29:58 -040070 mUserInfoController.addCallback(this);
Jason Monkabe19742015-09-29 09:47:06 -040071 } else {
Jason Monk88529052016-11-04 13:29:58 -040072 mUserInfoController.removeCallback(this);
Jason Monkabe19742015-09-29 09:47:06 -040073 }
74 }
75
76 @Override
Jason Monk39c98e62016-03-16 09:18:35 -040077 public CharSequence getTileLabel() {
78 return getState().label;
79 }
80
81 @Override
Jason Monkabe19742015-09-29 09:47:06 -040082 protected void handleUpdateState(State state, Object arg) {
83 final Pair<String, Drawable> p = arg != null ? (Pair<String, Drawable>) arg : mLastUpdate;
Jason Monkba2318e2015-12-08 09:04:23 -050084 if (p != null) {
85 state.label = p.first;
86 // TODO: Better content description.
87 state.contentDescription = p.first;
88 state.icon = new Icon() {
89 @Override
90 public Drawable getDrawable(Context context) {
91 return p.second;
92 }
93 };
94 } else {
95 // TODO: Default state.
96 }
Jason Monkabe19742015-09-29 09:47:06 -040097 }
98
99 @Override
Jiaquan Hee1206372016-05-03 14:11:23 -0700100 public void onUserInfoChanged(String name, Drawable picture, String userAccount) {
Jason Monkabe19742015-09-29 09:47:06 -0400101 mLastUpdate = new Pair<>(name, picture);
102 refreshState(mLastUpdate);
103 }
104}