From 1a13af51bada6ada33243f38ae47ded6630c4564 Mon Sep 17 00:00:00 2001 From: Heemin Seog Date: Thu, 3 Oct 2019 16:15:50 -0700 Subject: DO NOT MERGE Add support for unprovisioned top nav bar Also listen for changes to user setup rather than device provisioned Bug: 140748928 Test: manual with custom SUW apk Change-Id: Iabab489269d3dbfafd150a919020ac7921e45768 --- .../car_top_navigation_bar_unprovisioned.xml | 147 +++++++++++++++++++++ .../CarSystemUI/res/layout/super_status_bar.xml | 6 +- .../systemui/statusbar/car/CarStatusBar.java | 117 +++++++++------- 3 files changed, 222 insertions(+), 48 deletions(-) create mode 100644 packages/CarSystemUI/res/layout/car_top_navigation_bar_unprovisioned.xml diff --git a/packages/CarSystemUI/res/layout/car_top_navigation_bar_unprovisioned.xml b/packages/CarSystemUI/res/layout/car_top_navigation_bar_unprovisioned.xml new file mode 100644 index 000000000000..8247211dcb32 --- /dev/null +++ b/packages/CarSystemUI/res/layout/car_top_navigation_bar_unprovisioned.xml @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/CarSystemUI/res/layout/super_status_bar.xml b/packages/CarSystemUI/res/layout/super_status_bar.xml index e1bcc2e5f86c..0b346260896a 100644 --- a/packages/CarSystemUI/res/layout/super_status_bar.xml +++ b/packages/CarSystemUI/res/layout/super_status_bar.xml @@ -69,10 +69,10 @@ android:visibility="gone" /> - + android:layout_height="wrap_content"/> diff --git a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java index 25191f6a9617..c27548ca8770 100644 --- a/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java +++ b/packages/CarSystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java @@ -109,9 +109,11 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt private BatteryMeterView mBatteryMeterView; private Drawable mNotificationPanelBackground; + private ViewGroup mTopNavigationBarContainer; private ViewGroup mNavigationBarWindow; private ViewGroup mLeftNavigationBarWindow; private ViewGroup mRightNavigationBarWindow; + private CarNavigationBarView mTopNavigationBarView; private CarNavigationBarView mNavigationBarView; private CarNavigationBarView mLeftNavigationBarView; private CarNavigationBarView mRightNavigationBarView; @@ -123,7 +125,7 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt private CarFacetButtonController mCarFacetButtonController; private ActivityManagerWrapper mActivityManagerWrapper; private DeviceProvisionedController mDeviceProvisionedController; - private boolean mDeviceIsProvisioned = true; + private boolean mDeviceIsSetUpForUser = true; private HvacController mHvacController; private DrivingStateHelper mDrivingStateHelper; private PowerManagerHelper mPowerManagerHelper; @@ -144,6 +146,9 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt private boolean mNotificationListAtBottom; // Was the notification list at the bottom when the user first touched the screen private boolean mNotificationListAtBottomAtTimeOfTouch; + // To be attached to the top navigation bar (i.e. status bar) to pull down the notification + // panel. + private View.OnTouchListener mTopNavBarNotificationTouchListener; // To be attached to the navigation bars such that they can close the notification panel if // it's open. private View.OnTouchListener mNavBarNotificationTouchListener; @@ -193,7 +198,7 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt // get the provisioned state before calling the parent class since it's that flow that // builds the nav bar mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class); - mDeviceIsProvisioned = mDeviceProvisionedController.isDeviceProvisioned(); + mDeviceIsSetUpForUser = mDeviceProvisionedController.isCurrentUserSetup(); // Keyboard related setup, before nav bars are created. mHideNavBarForKeyboard = mContext.getResources().getBoolean( @@ -205,6 +210,10 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt mScreenLifecycle = Dependency.get(ScreenLifecycle.class); mScreenLifecycle.addObserver(mScreenObserver); + // Need to initialize HVAC controller before calling super.start - before system bars are + // created. + mHvacController = new HvacController(mContext); + super.start(); mTaskStackListener = new TaskStackListenerImpl(); mActivityManagerWrapper = ActivityManagerWrapper.getInstance(); @@ -223,25 +232,18 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt mHvacController.connectToCarService(); - CarSystemUIFactory factory = SystemUIFactory.getInstance(); - if (!mDeviceIsProvisioned) { - mDeviceProvisionedController.addCallback( - new DeviceProvisionedController.DeviceProvisionedListener() { - @Override - public void onDeviceProvisionedChanged() { - mHandler.post(() -> { - // on initial boot we are getting a call even though the value - // is the same so we are confirming the reset is needed - boolean deviceProvisioned = - mDeviceProvisionedController.isDeviceProvisioned(); - if (mDeviceIsProvisioned != deviceProvisioned) { - mDeviceIsProvisioned = deviceProvisioned; - restartNavBars(); - } - }); - } - }); - } + mDeviceProvisionedController.addCallback( + new DeviceProvisionedController.DeviceProvisionedListener() { + @Override + public void onUserSetupChanged() { + mHandler.post(() -> restartNavBarsIfNecessary()); + } + + @Override + public void onUserSwitched() { + mHandler.post(() -> restartNavBarsIfNecessary()); + } + }); // Register a listener for driving state changes. mDrivingStateHelper = new DrivingStateHelper(mContext, this::onDrivingStateChanged); @@ -253,6 +255,14 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt mSwitchToGuestTimer = new SwitchToGuestTimer(mContext); } + private void restartNavBarsIfNecessary() { + boolean currentUserSetup = mDeviceProvisionedController.isCurrentUserSetup(); + if (mDeviceIsSetUpForUser != currentUserSetup) { + mDeviceIsSetUpForUser = currentUserSetup; + restartNavBars(); + } + } + /** * Remove all content from navbars and rebuild them. Used to allow for different nav bars * before and after the device is provisioned. . Also for change of density and font size. @@ -261,8 +271,8 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt // remove and reattach all hvac components such that we don't keep a reference to unused // ui elements mHvacController.removeAllComponents(); - addTemperatureViewToController(mStatusBarWindow); mCarFacetButtonController.removeAll(); + if (mNavigationBarWindow != null) { mNavigationBarWindow.removeAllViews(); mNavigationBarView = null; @@ -356,7 +366,6 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt @Override protected void makeStatusBarView(@Nullable RegisterStatusBarResult result) { super.makeStatusBarView(result); - mHvacController = new HvacController(mContext); CarSystemUIFactory factory = SystemUIFactory.getInstance(); mCarFacetButtonController = factory.getCarDependencyComponent() @@ -381,7 +390,8 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt * touch listeners needed for opening and closing the notification panel */ private void connectNotificationsUI() { - // Attached to the status bar to detect pull down of the notification shade. + // Attached to the top navigation bar (i.e. status bar) to detect pull down of the + // notification shade. GestureDetector openGestureDetector = new GestureDetector(mContext, new OpenNotificationGestureListener() { @Override @@ -414,6 +424,18 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt GestureDetector handleBarCloseNotificationGestureDetector = new GestureDetector(mContext, new HandleBarCloseNotificationGestureListener()); + mTopNavBarNotificationTouchListener = (v, event) -> { + if (!mDeviceIsSetUpForUser) { + return true; + } + boolean consumed = openGestureDetector.onTouchEvent(event); + if (consumed) { + return true; + } + maybeCompleteAnimation(event); + return true; + }; + mNavBarNotificationTouchListener = (v, event) -> { boolean consumed = navBarCloseNotificationGestureDetector.onTouchEvent(event); @@ -424,21 +446,6 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt return true; }; - // The following are the ui elements that the user would call the status bar. - // This will set the status bar so it they can make call backs. - CarNavigationBarView topBar = mStatusBarWindow.findViewById(R.id.car_top_bar); - topBar.setStatusBar(this); - topBar.setStatusBarWindowTouchListener((v1, event1) -> { - - boolean consumed = openGestureDetector.onTouchEvent(event1); - if (consumed) { - return true; - } - maybeCompleteAnimation(event1); - return true; - } - ); - mNotificationClickHandlerFactory = new NotificationClickHandlerFactory( mBarService, launchResult -> { @@ -745,23 +752,30 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt } private void buildNavBarContent() { + // Always build top bar. + buildTopBar((mDeviceIsSetUpForUser) ? R.layout.car_top_navigation_bar : + R.layout.car_top_navigation_bar_unprovisioned); + if (mShowBottom) { - buildBottomBar((mDeviceIsProvisioned) ? R.layout.car_navigation_bar : + buildBottomBar((mDeviceIsSetUpForUser) ? R.layout.car_navigation_bar : R.layout.car_navigation_bar_unprovisioned); } if (mShowLeft) { - buildLeft((mDeviceIsProvisioned) ? R.layout.car_left_navigation_bar : + buildLeft((mDeviceIsSetUpForUser) ? R.layout.car_left_navigation_bar : R.layout.car_left_navigation_bar_unprovisioned); } if (mShowRight) { - buildRight((mDeviceIsProvisioned) ? R.layout.car_right_navigation_bar : + buildRight((mDeviceIsSetUpForUser) ? R.layout.car_right_navigation_bar : R.layout.car_right_navigation_bar_unprovisioned); } } private void buildNavBarWindows() { + mTopNavigationBarContainer = mStatusBarWindow + .findViewById(R.id.car_top_navigation_bar_container); + if (mShowBottom) { mNavigationBarWindow = (ViewGroup) View.inflate(mContext, R.layout.navigation_bar_window, null); @@ -883,6 +897,19 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt mWindowManager.removeView(mNavigationBarWindow); } + private void buildTopBar(int layout) { + mTopNavigationBarContainer.removeAllViews(); + View.inflate(mContext, layout, mTopNavigationBarContainer); + mTopNavigationBarView = (CarNavigationBarView) mTopNavigationBarContainer.getChildAt(0); + if (mTopNavigationBarView == null) { + Log.e(TAG, "CarStatusBar failed inflate for R.layout.car_top_navigation_bar"); + throw new RuntimeException("Unable to build top nav bar due to missing layout"); + } + mTopNavigationBarView.setStatusBar(this); + addTemperatureViewToController(mTopNavigationBarView); + mTopNavigationBarView.setStatusBarWindowTouchListener(mTopNavBarNotificationTouchListener); + } + private void buildBottomBar(int layout) { // SystemUI requires that the navigation bar view have a parent. Since the regular // StatusBar inflates navigation_bar_window as this parent view, use the same view for the @@ -891,7 +918,7 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt mNavigationBarView = (CarNavigationBarView) mNavigationBarWindow.getChildAt(0); if (mNavigationBarView == null) { Log.e(TAG, "CarStatusBar failed inflate for R.layout.car_navigation_bar"); - throw new RuntimeException("Unable to build botom nav bar due to missing layout"); + throw new RuntimeException("Unable to build bottom nav bar due to missing layout"); } mNavigationBarView.setStatusBar(this); addTemperatureViewToController(mNavigationBarView); @@ -902,7 +929,7 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt View.inflate(mContext, layout, mLeftNavigationBarWindow); mLeftNavigationBarView = (CarNavigationBarView) mLeftNavigationBarWindow.getChildAt(0); if (mLeftNavigationBarView == null) { - Log.e(TAG, "CarStatusBar failed inflate for R.layout.car_navigation_bar"); + Log.e(TAG, "CarStatusBar failed inflate for R.layout.car_left_navigation_bar"); throw new RuntimeException("Unable to build left nav bar due to missing layout"); } mLeftNavigationBarView.setStatusBar(this); @@ -915,7 +942,7 @@ public class CarStatusBar extends StatusBar implements CarBatteryController.Batt View.inflate(mContext, layout, mRightNavigationBarWindow); mRightNavigationBarView = (CarNavigationBarView) mRightNavigationBarWindow.getChildAt(0); if (mRightNavigationBarView == null) { - Log.e(TAG, "CarStatusBar failed inflate for R.layout.car_navigation_bar"); + Log.e(TAG, "CarStatusBar failed inflate for R.layout.car_right_navigation_bar"); throw new RuntimeException("Unable to build right nav bar due to missing layout"); } mRightNavigationBarView.setStatusBar(this); -- cgit v1.2.3-59-g8ed1b