blob: 0389030a17b2c3cc30e5336508854241fe784fb6 [file] [log] [blame]
Anthony Chen54daefe2017-04-07 17:19:54 -07001/*
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 */
14package com.android.systemui.qs.car;
15
16import android.content.Context;
17import android.content.Intent;
18import android.graphics.drawable.Drawable;
Anthony Chen54daefe2017-04-07 17:19:54 -070019import android.util.AttributeSet;
Bryan Eyler2ff95842017-08-08 16:53:33 -070020import android.util.Log;
Anthony Chen54daefe2017-04-07 17:19:54 -070021import android.widget.ImageView;
22import android.widget.RelativeLayout;
Bryan Eylercade2252017-08-31 17:57:45 -070023import android.widget.TextView;
Anthony Chen54daefe2017-04-07 17:19:54 -070024
Gus Prevasab336792018-11-14 13:52:20 -050025import androidx.annotation.Nullable;
26
Anthony Chen54daefe2017-04-07 17:19:54 -070027import com.android.systemui.Dependency;
28import com.android.systemui.R;
29import com.android.systemui.plugins.ActivityStarter;
30import com.android.systemui.qs.QSFooter;
31import com.android.systemui.qs.QSPanel;
32import com.android.systemui.statusbar.phone.MultiUserSwitch;
33import com.android.systemui.statusbar.policy.DeviceProvisionedController;
34import 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 */
40public class CarQSFooter extends RelativeLayout implements QSFooter,
41 UserInfoController.OnUserInfoChangedListener {
Bryan Eyler2ff95842017-08-08 16:53:33 -070042 private static final String TAG = "CarQSFooter";
43
Anthony Chen54daefe2017-04-07 17:19:54 -070044 private UserInfoController mUserInfoController;
45
46 private MultiUserSwitch mMultiUserSwitch;
Bryan Eylercade2252017-08-31 17:57:45 -070047 private TextView mUserName;
Anthony Chen54daefe2017-04-07 17:19:54 -070048 private ImageView mMultiUserAvatar;
Bryan Eyler715bdbc2017-10-10 11:56:21 -070049 private CarQSFragment.UserSwitchCallback mUserSwitchCallback;
Anthony Chen54daefe2017-04-07 17:19:54 -070050
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 Eylercade2252017-08-31 17:57:45 -070060 mUserName = findViewById(R.id.user_name);
Anthony Chen54daefe2017-04-07 17:19:54 -070061
62 mUserInfoController = Dependency.get(UserInfoController.class);
63
Bryan Eyler2ff95842017-08-08 16:53:33 -070064 mMultiUserSwitch.setOnClickListener(v -> {
Bryan Eyler715bdbc2017-10-10 11:56:21 -070065 if (mUserSwitchCallback == null) {
Bryan Eyler2ff95842017-08-08 16:53:33 -070066 Log.e(TAG, "CarQSFooter not properly set up; cannot display user switcher.");
67 return;
68 }
69
Bryan Eyler715bdbc2017-10-10 11:56:21 -070070 if (!mUserSwitchCallback.isShowing()) {
71 mUserSwitchCallback.show();
Bryan Eyler2ff95842017-08-08 16:53:33 -070072 } else {
Bryan Eyler715bdbc2017-10-10 11:56:21 -070073 mUserSwitchCallback.hide();
Bryan Eyler2ff95842017-08-08 16:53:33 -070074 }
75 });
76
Anthony Chen54daefe2017-04-07 17:19:54 -070077 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 Eylercade2252017-08-31 17:57:45 -070094 mUserName.setText(name);
Anthony Chen54daefe2017-04-07 17:19:54 -070095 }
96
97 @Override
98 public void setQSPanel(@Nullable QSPanel panel) {
99 if (panel != null) {
100 mMultiUserSwitch.setQsPanel(panel);
101 }
102 }
103
Bryan Eyler715bdbc2017-10-10 11:56:21 -0700104 public void setUserSwitchCallback(CarQSFragment.UserSwitchCallback callback) {
105 mUserSwitchCallback = callback;
Bryan Eyler2ff95842017-08-08 16:53:33 -0700106 }
107
Anthony Chen54daefe2017-04-07 17:19:54 -0700108 @Override
109 public void setListening(boolean listening) {
110 if (listening) {
111 mUserInfoController.addCallback(this);
112 } else {
113 mUserInfoController.removeCallback(this);
114 }
115 }
116
Anthony Chen54daefe2017-04-07 17:19:54 -0700117 @Override
Amin Shaikh8a3e23c2018-04-17 11:14:32 -0400118 public void setExpandClickListener(OnClickListener onClickListener) {
Anthony Chen54daefe2017-04-07 17:19:54 -0700119 // No view that should expand/collapse the quick settings.
Anthony Chen54daefe2017-04-07 17:19:54 -0700120 }
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}