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