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 19 import android.content.Context; 20 import android.content.Intent; 21 import android.util.AttributeSet; 22 import android.view.LayoutInflater; 23 import android.view.View; 24 import android.view.ViewGroup; 25 26 import com.android.internal.logging.MetricsLogger; 27 import com.android.internal.logging.nano.MetricsProto.MetricsEvent; 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; 32 /** 33 * Quick settings detail view for user switching. 34 */ 35 public class UserDetailView extends PseudoGridView { 36 37 protected Adapter mAdapter; 38 UserDetailView(Context context, AttributeSet attrs)39 public UserDetailView(Context context, AttributeSet attrs) { 40 super(context, attrs); 41 } 42 inflate(Context context, ViewGroup parent, boolean attach)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 createAndSetAdapter(UserSwitcherController controller)48 public void createAndSetAdapter(UserSwitcherController controller) { 49 mAdapter = new Adapter(mContext, controller); 50 ViewGroupAdapterBridge.link(this, mAdapter); 51 } 52 refreshAdapter()53 public void refreshAdapter() { 54 mAdapter.refresh(); 55 } 56 57 public static class Adapter extends UserSwitcherController.BaseUserAdapter 58 implements OnClickListener { 59 60 private final Context mContext; 61 protected UserSwitcherController mController; 62 Adapter(Context context, UserSwitcherController controller)63 public Adapter(Context context, UserSwitcherController controller) { 64 super(controller); 65 mContext = context; 66 mController = controller; 67 } 68 69 @Override getView(int position, View convertView, ViewGroup parent)70 public View getView(int position, View convertView, ViewGroup parent) { 71 UserSwitcherController.UserRecord item = getItem(position); 72 return createUserDetailItemView(convertView, parent, item); 73 } 74 createUserDetailItemView(View convertView, ViewGroup parent, UserSwitcherController.UserRecord item)75 public UserDetailItemView createUserDetailItemView(View convertView, ViewGroup parent, 76 UserSwitcherController.UserRecord item) { 77 UserDetailItemView v = UserDetailItemView.convertOrInflate( 78 mContext, convertView, parent); 79 if (!item.isCurrent || item.isGuest) { 80 v.setOnClickListener(this); 81 } else { 82 v.setOnClickListener(null); 83 v.setClickable(false); 84 } 85 String name = getName(mContext, item); 86 if (item.picture == null) { 87 v.bind(name, getDrawable(mContext, item), item.resolveId()); 88 } else { 89 v.bind(name, item.picture, item.info.id); 90 } 91 v.setActivated(item.isCurrent); 92 v.setDisabledByAdmin(item.isDisabledByAdmin); 93 if (!item.isSwitchToEnabled) { 94 v.setEnabled(false); 95 } 96 v.setTag(item); 97 return v; 98 } 99 100 @Override onClick(View view)101 public void onClick(View view) { 102 UserSwitcherController.UserRecord tag = 103 (UserSwitcherController.UserRecord) view.getTag(); 104 if (tag.isDisabledByAdmin) { 105 final Intent intent = RestrictedLockUtils.getShowAdminSupportDetailsIntent( 106 mContext, tag.enforcedAdmin); 107 mController.startActivity(intent); 108 } else if (tag.isSwitchToEnabled) { 109 MetricsLogger.action(mContext, MetricsEvent.QS_SWITCH_USER); 110 switchTo(tag); 111 } 112 } 113 } 114 } 115