blob: d4f54b64adc2335d66534e15047632fdc8ec8731 [file] [log] [blame]
Adrian Roos00a0b1f2014-07-16 16:44:49 +02001/*
2 * Copyright (C) 2014 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
17package com.android.systemui.qs.tiles;
18
Chris Wren9e7283f2015-05-08 17:23:47 -040019import com.android.internal.logging.MetricsLogger;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020020import com.android.systemui.R;
Adrian Roos19408922014-08-07 20:54:12 +020021import com.android.systemui.qs.PseudoGridView;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020022import com.android.systemui.statusbar.policy.UserSwitcherController;
23
24import android.content.Context;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020025import android.util.AttributeSet;
26import android.view.LayoutInflater;
27import android.view.View;
28import android.view.ViewGroup;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020029
30/**
31 * Quick settings detail view for user switching.
32 */
Adrian Roos19408922014-08-07 20:54:12 +020033public class UserDetailView extends PseudoGridView {
Adrian Roos00a0b1f2014-07-16 16:44:49 +020034
Adrian Roos19408922014-08-07 20:54:12 +020035 private Adapter mAdapter;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020036
37 public UserDetailView(Context context, AttributeSet attrs) {
Adrian Roos19408922014-08-07 20:54:12 +020038 super(context, attrs);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020039 }
40
41 public static UserDetailView inflate(Context context, ViewGroup parent, boolean attach) {
42 return (UserDetailView) LayoutInflater.from(context).inflate(
43 R.layout.qs_user_detail, parent, attach);
44 }
45
46 public void createAndSetAdapter(UserSwitcherController controller) {
Adrian Roos19408922014-08-07 20:54:12 +020047 mAdapter = new Adapter(mContext, controller);
48 ViewGroupAdapterBridge.link(this, mAdapter);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020049 }
50
Adrian Roos844c92b2014-12-01 14:19:05 +010051 public void refreshAdapter() {
52 mAdapter.refresh();
53 }
54
Adrian Roos19408922014-08-07 20:54:12 +020055 public static class Adapter extends UserSwitcherController.BaseUserAdapter
56 implements OnClickListener {
Adrian Roos00a0b1f2014-07-16 16:44:49 +020057
58 private Context mContext;
59
60 public Adapter(Context context, UserSwitcherController controller) {
61 super(controller);
62 mContext = context;
63 }
64
65 @Override
66 public View getView(int position, View convertView, ViewGroup parent) {
67 UserSwitcherController.UserRecord item = getItem(position);
68 UserDetailItemView v = UserDetailItemView.convertOrInflate(
69 mContext, convertView, parent);
Adrian Roos19408922014-08-07 20:54:12 +020070 if (v != convertView) {
71 v.setOnClickListener(this);
72 }
Adrian Roose9c7d432014-07-17 18:27:38 +020073 String name = getName(mContext, item);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020074 if (item.picture == null) {
Adrian Roosccdff622014-08-06 00:07:18 +020075 v.bind(name, getDrawable(mContext, item));
Adrian Roos00a0b1f2014-07-16 16:44:49 +020076 } else {
77 v.bind(name, item.picture);
78 }
79 v.setActivated(item.isCurrent);
80 v.setTag(item);
81 return v;
82 }
Adrian Roos19408922014-08-07 20:54:12 +020083
84 @Override
85 public void onClick(View view) {
86 UserSwitcherController.UserRecord tag =
87 (UserSwitcherController.UserRecord) view.getTag();
Chris Wren9e7283f2015-05-08 17:23:47 -040088 MetricsLogger.action(mContext, MetricsLogger.QS_SWITCH_USER);
Adrian Roos19408922014-08-07 20:54:12 +020089 switchTo(tag);
90 }
Adrian Roos00a0b1f2014-07-16 16:44:49 +020091 }
92}