MultiUserSwitch.java revision 1de02ee3eab1a8ef326557b76e13c0901b9e9164
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.text.TextUtils; 25import android.util.AttributeSet; 26import android.view.View; 27import android.view.accessibility.AccessibilityEvent; 28import android.widget.FrameLayout; 29 30import com.android.systemui.R; 31import com.android.systemui.qs.QSPanel; 32import com.android.systemui.statusbar.policy.KeyguardUserSwitcher; 33 34/** 35 * Container for image of the multi user switcher (tappable). 36 */ 37public class MultiUserSwitch extends FrameLayout implements View.OnClickListener { 38 39 private QSPanel mQsPanel; 40 private KeyguardUserSwitcher mKeyguardUserSwitcher; 41 private boolean mKeyguardMode; 42 final UserManager mUserManager; 43 44 public MultiUserSwitch(Context context, AttributeSet attrs) { 45 super(context, attrs); 46 mUserManager = UserManager.get(getContext()); 47 } 48 49 @Override 50 protected void onFinishInflate() { 51 super.onFinishInflate(); 52 setOnClickListener(this); 53 } 54 55 public void setQsPanel(QSPanel qsPanel) { 56 mQsPanel = qsPanel; 57 } 58 59 public void setKeyguardUserSwitcher(KeyguardUserSwitcher keyguardUserSwitcher) { 60 mKeyguardUserSwitcher = keyguardUserSwitcher; 61 } 62 63 public void setKeyguardMode(boolean keyguardShowing) { 64 mKeyguardMode = keyguardShowing; 65 } 66 67 @Override 68 public void onClick(View v) { 69 final UserManager um = UserManager.get(getContext()); 70 if (um.isUserSwitcherEnabled()) { 71 if (mKeyguardMode) { 72 if (mKeyguardUserSwitcher != null) { 73 mKeyguardUserSwitcher.show(true /* animate */); 74 } 75 } else { 76 mQsPanel.showDetailAdapter(true, 77 mQsPanel.getHost().getUserSwitcherController().userDetailAdapter); 78 } 79 } else { 80 Intent intent = ContactsContract.QuickContact.composeQuickContactsIntent( 81 getContext(), v, ContactsContract.Profile.CONTENT_URI, 82 ContactsContract.QuickContact.MODE_LARGE, null); 83 getContext().startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT)); 84 } 85 } 86 87 @Override 88 public void onPopulateAccessibilityEvent(AccessibilityEvent event) { 89 super.onPopulateAccessibilityEvent(event); 90 91 if (isClickable()) { 92 final UserManager um = UserManager.get(getContext()); 93 String text = mContext.getString(um.isUserSwitcherEnabled() 94 ? R.string.accessibility_multi_user_switch_switcher 95 : R.string.accessibility_multi_user_switch_quick_contact); 96 if (!TextUtils.isEmpty(text)) { 97 event.getText().add(text); 98 } 99 } 100 101 } 102 103 @Override 104 public boolean hasOverlappingRendering() { 105 return false; 106 } 107} 108