blob: 2c8a4784e5f2afd03c0dd214cce78fb763766be1 [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;
Chris Wrenf6e9228b2016-01-26 18:04:35 -050027import com.android.internal.logging.MetricsProto.MetricsEvent;
Sudheer Shanka1c7cda82015-12-31 14:46:02 +000028import com.android.settingslib.RestrictedLockUtils;
29import com.android.systemui.R;
30import com.android.systemui.qs.PseudoGridView;
31import com.android.systemui.statusbar.policy.UserSwitcherController;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020032/**
33 * Quick settings detail view for user switching.
34 */
Adrian Roos19408922014-08-07 20:54:12 +020035public class UserDetailView extends PseudoGridView {
Adrian Roos00a0b1f2014-07-16 16:44:49 +020036
Adrian Roos19408922014-08-07 20:54:12 +020037 private Adapter mAdapter;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020038
39 public UserDetailView(Context context, AttributeSet attrs) {
Adrian Roos19408922014-08-07 20:54:12 +020040 super(context, attrs);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020041 }
42
43 public static UserDetailView inflate(Context context, ViewGroup parent, boolean attach) {
44 return (UserDetailView) LayoutInflater.from(context).inflate(
45 R.layout.qs_user_detail, parent, attach);
46 }
47
48 public void createAndSetAdapter(UserSwitcherController controller) {
Adrian Roos19408922014-08-07 20:54:12 +020049 mAdapter = new Adapter(mContext, controller);
50 ViewGroupAdapterBridge.link(this, mAdapter);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020051 }
52
Adrian Roos844c92b2014-12-01 14:19:05 +010053 public void refreshAdapter() {
54 mAdapter.refresh();
55 }
56
Adrian Roos19408922014-08-07 20:54:12 +020057 public static class Adapter extends UserSwitcherController.BaseUserAdapter
58 implements OnClickListener {
Adrian Roos00a0b1f2014-07-16 16:44:49 +020059
Sudheer Shanka1c7cda82015-12-31 14:46:02 +000060 private final Context mContext;
61 private final UserSwitcherController mController;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020062
63 public Adapter(Context context, UserSwitcherController controller) {
64 super(controller);
65 mContext = context;
Sudheer Shanka1c7cda82015-12-31 14:46:02 +000066 mController = controller;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020067 }
68
69 @Override
70 public View getView(int position, View convertView, ViewGroup parent) {
71 UserSwitcherController.UserRecord item = getItem(position);
72 UserDetailItemView v = UserDetailItemView.convertOrInflate(
73 mContext, convertView, parent);
Adrian Roos19408922014-08-07 20:54:12 +020074 if (v != convertView) {
75 v.setOnClickListener(this);
76 }
Adrian Roose9c7d432014-07-17 18:27:38 +020077 String name = getName(mContext, item);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020078 if (item.picture == null) {
Adrian Roosccdff622014-08-06 00:07:18 +020079 v.bind(name, getDrawable(mContext, item));
Adrian Roos00a0b1f2014-07-16 16:44:49 +020080 } else {
81 v.bind(name, item.picture);
82 }
83 v.setActivated(item.isCurrent);
Sudheer Shanka1c7cda82015-12-31 14:46:02 +000084 v.setDisabledByAdmin(item.isDisabledByAdmin);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020085 v.setTag(item);
86 return v;
87 }
Adrian Roos19408922014-08-07 20:54:12 +020088
89 @Override
90 public void onClick(View view) {
91 UserSwitcherController.UserRecord tag =
92 (UserSwitcherController.UserRecord) view.getTag();
Sudheer Shanka1c7cda82015-12-31 14:46:02 +000093 if (tag.isDisabledByAdmin) {
94 final Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(
95 mContext, tag.enforcedAdmin);
96 mController.startActivity(intent);
97 } else {
Chris Wrenf6e9228b2016-01-26 18:04:35 -050098 MetricsLogger.action(mContext, MetricsEvent.QS_SWITCH_USER);
Sudheer Shanka1c7cda82015-12-31 14:46:02 +000099 switchTo(tag);
100 }
Adrian Roos19408922014-08-07 20:54:12 +0200101 }
Adrian Roos00a0b1f2014-07-16 16:44:49 +0200102 }
103}