MultiUserSwitch.java revision 1e4ecf8e7b9351c772d4545adcf89493966da73d
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; 33import com.android.systemui.statusbar.policy.UserSwitcherController; 34 35/** 36 * Container for image of the multi user switcher (tappable). 37 */ 38public 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 final UserManager um = UserManager.get(getContext()); 71 if (um.isUserSwitcherEnabled()) { 72 if (mKeyguardMode) { 73 if (mKeyguardUserSwitcher != null) { 74 mKeyguardUserSwitcher.show(true /* animate */); 75 } 76 } else { 77 if (mQsPanel != null) { 78 mQsPanel.showDetailAdapter(true, 79 mQsPanel.getHost().getUserSwitcherController().userDetailAdapter); 80 } 81 } 82 } else { 83 Intent intent = ContactsContract.QuickContact.composeQuickContactsIntent( 84 getContext(), v, ContactsContract.Profile.CONTENT_URI, 85 ContactsContract.QuickContact.MODE_LARGE, null); 86 getContext().startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT)); 87 } 88 } 89 90 @Override 91 public void onPopulateAccessibilityEvent(AccessibilityEvent event) { 92 super.onPopulateAccessibilityEvent(event); 93 94 if (isClickable()) { 95 final UserManager um = UserManager.get(getContext()); 96 String text; 97 if (um.isUserSwitcherEnabled()) { 98 String currentUser = null; 99 if (mQsPanel != null) { 100 UserSwitcherController controller = mQsPanel.getHost() 101 .getUserSwitcherController(); 102 currentUser = controller.getCurrentUserName(mContext); 103 } 104 if (TextUtils.isEmpty(currentUser)) { 105 text = mContext.getString(R.string.accessibility_multi_user_switch_switcher); 106 } else { 107 text = mContext.getString( 108 R.string.accessibility_multi_user_switch_switcher_with_current, 109 currentUser); 110 } 111 } else { 112 text = mContext.getString(R.string.accessibility_multi_user_switch_quick_contact); 113 } 114 if (!TextUtils.isEmpty(text)) { 115 event.getText().add(text); 116 } 117 } 118 119 } 120 121 @Override 122 public boolean hasOverlappingRendering() { 123 return false; 124 } 125} 126