blob: 4add3cbfd2f92bf74774789a8d125ea9e98f0562 [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;
Victor Chan1c6d0582016-01-09 16:26:37 -080025import android.os.Handler;
26import android.os.Looper;
Jorim Jaggi2adba072016-03-03 13:43:39 +010027import android.os.RemoteException;
Rakesh Iyer1186faa2015-12-07 16:48:46 -080028import android.view.View;
29import android.view.ViewGroup.LayoutParams;
Rakesh Iyer2790a372016-01-22 15:33:39 -080030import android.view.ViewStub;
Rakesh Iyer1186faa2015-12-07 16:48:46 -080031import android.view.WindowManager;
32
33import com.android.systemui.R;
Victor Chan1c6d0582016-01-09 16:26:37 -080034import com.android.systemui.recents.Recents;
35import com.android.systemui.recents.misc.SystemServicesProxy;
Jaewan Kim938a50b2016-03-14 17:35:43 +090036import com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener;
Rakesh Iyer2790a372016-01-22 15:33:39 -080037import com.android.systemui.statusbar.StatusBarState;
Rakesh Iyer1186faa2015-12-07 16:48:46 -080038import com.android.systemui.statusbar.phone.PhoneStatusBar;
39
40/**
41 * A status bar (and navigation bar) tailored for the automotive use case.
42 */
43public class CarStatusBar extends PhoneStatusBar {
Victor Chan1c6d0582016-01-09 16:26:37 -080044 private TaskStackListenerImpl mTaskStackListener;
Victor Chan1c6d0582016-01-09 16:26:37 -080045
46 private CarNavigationBarView mCarNavigationBar;
47 private CarNavigationBarController mController;
Rakesh Iyer2790a372016-01-22 15:33:39 -080048 private FullscreenUserSwitcher mFullscreenUserSwitcher;
Victor Chan1c6d0582016-01-09 16:26:37 -080049
50 @Override
51 public void start() {
52 super.start();
Jaewan Kim938a50b2016-03-14 17:35:43 +090053 mTaskStackListener = new TaskStackListenerImpl();
54 SystemServicesProxy.getInstance(mContext).registerTaskStackListener(mTaskStackListener);
Rakesh Iyer9f831f62016-02-16 20:06:22 -080055 registerPackageChangeReceivers();
Victor Chan1c6d0582016-01-09 16:26:37 -080056 }
57
Rakesh Iyer1186faa2015-12-07 16:48:46 -080058 @Override
59 protected void addNavigationBar() {
60 WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
61 LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
62 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
Victor Chan1c6d0582016-01-09 16:26:37 -080063 WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
64 | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
65 | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
66 | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
67 | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
68 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
Rakesh Iyer1186faa2015-12-07 16:48:46 -080069 PixelFormat.TRANSLUCENT);
70 lp.setTitle("CarNavigationBar");
71 lp.windowAnimations = 0;
72 mWindowManager.addView(mNavigationBarView, lp);
73 }
74
75 @Override
76 protected void createNavigationBarView(Context context) {
77 if (mNavigationBarView != null) {
78 return;
79 }
Victor Chan1c6d0582016-01-09 16:26:37 -080080 mCarNavigationBar =
Rakesh Iyer1186faa2015-12-07 16:48:46 -080081 (CarNavigationBarView) View.inflate(context, R.layout.car_navigation_bar, null);
Victor Chan1c6d0582016-01-09 16:26:37 -080082 mController = new CarNavigationBarController(context, mCarNavigationBar,
83 this /* ActivityStarter*/);
84 mNavigationBarView = mCarNavigationBar;
Rakesh Iyer9f831f62016-02-16 20:06:22 -080085
86 }
87
88 private BroadcastReceiver mPackageChangeReceiver = new BroadcastReceiver() {
89 @Override
90 public void onReceive(Context context, Intent intent) {
91 if (intent.getData() == null || mController == null) {
92 return;
93 }
94 String packageName = intent.getData().getSchemeSpecificPart();
95 mController.onPackageChange(packageName);
96 }
97 };
98
99 private void registerPackageChangeReceivers() {
100 IntentFilter filter = new IntentFilter();
101 filter.addAction(Intent.ACTION_PACKAGE_ADDED);
102 filter.addAction(Intent.ACTION_PACKAGE_REMOVED);
103 filter.addDataScheme("package");
104 mContext.registerReceiver(mPackageChangeReceiver, filter);
Rakesh Iyer1186faa2015-12-07 16:48:46 -0800105 }
Victor Chanecdb8b02016-01-07 18:32:43 -0800106
107 @Override
108 protected void repositionNavigationBar() {
109 // The navigation bar for a vehicle will not need to be repositioned, as it is always
110 // set at the bottom.
111 }
Victor Chan1c6d0582016-01-09 16:26:37 -0800112
113 /**
Jaewan Kim938a50b2016-03-14 17:35:43 +0900114 * An implementation of TaskStackListener, that listens for changes in the system task
Victor Chan1c6d0582016-01-09 16:26:37 -0800115 * stack and notifies the navigation bar.
116 */
Jaewan Kim938a50b2016-03-14 17:35:43 +0900117 private class TaskStackListenerImpl extends TaskStackListener {
Wale Ogunwale480dca02016-02-06 13:58:29 -0800118 @Override
Victor Chan1c6d0582016-01-09 16:26:37 -0800119 public void onTaskStackChanged() {
Victor Chan1c6d0582016-01-09 16:26:37 -0800120 SystemServicesProxy ssp = Recents.getSystemServices();
121 ActivityManager.RunningTaskInfo runningTaskInfo = ssp.getTopMostTask();
122 mController.taskChanged(runningTaskInfo.baseActivity.getPackageName());
123 }
Victor Chan1c6d0582016-01-09 16:26:37 -0800124 }
Rakesh Iyer2790a372016-01-22 15:33:39 -0800125
126 @Override
127 protected void createUserSwitcher() {
128 if (mUserSwitcherController.useFullscreenUserSwitcher()) {
129 mFullscreenUserSwitcher = new FullscreenUserSwitcher(this, mUserSwitcherController,
130 (ViewStub) mStatusBarWindow.findViewById(R.id.fullscreen_user_switcher_stub));
131 } else {
132 super.createUserSwitcher();
133 }
134 }
135
136 @Override
137 public void userSwitched(int newUserId) {
138 super.userSwitched(newUserId);
139 if (mFullscreenUserSwitcher != null) {
140 mFullscreenUserSwitcher.onUserSwitched(newUserId);
141 }
142 }
143
144 @Override
145 public void updateKeyguardState(boolean goingToFullShade, boolean fromShadeLocked) {
146 super.updateKeyguardState(goingToFullShade, fromShadeLocked);
147 if (mFullscreenUserSwitcher != null) {
148 if (mState == StatusBarState.FULLSCREEN_USER_SWITCHER) {
149 mFullscreenUserSwitcher.show();
150 } else {
151 mFullscreenUserSwitcher.hide();
152 }
153 }
154 }
Rakesh Iyer1186faa2015-12-07 16:48:46 -0800155}