Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 79ab046c authored by Brad Stenning's avatar Brad Stenning Committed by android-build-merger
Browse files

Merge "Allow for the different nav bars before the device is provisioned Split...

Merge "Allow for the different nav bars before the device is provisioned Split window creation from content creation so I could remove and add new content once the provisioned state changed." into pi-dev
am: 1fe1ef0d

Change-Id: I4595133eef28d81622f35bdcb4fd0a814acb4a41
parents e42450f9 1fe1ef0d
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@

    <dimen name="car_navigation_button_width">64dp</dimen>
    <dimen name="car_navigation_bar_width">760dp</dimen>
    <dimen name="car_left_navigation_bar_width">96dp</dimen>
    <dimen name="car_right_navigation_bar_width">96dp</dimen>

    <dimen name="car_page_indicator_dot_diameter">12dp</dimen>
    <dimen name="car_page_indicator_margin_bottom">24dp</dimen>
+6 −0
Original line number Diff line number Diff line
@@ -46,6 +46,12 @@ public class CarFacetButtonController {
        }
    }

    public void removeAll() {
        mButtonsByCategory.clear();
        mButtonsByPackage.clear();
        mSelectedFacetButton = null;
    }

    /**
     * This will unselect the currently selected CarFacetButton and determine which one should be
     * selected next. It does this by reading the properties on the CarFacetButton and seeing if
+134 −84
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import com.android.systemui.statusbar.car.hvac.HvacController;
import com.android.systemui.statusbar.phone.CollapsedStatusBarFragment;
import com.android.systemui.statusbar.phone.StatusBar;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.UserSwitcherController;

import java.io.FileDescriptor;
@@ -80,12 +81,16 @@ public class CarStatusBar extends StatusBar implements
    private boolean mShowRight;
    private boolean mShowBottom;
    private CarFacetButtonController mCarFacetButtonController;
    private ActivityManagerWrapper mActivityManagerWrapper;
    private DeviceProvisionedController mDeviceProvisionedController;
    private boolean mDeviceIsProvisioned = true;

    @Override
    public void start() {
        super.start();
        mTaskStackListener = new TaskStackListenerImpl();
        ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
        mActivityManagerWrapper = ActivityManagerWrapper.getInstance();
        mActivityManagerWrapper.registerTaskStackListener(mTaskStackListener);

        mStackScroller.setScrollingEnabled(true);

@@ -96,12 +101,54 @@ public class CarStatusBar extends StatusBar implements
            Log.d(TAG, "Connecting to HVAC service");
            Dependency.get(HvacController.class).connectToCarService();
        }
        mCarFacetButtonController = Dependency.get(CarFacetButtonController.class);
        mDeviceProvisionedController = Dependency.get(DeviceProvisionedController.class);
        mDeviceIsProvisioned = mDeviceProvisionedController.isDeviceProvisioned();
        if (!mDeviceIsProvisioned) {
            mDeviceProvisionedController.addCallback(
                    new DeviceProvisionedController.DeviceProvisionedListener() {
                        @Override
                        public void onDeviceProvisionedChanged() {
                            mDeviceIsProvisioned =
                                    mDeviceProvisionedController.isDeviceProvisioned();
                            restartNavBars();
                        }
                    });
        }
    }

    /**
     * Remove all content from navbars and rebuild them. Used to allow for different nav bars
     * before and after the device is provisioned
     */
    private void restartNavBars() {
        mCarFacetButtonController.removeAll();
        if (ENABLE_HVAC_CONNECTION) {
            Dependency.get(HvacController.class).removeAllComponents();
        }
        if (mNavigationBarWindow != null) {
            mNavigationBarWindow.removeAllViews();
            mNavigationBarView = null;
        }

        if (mLeftNavigationBarWindow != null) {
            mLeftNavigationBarWindow.removeAllViews();
            mLeftNavigationBarView = null;
        }

        if (mRightNavigationBarWindow != null) {
            mRightNavigationBarWindow.removeAllViews();
            mRightNavigationBarView = null;
        }
        buildNavBarContent();
    }


    @Override
    public void destroy() {
        mCarBatteryController.stopListening();
        mConnectedDeviceSignalController.stopListening();
        mActivityManagerWrapper.unregisterTaskStackListener(mTaskStackListener);

        if (mNavigationBarWindow != null) {
            mWindowManager.removeViewImmediate(mNavigationBarWindow);
@@ -117,10 +164,10 @@ public class CarStatusBar extends StatusBar implements
            mWindowManager.removeViewImmediate(mRightNavigationBarWindow);
            mRightNavigationBarView = null;
        }

        super.destroy();
    }


    @Override
    protected void makeStatusBarView() {
        super.makeStatusBarView();
@@ -167,55 +214,52 @@ public class CarStatusBar extends StatusBar implements

    @Override
    protected void createNavigationBar() {
        mCarFacetButtonController = Dependency.get(CarFacetButtonController.class);
        if (mNavigationBarView != null) {
            return;
        mShowBottom = mContext.getResources().getBoolean(R.bool.config_enableBottomNavigationBar);
        mShowLeft = mContext.getResources().getBoolean(R.bool.config_enableLeftNavigationBar);
        mShowRight = mContext.getResources().getBoolean(R.bool.config_enableRightNavigationBar);

        buildNavBarWindows();
        buildNavBarContent();
        attachNavBarWindows();
    }

        mShowBottom = mContext.getResources().getBoolean(R.bool.config_enableBottomNavigationBar);
    private void buildNavBarContent() {
        if (mShowBottom) {
            buildBottomBar();
            buildBottomBar((mDeviceIsProvisioned) ? R.layout.car_navigation_bar :
                    R.layout.car_navigation_bar_unprovisioned);
        }

        int widthForSides = mContext.getResources().getDimensionPixelSize(
                R.dimen.navigation_bar_height_car_mode);


        mShowLeft = mContext.getResources().getBoolean(R.bool.config_enableLeftNavigationBar);

        if (mShowLeft) {
            buildLeft(widthForSides);
            buildLeft((mDeviceIsProvisioned) ? R.layout.car_left_navigation_bar :
                    R.layout.car_left_navigation_bar_unprovisioned);
        }

        mShowRight = mContext.getResources().getBoolean(R.bool.config_enableRightNavigationBar);

        if (mShowRight) {
            buildRight(widthForSides);
            buildRight((mDeviceIsProvisioned) ? R.layout.car_right_navigation_bar :
                    R.layout.car_right_navigation_bar_unprovisioned);
        }

    }

    private void buildNavBarWindows() {
        if (mShowBottom) {

    private void buildBottomBar() {
        // 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
        // CarNavigationBarView.
             mNavigationBarWindow = (ViewGroup) View.inflate(mContext,
                    R.layout.navigation_bar_window, null);
        if (mNavigationBarWindow == null) {
            Log.e(TAG, "CarStatusBar failed inflate for R.layout.navigation_bar_window");
        }
        if (mShowLeft) {
            mLeftNavigationBarWindow = (ViewGroup) View.inflate(mContext,
                R.layout.navigation_bar_window, null);
        }
        if (mShowRight) {
            mRightNavigationBarWindow = (ViewGroup) View.inflate(mContext,
                    R.layout.navigation_bar_window, null);
        }


        View.inflate(mContext, R.layout.car_navigation_bar, mNavigationBarWindow);
        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");
    }
        mNavigationBarView.setStatusBar(this);

    private void attachNavBarWindows() {

        if (mShowBottom) {
            WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.TYPE_NAVIGATION_BAR,
@@ -226,28 +270,13 @@ public class CarStatusBar extends StatusBar implements
                    PixelFormat.TRANSLUCENT);
            lp.setTitle("CarNavigationBar");
            lp.windowAnimations = 0;


            mWindowManager.addView(mNavigationBarWindow, lp);
        }

    private void buildLeft(int widthForSides) {
        mLeftNavigationBarWindow = (ViewGroup) View.inflate(mContext,
                R.layout.navigation_bar_window, null);
        if (mLeftNavigationBarWindow == null) {
            Log.e(TAG, "CarStatusBar failed inflate for R.layout.navigation_bar_window");
        }

        View.inflate(mContext, R.layout.car_left_navigation_bar, mLeftNavigationBarWindow);
        mLeftNavigationBarView = (CarNavigationBarView) mLeftNavigationBarWindow.getChildAt(0);
        if (mLeftNavigationBarView == null) {
            Log.e(TAG, "CarStatusBar failed inflate for R.layout.car_navigation_bar");
            throw new RuntimeException("Unable to build left nav bar due to missing layout");
        }
        mLeftNavigationBarView.setStatusBar(this);

        if (mShowLeft) {
            int width = mContext.getResources().getDimensionPixelSize(
                    R.dimen.car_left_navigation_bar_width);
            WindowManager.LayoutParams leftlp = new WindowManager.LayoutParams(
                widthForSides, LayoutParams.MATCH_PARENT,
                    width, LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL,
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                            | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
@@ -260,25 +289,11 @@ public class CarStatusBar extends StatusBar implements
            leftlp.gravity = Gravity.LEFT;
            mWindowManager.addView(mLeftNavigationBarWindow, leftlp);
        }


    private void buildRight(int widthForSides) {
        mRightNavigationBarWindow = (ViewGroup) View.inflate(mContext,
                R.layout.navigation_bar_window, null);
        if (mRightNavigationBarWindow == null) {
            Log.e(TAG, "CarStatusBar failed inflate for R.layout.navigation_bar_window");
        }

        View.inflate(mContext, R.layout.car_right_navigation_bar, mRightNavigationBarWindow);
        mRightNavigationBarView = (CarNavigationBarView) mRightNavigationBarWindow.getChildAt(0);
        if (mRightNavigationBarView == null) {
            Log.e(TAG, "CarStatusBar failed inflate for R.layout.car_navigation_bar");
            throw new RuntimeException("Unable to build right nav bar due to missing layout");
        }
        mRightNavigationBarView.setStatusBar(this);

        if (mShowRight) {
            int width = mContext.getResources().getDimensionPixelSize(
                    R.dimen.car_right_navigation_bar_width);
            WindowManager.LayoutParams rightlp = new WindowManager.LayoutParams(
                widthForSides, LayoutParams.MATCH_PARENT,
                    width, LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL,
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                            | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
@@ -292,6 +307,41 @@ public class CarStatusBar extends StatusBar implements
            mWindowManager.addView(mRightNavigationBarWindow, rightlp);
        }

    }

    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
        // CarNavigationBarView.
        View.inflate(mContext, layout, mNavigationBarWindow);
        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");
        }
        mNavigationBarView.setStatusBar(this);
    }

    private void buildLeft(int layout) {
        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");
            throw new RuntimeException("Unable to build left nav bar due to missing layout");
        }
        mLeftNavigationBarView.setStatusBar(this);
    }


    private void buildRight(int layout) {
        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");
            throw new RuntimeException("Unable to build right nav bar due to missing layout");
        }
    }

    @Override
    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        //When executing dump() funciton simultaneously, we need to serialize them
+8 −0
Original line number Diff line number Diff line
@@ -175,6 +175,14 @@ public class HvacController {
        }
    };

    /**
     * Removes all registered components. This is useful if you need to rebuild the UI since
     * components self register.
     */
    public void removeAllComponents() {
        mTempComponents.clear();
    }

    /**
     * Key for storing {@link TemperatureView}s in a hash map
     */