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

Commit 44ef2fbc authored by Abdelrahman Awadalla's avatar Abdelrahman Awadalla Committed by Android (Google) Code Review
Browse files

Merge "Change touchpad visualizer colors by system theme" into main

parents 906a8ada 1f3603ab
Loading
Loading
Loading
Loading
+40 −14
Original line number Diff line number Diff line
@@ -52,6 +52,8 @@ public class TouchpadDebugView extends LinearLayout {
    private static final float DEFAULT_RES_Y = 45f;
    private static final int TEXT_PADDING_DP = 12;
    private static final int ROUNDED_CORNER_RADIUS_DP = 24;
    private static final int BUTTON_PRESSED_BACKGROUND_COLOR = Color.rgb(118, 151, 99);
    private static final int BUTTON_RELEASED_BACKGROUND_COLOR = Color.rgb(84, 85, 169);

    /**
     * Input device ID for the touchpad that this debug view is displaying.
@@ -75,6 +77,8 @@ public class TouchpadDebugView extends LinearLayout {
    private int mWindowLocationBeforeDragY;
    private int mLatestGestureType = 0;
    private TextView mGestureInfoView;
    private TextView mNameView;

    @NonNull
    private TouchpadHardwareState mLastTouchpadState =
            new TouchpadHardwareState(0, 0 /* buttonsDown */, 0, 0,
@@ -119,35 +123,34 @@ public class TouchpadDebugView extends LinearLayout {
                LayoutParams.WRAP_CONTENT));
        setBackgroundColor(Color.TRANSPARENT);

        TextView nameView = new TextView(context);
        nameView.setBackgroundColor(Color.RED);
        nameView.setTextSize(TEXT_SIZE_SP);
        nameView.setText(Objects.requireNonNull(Objects.requireNonNull(
        mNameView = new TextView(context);
        mNameView.setBackgroundColor(BUTTON_RELEASED_BACKGROUND_COLOR);
        mNameView.setTextSize(TEXT_SIZE_SP);
        mNameView.setText(Objects.requireNonNull(Objects.requireNonNull(
                        mContext.getSystemService(InputManager.class))
                .getInputDevice(touchpadId)).getName());
        nameView.setGravity(Gravity.CENTER);
        nameView.setTextColor(Color.WHITE);
        mNameView.setGravity(Gravity.CENTER);
        mNameView.setTextColor(Color.WHITE);
        int paddingInDP = (int) TypedValue.applyDimension(COMPLEX_UNIT_DIP, TEXT_PADDING_DP,
                getResources().getDisplayMetrics());
        nameView.setPadding(paddingInDP, paddingInDP, paddingInDP, paddingInDP);
        nameView.setLayoutParams(
        mNameView.setPadding(paddingInDP, paddingInDP, paddingInDP, paddingInDP);
        mNameView.setLayoutParams(
                new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

        mTouchpadVisualizationView = new TouchpadVisualizationView(context,
                mTouchpadHardwareProperties);
        mTouchpadVisualizationView.setBackgroundColor(Color.WHITE);

        mGestureInfoView = new TextView(context);
        mGestureInfoView.setBackgroundColor(Color.BLACK);
        mGestureInfoView.setTextSize(TEXT_SIZE_SP);
        mGestureInfoView.setText("Latest Gesture: ");
        mGestureInfoView.setGravity(Gravity.CENTER);
        mGestureInfoView.setTextColor(Color.WHITE);
        mGestureInfoView.setPadding(paddingInDP, paddingInDP, paddingInDP, paddingInDP);
        mGestureInfoView.setLayoutParams(
                new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

        addView(nameView);
        updateTheme(getResources().getConfiguration().uiMode);

        addView(mNameView);
        addView(mTouchpadVisualizationView);
        addView(mGestureInfoView);

@@ -239,6 +242,8 @@ public class TouchpadDebugView extends LinearLayout {
    @Override
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        updateTheme(newConfig.uiMode);
        updateScreenDimensions();
        updateViewsDimensions();

@@ -250,6 +255,27 @@ public class TouchpadDebugView extends LinearLayout {
        mWindowManager.updateViewLayout(this, mWindowLayoutParams);
    }

    private void updateTheme(int uiMode) {
        int currentNightMode = uiMode & Configuration.UI_MODE_NIGHT_MASK;
        if (currentNightMode == Configuration.UI_MODE_NIGHT_YES) {
            setNightModeTheme();
        } else {
            setLightModeTheme();
        }
    }

    private void setLightModeTheme() {
        mTouchpadVisualizationView.setLightModeTheme();
        mGestureInfoView.setBackgroundColor(Color.WHITE);
        mGestureInfoView.setTextColor(Color.BLACK);
    }

    private void setNightModeTheme() {
        mTouchpadVisualizationView.setNightModeTheme();
        mGestureInfoView.setBackgroundColor(Color.BLACK);
        mGestureInfoView.setTextColor(Color.WHITE);
    }

    private boolean isSlopExceeded(float deltaX, float deltaY) {
        return deltaX * deltaX + deltaY * deltaY >= mTouchSlop * mTouchSlop;
    }
@@ -333,12 +359,12 @@ public class TouchpadDebugView extends LinearLayout {

    private void onTouchpadButtonPress() {
        Slog.d(TAG, "You clicked me!");
        getChildAt(0).setBackgroundColor(Color.BLUE);
        mNameView.setBackgroundColor(BUTTON_PRESSED_BACKGROUND_COLOR);
    }

    private void onTouchpadButtonRelease() {
        Slog.d(TAG, "You released the click");
        getChildAt(0).setBackgroundColor(Color.RED);
        mNameView.setBackgroundColor(BUTTON_RELEASED_BACKGROUND_COLOR);
    }

    /**
+19 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.server.input.debug;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.Slog;
@@ -58,11 +59,9 @@ public class TouchpadVisualizationView extends View {
        mScaleFactor = 1;
        mOvalStrokePaint = new Paint();
        mOvalStrokePaint.setAntiAlias(true);
        mOvalStrokePaint.setARGB(255, 0, 0, 0);
        mOvalStrokePaint.setStyle(Paint.Style.STROKE);
        mOvalFillPaint = new Paint();
        mOvalFillPaint.setAntiAlias(true);
        mOvalFillPaint.setARGB(255, 0, 0, 0);
        mTracePaint = new Paint();
        mTracePaint.setAntiAlias(false);
        mTracePaint.setARGB(255, 0, 0, 255);
@@ -195,6 +194,24 @@ public class TouchpadVisualizationView extends View {
        mScaleFactor = scaleFactor;
    }

    /**
     * Change the colors of the objects inside the view to light mode theme.
     */
    public void setLightModeTheme() {
        this.setBackgroundColor(Color.rgb(20, 20, 20));
        mOvalFillPaint.setARGB(255, 255, 255, 255);
        mOvalStrokePaint.setARGB(255, 255, 255, 255);
    }

    /**
     * Change the colors of the objects inside the view to night mode theme.
     */
    public void setNightModeTheme() {
        this.setBackgroundColor(Color.rgb(240, 240, 240));
        mOvalFillPaint.setARGB(255, 0, 0, 0);
        mOvalStrokePaint.setARGB(255, 0, 0, 0);
    }

    private float translateX(float x) {
        return translateRange(mTouchpadHardwareProperties.getLeft(),
                mTouchpadHardwareProperties.getRight(), 0, getWidth(), x);
+4 −4
Original line number Diff line number Diff line
@@ -321,26 +321,26 @@ public class TouchpadDebugViewTest {
                new TouchpadHardwareState(0, 1 /* buttonsDown */, 0, 0,
                        new TouchpadFingerState[0]), TOUCHPAD_DEVICE_ID);

        assertEquals(((ColorDrawable) child.getBackground()).getColor(), Color.BLUE);
        assertEquals(((ColorDrawable) child.getBackground()).getColor(), Color.rgb(118, 151, 99));

        mTouchpadDebugView.updateHardwareState(
                new TouchpadHardwareState(0, 0 /* buttonsDown */, 0, 0,
                        new TouchpadFingerState[0]), TOUCHPAD_DEVICE_ID);

        assertEquals(((ColorDrawable) child.getBackground()).getColor(), Color.RED);
        assertEquals(((ColorDrawable) child.getBackground()).getColor(), Color.rgb(84, 85, 169));

        mTouchpadDebugView.updateHardwareState(
                new TouchpadHardwareState(0, 1 /* buttonsDown */, 0, 0,
                        new TouchpadFingerState[0]), TOUCHPAD_DEVICE_ID);

        assertEquals(((ColorDrawable) child.getBackground()).getColor(), Color.BLUE);
        assertEquals(((ColorDrawable) child.getBackground()).getColor(), Color.rgb(118, 151, 99));

        // Color should not change because hardware state of a different touchpad
        mTouchpadDebugView.updateHardwareState(
                new TouchpadHardwareState(0, 0 /* buttonsDown */, 0, 0,
                        new TouchpadFingerState[0]), TOUCHPAD_DEVICE_ID + 1);

        assertEquals(((ColorDrawable) child.getBackground()).getColor(), Color.BLUE);
        assertEquals(((ColorDrawable) child.getBackground()).getColor(), Color.rgb(118, 151, 99));
    }

    @Test