Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file |
| 5 | * except in compliance with the License. You may obtain a copy of the License at |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software distributed under the |
| 10 | * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 11 | * KIND, either express or implied. See the License for the specific language governing |
| 12 | * permissions and limitations under the License. |
| 13 | */ |
| 14 | package com.android.systemui.qs.car; |
| 15 | |
| 16 | import android.content.Context; |
| 17 | import android.content.Intent; |
| 18 | import android.graphics.drawable.Drawable; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 19 | import android.util.AttributeSet; |
Bryan Eyler | 2ff9584 | 2017-08-08 16:53:33 -0700 | [diff] [blame] | 20 | import android.util.Log; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 21 | import android.widget.ImageView; |
| 22 | import android.widget.RelativeLayout; |
Bryan Eyler | cade225 | 2017-08-31 17:57:45 -0700 | [diff] [blame] | 23 | import android.widget.TextView; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 24 | |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 25 | import androidx.annotation.Nullable; |
| 26 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 27 | import com.android.systemui.Dependency; |
| 28 | import com.android.systemui.R; |
| 29 | import com.android.systemui.plugins.ActivityStarter; |
| 30 | import com.android.systemui.qs.QSFooter; |
| 31 | import com.android.systemui.qs.QSPanel; |
| 32 | import com.android.systemui.statusbar.phone.MultiUserSwitch; |
| 33 | import com.android.systemui.statusbar.policy.DeviceProvisionedController; |
| 34 | import com.android.systemui.statusbar.policy.UserInfoController; |
| 35 | |
| 36 | /** |
| 37 | * The footer view that displays below the status bar in the auto use-case. This view shows the |
| 38 | * user switcher and access to settings. |
| 39 | */ |
| 40 | public class CarQSFooter extends RelativeLayout implements QSFooter, |
| 41 | UserInfoController.OnUserInfoChangedListener { |
Bryan Eyler | 2ff9584 | 2017-08-08 16:53:33 -0700 | [diff] [blame] | 42 | private static final String TAG = "CarQSFooter"; |
| 43 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 44 | private UserInfoController mUserInfoController; |
| 45 | |
| 46 | private MultiUserSwitch mMultiUserSwitch; |
Bryan Eyler | cade225 | 2017-08-31 17:57:45 -0700 | [diff] [blame] | 47 | private TextView mUserName; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 48 | private ImageView mMultiUserAvatar; |
Bryan Eyler | 715bdbc | 2017-10-10 11:56:21 -0700 | [diff] [blame] | 49 | private CarQSFragment.UserSwitchCallback mUserSwitchCallback; |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 50 | |
| 51 | public CarQSFooter(Context context, AttributeSet attrs) { |
| 52 | super(context, attrs); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | protected void onFinishInflate() { |
| 57 | super.onFinishInflate(); |
| 58 | mMultiUserSwitch = findViewById(R.id.multi_user_switch); |
| 59 | mMultiUserAvatar = mMultiUserSwitch.findViewById(R.id.multi_user_avatar); |
Bryan Eyler | cade225 | 2017-08-31 17:57:45 -0700 | [diff] [blame] | 60 | mUserName = findViewById(R.id.user_name); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 61 | |
| 62 | mUserInfoController = Dependency.get(UserInfoController.class); |
| 63 | |
Bryan Eyler | 2ff9584 | 2017-08-08 16:53:33 -0700 | [diff] [blame] | 64 | mMultiUserSwitch.setOnClickListener(v -> { |
Bryan Eyler | 715bdbc | 2017-10-10 11:56:21 -0700 | [diff] [blame] | 65 | if (mUserSwitchCallback == null) { |
Bryan Eyler | 2ff9584 | 2017-08-08 16:53:33 -0700 | [diff] [blame] | 66 | Log.e(TAG, "CarQSFooter not properly set up; cannot display user switcher."); |
| 67 | return; |
| 68 | } |
| 69 | |
Bryan Eyler | 715bdbc | 2017-10-10 11:56:21 -0700 | [diff] [blame] | 70 | if (!mUserSwitchCallback.isShowing()) { |
| 71 | mUserSwitchCallback.show(); |
Bryan Eyler | 2ff9584 | 2017-08-08 16:53:33 -0700 | [diff] [blame] | 72 | } else { |
Bryan Eyler | 715bdbc | 2017-10-10 11:56:21 -0700 | [diff] [blame] | 73 | mUserSwitchCallback.hide(); |
Bryan Eyler | 2ff9584 | 2017-08-08 16:53:33 -0700 | [diff] [blame] | 74 | } |
| 75 | }); |
| 76 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 77 | findViewById(R.id.settings_button).setOnClickListener(v -> { |
| 78 | ActivityStarter activityStarter = Dependency.get(ActivityStarter.class); |
| 79 | |
| 80 | if (!Dependency.get(DeviceProvisionedController.class).isCurrentUserSetup()) { |
| 81 | // If user isn't setup just unlock the device and dump them back at SUW. |
| 82 | activityStarter.postQSRunnableDismissingKeyguard(() -> { }); |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | activityStarter.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS), |
| 87 | true /* dismissShade */); |
| 88 | }); |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public void onUserInfoChanged(String name, Drawable picture, String userAccount) { |
| 93 | mMultiUserAvatar.setImageDrawable(picture); |
Bryan Eyler | cade225 | 2017-08-31 17:57:45 -0700 | [diff] [blame] | 94 | mUserName.setText(name); |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @Override |
| 98 | public void setQSPanel(@Nullable QSPanel panel) { |
| 99 | if (panel != null) { |
| 100 | mMultiUserSwitch.setQsPanel(panel); |
| 101 | } |
| 102 | } |
| 103 | |
Bryan Eyler | 715bdbc | 2017-10-10 11:56:21 -0700 | [diff] [blame] | 104 | public void setUserSwitchCallback(CarQSFragment.UserSwitchCallback callback) { |
| 105 | mUserSwitchCallback = callback; |
Bryan Eyler | 2ff9584 | 2017-08-08 16:53:33 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 108 | @Override |
| 109 | public void setListening(boolean listening) { |
| 110 | if (listening) { |
| 111 | mUserInfoController.addCallback(this); |
| 112 | } else { |
| 113 | mUserInfoController.removeCallback(this); |
| 114 | } |
| 115 | } |
| 116 | |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 117 | @Override |
Amin Shaikh | 8a3e23c | 2018-04-17 11:14:32 -0400 | [diff] [blame] | 118 | public void setExpandClickListener(OnClickListener onClickListener) { |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 119 | // No view that should expand/collapse the quick settings. |
Anthony Chen | 54daefe | 2017-04-07 17:19:54 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public void setExpanded(boolean expanded) { |
| 124 | // Do nothing because the quick settings cannot be expanded. |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public void setExpansion(float expansion) { |
| 129 | // Do nothing because the quick settings cannot be expanded. |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public void setKeyguardShowing(boolean keyguardShowing) { |
| 134 | // Do nothing because the footer will not be shown when the keyguard is up. |
| 135 | } |
| 136 | } |