UserDetailItemView.java revision c0d7058b14c24cd07912f5629c26b39b7b4673d5
100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos/* 200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * Copyright (C) 2014 The Android Open Source Project 300a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * 400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * Licensed under the Apache License, Version 2.0 (the "License"); 500a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * you may not use this file except in compliance with the License. 600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * You may obtain a copy of the License at 700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * 800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * http://www.apache.org/licenses/LICENSE-2.0 900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * 1000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * Unless required by applicable law or agreed to in writing, software 1100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * distributed under the License is distributed on an "AS IS" BASIS, 1200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1300a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * See the License for the specific language governing permissions and 1400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * limitations under the License 1500a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos */ 1600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos 1700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roospackage com.android.systemui.qs.tiles; 1800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos 1900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.content.Context; 20e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggiimport android.content.res.Configuration; 21ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roosimport android.content.res.TypedArray; 2200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.graphics.Bitmap; 23ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roosimport android.graphics.Typeface; 2400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.graphics.drawable.Drawable; 2500a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.util.AttributeSet; 2600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.view.LayoutInflater; 2700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.view.View; 2800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.view.ViewGroup; 2900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.widget.LinearLayout; 3000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.widget.TextView; 3100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos 32c0d7058b14c24cd07912f5629c26b39b7b4673d5Winsonimport com.android.internal.util.ArrayUtils; 33c0d7058b14c24cd07912f5629c26b39b7b4673d5Winsonimport com.android.systemui.FontSizeUtils; 34c0d7058b14c24cd07912f5629c26b39b7b4673d5Winsonimport com.android.systemui.R; 35c0d7058b14c24cd07912f5629c26b39b7b4673d5Winsonimport com.android.systemui.statusbar.phone.UserAvatarView; 36c0d7058b14c24cd07912f5629c26b39b7b4673d5Winson 3700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos/** 3800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * Displays one user in the {@link UserDetailView} view. 3900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos */ 4000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roospublic class UserDetailItemView extends LinearLayout { 4100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos 4200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos private UserAvatarView mAvatar; 4300a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos private TextView mName; 44ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos private Typeface mRegularTypeface; 45ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos private Typeface mActivatedTypeface; 461c7cda8bbfb848961536a4adbf2c81c5ffddae16Sudheer Shanka private View mRestrictedPadlock; 4700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos 4800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos public UserDetailItemView(Context context) { 4900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos this(context, null); 5000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos } 5100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos 5200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos public UserDetailItemView(Context context, AttributeSet attrs) { 5300a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos this(context, attrs, 0); 5400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos } 5500a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos 5600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos public UserDetailItemView(Context context, AttributeSet attrs, int defStyleAttr) { 5700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos this(context, attrs, defStyleAttr, 0); 5800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos } 5900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos 6000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos public UserDetailItemView(Context context, AttributeSet attrs, int defStyleAttr, 6100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos int defStyleRes) { 6200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos super(context, attrs, defStyleAttr, defStyleRes); 631c7cda8bbfb848961536a4adbf2c81c5ffddae16Sudheer Shanka 64ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos final TypedArray a = context.obtainStyledAttributes( 65ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos attrs, R.styleable.UserDetailItemView, defStyleAttr, defStyleRes); 66ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos final int N = a.getIndexCount(); 67ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos for (int i = 0; i < N; i++) { 68ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos int attr = a.getIndex(i); 69ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos switch (attr) { 70ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos case R.styleable.UserDetailItemView_regularFontFamily: 71ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos mRegularTypeface = Typeface.create(a.getString(attr), 0 /* style */); 72ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos break; 73ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos case R.styleable.UserDetailItemView_activatedFontFamily: 74ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos mActivatedTypeface = Typeface.create(a.getString(attr), 0 /* style */); 75ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos break; 76ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos } 77ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos } 78ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos a.recycle(); 7900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos } 8000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos 8100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos public static UserDetailItemView convertOrInflate(Context context, View convertView, 8200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos ViewGroup root) { 8300a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos if (!(convertView instanceof UserDetailItemView)) { 8400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos convertView = LayoutInflater.from(context).inflate( 8500a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos R.layout.qs_user_detail_item, root, false); 8600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos } 8700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos return (UserDetailItemView) convertView; 8800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos } 8900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos 9000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos public void bind(String name, Bitmap picture) { 9100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos mName.setText(name); 9200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos mAvatar.setBitmap(picture); 9300a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos } 9400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos 9500a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos public void bind(String name, Drawable picture) { 9600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos mName.setText(name); 9700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos mAvatar.setDrawable(picture); 9800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos } 9900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos 1001c7cda8bbfb848961536a4adbf2c81c5ffddae16Sudheer Shanka public void setDisabledByAdmin(boolean disabled) { 1011c7cda8bbfb848961536a4adbf2c81c5ffddae16Sudheer Shanka mRestrictedPadlock.setVisibility(disabled ? View.VISIBLE : View.GONE); 1021c7cda8bbfb848961536a4adbf2c81c5ffddae16Sudheer Shanka mName.setEnabled(!disabled); 1031c7cda8bbfb848961536a4adbf2c81c5ffddae16Sudheer Shanka mAvatar.setDisabled(disabled); 1041c7cda8bbfb848961536a4adbf2c81c5ffddae16Sudheer Shanka } 1051c7cda8bbfb848961536a4adbf2c81c5ffddae16Sudheer Shanka 10600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos @Override 10700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos protected void onFinishInflate() { 10800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos mAvatar = (UserAvatarView) findViewById(R.id.user_picture); 10900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos mName = (TextView) findViewById(R.id.user_name); 110ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos if (mRegularTypeface == null) { 111ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos mRegularTypeface = mName.getTypeface(); 112ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos } 113ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos if (mActivatedTypeface == null) { 114ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos mActivatedTypeface = mName.getTypeface(); 115ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos } 116ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos updateTypeface(); 1171c7cda8bbfb848961536a4adbf2c81c5ffddae16Sudheer Shanka mRestrictedPadlock = findViewById(R.id.restricted_padlock); 11800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos } 11900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos 120ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos @Override 121e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi protected void onConfigurationChanged(Configuration newConfig) { 122e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi super.onConfigurationChanged(newConfig); 123e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi FontSizeUtils.updateFontSize(mName, R.dimen.qs_detail_item_secondary_text_size); 124e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi } 125e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi 126e17c4b49a41ec9de5c1d7f229273fc4677ec24b1Jorim Jaggi @Override 127ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos protected void drawableStateChanged() { 128ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos super.drawableStateChanged(); 129ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos updateTypeface(); 130ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos } 131ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos 132ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos private void updateTypeface() { 133ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos boolean activated = ArrayUtils.contains(getDrawableState(), android.R.attr.state_activated); 134ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos mName.setTypeface(activated ? mActivatedTypeface : mRegularTypeface); 135ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos } 13698f8530af3bb8636b7b173443c90686c485205d6Jorim Jaggi 13798f8530af3bb8636b7b173443c90686c485205d6Jorim Jaggi @Override 13898f8530af3bb8636b7b173443c90686c485205d6Jorim Jaggi public boolean hasOverlappingRendering() { 13998f8530af3bb8636b7b173443c90686c485205d6Jorim Jaggi return false; 14098f8530af3bb8636b7b173443c90686c485205d6Jorim Jaggi } 14100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos} 142