UserDetailView.java revision 9e7283f6a31bc2beb75c84c6173968a46582c563
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 17package com.android.systemui.qs.tiles; 18 19import com.android.internal.logging.MetricsLogger; 20import com.android.systemui.R; 21import com.android.systemui.qs.PseudoGridView; 22import com.android.systemui.statusbar.policy.UserSwitcherController; 23 24import android.content.Context; 25import android.util.AttributeSet; 26import android.view.LayoutInflater; 27import android.view.View; 28import android.view.ViewGroup; 29 30/** 31 * Quick settings detail view for user switching. 32 */ 33public class UserDetailView extends PseudoGridView { 34 35 private Adapter mAdapter; 36 37 public UserDetailView(Context context, AttributeSet attrs) { 38 super(context, attrs); 39 } 40 41 public static UserDetailView inflate(Context context, ViewGroup parent, boolean attach) { 42 return (UserDetailView) LayoutInflater.from(context).inflate( 43 R.layout.qs_user_detail, parent, attach); 44 } 45 46 public void createAndSetAdapter(UserSwitcherController controller) { 47 mAdapter = new Adapter(mContext, controller); 48 ViewGroupAdapterBridge.link(this, mAdapter); 49 } 50 51 public void refreshAdapter() { 52 mAdapter.refresh(); 53 } 54 55 public static class Adapter extends UserSwitcherController.BaseUserAdapter 56 implements OnClickListener { 57 58 private Context mContext; 59 60 public Adapter(Context context, UserSwitcherController controller) { 61 super(controller); 62 mContext = context; 63 } 64 65 @Override 66 public View getView(int position, View convertView, ViewGroup parent) { 67 UserSwitcherController.UserRecord item = getItem(position); 68 UserDetailItemView v = UserDetailItemView.convertOrInflate( 69 mContext, convertView, parent); 70 if (v != convertView) { 71 v.setOnClickListener(this); 72 } 73 String name = getName(mContext, item); 74 if (item.picture == null) { 75 v.bind(name, getDrawable(mContext, item)); 76 } else { 77 v.bind(name, item.picture); 78 } 79 v.setActivated(item.isCurrent); 80 v.setTag(item); 81 return v; 82 } 83 84 @Override 85 public void onClick(View view) { 86 UserSwitcherController.UserRecord tag = 87 (UserSwitcherController.UserRecord) view.getTag(); 88 MetricsLogger.action(mContext, MetricsLogger.QS_SWITCH_USER); 89 switchTo(tag); 90 } 91 } 92} 93