MultiUserSwitch.java revision 723632ea1ae30b33e9c2055194a4464f00c48c61
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
17package com.android.systemui.statusbar.phone;
18
19import android.content.Context;
20import android.content.Intent;
21import android.os.UserHandle;
22import android.os.UserManager;
23import android.provider.ContactsContract;
24import android.util.AttributeSet;
25import android.view.View;
26import android.widget.FrameLayout;
27
28import com.android.systemui.qs.QSPanel;
29import com.android.systemui.statusbar.policy.KeyguardUserSwitcher;
30
31/**
32 * Container for image of the multi user switcher (tappable).
33 */
34public class MultiUserSwitch extends FrameLayout implements View.OnClickListener {
35
36    private QSPanel mQsPanel;
37    private KeyguardUserSwitcher mKeyguardUserSwitcher;
38    private boolean mKeyguardMode;
39
40    public MultiUserSwitch(Context context, AttributeSet attrs) {
41        super(context, attrs);
42    }
43
44    @Override
45    protected void onFinishInflate() {
46        super.onFinishInflate();
47        setOnClickListener(this);
48    }
49
50    public void setQsPanel(QSPanel qsPanel) {
51        mQsPanel = qsPanel;
52    }
53
54    public void setKeyguardUserSwitcher(KeyguardUserSwitcher keyguardUserSwitcher) {
55        mKeyguardUserSwitcher = keyguardUserSwitcher;
56    }
57
58    public void setKeyguardMode(boolean keyguardShowing) {
59        mKeyguardMode = keyguardShowing;
60    }
61
62    @Override
63    public void onClick(View v) {
64        final UserManager um = UserManager.get(getContext());
65        if (um.isUserSwitcherEnabled()) {
66            if (mKeyguardMode) {
67                if (mKeyguardUserSwitcher != null) {
68                    mKeyguardUserSwitcher.show();
69                }
70            } else {
71                mQsPanel.showDetailAdapter(true,
72                        mQsPanel.getHost().getUserSwitcherController().userDetailAdapter);
73            }
74        } else {
75            Intent intent = ContactsContract.QuickContact.composeQuickContactsIntent(
76                    getContext(), v, ContactsContract.Profile.CONTENT_URI,
77                    ContactsContract.QuickContact.MODE_LARGE, null);
78            getContext().startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
79        }
80    }
81}
82