1 /* 2 * Copyright (C) 2018 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.qs.car; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.graphics.drawable.Drawable; 22 import android.util.AttributeSet; 23 import android.util.Log; 24 import android.widget.ImageView; 25 import android.widget.RelativeLayout; 26 import android.widget.TextView; 27 28 import androidx.annotation.Nullable; 29 30 import com.android.systemui.Dependency; 31 import com.android.systemui.R; 32 import com.android.systemui.plugins.ActivityStarter; 33 import com.android.systemui.qs.QSFooter; 34 import com.android.systemui.qs.QSPanel; 35 import com.android.systemui.statusbar.phone.MultiUserSwitch; 36 import com.android.systemui.statusbar.policy.DeviceProvisionedController; 37 import com.android.systemui.statusbar.policy.UserInfoController; 38 39 /** 40 * The footer view that displays below the status bar in the auto use-case. This view shows the 41 * user switcher and access to settings. 42 */ 43 public class CarQSFooter extends RelativeLayout implements QSFooter, 44 UserInfoController.OnUserInfoChangedListener { 45 private static final String TAG = "CarQSFooter"; 46 47 private UserInfoController mUserInfoController; 48 49 private MultiUserSwitch mMultiUserSwitch; 50 private TextView mUserName; 51 private ImageView mMultiUserAvatar; 52 private CarQSFragment.UserSwitchCallback mUserSwitchCallback; 53 CarQSFooter(Context context, AttributeSet attrs)54 public CarQSFooter(Context context, AttributeSet attrs) { 55 super(context, attrs); 56 } 57 58 @Override onFinishInflate()59 protected void onFinishInflate() { 60 super.onFinishInflate(); 61 mMultiUserSwitch = findViewById(R.id.multi_user_switch); 62 mMultiUserAvatar = mMultiUserSwitch.findViewById(R.id.multi_user_avatar); 63 mUserName = findViewById(R.id.user_name); 64 65 mUserInfoController = Dependency.get(UserInfoController.class); 66 67 mMultiUserSwitch.setOnClickListener(v -> { 68 if (mUserSwitchCallback == null) { 69 Log.e(TAG, "CarQSFooter not properly set up; cannot display user switcher."); 70 return; 71 } 72 73 if (!mUserSwitchCallback.isShowing()) { 74 mUserSwitchCallback.show(); 75 } else { 76 mUserSwitchCallback.hide(); 77 } 78 }); 79 80 findViewById(R.id.settings_button).setOnClickListener(v -> { 81 ActivityStarter activityStarter = Dependency.get(ActivityStarter.class); 82 83 if (!Dependency.get(DeviceProvisionedController.class).isCurrentUserSetup()) { 84 // If user isn't setup just unlock the device and dump them back at SUW. 85 activityStarter.postQSRunnableDismissingKeyguard(() -> { }); 86 return; 87 } 88 89 activityStarter.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS), 90 true /* dismissShade */); 91 }); 92 } 93 94 @Override onUserInfoChanged(String name, Drawable picture, String userAccount)95 public void onUserInfoChanged(String name, Drawable picture, String userAccount) { 96 mMultiUserAvatar.setImageDrawable(picture); 97 mUserName.setText(name); 98 } 99 100 @Override setQSPanel(@ullable QSPanel panel)101 public void setQSPanel(@Nullable QSPanel panel) { 102 if (panel != null) { 103 mMultiUserSwitch.setQsPanel(panel); 104 } 105 } 106 setUserSwitchCallback(CarQSFragment.UserSwitchCallback callback)107 public void setUserSwitchCallback(CarQSFragment.UserSwitchCallback callback) { 108 mUserSwitchCallback = callback; 109 } 110 111 @Override setListening(boolean listening)112 public void setListening(boolean listening) { 113 if (listening) { 114 mUserInfoController.addCallback(this); 115 } else { 116 mUserInfoController.removeCallback(this); 117 } 118 } 119 120 @Override setExpandClickListener(OnClickListener onClickListener)121 public void setExpandClickListener(OnClickListener onClickListener) { 122 // No view that should expand/collapse the quick settings. 123 } 124 125 @Override setExpanded(boolean expanded)126 public void setExpanded(boolean expanded) { 127 // Do nothing because the quick settings cannot be expanded. 128 } 129 130 @Override setExpansion(float expansion)131 public void setExpansion(float expansion) { 132 // Do nothing because the quick settings cannot be expanded. 133 } 134 135 @Override setKeyguardShowing(boolean keyguardShowing)136 public void setKeyguardShowing(boolean keyguardShowing) { 137 // Do nothing because the footer will not be shown when the keyguard is up. 138 } 139 } 140