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

Commit 5ba15fd9 authored by Abdelrahman Awadalla's avatar Abdelrahman Awadalla
Browse files

Show the value of the pressure on touchpad visualizer

Displaying the value of the pressure reported by the touchpad hardware state for each finger. The pressure value is being displayed on the top of the ovals that represents the fingers and follow the oval wherever it moves to.

Test: Build
Test: Presubmit checks
Bug: 368692662
Flag: com.android.hardware.input.touchpad_visualizer
Change-Id: Iafb29c19623480a7bc301786f284eb6a6c4a152d
parent 8b15ee5a
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import com.android.server.input.TouchpadHardwareState;

import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

public class TouchpadVisualizationView extends View {
@@ -50,6 +51,7 @@ public class TouchpadVisualizationView extends View {
    private final Paint mOvalFillPaint;
    private final Paint mTracePaint;
    private final Paint mCenterPointPaint;
    private final Paint mPressureTextPaint;
    private final RectF mTempOvalRect = new RectF();

    public TouchpadVisualizationView(Context context,
@@ -71,6 +73,8 @@ public class TouchpadVisualizationView extends View {
        mCenterPointPaint.setAntiAlias(true);
        mCenterPointPaint.setARGB(255, 255, 0, 0);
        mCenterPointPaint.setStrokeWidth(2);
        mPressureTextPaint = new Paint();
        mPressureTextPaint.setAntiAlias(true);
    }

    private void removeOldPoints() {
@@ -134,6 +138,13 @@ public class TouchpadVisualizationView extends View {
            mOvalFillPaint.setAlpha((int) pressureToOpacity);

            drawOval(canvas, newX, newY, newTouchMajor, newTouchMinor, newAngle);

            String formattedPressure = String.format(Locale.getDefault(), "Ps: %.2f",
                    touchpadFingerState.getPressure());
            float textWidth = mPressureTextPaint.measureText(formattedPressure);

            canvas.drawText(formattedPressure, newX - textWidth / 2,
                    newY - newTouchMajor / 2, mPressureTextPaint);
        }

        mTempFingerStatesByTrackingId.clear();
@@ -199,6 +210,7 @@ public class TouchpadVisualizationView extends View {
     */
    public void setLightModeTheme() {
        this.setBackgroundColor(Color.rgb(20, 20, 20));
        mPressureTextPaint.setARGB(255, 255, 255, 255);
        mOvalFillPaint.setARGB(255, 255, 255, 255);
        mOvalStrokePaint.setARGB(255, 255, 255, 255);
    }
@@ -208,6 +220,7 @@ public class TouchpadVisualizationView extends View {
     */
    public void setNightModeTheme() {
        this.setBackgroundColor(Color.rgb(240, 240, 240));
        mPressureTextPaint.setARGB(255, 0, 0, 0);
        mOvalFillPaint.setARGB(255, 0, 0, 0);
        mOvalStrokePaint.setARGB(255, 0, 0, 0);
    }