1/*
2 * Copyright (C) 2015 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
17package com.android.systemui.statusbar.car;
18
19import android.app.UiModeManager;
20import android.content.Context;
21import android.util.AttributeSet;
22import android.util.Log;
23import android.view.View;
24import android.widget.LinearLayout;
25import android.widget.TextView;
26
27import com.android.keyguard.AlphaOptimizedImageButton;
28import com.android.systemui.Dependency;
29import com.android.systemui.R;
30import com.android.systemui.statusbar.phone.StatusBarIconController;
31
32/**
33 * A custom navigation bar for the automotive use case.
34 * <p>
35 * The navigation bar in the automotive use case is more like a list of shortcuts, rendered
36 * in a linear layout.
37 */
38class CarNavigationBarView extends LinearLayout {
39    private View mNavButtons;
40    private AlphaOptimizedImageButton mNotificationsButton;
41    private CarStatusBar mCarStatusBar;
42    private Context mContext;
43    private View mLockScreenButtons;
44
45    public CarNavigationBarView(Context context, AttributeSet attrs) {
46        super(context, attrs);
47        mContext = context;
48    }
49
50    @Override
51    public void onFinishInflate() {
52        mNavButtons = findViewById(R.id.nav_buttons);
53        mLockScreenButtons = findViewById(R.id.lock_screen_nav_buttons);
54
55        mNotificationsButton = findViewById(R.id.notifications);
56        if (mNotificationsButton != null) {
57            mNotificationsButton.setOnClickListener(this::onNotificationsClick);
58        }
59        View mStatusIcons = findViewById(R.id.statusIcons);
60        if (mStatusIcons != null) {
61            // Attach the controllers for Status icons such as wifi and bluetooth if the standard
62            // container is in the view.
63            StatusBarIconController.DarkIconManager mDarkIconManager =
64                    new StatusBarIconController.DarkIconManager(
65                            mStatusIcons.findViewById(R.id.statusIcons));
66            mDarkIconManager.setShouldLog(true);
67            Dependency.get(StatusBarIconController.class).addIconGroup(mDarkIconManager);
68        }
69
70    }
71
72    void setStatusBar(CarStatusBar carStatusBar) {
73        mCarStatusBar = carStatusBar;
74    }
75
76    protected void onNotificationsClick(View v) {
77        mCarStatusBar.togglePanel();
78    }
79
80    /**
81     * If there are buttons declared in the layout they will be shown and the normal
82     * Nav buttons will be hidden.
83     */
84    public void showKeyguardButtons() {
85        if (mLockScreenButtons == null) {
86            return;
87        }
88        mLockScreenButtons.setVisibility(View.VISIBLE);
89        mNavButtons.setVisibility(View.GONE);
90    }
91
92    /**
93     * If there are buttons declared in the layout they will be hidden and the normal
94     * Nav buttons will be shown.
95     */
96    public void hideKeyguardButtons() {
97        if (mLockScreenButtons == null) {
98            return;
99        }
100        mNavButtons.setVisibility(View.VISIBLE);
101        mLockScreenButtons.setVisibility(View.GONE);
102    }
103}
104