Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package com.android.systemui.qs.tiles; |
| 17 | |
| 18 | import android.content.Context; |
| 19 | import android.graphics.drawable.Drawable; |
| 20 | import android.util.Pair; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 21 | import com.android.internal.logging.MetricsProto.MetricsEvent; |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 22 | import com.android.systemui.qs.QSTile; |
| 23 | import com.android.systemui.statusbar.policy.UserInfoController; |
| 24 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
| 25 | |
| 26 | public 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 Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 55 | return MetricsEvent.QS_USER_TILE; |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 56 | } |
| 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 Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 70 | 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 Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public void onUserInfoChanged(String name, Drawable picture) { |
| 87 | mLastUpdate = new Pair<>(name, picture); |
| 88 | refreshState(mLastUpdate); |
| 89 | } |
| 90 | } |