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