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; |
| 27 | import com.android.settingslib.RestrictedLockUtils; |
| 28 | import com.android.systemui.R; |
| 29 | import com.android.systemui.qs.PseudoGridView; |
| 30 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 31 | /** |
| 32 | * Quick settings detail view for user switching. |
| 33 | */ |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 34 | public class UserDetailView extends PseudoGridView { |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 35 | |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 36 | private Adapter mAdapter; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 37 | |
| 38 | public UserDetailView(Context context, AttributeSet attrs) { |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 39 | super(context, attrs); |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 40 | } |
| 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 Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 48 | mAdapter = new Adapter(mContext, controller); |
| 49 | ViewGroupAdapterBridge.link(this, mAdapter); |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 50 | } |
| 51 | |
Adrian Roos | 844c92b | 2014-12-01 14:19:05 +0100 | [diff] [blame] | 52 | public void refreshAdapter() { |
| 53 | mAdapter.refresh(); |
| 54 | } |
| 55 | |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 56 | public static class Adapter extends UserSwitcherController.BaseUserAdapter |
| 57 | implements OnClickListener { |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 58 | |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame^] | 59 | private final Context mContext; |
| 60 | private final UserSwitcherController mController; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 61 | |
| 62 | public Adapter(Context context, UserSwitcherController controller) { |
| 63 | super(controller); |
| 64 | mContext = context; |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame^] | 65 | mController = controller; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 66 | } |
| 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 Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 73 | if (v != convertView) { |
| 74 | v.setOnClickListener(this); |
| 75 | } |
Adrian Roos | e9c7d43 | 2014-07-17 18:27:38 +0200 | [diff] [blame] | 76 | String name = getName(mContext, item); |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 77 | if (item.picture == null) { |
Adrian Roos | ccdff62 | 2014-08-06 00:07:18 +0200 | [diff] [blame] | 78 | v.bind(name, getDrawable(mContext, item)); |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 79 | } else { |
| 80 | v.bind(name, item.picture); |
| 81 | } |
| 82 | v.setActivated(item.isCurrent); |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame^] | 83 | v.setDisabledByAdmin(item.isDisabledByAdmin); |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 84 | v.setTag(item); |
| 85 | return v; |
| 86 | } |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 87 | |
| 88 | @Override |
| 89 | public void onClick(View view) { |
| 90 | UserSwitcherController.UserRecord tag = |
| 91 | (UserSwitcherController.UserRecord) view.getTag(); |
Sudheer Shanka | 1c7cda8 | 2015-12-31 14:46:02 +0000 | [diff] [blame^] | 92 | 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 Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 100 | } |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 101 | } |
| 102 | } |