Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 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 | |
| 17 | package com.android.systemui.statusbar.car; |
| 18 | |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 19 | import android.app.ActivityManager; |
Rakesh Iyer | 9f831f6 | 2016-02-16 20:06:22 -0800 | [diff] [blame] | 20 | import android.content.BroadcastReceiver; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 21 | import android.content.Context; |
Rakesh Iyer | 9f831f6 | 2016-02-16 20:06:22 -0800 | [diff] [blame] | 22 | import android.content.Intent; |
| 23 | import android.content.IntentFilter; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 24 | import android.graphics.PixelFormat; |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 25 | import android.os.Handler; |
| 26 | import android.os.Looper; |
Jorim Jaggi | 2adba07 | 2016-03-03 13:43:39 +0100 | [diff] [blame^] | 27 | import android.os.RemoteException; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 28 | import android.view.View; |
| 29 | import android.view.ViewGroup.LayoutParams; |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 30 | import android.view.ViewStub; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 31 | import android.view.WindowManager; |
| 32 | |
| 33 | import com.android.systemui.R; |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 34 | import com.android.systemui.recents.Recents; |
| 35 | import com.android.systemui.recents.misc.SystemServicesProxy; |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 36 | import com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener; |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 37 | import com.android.systemui.statusbar.StatusBarState; |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 38 | import com.android.systemui.statusbar.phone.PhoneStatusBar; |
| 39 | |
| 40 | /** |
| 41 | * A status bar (and navigation bar) tailored for the automotive use case. |
| 42 | */ |
| 43 | public class CarStatusBar extends PhoneStatusBar { |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 44 | private TaskStackListenerImpl mTaskStackListener; |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 45 | |
| 46 | private CarNavigationBarView mCarNavigationBar; |
| 47 | private CarNavigationBarController mController; |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 48 | private FullscreenUserSwitcher mFullscreenUserSwitcher; |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 49 | |
| 50 | @Override |
| 51 | public void start() { |
| 52 | super.start(); |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 53 | mTaskStackListener = new TaskStackListenerImpl(); |
| 54 | SystemServicesProxy.getInstance(mContext).registerTaskStackListener(mTaskStackListener); |
Rakesh Iyer | 9f831f6 | 2016-02-16 20:06:22 -0800 | [diff] [blame] | 55 | registerPackageChangeReceivers(); |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 58 | @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 Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 63 | 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 Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 69 | 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 Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 80 | mCarNavigationBar = |
Rakesh Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 81 | (CarNavigationBarView) View.inflate(context, R.layout.car_navigation_bar, null); |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 82 | mController = new CarNavigationBarController(context, mCarNavigationBar, |
| 83 | this /* ActivityStarter*/); |
| 84 | mNavigationBarView = mCarNavigationBar; |
Rakesh Iyer | 9f831f6 | 2016-02-16 20:06:22 -0800 | [diff] [blame] | 85 | |
| 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 Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 105 | } |
Victor Chan | ecdb8b0 | 2016-01-07 18:32:43 -0800 | [diff] [blame] | 106 | |
| 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 Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 112 | |
| 113 | /** |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 114 | * An implementation of TaskStackListener, that listens for changes in the system task |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 115 | * stack and notifies the navigation bar. |
| 116 | */ |
Jaewan Kim | 938a50b | 2016-03-14 17:35:43 +0900 | [diff] [blame] | 117 | private class TaskStackListenerImpl extends TaskStackListener { |
Wale Ogunwale | 480dca0 | 2016-02-06 13:58:29 -0800 | [diff] [blame] | 118 | @Override |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 119 | public void onTaskStackChanged() { |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 120 | SystemServicesProxy ssp = Recents.getSystemServices(); |
| 121 | ActivityManager.RunningTaskInfo runningTaskInfo = ssp.getTopMostTask(); |
| 122 | mController.taskChanged(runningTaskInfo.baseActivity.getPackageName()); |
| 123 | } |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 124 | } |
Rakesh Iyer | 2790a37 | 2016-01-22 15:33:39 -0800 | [diff] [blame] | 125 | |
| 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 Iyer | 1186faa | 2015-12-07 16:48:46 -0800 | [diff] [blame] | 155 | } |