UserDetailItemView.java revision 00a0b1f397557790cf9ab55fe06e72a96ebc5353
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 com.android.systemui.R;
2000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport com.android.systemui.statusbar.phone.UserAvatarView;
2100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
2200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.content.Context;
2300a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.graphics.Bitmap;
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
3200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos/**
3300a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * Displays one user in the {@link UserDetailView} view.
3400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos */
3500a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roospublic class UserDetailItemView extends LinearLayout {
3600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
3700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    private UserAvatarView mAvatar;
3800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    private TextView mName;
3900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
4000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    public UserDetailItemView(Context context) {
4100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        this(context, null);
4200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    }
4300a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
4400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    public UserDetailItemView(Context context, AttributeSet attrs) {
4500a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        this(context, attrs, 0);
4600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    }
4700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
4800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    public UserDetailItemView(Context context, AttributeSet attrs, int defStyleAttr) {
4900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        this(context, attrs, defStyleAttr, 0);
5000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    }
5100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
5200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    public UserDetailItemView(Context context, AttributeSet attrs, int defStyleAttr,
5300a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos            int defStyleRes) {
5400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        super(context, attrs, defStyleAttr, defStyleRes);
5500a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    }
5600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
5700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    public static UserDetailItemView convertOrInflate(Context context, View convertView,
5800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos            ViewGroup root) {
5900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        if (!(convertView instanceof UserDetailItemView)) {
6000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos            convertView = LayoutInflater.from(context).inflate(
6100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos                    R.layout.qs_user_detail_item, root, false);
6200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        }
6300a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        return (UserDetailItemView) convertView;
6400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    }
6500a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
6600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    public void bind(String name, Bitmap picture) {
6700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        mName.setText(name);
6800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        mAvatar.setBitmap(picture);
6900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    }
7000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
7100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    public void bind(String name, Drawable picture) {
7200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        mName.setText(name);
7300a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        mAvatar.setDrawable(picture);
7400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    }
7500a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
7600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    @Override
7700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    protected void onFinishInflate() {
7800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        mAvatar = (UserAvatarView) findViewById(R.id.user_picture);
7900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        mName = (TextView) findViewById(R.id.user_name);
8000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    }
8100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
8200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos}
83