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;
19 import android.support.annotation.Nullable;
20 import android.util.AttributeSet;
21 import android.util.Log;
22 import android.view.View;
23 import android.widget.ImageView;
24 import android.widget.RelativeLayout;
25 import android.widget.TextView;
26 
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 {
42     private static final String TAG = "CarQSFooter";
43 
44     private UserInfoController mUserInfoController;
45 
46     private MultiUserSwitch mMultiUserSwitch;
47     private TextView mUserName;
48     private ImageView mMultiUserAvatar;
49     private CarQSFragment.UserSwitchCallback mUserSwitchCallback;
50 
CarQSFooter(Context context, AttributeSet attrs)51     public CarQSFooter(Context context, AttributeSet attrs) {
52         super(context, attrs);
53     }
54 
55     @Override
onFinishInflate()56     protected void onFinishInflate() {
57         super.onFinishInflate();
58         mMultiUserSwitch = findViewById(R.id.multi_user_switch);
59         mMultiUserAvatar = mMultiUserSwitch.findViewById(R.id.multi_user_avatar);
60         mUserName = findViewById(R.id.user_name);
61 
62         mUserInfoController = Dependency.get(UserInfoController.class);
63 
64         mMultiUserSwitch.setOnClickListener(v -> {
65             if (mUserSwitchCallback == null) {
66                 Log.e(TAG, "CarQSFooter not properly set up; cannot display user switcher.");
67                 return;
68             }
69 
70             if (!mUserSwitchCallback.isShowing()) {
71                 mUserSwitchCallback.show();
72             } else {
73                 mUserSwitchCallback.hide();
74             }
75         });
76 
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
onUserInfoChanged(String name, Drawable picture, String userAccount)92     public void onUserInfoChanged(String name, Drawable picture, String userAccount) {
93         mMultiUserAvatar.setImageDrawable(picture);
94         mUserName.setText(name);
95     }
96 
97     @Override
setQSPanel(@ullable QSPanel panel)98     public void setQSPanel(@Nullable QSPanel panel) {
99         if (panel != null) {
100             mMultiUserSwitch.setQsPanel(panel);
101         }
102     }
103 
setUserSwitchCallback(CarQSFragment.UserSwitchCallback callback)104     public void setUserSwitchCallback(CarQSFragment.UserSwitchCallback callback) {
105         mUserSwitchCallback = callback;
106     }
107 
108     @Override
setListening(boolean listening)109     public void setListening(boolean listening) {
110         if (listening) {
111             mUserInfoController.addCallback(this);
112         } else {
113             mUserInfoController.removeCallback(this);
114         }
115     }
116 
117     @Override
setExpandClickListener(OnClickListener onClickListener)118     public void setExpandClickListener(OnClickListener onClickListener) {
119         // No view that should expand/collapse the quick settings.
120     }
121 
122     @Override
setExpanded(boolean expanded)123     public void setExpanded(boolean expanded) {
124         // Do nothing because the quick settings cannot be expanded.
125     }
126 
127     @Override
setExpansion(float expansion)128     public void setExpansion(float expansion) {
129         // Do nothing because the quick settings cannot be expanded.
130     }
131 
132     @Override
setKeyguardShowing(boolean keyguardShowing)133     public void setKeyguardShowing(boolean keyguardShowing) {
134         // Do nothing because the footer will not be shown when the keyguard is up.
135     }
136 }
137