Home | History | Annotate | Download | only in phone
      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 (UserSwitcherController.isUserSwitcherAvailable(mUserManager)) {
     71             if (mKeyguardMode) {
     72                 if (mKeyguardUserSwitcher != null) {
     73                     mKeyguardUserSwitcher.show(true /* animate */);
     74                 }
     75             } else {
     76                 if (mQsPanel != null) {
     77                     UserSwitcherController userSwitcherController =
     78                             mQsPanel.getHost().getUserSwitcherController();
     79                     if (userSwitcherController != null) {
     80                         mQsPanel.showDetailAdapter(true, userSwitcherController.userDetailAdapter);
     81                     }
     82                 }
     83             }
     84         } else {
     85             Intent intent = ContactsContract.QuickContact.composeQuickContactsIntent(
     86                     getContext(), v, ContactsContract.Profile.CONTENT_URI,
     87                     ContactsContract.QuickContact.MODE_LARGE, null);
     88             getContext().startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
     89         }
     90     }
     91 
     92     @Override
     93     public void onPopulateAccessibilityEvent(AccessibilityEvent event) {
     94         super.onPopulateAccessibilityEvent(event);
     95 
     96         if (isClickable()) {
     97             String text;
     98             if (UserSwitcherController.isUserSwitcherAvailable(mUserManager)) {
     99                 String currentUser = null;
    100                 if (mQsPanel != null) {
    101                     UserSwitcherController controller = mQsPanel.getHost()
    102                             .getUserSwitcherController();
    103                     if (controller != null) {
    104                         currentUser = controller.getCurrentUserName(mContext);
    105                     }
    106                 }
    107                 if (TextUtils.isEmpty(currentUser)) {
    108                     text = mContext.getString(R.string.accessibility_multi_user_switch_switcher);
    109                 } else {
    110                     text = mContext.getString(
    111                             R.string.accessibility_multi_user_switch_switcher_with_current,
    112                             currentUser);
    113                 }
    114             } else {
    115                 text = mContext.getString(R.string.accessibility_multi_user_switch_quick_contact);
    116             }
    117             if (!TextUtils.isEmpty(text)) {
    118                 event.getText().add(text);
    119             }
    120         }
    121 
    122     }
    123 
    124     @Override
    125     public boolean hasOverlappingRendering() {
    126         return false;
    127     }
    128 
    129 }
    130