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; |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 19 | import android.content.Intent; |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 20 | import android.graphics.drawable.Drawable; |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 21 | import android.provider.Settings; |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 22 | import android.util.Pair; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 23 | |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 24 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | 0ceef21 | 2016-11-02 14:05:23 -0400 | [diff] [blame] | 25 | import com.android.systemui.plugins.qs.QS.DetailAdapter; |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 26 | import com.android.systemui.qs.QSTile; |
| 27 | import com.android.systemui.statusbar.policy.UserInfoController; |
| 28 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
| 29 | |
| 30 | public 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 Monk | 62b63a0 | 2016-02-02 15:15:31 -0500 | [diff] [blame] | 43 | public State newTileState() { |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 44 | return new QSTile.State(); |
| 45 | } |
| 46 | |
| 47 | @Override |
Jason Monk | 76c67aa | 2016-02-19 14:49:42 -0500 | [diff] [blame] | 48 | public Intent getLongClickIntent() { |
| 49 | return new Intent(Settings.ACTION_USER_SETTINGS); |
| 50 | } |
| 51 | |
| 52 | @Override |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 53 | 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 Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 64 | return MetricsEvent.QS_USER_TILE; |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public void setListening(boolean listening) { |
| 69 | if (listening) { |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 70 | mUserInfoController.addCallback(this); |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 71 | } else { |
Jason Monk | 8852905 | 2016-11-04 13:29:58 -0400 | [diff] [blame] | 72 | mUserInfoController.removeCallback(this); |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
| 76 | @Override |
Jason Monk | 39c98e6 | 2016-03-16 09:18:35 -0400 | [diff] [blame] | 77 | public CharSequence getTileLabel() { |
| 78 | return getState().label; |
| 79 | } |
| 80 | |
| 81 | @Override |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 82 | protected void handleUpdateState(State state, Object arg) { |
| 83 | final Pair<String, Drawable> p = arg != null ? (Pair<String, Drawable>) arg : mLastUpdate; |
Jason Monk | ba2318e | 2015-12-08 09:04:23 -0500 | [diff] [blame] | 84 | 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 Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | @Override |
Jiaquan He | e120637 | 2016-05-03 14:11:23 -0700 | [diff] [blame] | 100 | public void onUserInfoChanged(String name, Drawable picture, String userAccount) { |
Jason Monk | abe1974 | 2015-09-29 09:47:06 -0400 | [diff] [blame] | 101 | mLastUpdate = new Pair<>(name, picture); |
| 102 | refreshState(mLastUpdate); |
| 103 | } |
| 104 | } |