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