blob: 08cd053b59032e63df5f844b492896afd597f7cc [file] [log] [blame]
Rakesh Iyer1186faa2015-12-07 16:48:46 -08001/*
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
Victor Chan1c6d0582016-01-09 16:26:37 -080019import android.app.ActivityManager;
20import android.app.ITaskStackListener;
Rakesh Iyer1186faa2015-12-07 16:48:46 -080021import android.content.Context;
22import android.graphics.PixelFormat;
Victor Chan1c6d0582016-01-09 16:26:37 -080023import android.os.Handler;
24import android.os.Looper;
Rakesh Iyer1186faa2015-12-07 16:48:46 -080025import android.view.View;
26import android.view.ViewGroup.LayoutParams;
Rakesh Iyer2790a372016-01-22 15:33:39 -080027import android.view.ViewStub;
Rakesh Iyer1186faa2015-12-07 16:48:46 -080028import android.view.WindowManager;
29
30import com.android.systemui.R;
Victor Chan1c6d0582016-01-09 16:26:37 -080031import com.android.systemui.recents.Recents;
32import com.android.systemui.recents.misc.SystemServicesProxy;
Rakesh Iyer2790a372016-01-22 15:33:39 -080033import com.android.systemui.statusbar.StatusBarState;
Rakesh Iyer1186faa2015-12-07 16:48:46 -080034import com.android.systemui.statusbar.phone.PhoneStatusBar;
35
36/**
37 * A status bar (and navigation bar) tailored for the automotive use case.
38 */
39public class CarStatusBar extends PhoneStatusBar {
Victor Chan1c6d0582016-01-09 16:26:37 -080040 private SystemServicesProxy mSystemServicesProxy;
41 private TaskStackListenerImpl mTaskStackListener;
42 private Handler mHandler;
43
44 private CarNavigationBarView mCarNavigationBar;
45 private CarNavigationBarController mController;
Rakesh Iyer2790a372016-01-22 15:33:39 -080046 private FullscreenUserSwitcher mFullscreenUserSwitcher;
Victor Chan1c6d0582016-01-09 16:26:37 -080047
48 @Override
49 public void start() {
50 super.start();
51 mHandler = new Handler();
52 mTaskStackListener = new TaskStackListenerImpl(mHandler);
53 mSystemServicesProxy = new SystemServicesProxy(mContext);
54 mSystemServicesProxy.registerTaskStackListener(mTaskStackListener);
55 }
56
Rakesh Iyer1186faa2015-12-07 16:48:46 -080057 @Override
58 protected void addNavigationBar() {
59 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
60 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
61 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
Victor Chan1c6d0582016-01-09 16:26:37 -080062 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
63 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
64 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
65 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
66 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
67 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
Rakesh Iyer1186faa2015-12-07 16:48:46 -080068 PixelFormat.TRANSLUCENT);
69 lp.setTitle("CarNavigationBar");
70 lp.windowAnimations = 0;
71 mWindowManager.addView(mNavigationBarView, lp);
72 }
73
74 @Override
75 protected void createNavigationBarView(Context context) {
76 if (mNavigationBarView != null) {
77 return;
78 }
Victor Chan1c6d0582016-01-09 16:26:37 -080079 mCarNavigationBar =
Rakesh Iyer1186faa2015-12-07 16:48:46 -080080 (CarNavigationBarView) View.inflate(context, R.layout.car_navigation_bar, null);
Victor Chan1c6d0582016-01-09 16:26:37 -080081 mController = new CarNavigationBarController(context, mCarNavigationBar,
82 this /* ActivityStarter*/);
83 mNavigationBarView = mCarNavigationBar;
Rakesh Iyer1186faa2015-12-07 16:48:46 -080084 }
Victor Chanecdb8b02016-01-07 18:32:43 -080085
86 @Override
87 protected void repositionNavigationBar() {
88 // The navigation bar for a vehicle will not need to be repositioned, as it is always
89 // set at the bottom.
90 }
Victor Chan1c6d0582016-01-09 16:26:37 -080091
92 /**
93 * An implementation of ITaskStackListener, that listens for changes in the system task
94 * stack and notifies the navigation bar.
95 */
96 private class TaskStackListenerImpl extends ITaskStackListener.Stub implements Runnable {
97 private Handler mHandler;
98
99 public TaskStackListenerImpl(Handler handler) {
100 this.mHandler = handler;
101 }
102
103 @Override
104 public void onActivityPinned() {
105 }
106
107 @Override
Wale Ogunwalecc25a8a2016-01-23 14:31:37 -0800108 public void onPinnedActivityRestartAttempt() {
109 }
110
111 @Override
Wale Ogunwale480dca02016-02-06 13:58:29 -0800112 public void onPinnedStackAnimationEnded() {
113 }
114
115 @Override
Victor Chan1c6d0582016-01-09 16:26:37 -0800116 public void onTaskStackChanged() {
117 mHandler.removeCallbacks(this);
118 mHandler.post(this);
119 }
120
121 @Override
122 public void run() {
123 ensureMainThread();
124 SystemServicesProxy ssp = Recents.getSystemServices();
125 ActivityManager.RunningTaskInfo runningTaskInfo = ssp.getTopMostTask();
126 mController.taskChanged(runningTaskInfo.baseActivity.getPackageName());
127 }
128
129 private void ensureMainThread() {
130 if (!Looper.getMainLooper().isCurrentThread()) {
131 throw new RuntimeException("Must be called on the UI thread");
132 }
133 }
134 }
Rakesh Iyer2790a372016-01-22 15:33:39 -0800135
136 @Override
137 protected void createUserSwitcher() {
138 if (mUserSwitcherController.useFullscreenUserSwitcher()) {
139 mFullscreenUserSwitcher = new FullscreenUserSwitcher(this, mUserSwitcherController,
140 (ViewStub) mStatusBarWindow.findViewById(R.id.fullscreen_user_switcher_stub));
141 } else {
142 super.createUserSwitcher();
143 }
144 }
145
146 @Override
147 public void userSwitched(int newUserId) {
148 super.userSwitched(newUserId);
149 if (mFullscreenUserSwitcher != null) {
150 mFullscreenUserSwitcher.onUserSwitched(newUserId);
151 }
152 }
153
154 @Override
155 public void updateKeyguardState(boolean goingToFullShade, boolean fromShadeLocked) {
156 super.updateKeyguardState(goingToFullShade, fromShadeLocked);
157 if (mFullscreenUserSwitcher != null) {
158 if (mState == StatusBarState.FULLSCREEN_USER_SWITCHER) {
159 mFullscreenUserSwitcher.show();
160 } else {
161 mFullscreenUserSwitcher.hide();
162 }
163 }
164 }
Rakesh Iyer1186faa2015-12-07 16:48:46 -0800165}