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