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