blob: 67eef568ead24c262262ac423ca17804a78aa01c [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
19import com.android.systemui.R;
20import com.android.systemui.statusbar.policy.UserSwitcherController;
21
22import android.content.Context;
23import android.content.Intent;
24import android.util.AttributeSet;
25import android.view.LayoutInflater;
26import android.view.View;
27import android.view.ViewGroup;
28import android.widget.AdapterView;
29import android.widget.GridView;
30
31/**
32 * Quick settings detail view for user switching.
33 */
34public class UserDetailView extends GridView {
35
36 public UserDetailView(Context context) {
37 this(context, null);
38 }
39
40 public UserDetailView(Context context, AttributeSet attrs) {
41 this(context, attrs, android.R.attr.gridViewStyle);
42 }
43
44 public UserDetailView(Context context, AttributeSet attrs, int defStyleAttr) {
45 this(context, attrs, defStyleAttr, 0);
46 }
47
48 public UserDetailView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
49 super(context, attrs, defStyleAttr, defStyleRes);
50
51 setOnItemClickListener(new OnItemClickListener() {
52 @Override
53 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
54 UserSwitcherController.UserRecord tag =
55 (UserSwitcherController.UserRecord) view.getTag();
56 ((Adapter)getAdapter()).switchTo(tag);
57 }
58 });
59 }
60
61 public static UserDetailView inflate(Context context, ViewGroup parent, boolean attach) {
62 return (UserDetailView) LayoutInflater.from(context).inflate(
63 R.layout.qs_user_detail, parent, attach);
64 }
65
66 public void createAndSetAdapter(UserSwitcherController controller) {
67 setAdapter(new Adapter(mContext, controller));
68 }
69
70 public static class Adapter extends UserSwitcherController.BaseUserAdapter {
71
72 private Context mContext;
73
74 public Adapter(Context context, UserSwitcherController controller) {
75 super(controller);
76 mContext = context;
77 }
78
79 @Override
80 public View getView(int position, View convertView, ViewGroup parent) {
81 UserSwitcherController.UserRecord item = getItem(position);
82 UserDetailItemView v = UserDetailItemView.convertOrInflate(
83 mContext, convertView, parent);
Adrian Roose9c7d432014-07-17 18:27:38 +020084 String name = getName(mContext, item);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020085 if (item.picture == null) {
Adrian Roos19f653e2014-07-17 00:32:13 +020086 v.bind(name, mContext.getDrawable(R.drawable.ic_account_circle_qs));
Adrian Roos00a0b1f2014-07-16 16:44:49 +020087 } else {
88 v.bind(name, item.picture);
89 }
90 v.setActivated(item.isCurrent);
91 v.setTag(item);
92 return v;
93 }
94 }
95}