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