• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.content.Context;
20 import android.content.res.Configuration;
21 import android.content.res.TypedArray;
22 import android.graphics.Bitmap;
23 import android.graphics.Typeface;
24 import android.graphics.drawable.Drawable;
25 import android.util.AttributeSet;
26 import android.view.LayoutInflater;
27 import android.view.View;
28 import android.view.ViewGroup;
29 import android.widget.LinearLayout;
30 import android.widget.TextView;
31 
32 import com.android.internal.util.ArrayUtils;
33 import com.android.settingslib.drawable.UserIconDrawable;
34 import com.android.systemui.FontSizeUtils;
35 import com.android.systemui.R;
36 import com.android.systemui.statusbar.phone.UserAvatarView;
37 
38 /**
39  * Displays one user in the {@link UserDetailView} view.
40  */
41 public class UserDetailItemView extends LinearLayout {
42 
43     private UserAvatarView mAvatar;
44     private TextView mName;
45     private Typeface mRegularTypeface;
46     private Typeface mActivatedTypeface;
47     private View mRestrictedPadlock;
48 
UserDetailItemView(Context context)49     public UserDetailItemView(Context context) {
50         this(context, null);
51     }
52 
UserDetailItemView(Context context, AttributeSet attrs)53     public UserDetailItemView(Context context, AttributeSet attrs) {
54         this(context, attrs, 0);
55     }
56 
UserDetailItemView(Context context, AttributeSet attrs, int defStyleAttr)57     public UserDetailItemView(Context context, AttributeSet attrs, int defStyleAttr) {
58         this(context, attrs, defStyleAttr, 0);
59     }
60 
UserDetailItemView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)61     public UserDetailItemView(Context context, AttributeSet attrs, int defStyleAttr,
62             int defStyleRes) {
63         super(context, attrs, defStyleAttr, defStyleRes);
64 
65         final TypedArray a = context.obtainStyledAttributes(
66                 attrs, R.styleable.UserDetailItemView, defStyleAttr, defStyleRes);
67         final int N = a.getIndexCount();
68         for (int i = 0; i < N; i++) {
69             int attr = a.getIndex(i);
70             switch (attr) {
71                 case R.styleable.UserDetailItemView_regularFontFamily:
72                     mRegularTypeface = Typeface.create(a.getString(attr), 0 /* style */);
73                     break;
74                 case R.styleable.UserDetailItemView_activatedFontFamily:
75                     mActivatedTypeface = Typeface.create(a.getString(attr), 0 /* style */);
76                     break;
77             }
78         }
79         a.recycle();
80     }
81 
convertOrInflate(Context context, View convertView, ViewGroup root)82     public static UserDetailItemView convertOrInflate(Context context, View convertView,
83             ViewGroup root) {
84         if (!(convertView instanceof UserDetailItemView)) {
85             convertView = LayoutInflater.from(context).inflate(
86                     R.layout.qs_user_detail_item, root, false);
87         }
88         return (UserDetailItemView) convertView;
89     }
90 
bind(String name, Bitmap picture, int userId)91     public void bind(String name, Bitmap picture, int userId) {
92         mName.setText(name);
93         mAvatar.setAvatarWithBadge(picture, userId);
94     }
95 
bind(String name, Drawable picture, int userId)96     public void bind(String name, Drawable picture, int userId) {
97         mName.setText(name);
98         mAvatar.setDrawableWithBadge(picture, userId);
99     }
100 
setAvatarEnabled(boolean enabled)101     public void setAvatarEnabled(boolean enabled) {
102         mAvatar.setEnabled(enabled);
103     }
104 
setDisabledByAdmin(boolean disabled)105     public void setDisabledByAdmin(boolean disabled) {
106         mRestrictedPadlock.setVisibility(disabled ? View.VISIBLE : View.GONE);
107         mName.setEnabled(!disabled);
108         mAvatar.setEnabled(!disabled);
109     }
110 
setEnabled(boolean enabled)111     public void setEnabled(boolean enabled) {
112         mName.setEnabled(enabled);
113         mAvatar.setEnabled(enabled);
114     }
115 
116     @Override
onFinishInflate()117     protected void onFinishInflate() {
118         mAvatar = (UserAvatarView) findViewById(R.id.user_picture);
119         mName = (TextView) findViewById(R.id.user_name);
120         if (mRegularTypeface == null) {
121             mRegularTypeface = mName.getTypeface();
122         }
123         if (mActivatedTypeface == null) {
124             mActivatedTypeface = mName.getTypeface();
125         }
126         updateTypeface();
127         mRestrictedPadlock = findViewById(R.id.restricted_padlock);
128     }
129 
130     @Override
onConfigurationChanged(Configuration newConfig)131     protected void onConfigurationChanged(Configuration newConfig) {
132         super.onConfigurationChanged(newConfig);
133         FontSizeUtils.updateFontSize(mName, R.dimen.qs_detail_item_secondary_text_size);
134     }
135 
136     @Override
drawableStateChanged()137     protected void drawableStateChanged() {
138         super.drawableStateChanged();
139         updateTypeface();
140     }
141 
updateTypeface()142     private void updateTypeface() {
143         boolean activated = ArrayUtils.contains(getDrawableState(), android.R.attr.state_activated);
144         mName.setTypeface(activated ? mActivatedTypeface : mRegularTypeface);
145     }
146 
147     @Override
hasOverlappingRendering()148     public boolean hasOverlappingRendering() {
149         return false;
150     }
151 }
152