blob: 91d38bd075bf8fae201bff30df009ef51a6af84c [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;
Tamas Berghammer383db5eb2016-06-22 15:21:38 +010027import com.android.internal.logging.nano.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
Muyuan Li92c91412016-05-04 17:06:29 -070037 protected 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;
Muyuan Li92c91412016-05-04 17:06:29 -070061 protected 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);
Muyuan Li92c91412016-05-04 17:06:29 -070072 return createUserDetailItemView(convertView, parent, item);
73 }
74
75 public UserDetailItemView createUserDetailItemView(View convertView, ViewGroup parent,
76 UserSwitcherController.UserRecord item) {
Adrian Roos00a0b1f2014-07-16 16:44:49 +020077 UserDetailItemView v = UserDetailItemView.convertOrInflate(
78 mContext, convertView, parent);
Adrian Roos19408922014-08-07 20:54:12 +020079 if (v != convertView) {
80 v.setOnClickListener(this);
81 }
Adrian Roose9c7d432014-07-17 18:27:38 +020082 String name = getName(mContext, item);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020083 if (item.picture == null) {
Evan Roskyaa7f51f2016-03-16 13:15:53 -070084 v.bind(name, getDrawable(mContext, item), item.resolveId());
Adrian Roos00a0b1f2014-07-16 16:44:49 +020085 } else {
Evan Roskyaa7f51f2016-03-16 13:15:53 -070086 v.bind(name, item.picture, item.info.id);
Adrian Roos00a0b1f2014-07-16 16:44:49 +020087 }
88 v.setActivated(item.isCurrent);
Sudheer Shanka1c7cda82015-12-31 14:46:02 +000089 v.setDisabledByAdmin(item.isDisabledByAdmin);
Fyodor Kupolov07140f72016-02-17 10:46:11 -080090 if (!item.isSwitchToEnabled) {
91 v.setEnabled(false);
92 }
Adrian Roos00a0b1f2014-07-16 16:44:49 +020093 v.setTag(item);
94 return v;
95 }
Adrian Roos19408922014-08-07 20:54:12 +020096
97 @Override
98 public void onClick(View view) {
99 UserSwitcherController.UserRecord tag =
100 (UserSwitcherController.UserRecord) view.getTag();
Sudheer Shanka1c7cda82015-12-31 14:46:02 +0000101 if (tag.isDisabledByAdmin) {
102 final Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent(
103 mContext, tag.enforcedAdmin);
104 mController.startActivity(intent);
Fyodor Kupolov07140f72016-02-17 10:46:11 -0800105 } else if (tag.isSwitchToEnabled) {
Chris Wrenf6e9228b2016-01-26 18:04:35 -0500106 MetricsLogger.action(mContext, MetricsEvent.QS_SWITCH_USER);
Sudheer Shanka1c7cda82015-12-31 14:46:02 +0000107 switchTo(tag);
108 }
Adrian Roos19408922014-08-07 20:54:12 +0200109 }
Adrian Roos00a0b1f2014-07-16 16:44:49 +0200110 }
111}