Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 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; |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 21 | import android.os.UserManager; |
| 22 | import android.provider.ContactsContract; |
Adrian Roos | 1de02ee | 2014-08-12 15:10:19 +0200 | [diff] [blame] | 23 | import android.text.TextUtils; |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 24 | import android.util.AttributeSet; |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 25 | import android.view.View; |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 26 | import android.view.ViewGroup; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 27 | import android.view.accessibility.AccessibilityEvent; |
| 28 | import android.view.accessibility.AccessibilityNodeInfo; |
| 29 | import android.widget.Button; |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 30 | import android.widget.FrameLayout; |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 31 | |
Adrian Roos | 1de02ee | 2014-08-12 15:10:19 +0200 | [diff] [blame] | 32 | import com.android.systemui.R; |
Jason Monk | 46767b7 | 2016-08-18 10:58:04 -0400 | [diff] [blame] | 33 | import com.android.systemui.plugins.qs.QSContainer.DetailAdapter; |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 34 | import com.android.systemui.qs.QSPanel; |
Adrian Roos | 723632e | 2014-07-23 21:13:21 +0200 | [diff] [blame] | 35 | import com.android.systemui.statusbar.policy.KeyguardUserSwitcher; |
Adrian Roos | 57cf570 | 2014-09-03 15:56:30 +0200 | [diff] [blame] | 36 | import com.android.systemui.statusbar.policy.UserSwitcherController; |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 37 | |
| 38 | /** |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 39 | * Container for image of the multi user switcher (tappable). |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 40 | */ |
Jorim Jaggi | 3f48f46 | 2014-07-08 16:53:29 +0200 | [diff] [blame] | 41 | public class MultiUserSwitch extends FrameLayout implements View.OnClickListener { |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 42 | |
Muyuan Li | 92c9141 | 2016-05-04 17:06:29 -0700 | [diff] [blame] | 43 | protected QSPanel mQsPanel; |
Adrian Roos | 723632e | 2014-07-23 21:13:21 +0200 | [diff] [blame] | 44 | private KeyguardUserSwitcher mKeyguardUserSwitcher; |
| 45 | private boolean mKeyguardMode; |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 46 | private UserSwitcherController.BaseUserAdapter mUserListener; |
| 47 | |
Adrian Roos | 1de02ee | 2014-08-12 15:10:19 +0200 | [diff] [blame] | 48 | final UserManager mUserManager; |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 49 | |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 50 | private final int[] mTmpInt2 = new int[2]; |
| 51 | |
Muyuan Li | 92c9141 | 2016-05-04 17:06:29 -0700 | [diff] [blame] | 52 | protected UserSwitcherController mUserSwitcherController; |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 53 | |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 54 | public MultiUserSwitch(Context context, AttributeSet attrs) { |
| 55 | super(context, attrs); |
Adrian Roos | 1de02ee | 2014-08-12 15:10:19 +0200 | [diff] [blame] | 56 | mUserManager = UserManager.get(getContext()); |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | @Override |
| 60 | protected void onFinishInflate() { |
| 61 | super.onFinishInflate(); |
| 62 | setOnClickListener(this); |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 63 | refreshContentDescription(); |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 64 | } |
| 65 | |
Adrian Roos | 1ef80fe | 2014-07-14 22:53:54 +0200 | [diff] [blame] | 66 | public void setQsPanel(QSPanel qsPanel) { |
| 67 | mQsPanel = qsPanel; |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 68 | setUserSwitcherController(qsPanel.getHost().getUserSwitcherController()); |
| 69 | } |
| 70 | |
Jason Monk | 69e76cc | 2016-01-26 10:56:37 -0500 | [diff] [blame] | 71 | public boolean hasMultipleUsers() { |
Steve Pfetsch | ef39ce8 | 2016-01-28 18:41:19 -0800 | [diff] [blame] | 72 | if (mUserListener == null) { |
| 73 | return false; |
| 74 | } |
Jason Monk | 69e76cc | 2016-01-26 10:56:37 -0500 | [diff] [blame] | 75 | return mUserListener.getCount() != 0; |
| 76 | } |
| 77 | |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 78 | public void setUserSwitcherController(UserSwitcherController userSwitcherController) { |
| 79 | mUserSwitcherController = userSwitcherController; |
| 80 | registerListener(); |
| 81 | refreshContentDescription(); |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 82 | } |
| 83 | |
Adrian Roos | 723632e | 2014-07-23 21:13:21 +0200 | [diff] [blame] | 84 | public void setKeyguardUserSwitcher(KeyguardUserSwitcher keyguardUserSwitcher) { |
| 85 | mKeyguardUserSwitcher = keyguardUserSwitcher; |
| 86 | } |
| 87 | |
| 88 | public void setKeyguardMode(boolean keyguardShowing) { |
| 89 | mKeyguardMode = keyguardShowing; |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 90 | registerListener(); |
| 91 | } |
| 92 | |
| 93 | private void registerListener() { |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 94 | if (mUserManager.isUserSwitcherEnabled() && mUserListener == null) { |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 95 | |
| 96 | final UserSwitcherController controller = mUserSwitcherController; |
| 97 | if (controller != null) { |
| 98 | mUserListener = new UserSwitcherController.BaseUserAdapter(controller) { |
| 99 | @Override |
| 100 | public void notifyDataSetChanged() { |
| 101 | refreshContentDescription(); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public View getView(int position, View convertView, ViewGroup parent) { |
| 106 | return null; |
| 107 | } |
| 108 | }; |
| 109 | refreshContentDescription(); |
| 110 | } |
| 111 | } |
Adrian Roos | 723632e | 2014-07-23 21:13:21 +0200 | [diff] [blame] | 112 | } |
| 113 | |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 114 | @Override |
| 115 | public void onClick(View v) { |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 116 | if (mUserManager.isUserSwitcherEnabled()) { |
Adrian Roos | 723632e | 2014-07-23 21:13:21 +0200 | [diff] [blame] | 117 | if (mKeyguardMode) { |
| 118 | if (mKeyguardUserSwitcher != null) { |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 119 | mKeyguardUserSwitcher.show(true /* animate */); |
Adrian Roos | 723632e | 2014-07-23 21:13:21 +0200 | [diff] [blame] | 120 | } |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 121 | } else if (mQsPanel != null && mUserSwitcherController != null) { |
| 122 | View center = getChildCount() > 0 ? getChildAt(0) : this; |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 123 | |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 124 | center.getLocationInWindow(mTmpInt2); |
| 125 | mTmpInt2[0] += center.getWidth() / 2; |
| 126 | mTmpInt2[1] += center.getHeight() / 2; |
Adrian Roos | 970be53 | 2014-11-21 15:50:16 +0100 | [diff] [blame] | 127 | |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 128 | mQsPanel.showDetailAdapter(true, |
Muyuan Li | 92c9141 | 2016-05-04 17:06:29 -0700 | [diff] [blame] | 129 | getUserDetailAdapter(), |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 130 | mTmpInt2); |
Adrian Roos | 723632e | 2014-07-23 21:13:21 +0200 | [diff] [blame] | 131 | } |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 132 | } else { |
Akira Oshimi | f37adce | 2015-02-25 13:57:28 +0900 | [diff] [blame] | 133 | if (mQsPanel != null) { |
Kaori Katou | ccf08d7 | 2015-05-26 16:25:04 +0900 | [diff] [blame] | 134 | Intent intent = ContactsContract.QuickContact.composeQuickContactsIntent( |
| 135 | getContext(), v, ContactsContract.Profile.CONTENT_URI, |
| 136 | ContactsContract.QuickContact.MODE_LARGE, null); |
Adrian Roos | bc3e2e1 | 2016-03-23 11:23:51 -0700 | [diff] [blame] | 137 | mQsPanel.getHost().startActivityDismissingKeyguard(intent); |
Akira Oshimi | f37adce | 2015-02-25 13:57:28 +0900 | [diff] [blame] | 138 | } |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 139 | } |
| 140 | } |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 141 | |
| 142 | @Override |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 143 | public void setClickable(boolean clickable) { |
| 144 | super.setClickable(clickable); |
| 145 | refreshContentDescription(); |
| 146 | } |
Adrian Roos | 1de02ee | 2014-08-12 15:10:19 +0200 | [diff] [blame] | 147 | |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 148 | private void refreshContentDescription() { |
| 149 | String currentUser = null; |
Fyodor Kupolov | cd86ebf | 2015-09-29 17:06:50 -0700 | [diff] [blame] | 150 | if (mUserManager.isUserSwitcherEnabled() |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 151 | && mUserSwitcherController != null) { |
| 152 | currentUser = mUserSwitcherController.getCurrentUserName(mContext); |
| 153 | } |
| 154 | |
| 155 | String text = null; |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 156 | |
| 157 | if (!TextUtils.isEmpty(currentUser)) { |
| 158 | text = mContext.getString( |
| 159 | R.string.accessibility_quick_settings_user, |
| 160 | currentUser); |
Adrian Roos | 1de02ee | 2014-08-12 15:10:19 +0200 | [diff] [blame] | 161 | } |
| 162 | |
Adrian Roos | ffc9097 | 2015-06-09 18:09:49 -0700 | [diff] [blame] | 163 | if (!TextUtils.equals(getContentDescription(), text)) { |
| 164 | setContentDescription(text); |
| 165 | } |
Adrian Roos | 1de02ee | 2014-08-12 15:10:19 +0200 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | @Override |
Julia Reynolds | 20aef8a | 2016-05-04 16:44:08 -0400 | [diff] [blame] | 169 | public void onInitializeAccessibilityEvent(AccessibilityEvent event) { |
| 170 | super.onInitializeAccessibilityEvent(event); |
| 171 | event.setClassName(Button.class.getName()); |
| 172 | } |
| 173 | |
| 174 | @Override |
| 175 | public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { |
| 176 | super.onInitializeAccessibilityNodeInfo(info); |
| 177 | info.setClassName(Button.class.getName()); |
| 178 | } |
| 179 | |
| 180 | @Override |
Jorim Jaggi | 98f8530 | 2014-08-07 17:45:04 +0200 | [diff] [blame] | 181 | public boolean hasOverlappingRendering() { |
| 182 | return false; |
| 183 | } |
Adrian Roos | 81e3e94 | 2014-09-18 21:11:20 +0200 | [diff] [blame] | 184 | |
Jason Monk | 46767b7 | 2016-08-18 10:58:04 -0400 | [diff] [blame] | 185 | protected DetailAdapter getUserDetailAdapter() { |
Muyuan Li | 92c9141 | 2016-05-04 17:06:29 -0700 | [diff] [blame] | 186 | return mUserSwitcherController.userDetailAdapter; |
| 187 | } |
Jorim Jaggi | 3d878be | 2014-05-10 03:22:32 +0200 | [diff] [blame] | 188 | } |