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

Commit 2aee4723 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

PointerLocationView: Reconfigure trace bitmap on display changes

The pointer trace/trail is drawn on a separate bitmap layer in the
PointerLocationView to avoid having to redraw the trail on each frame.
Whenever the display size changes, like when displayId 0 is remapped
from the internal display to an external display in a foldable device,
the trace bitmap should be reconfigured.

Bug: 407039712
Flag: EXEMPT bug fix
Test: Presubmit
Change-Id: Ifbbff80b83f035657cc88e1a905e55f03d4264bc
parent 3850d545
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.RectF;
import android.graphics.Region;
import android.hardware.display.DisplayManager;
import android.hardware.input.InputManager;
import android.hardware.input.InputManager.InputDeviceListener;
import android.os.Handler;
@@ -123,6 +124,7 @@ public class PointerLocationView extends View implements InputDeviceListener,
    }

    private final InputManager mIm;
    private final DisplayManager mDisplayManager;

    private final ViewConfiguration mVC;
    private final Paint mTextPaint;
@@ -170,11 +172,35 @@ public class PointerLocationView extends View implements InputDeviceListener,

    private float mDensity;

    private final DisplayManager.DisplayListener mDisplayListener =
            new DisplayManager.DisplayListener() {
                @Override
                public void onDisplayAdded(int displayId) {
                    onDisplayChanged(displayId);
                }

                @Override
                public void onDisplayRemoved(int displayId) {

                }

                @Override
                public void onDisplayChanged(int displayId) {
                    if (displayId != mContext.getDisplayId()) {
                        return;
                    }
                    // Reconfigure the trace bitmap whenever there are changes to the display, since
                    // the bitmap depends on display size.
                    configureTraceBitmap();
                }
            };

    public PointerLocationView(Context c) {
        super(c);
        setFocusableInTouchMode(true);

        mIm = c.getSystemService(InputManager.class);
        mDisplayManager = c.getSystemService(DisplayManager.class);

        mVC = ViewConfiguration.get(c);
        mTextPaint = new Paint();
@@ -798,6 +824,7 @@ public class PointerLocationView extends View implements InputDeviceListener,
        super.onAttachedToWindow();

        mIm.registerInputDeviceListener(this, getHandler());
        mDisplayManager.registerDisplayListener(mDisplayListener, getHandler());
        if (shouldShowSystemGestureExclusion()) {
            try {
                WindowManagerGlobal.getWindowManagerService()
@@ -820,6 +847,7 @@ public class PointerLocationView extends View implements InputDeviceListener,
        super.onDetachedFromWindow();

        mIm.unregisterInputDeviceListener(this);
        mDisplayManager.unregisterDisplayListener(mDisplayListener);
        try {
            WindowManagerGlobal.getWindowManagerService().unregisterSystemGestureExclusionListener(
                    mSystemGestureExclusionListener, mContext.getDisplayId());