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
199e7283f6a31bc2beb75c84c6173968a46582c563Chris Wrenimport com.android.internal.logging.MetricsLogger;
2000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport com.android.systemui.R;
211940892d891c1d2538f51608b6618af646ab7481Adrian Roosimport com.android.systemui.qs.PseudoGridView;
2200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport com.android.systemui.statusbar.policy.UserSwitcherController;
2300a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
2400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.content.Context;
2500a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.util.AttributeSet;
2600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.view.LayoutInflater;
2700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.view.View;
2800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roosimport android.view.ViewGroup;
2900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
3000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos/**
3100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos * Quick settings detail view for user switching.
3200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos */
331940892d891c1d2538f51608b6618af646ab7481Adrian Roospublic class UserDetailView extends PseudoGridView {
3400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
351940892d891c1d2538f51608b6618af646ab7481Adrian Roos    private Adapter mAdapter;
3600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
3700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    public UserDetailView(Context context, AttributeSet attrs) {
381940892d891c1d2538f51608b6618af646ab7481Adrian Roos        super(context, attrs);
3900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    }
4000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
4100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    public static UserDetailView inflate(Context context, ViewGroup parent, boolean attach) {
4200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        return (UserDetailView) LayoutInflater.from(context).inflate(
4300a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos                R.layout.qs_user_detail, parent, attach);
4400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    }
4500a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
4600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    public void createAndSetAdapter(UserSwitcherController controller) {
471940892d891c1d2538f51608b6618af646ab7481Adrian Roos        mAdapter = new Adapter(mContext, controller);
481940892d891c1d2538f51608b6618af646ab7481Adrian Roos        ViewGroupAdapterBridge.link(this, mAdapter);
4900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    }
5000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
51844c92b444dca7f5ef4d0943fb14e2cbeee49701Adrian Roos    public void refreshAdapter() {
52844c92b444dca7f5ef4d0943fb14e2cbeee49701Adrian Roos        mAdapter.refresh();
53844c92b444dca7f5ef4d0943fb14e2cbeee49701Adrian Roos    }
54844c92b444dca7f5ef4d0943fb14e2cbeee49701Adrian Roos
551940892d891c1d2538f51608b6618af646ab7481Adrian Roos    public static class Adapter extends UserSwitcherController.BaseUserAdapter
561940892d891c1d2538f51608b6618af646ab7481Adrian Roos            implements OnClickListener {
5700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
5800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        private Context mContext;
5900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
6000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        public Adapter(Context context, UserSwitcherController controller) {
6100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos            super(controller);
6200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos            mContext = context;
6300a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        }
6400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos
6500a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        @Override
6600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        public View getView(int position, View convertView, ViewGroup parent) {
6700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos            UserSwitcherController.UserRecord item = getItem(position);
6800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos            UserDetailItemView v = UserDetailItemView.convertOrInflate(
6900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos                    mContext, convertView, parent);
701940892d891c1d2538f51608b6618af646ab7481Adrian Roos            if (v != convertView) {
711940892d891c1d2538f51608b6618af646ab7481Adrian Roos                v.setOnClickListener(this);
721940892d891c1d2538f51608b6618af646ab7481Adrian Roos            }
73e9c7d431da85b5bc03ecaa964d7a491b01466a99Adrian Roos            String name = getName(mContext, item);
7400a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos            if (item.picture == null) {
75ccdff62159b41ab130a8f90d30edb9b9542d8c72Adrian Roos                v.bind(name, getDrawable(mContext, item));
7600a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos            } else {
7700a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos                v.bind(name, item.picture);
7800a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos            }
7900a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos            v.setActivated(item.isCurrent);
8000a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos            v.setTag(item);
8100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos            return v;
8200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos        }
831940892d891c1d2538f51608b6618af646ab7481Adrian Roos
841940892d891c1d2538f51608b6618af646ab7481Adrian Roos        @Override
851940892d891c1d2538f51608b6618af646ab7481Adrian Roos        public void onClick(View view) {
861940892d891c1d2538f51608b6618af646ab7481Adrian Roos            UserSwitcherController.UserRecord tag =
871940892d891c1d2538f51608b6618af646ab7481Adrian Roos                    (UserSwitcherController.UserRecord) view.getTag();
889e7283f6a31bc2beb75c84c6173968a46582c563Chris Wren            MetricsLogger.action(mContext, MetricsLogger.QS_SWITCH_USER);
891940892d891c1d2538f51608b6618af646ab7481Adrian Roos            switchTo(tag);
901940892d891c1d2538f51608b6618af646ab7481Adrian Roos        }
9100a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos    }
9200a0b1f397557790cf9ab55fe06e72a96ebc5353Adrian Roos}
93