Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.systemui.qs.tiles; |
| 18 | |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 19 | import android.content.Context; |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame] | 20 | import android.content.Intent; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 21 | import android.util.AttributeSet; |
| 22 | import android.view.LayoutInflater; |
| 23 | import android.view.View; |
| 24 | import android.view.ViewGroup; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 25 | |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame] | 26 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | cbd3f0c | 2016-06-22 15:21:38 +0100 | [diff] [blame^] | 27 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame] | 28 | import com.android.settingslib.RestrictedLockUtils; |
| 29 | import com.android.systemui.R; |
| 30 | import com.android.systemui.qs.PseudoGridView; |
| 31 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 32 | /** |
| 33 | * Quick settings detail view for user switching. |
| 34 | */ |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 35 | public class UserDetailView extends PseudoGridView { |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 36 | |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 37 | private Adapter mAdapter; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 38 | |
| 39 | public UserDetailView(Context context, AttributeSet attrs) { |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 40 | super(context, attrs); |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 41 | } |
| 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 Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 49 | mAdapter = new Adapter(mContext, controller); |
| 50 | ViewGroupAdapterBridge.link(this, mAdapter); |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 51 | } |
| 52 | |
Adrian Roos | 844c92b | 2014-12-01 14:19:05 +0100 | [diff] [blame] | 53 | public void refreshAdapter() { |
| 54 | mAdapter.refresh(); |
| 55 | } |
| 56 | |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 57 | public static class Adapter extends UserSwitcherController.BaseUserAdapter |
| 58 | implements OnClickListener { |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 59 | |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame] | 60 | private final Context mContext; |
| 61 | private final UserSwitcherController mController; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 62 | |
| 63 | public Adapter(Context context, UserSwitcherController controller) { |
| 64 | super(controller); |
| 65 | mContext = context; |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame] | 66 | mController = controller; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 67 | } |
| 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 Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 74 | if (v != convertView) { |
| 75 | v.setOnClickListener(this); |
| 76 | } |
Adrian Roos | e9c7d43 | 2014-07-17 18:27:38 +0200 | [diff] [blame] | 77 | String name = getName(mContext, item); |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 78 | if (item.picture == null) { |
Evan Rosky | aa7f51f | 2016-03-16 13:15:53 -0700 | [diff] [blame] | 79 | v.bind(name, getDrawable(mContext, item), item.resolveId()); |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 80 | } else { |
Evan Rosky | aa7f51f | 2016-03-16 13:15:53 -0700 | [diff] [blame] | 81 | v.bind(name, item.picture, item.info.id); |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 82 | } |
| 83 | v.setActivated(item.isCurrent); |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame] | 84 | v.setDisabledByAdmin(item.isDisabledByAdmin); |
Fyodor Kupolov | 07140f7 | 2016-02-17 10:46:11 -0800 | [diff] [blame] | 85 | if (!item.isSwitchToEnabled) { |
| 86 | v.setEnabled(false); |
| 87 | } |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 88 | v.setTag(item); |
| 89 | return v; |
| 90 | } |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 91 | |
| 92 | @Override |
| 93 | public void onClick(View view) { |
| 94 | UserSwitcherController.UserRecord tag = |
| 95 | (UserSwitcherController.UserRecord) view.getTag(); |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame] | 96 | if (tag.isDisabledByAdmin) { |
| 97 | final Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent( |
| 98 | mContext, tag.enforcedAdmin); |
| 99 | mController.startActivity(intent); |
Fyodor Kupolov | 07140f7 | 2016-02-17 10:46:11 -0800 | [diff] [blame] | 100 | } else if (tag.isSwitchToEnabled) { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 101 | MetricsLogger.action(mContext, MetricsEvent.QS_SWITCH_USER); |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame] | 102 | switchTo(tag); |
| 103 | } |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 104 | } |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 105 | } |
| 106 | } |