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 | |
Chris Wren | 9e7283f | 2015-05-08 17:23:47 -0400 | [diff] [blame] | 19 | import com.android.internal.logging.MetricsLogger; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 20 | import com.android.systemui.R; |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 21 | import com.android.systemui.qs.PseudoGridView; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 22 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
| 23 | |
| 24 | import android.content.Context; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 25 | import android.util.AttributeSet; |
| 26 | import android.view.LayoutInflater; |
| 27 | import android.view.View; |
| 28 | import android.view.ViewGroup; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Quick settings detail view for user switching. |
| 32 | */ |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 33 | public class UserDetailView extends PseudoGridView { |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 34 | |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 35 | private Adapter mAdapter; |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 36 | |
| 37 | public UserDetailView(Context context, AttributeSet attrs) { |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 38 | super(context, attrs); |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 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) { |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 47 | mAdapter = new Adapter(mContext, controller); |
| 48 | ViewGroupAdapterBridge.link(this, mAdapter); |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 49 | } |
| 50 | |
Adrian Roos | 844c92b | 2014-12-01 14:19:05 +0100 | [diff] [blame] | 51 | public void refreshAdapter() { |
| 52 | mAdapter.refresh(); |
| 53 | } |
| 54 | |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 55 | public static class Adapter extends UserSwitcherController.BaseUserAdapter |
| 56 | implements OnClickListener { |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 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); |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 70 | if (v != convertView) { |
| 71 | v.setOnClickListener(this); |
| 72 | } |
Adrian Roos | e9c7d43 | 2014-07-17 18:27:38 +0200 | [diff] [blame] | 73 | String name = getName(mContext, item); |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 74 | if (item.picture == null) { |
Adrian Roos | ccdff62 | 2014-08-06 00:07:18 +0200 | [diff] [blame] | 75 | v.bind(name, getDrawable(mContext, item)); |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 76 | } else { |
| 77 | v.bind(name, item.picture); |
| 78 | } |
| 79 | v.setActivated(item.isCurrent); |
| 80 | v.setTag(item); |
| 81 | return v; |
| 82 | } |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 83 | |
| 84 | @Override |
| 85 | public void onClick(View view) { |
| 86 | UserSwitcherController.UserRecord tag = |
| 87 | (UserSwitcherController.UserRecord) view.getTag(); |
Chris Wren | 9e7283f | 2015-05-08 17:23:47 -0400 | [diff] [blame] | 88 | MetricsLogger.action(mContext, MetricsLogger.QS_SWITCH_USER); |
Adrian Roos | 1940892 | 2014-08-07 20:54:12 +0200 | [diff] [blame] | 89 | switchTo(tag); |
| 90 | } |
Adrian Roos | 00a0b1f | 2014-07-16 16:44:49 +0200 | [diff] [blame] | 91 | } |
| 92 | } |