blob: 21c5c967ce96f291fdd34dd4fc3a8bbab9299831 [file] [log] [blame]
Adrian Roos00a0b1f2014-07-16 16:44:49 +02001/*
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
Adrian Roosccdff622014-08-06 00:07:18 +020019import com.android.internal.util.ArrayUtils;
Jorim Jaggie17c4b42014-08-26 17:27:31 +020020import com.android.systemui.FontSizeUtils;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020021import com.android.systemui.R;
22import com.android.systemui.statusbar.phone.UserAvatarView;
23
24import android.content.Context;
Jorim Jaggie17c4b42014-08-26 17:27:31 +020025import android.content.res.Configuration;
Adrian Roosccdff622014-08-06 00:07:18 +020026import android.content.res.TypedArray;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020027import android.graphics.Bitmap;
Adrian Roosccdff622014-08-06 00:07:18 +020028import android.graphics.Typeface;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020029import android.graphics.drawable.Drawable;
30import android.util.AttributeSet;
31import android.view.LayoutInflater;
32import android.view.View;
33import android.view.ViewGroup;
34import android.widget.LinearLayout;
35import android.widget.TextView;
36
37/**
38 * Displays one user in the {@link UserDetailView} view.
39 */
40public class UserDetailItemView extends LinearLayout {
41
42 private UserAvatarView mAvatar;
43 private TextView mName;
Adrian Roosccdff622014-08-06 00:07:18 +020044 private Typeface mRegularTypeface;
45 private Typeface mActivatedTypeface;
Adrian Roos00a0b1f2014-07-16 16:44:49 +020046
47 public UserDetailItemView(Context context) {
48 this(context, null);
49 }
50
51 public UserDetailItemView(Context context, AttributeSet attrs) {
52 this(context, attrs, 0);
53 }
54
55 public UserDetailItemView(Context context, AttributeSet attrs, int defStyleAttr) {
56 this(context, attrs, defStyleAttr, 0);
57 }
58
59 public UserDetailItemView(Context context, AttributeSet attrs, int defStyleAttr,
60 int defStyleRes) {
61 super(context, attrs, defStyleAttr, defStyleRes);
Adrian Roosccdff622014-08-06 00:07:18 +020062 final TypedArray a = context.obtainStyledAttributes(
63 attrs, R.styleable.UserDetailItemView, defStyleAttr, defStyleRes);
64 final int N = a.getIndexCount();
65 for (int i = 0; i < N; i++) {
66 int attr = a.getIndex(i);
67 switch (attr) {
68 case R.styleable.UserDetailItemView_regularFontFamily:
69 mRegularTypeface = Typeface.create(a.getString(attr), 0 /* style */);
70 break;
71 case R.styleable.UserDetailItemView_activatedFontFamily:
72 mActivatedTypeface = Typeface.create(a.getString(attr), 0 /* style */);
73 break;
74 }
75 }
76 a.recycle();
Adrian Roos00a0b1f2014-07-16 16:44:49 +020077 }
78
79 public static UserDetailItemView convertOrInflate(Context context, View convertView,
80 ViewGroup root) {
81 if (!(convertView instanceof UserDetailItemView)) {
82 convertView = LayoutInflater.from(context).inflate(
83 R.layout.qs_user_detail_item, root, false);
84 }
85 return (UserDetailItemView) convertView;
86 }
87
88 public void bind(String name, Bitmap picture) {
89 mName.setText(name);
90 mAvatar.setBitmap(picture);
91 }
92
93 public void bind(String name, Drawable picture) {
94 mName.setText(name);
95 mAvatar.setDrawable(picture);
96 }
97
98 @Override
99 protected void onFinishInflate() {
100 mAvatar = (UserAvatarView) findViewById(R.id.user_picture);
101 mName = (TextView) findViewById(R.id.user_name);
Adrian Roosccdff622014-08-06 00:07:18 +0200102 if (mRegularTypeface == null) {
103 mRegularTypeface = mName.getTypeface();
104 }
105 if (mActivatedTypeface == null) {
106 mActivatedTypeface = mName.getTypeface();
107 }
108 updateTypeface();
Adrian Roos00a0b1f2014-07-16 16:44:49 +0200109 }
110
Adrian Roosccdff622014-08-06 00:07:18 +0200111 @Override
Jorim Jaggie17c4b42014-08-26 17:27:31 +0200112 protected void onConfigurationChanged(Configuration newConfig) {
113 super.onConfigurationChanged(newConfig);
114 FontSizeUtils.updateFontSize(mName, R.dimen.qs_detail_item_secondary_text_size);
115 }
116
117 @Override
Adrian Roosccdff622014-08-06 00:07:18 +0200118 protected void drawableStateChanged() {
119 super.drawableStateChanged();
120 updateTypeface();
121 }
122
123 private void updateTypeface() {
124 boolean activated = ArrayUtils.contains(getDrawableState(), android.R.attr.state_activated);
125 mName.setTypeface(activated ? mActivatedTypeface : mRegularTypeface);
126 }
Jorim Jaggi98f85302014-08-07 17:45:04 +0200127
128 @Override
129 public boolean hasOverlappingRendering() {
130 return false;
131 }
Adrian Roos00a0b1f2014-07-16 16:44:49 +0200132}