blob: d1fc780f0767565dfee3ef1d5351822f96b268eb [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;
Rakesh Iyer9f831f62016-02-16 20:06:22 -080020import android.content.BroadcastReceiver;
Rakesh Iyer1186faa2015-12-07 16:48:46 -080021import android.content.Context;
Rakesh Iyer9f831f62016-02-16 20:06:22 -080022import android.content.Intent;
23import android.content.IntentFilter;
Rakesh Iyer1186faa2015-12-07 16:48:46 -080024import android.graphics.PixelFormat;
Anthony Chenda62fdcd52016-04-06 16:15:14 -070025import android.util.Log;
Rakesh Iyer1186faa2015-12-07 16:48:46 -080026import android.view.View;
27import android.view.ViewGroup.LayoutParams;
Rakesh Iyer2790a372016-01-22 15:33:39 -080028import android.view.ViewStub;
Rakesh Iyer1186faa2015-12-07 16:48:46 -080029import android.view.WindowManager;
Anthony Chenda62fdcd52016-04-06 16:15:14 -070030import com.android.systemui.BatteryMeterView;
Rakesh Iyer1186faa2015-12-07 16:48:46 -080031import com.android.systemui.R;
Victor Chan1c6d0582016-01-09 16:26:37 -080032import com.android.systemui.recents.Recents;
33import com.android.systemui.recents.misc.SystemServicesProxy;
Jaewan Kim938a50b2016-03-14 17:35:43 +090034import com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener;
Rakesh Iyer2790a372016-01-22 15:33:39 -080035import com.android.systemui.statusbar.StatusBarState;
Rakesh Iyer1186faa2015-12-07 16:48:46 -080036import com.android.systemui.statusbar.phone.PhoneStatusBar;
Anthony Chenda62fdcd52016-04-06 16:15:14 -070037import com.android.systemui.statusbar.phone.PhoneStatusBarView;
38import com.android.systemui.statusbar.policy.BatteryController;
Rakesh Iyer1186faa2015-12-07 16:48:46 -080039
40/**
41 * A status bar (and navigation bar) tailored for the automotive use case.
42 */
Anthony Chenda62fdcd52016-04-06 16:15:14 -070043public class CarStatusBar extends PhoneStatusBar implements
44 CarBatteryController.BatteryViewHandler {
45 private static final String TAG = "CarStatusBar";
46
Victor Chan1c6d0582016-01-09 16:26:37 -080047 private TaskStackListenerImpl mTaskStackListener;
Victor Chan1c6d0582016-01-09 16:26:37 -080048
49 private CarNavigationBarView mCarNavigationBar;
50 private CarNavigationBarController mController;
Rakesh Iyer2790a372016-01-22 15:33:39 -080051 private FullscreenUserSwitcher mFullscreenUserSwitcher;
Victor Chan1c6d0582016-01-09 16:26:37 -080052
Anthony Chenda62fdcd52016-04-06 16:15:14 -070053 private CarBatteryController mCarBatteryController;
54 private BatteryMeterView mBatteryMeterView;
55
Victor Chan1c6d0582016-01-09 16:26:37 -080056 @Override
57 public void start() {
58 super.start();
Jaewan Kim938a50b2016-03-14 17:35:43 +090059 mTaskStackListener = new TaskStackListenerImpl();
60 SystemServicesProxy.getInstance(mContext).registerTaskStackListener(mTaskStackListener);
Rakesh Iyer9f831f62016-02-16 20:06:22 -080061 registerPackageChangeReceivers();
Anthony Chenda62fdcd52016-04-06 16:15:14 -070062
63 mCarBatteryController.startListening();
64 }
65
66 @Override
67 public void destroy() {
68 mCarBatteryController.stopListening();
69 super.destroy();
70 }
71
72 @Override
73 protected PhoneStatusBarView makeStatusBarView() {
74 PhoneStatusBarView statusBarView = super.makeStatusBarView();
75
76 mBatteryMeterView = ((BatteryMeterView) statusBarView.findViewById(R.id.battery));
77
78 // By default, the BatteryMeterView should not be visible. It will be toggled visible
79 // when a device has connected by bluetooth.
80 mBatteryMeterView.setVisibility(View.GONE);
81
82 if (Log.isLoggable(TAG, Log.DEBUG)) {
83 Log.d(TAG, "makeStatusBarView(). mBatteryMeterView: " + mBatteryMeterView);
84 }
85
86 return statusBarView;
87 }
88
89 @Override
90 protected BatteryController createBatteryController() {
91 mCarBatteryController = new CarBatteryController(mContext);
92 mCarBatteryController.addBatteryViewHandler(this);
93 return mCarBatteryController;
Victor Chan1c6d0582016-01-09 16:26:37 -080094 }
95
Rakesh Iyer1186faa2015-12-07 16:48:46 -080096 @Override
97 protected void addNavigationBar() {
98 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
99 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
100 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
Victor Chan1c6d0582016-01-09 16:26:37 -0800101 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
102 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
103 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
104 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
105 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
106 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
Rakesh Iyer1186faa2015-12-07 16:48:46 -0800107 PixelFormat.TRANSLUCENT);
108 lp.setTitle("CarNavigationBar");
109 lp.windowAnimations = 0;
110 mWindowManager.addView(mNavigationBarView, lp);
111 }
112
113 @Override
114 protected void createNavigationBarView(Context context) {
115 if (mNavigationBarView != null) {
116 return;
117 }
Victor Chan1c6d0582016-01-09 16:26:37 -0800118 mCarNavigationBar =
Rakesh Iyer1186faa2015-12-07 16:48:46 -0800119 (CarNavigationBarView) View.inflate(context, R.layout.car_navigation_bar, null);
Victor Chan1c6d0582016-01-09 16:26:37 -0800120 mController = new CarNavigationBarController(context, mCarNavigationBar,
121 this /* ActivityStarter*/);
122 mNavigationBarView = mCarNavigationBar;
Rakesh Iyer9f831f62016-02-16 20:06:22 -0800123
124 }
125
Anthony Chenda62fdcd52016-04-06 16:15:14 -0700126 @Override
127 public void showBatteryView() {
128 if (Log.isLoggable(TAG, Log.DEBUG)) {
129 Log.d(TAG, "showBatteryView(). mBatteryMeterView: " + mBatteryMeterView);
130 }
131
132 if (mBatteryMeterView != null) {
133 mBatteryMeterView.setVisibility(View.VISIBLE);
134 }
135 }
136
137 @Override
138 public void hideBatteryView() {
139 if (Log.isLoggable(TAG, Log.DEBUG)) {
140 Log.d(TAG, "hideBatteryView(). mBatteryMeterView: " + mBatteryMeterView);
141 }
142
143 if (mBatteryMeterView != null) {
144 mBatteryMeterView.setVisibility(View.GONE);
145 }
146 }
147
Rakesh Iyer9f831f62016-02-16 20:06:22 -0800148 private BroadcastReceiver mPackageChangeReceiver = new BroadcastReceiver() {
149 @Override
150 public void onReceive(Context context, Intent intent) {
151 if (intent.getData() == null || mController == null) {
152 return;
153 }
154 String packageName = intent.getData().getSchemeSpecificPart();
155 mController.onPackageChange(packageName);
156 }
157 };
158
159 private void registerPackageChangeReceivers() {
160 IntentFilter filter = new IntentFilter();
161 filter.addAction(Intent.ACTION_PACKAGE_ADDED);
162 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
163 filter.addDataScheme("package");
164 mContext.registerReceiver(mPackageChangeReceiver, filter);
Rakesh Iyer1186faa2015-12-07 16:48:46 -0800165 }
Victor Chanecdb8b02016-01-07 18:32:43 -0800166
167 @Override
168 protected void repositionNavigationBar() {
169 // The navigation bar for a vehicle will not need to be repositioned, as it is always
170 // set at the bottom.
171 }
Victor Chan1c6d0582016-01-09 16:26:37 -0800172
173 /**
Jaewan Kim938a50b2016-03-14 17:35:43 +0900174 * An implementation of TaskStackListener, that listens for changes in the system task
Victor Chan1c6d0582016-01-09 16:26:37 -0800175 * stack and notifies the navigation bar.
176 */
Jaewan Kim938a50b2016-03-14 17:35:43 +0900177 private class TaskStackListenerImpl extends TaskStackListener {
Wale Ogunwale480dca02016-02-06 13:58:29 -0800178 @Override
Victor Chan1c6d0582016-01-09 16:26:37 -0800179 public void onTaskStackChanged() {
Victor Chan1c6d0582016-01-09 16:26:37 -0800180 SystemServicesProxy ssp = Recents.getSystemServices();
Winsond46b7272016-04-20 11:54:27 -0700181 ActivityManager.RunningTaskInfo runningTaskInfo = ssp.getRunningTask();
Victor Chan1c6d0582016-01-09 16:26:37 -0800182 mController.taskChanged(runningTaskInfo.baseActivity.getPackageName());
183 }
Victor Chan1c6d0582016-01-09 16:26:37 -0800184 }
Rakesh Iyer2790a372016-01-22 15:33:39 -0800185
186 @Override
187 protected void createUserSwitcher() {
188 if (mUserSwitcherController.useFullscreenUserSwitcher()) {
189 mFullscreenUserSwitcher = new FullscreenUserSwitcher(this, mUserSwitcherController,
190 (ViewStub) mStatusBarWindow.findViewById(R.id.fullscreen_user_switcher_stub));
191 } else {
192 super.createUserSwitcher();
193 }
194 }
195
196 @Override
197 public void userSwitched(int newUserId) {
198 super.userSwitched(newUserId);
199 if (mFullscreenUserSwitcher != null) {
200 mFullscreenUserSwitcher.onUserSwitched(newUserId);
201 }
202 }
203
204 @Override
205 public void updateKeyguardState(boolean goingToFullShade, boolean fromShadeLocked) {
206 super.updateKeyguardState(goingToFullShade, fromShadeLocked);
207 if (mFullscreenUserSwitcher != null) {
208 if (mState == StatusBarState.FULLSCREEN_USER_SWITCHER) {
209 mFullscreenUserSwitcher.show();
210 } else {
211 mFullscreenUserSwitcher.hide();
212 }
213 }
214 }
Rakesh Iyer1186faa2015-12-07 16:48:46 -0800215}