blob: c524edca5148edd203dfe2e802469a90238afce0 [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;
Adrian Roos19408922014-08-07 20:54:12 +020020import com.android.systemui.qs.PseudoGridView;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020021import com.android.systemui.statusbar.policy.UserSwitcherController;
22
23import android.content.Context;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020024import android.util.AttributeSet;
25import android.view.LayoutInflater;
26import android.view.View;
27import android.view.ViewGroup;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020028
29/**
30 * Quick settings detail view for user switching.
31 */
Adrian Roos19408922014-08-07 20:54:12 +020032public class UserDetailView extends PseudoGridView {
Adrian Roos00a0b1f2014-07-16 16:44:49 +020033
Adrian Roos19408922014-08-07 20:54:12 +020034 private Adapter mAdapter;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020035
36 public UserDetailView(Context context, AttributeSet attrs) {
Adrian Roos19408922014-08-07 20:54:12 +020037 super(context, attrs);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020038 }
39
40 public static UserDetailView inflate(Context context, ViewGroup parent, boolean attach) {
41 return (UserDetailView) LayoutInflater.from(context).inflate(
42 R.layout.qs_user_detail, parent, attach);
43 }
44
45 public void createAndSetAdapter(UserSwitcherController controller) {
Adrian Roos19408922014-08-07 20:54:12 +020046 mAdapter = new Adapter(mContext, controller);
47 ViewGroupAdapterBridge.link(this, mAdapter);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020048 }
49
Adrian Roos19408922014-08-07 20:54:12 +020050 public static class Adapter extends UserSwitcherController.BaseUserAdapter
51 implements OnClickListener {
Adrian Roos00a0b1f2014-07-16 16:44:49 +020052
53 private Context mContext;
54
55 public Adapter(Context context, UserSwitcherController controller) {
56 super(controller);
57 mContext = context;
58 }
59
60 @Override
61 public View getView(int position, View convertView, ViewGroup parent) {
62 UserSwitcherController.UserRecord item = getItem(position);
63 UserDetailItemView v = UserDetailItemView.convertOrInflate(
64 mContext, convertView, parent);
Adrian Roos19408922014-08-07 20:54:12 +020065 if (v != convertView) {
66 v.setOnClickListener(this);
67 }
Adrian Roose9c7d432014-07-17 18:27:38 +020068 String name = getName(mContext, item);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020069 if (item.picture == null) {
Adrian Roosccdff622014-08-06 00:07:18 +020070 v.bind(name, getDrawable(mContext, item));
Adrian Roos00a0b1f2014-07-16 16:44:49 +020071 } else {
72 v.bind(name, item.picture);
73 }
74 v.setActivated(item.isCurrent);
75 v.setTag(item);
76 return v;
77 }
Adrian Roos19408922014-08-07 20:54:12 +020078
79 @Override
80 public void onClick(View view) {
81 UserSwitcherController.UserRecord tag =
82 (UserSwitcherController.UserRecord) view.getTag();
83 switchTo(tag);
84 }
Adrian Roos00a0b1f2014-07-16 16:44:49 +020085 }
86}