blob: b44ef0b46493098feb3e0864720458887a5d45eb [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
Adrian Roos00a0b1f2014-07-16 16:44:49 +020019import android.content.Context;
Sudheer Shanka1c7cda82015-12-31 14:46:02 +000020import android.content.Intent;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020021import android.util.AttributeSet;
22import android.view.LayoutInflater;
23import android.view.View;
24import android.view.ViewGroup;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020025
Sudheer Shanka1c7cda82015-12-31 14:46:02 +000026import com.android.internal.logging.MetricsLogger;
27import com.android.settingslib.RestrictedLockUtils;
28import com.android.systemui.R;
29import com.android.systemui.qs.PseudoGridView;
30import com.android.systemui.statusbar.policy.UserSwitcherController;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020031/**
32 * Quick settings detail view for user switching.
33 */
Adrian Roos19408922014-08-07 20:54:12 +020034public class UserDetailView extends PseudoGridView {
Adrian Roos00a0b1f2014-07-16 16:44:49 +020035
Adrian Roos19408922014-08-07 20:54:12 +020036 private Adapter mAdapter;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020037
38 public UserDetailView(Context context, AttributeSet attrs) {
Adrian Roos19408922014-08-07 20:54:12 +020039 super(context, attrs);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020040 }
41
42 public static UserDetailView inflate(Context context, ViewGroup parent, boolean attach) {
43 return (UserDetailView) LayoutInflater.from(context).inflate(
44 R.layout.qs_user_detail, parent, attach);
45 }
46
47 public void createAndSetAdapter(UserSwitcherController controller) {
Adrian Roos19408922014-08-07 20:54:12 +020048 mAdapter = new Adapter(mContext, controller);
49 ViewGroupAdapterBridge.link(this, mAdapter);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020050 }
51
Adrian Roos844c92b2014-12-01 14:19:05 +010052 public void refreshAdapter() {
53 mAdapter.refresh();
54 }
55
Adrian Roos19408922014-08-07 20:54:12 +020056 public static class Adapter extends UserSwitcherController.BaseUserAdapter
57 implements OnClickListener {
Adrian Roos00a0b1f2014-07-16 16:44:49 +020058
Sudheer Shanka1c7cda82015-12-31 14:46:02 +000059 private final Context mContext;
60 private final UserSwitcherController mController;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020061
62 public Adapter(Context context, UserSwitcherController controller) {
63 super(controller);
64 mContext = context;
Sudheer Shanka1c7cda82015-12-31 14:46:02 +000065 mController = controller;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020066 }
67
68 @Override
69 public View getView(int position, View convertView, ViewGroup parent) {
70 UserSwitcherController.UserRecord item = getItem(position);
71 UserDetailItemView v = UserDetailItemView.convertOrInflate(
72 mContext, convertView, parent);
Adrian Roos19408922014-08-07 20:54:12 +020073 if (v != convertView) {
74 v.setOnClickListener(this);
75 }
Adrian Roose9c7d432014-07-17 18:27:38 +020076 String name = getName(mContext, item);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020077 if (item.picture == null) {
Adrian Roosccdff622014-08-06 00:07:18 +020078 v.bind(name, getDrawable(mContext, item));
Adrian Roos00a0b1f2014-07-16 16:44:49 +020079 } else {
80 v.bind(name, item.picture);
81 }
82 v.setActivated(item.isCurrent);
Sudheer Shanka1c7cda82015-12-31 14:46:02 +000083 v.setDisabledByAdmin(item.isDisabledByAdmin);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020084 v.setTag(item);
85 return v;
86 }
Adrian Roos19408922014-08-07 20:54:12 +020087
88 @Override
89 public void onClick(View view) {
90 UserSwitcherController.UserRecord tag =
91 (UserSwitcherController.UserRecord) view.getTag();
Sudheer Shanka1c7cda82015-12-31 14:46:02 +000092 if (tag.isDisabledByAdmin) {
93 final Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(
94 mContext, tag.enforcedAdmin);
95 mController.startActivity(intent);
96 } else {
97 MetricsLogger.action(mContext, MetricsLogger.QS_SWITCH_USER);
98 switchTo(tag);
99 }
Adrian Roos19408922014-08-07 20:54:12 +0200100 }
Adrian Roos00a0b1f2014-07-16 16:44:49 +0200101 }
102}