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

Commit 3645184a authored by Abhijoy Saha's avatar Abhijoy Saha
Browse files

Allow HUNs to be shown over Overlay Window.

Bug: 151832454
Test: Manual, Unit Tests
Change-Id: I7d8102eba5fecc060f9570e5da4223dfe8c68802
parent 0a19f879
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ public class CarNavigationBarController {
    }

    /**
     * Hides all navigation bars.
     * Hides all system bars.
     */
    public void hideBars() {
        if (mTopView != null) {
@@ -85,7 +85,7 @@ public class CarNavigationBarController {
    }

    /**
     * Shows all navigation bars.
     * Shows all system bars.
     */
    public void showBars() {
        if (mTopView != null) {
+9 −14
Original line number Diff line number Diff line
@@ -29,41 +29,40 @@ import android.widget.FrameLayout;
import com.android.car.notification.R;
import com.android.car.notification.headsup.CarHeadsUpNotificationContainer;
import com.android.systemui.car.CarDeviceProvisionedController;
import com.android.systemui.car.window.OverlayViewGlobalStateController;
import com.android.systemui.dagger.qualifiers.Main;

import javax.inject.Inject;
import javax.inject.Singleton;

import dagger.Lazy;

/**
 * A controller for SysUI's HUN display.
 */
@Singleton
public class CarHeadsUpNotificationSystemContainer implements CarHeadsUpNotificationContainer {
    private final CarDeviceProvisionedController mCarDeviceProvisionedController;
    private final Lazy<NotificationPanelViewController> mNotificationPanelViewControllerLazy;
    private final OverlayViewGlobalStateController mOverlayViewGlobalStateController;

    private final ViewGroup mWindow;
    private final FrameLayout mHeadsUpContentFrame;

    private final boolean mEnableHeadsUpNotificationWhenNotificationShadeOpen;

    @Inject
    CarHeadsUpNotificationSystemContainer(Context context,
            @Main Resources resources,
            CarDeviceProvisionedController deviceProvisionedController,
            WindowManager windowManager,
            Lazy<NotificationPanelViewController> notificationPanelViewControllerLazy) {
            OverlayViewGlobalStateController overlayViewGlobalStateController) {
        mCarDeviceProvisionedController = deviceProvisionedController;
        mNotificationPanelViewControllerLazy = notificationPanelViewControllerLazy;
        mOverlayViewGlobalStateController = overlayViewGlobalStateController;

        boolean showOnBottom = resources.getBoolean(R.bool.config_showHeadsUpNotificationOnBottom);

        // Use TYPE_STATUS_BAR_SUB_PANEL window type since we need to find a window that is above
        // status bar but below navigation bar.
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG,
                WindowManager.LayoutParams.TYPE_STATUS_BAR_SUB_PANEL,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
                PixelFormat.TRANSLUCENT);
@@ -78,15 +77,11 @@ public class CarHeadsUpNotificationSystemContainer implements CarHeadsUpNotifica
        windowManager.addView(mWindow, lp);
        mWindow.setVisibility(View.INVISIBLE);
        mHeadsUpContentFrame = mWindow.findViewById(R.id.headsup_content);

        mEnableHeadsUpNotificationWhenNotificationShadeOpen = resources.getBoolean(
                R.bool.config_enableHeadsUpNotificationWhenNotificationShadeOpen);
    }

    private void animateShow() {
        if ((mEnableHeadsUpNotificationWhenNotificationShadeOpen
                || !mNotificationPanelViewControllerLazy.get().isPanelExpanded())
                && mCarDeviceProvisionedController.isCurrentUserFullySetup()) {
        if (mCarDeviceProvisionedController.isCurrentUserFullySetup()
                && mOverlayViewGlobalStateController.shouldShowHUN()) {
            mWindow.setVisibility(View.VISIBLE);
        }
    }
+15 −0
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ public class NotificationPanelViewController extends OverlayPanelViewController
    private final CarNotificationListener mCarNotificationListener;
    private final NotificationClickHandlerFactory mNotificationClickHandlerFactory;
    private final StatusBarStateController mStatusBarStateController;
    private final boolean mEnableHeadsUpNotificationWhenNotificationShadeOpen;

    private float mInitialBackgroundAlpha;
    private float mBackgroundAlphaDiff;
@@ -144,6 +145,10 @@ public class NotificationPanelViewController extends OverlayPanelViewController
                            + " percentage");
        }
        mBackgroundAlphaDiff = finalBackgroundAlpha - mInitialBackgroundAlpha;

        mEnableHeadsUpNotificationWhenNotificationShadeOpen = mResources.getBoolean(
                com.android.car.notification.R.bool
                        .config_enableHeadsUpNotificationWhenNotificationShadeOpen);
    }

    @Override
@@ -151,6 +156,16 @@ public class NotificationPanelViewController extends OverlayPanelViewController
        reinflate();
    }

    @Override
    protected boolean shouldShowNavigationBar() {
        return true;
    }

    @Override
    protected boolean shouldShowHUN() {
        return mEnableHeadsUpNotificationWhenNotificationShadeOpen;
    }

    /** Reinflates the view. */
    public void reinflate() {
        ViewGroup container = (ViewGroup) getLayout();
+2 −2
Original line number Diff line number Diff line
@@ -375,10 +375,10 @@ public abstract class OverlayPanelViewController extends OverlayViewController {
        }

        if (visible && !getOverlayViewGlobalStateController().isWindowVisible()) {
            getOverlayViewGlobalStateController().setWindowVisible(true);
            getOverlayViewGlobalStateController().showView(/* panelViewController= */ this);
        }
        if (!visible && getOverlayViewGlobalStateController().isWindowVisible()) {
            getOverlayViewGlobalStateController().setWindowVisible(false);
            getOverlayViewGlobalStateController().hideView(/* panelViewController= */ this);
        }
        getLayout().setVisibility(visible ? View.VISIBLE : View.INVISIBLE);
        getOverlayViewGlobalStateController().setWindowFocusable(visible);
+15 −2
Original line number Diff line number Diff line
@@ -54,7 +54,6 @@ public class OverlayViewController {
        mOverlayViewGlobalStateController.hideView(/* viewController= */ this, this::hide);
    }


    /**
     * Inflate layout owned by controller.
     */
@@ -72,7 +71,7 @@ public class OverlayViewController {
    }

    /**
     * Returns [@code true} if layout owned by controller has been inflated.
     * Returns {@code true} if layout owned by controller has been inflated.
     */
    public final boolean isInflated() {
        return mLayout != null;
@@ -125,4 +124,18 @@ public class OverlayViewController {
    protected final OverlayViewGlobalStateController getOverlayViewGlobalStateController() {
        return mOverlayViewGlobalStateController;
    }

    /**
     * Returns {@code true} if heads up notifications should be displayed over this view.
     */
    protected boolean shouldShowHUN() {
        return true;
    }

    /**
     * Returns {@code true} if navigation bar should be displayed over this view.
     */
    protected boolean shouldShowNavigationBar() {
        return false;
    }
}
Loading