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

Commit ace8a9b5 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

Density-dependent painting in PointerLocationView

Some of the details around pointers that are drawn in
PointerLocationView are very small, such as circles with radii of 3
pixels. Since screen densities have increased, these are really hard to
see, so treat these hardcoded values as DP intead of pixels so they
appear similar in screens of different densities.

Bug: 215378937
Test: manual
Change-Id: Iad59095ba98761939c6c56c13a426cb447f88713
parent 3f938a40
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -163,6 +163,8 @@ public class PointerLocationView extends View implements InputDeviceListener,
    @UnsupportedAppUsage
    private boolean mPrintCoords = true;

    private float mDensity;

    public PointerLocationView(Context c) {
        super(c);
        setFocusableInTouchMode(true);
@@ -357,19 +359,20 @@ public class PointerLocationView extends View implements InputDeviceListener,

                // Draw current touch ellipse.
                mPaint.setARGB(255, pressureLevel, 255 - pressureLevel, 128);
                drawOval(canvas, ps.mCoords.x, ps.mCoords.y, ps.mCoords.touchMajor,
                        ps.mCoords.touchMinor, ps.mCoords.orientation, mPaint);
                drawOval(canvas, ps.mCoords.x, ps.mCoords.y, ps.mCoords.touchMajor * mDensity,
                        ps.mCoords.touchMinor * mDensity, ps.mCoords.orientation, mPaint);

                // Draw current tool ellipse.
                mPaint.setARGB(255, pressureLevel, 128, 255 - pressureLevel);
                drawOval(canvas, ps.mCoords.x, ps.mCoords.y, ps.mCoords.toolMajor,
                        ps.mCoords.toolMinor, ps.mCoords.orientation, mPaint);
                drawOval(canvas, ps.mCoords.x, ps.mCoords.y, ps.mCoords.toolMajor * mDensity,
                        ps.mCoords.toolMinor * mDensity, ps.mCoords.orientation, mPaint);

                // Draw the orientation arrow.
                float arrowSize = ps.mCoords.toolMajor * 0.7f;
                if (arrowSize < 20) {
                    arrowSize = 20;
                }
                arrowSize *= mDensity;
                mPaint.setARGB(255, pressureLevel, 255, 0);
                float orientationVectorX = (float) (Math.sin(ps.mCoords.orientation)
                        * arrowSize);
@@ -398,7 +401,7 @@ public class PointerLocationView extends View implements InputDeviceListener,
                canvas.drawCircle(
                        ps.mCoords.x + orientationVectorX * tiltScale,
                        ps.mCoords.y + orientationVectorY * tiltScale,
                        3.0f, mPaint);
                        3.0f * mDensity, mPaint);

                // Draw the current bounding box
                if (ps.mHasBoundingBox) {
@@ -1003,10 +1006,10 @@ public class PointerLocationView extends View implements InputDeviceListener,

    // Compute size by display density.
    private void configureDensityDependentFactors() {
        final float density = getResources().getDisplayMetrics().density;
        mTextPaint.setTextSize(10 * density);
        mPaint.setStrokeWidth(1 * density);
        mCurrentPointPaint.setStrokeWidth(1 * density);
        mPathPaint.setStrokeWidth(1 * density);
        mDensity = getResources().getDisplayMetrics().density;
        mTextPaint.setTextSize(10 * mDensity);
        mPaint.setStrokeWidth(1 * mDensity);
        mCurrentPointPaint.setStrokeWidth(1 * mDensity);
        mPathPaint.setStrokeWidth(1 * mDensity);
    }
}