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); |
| 84 | String name; |
| 85 | if (item.isGuest) { |
| 86 | name = mContext.getString( |
| 87 | item.info == null ? R.string.guest_new_guest : R.string.guest_nickname); |
| 88 | } else { |
| 89 | name = item.info.name; |
| 90 | } |
| 91 | if (item.picture == null) { |
| 92 | v.bind(name, mContext.getDrawable(R.drawable.ic_account_circle)); |
| 93 | } else { |
| 94 | v.bind(name, item.picture); |
| 95 | } |
| 96 | v.setActivated(item.isCurrent); |
| 97 | v.setTag(item); |
| 98 | return v; |
| 99 | } |
| 100 | } |
| 101 | } |