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

Commit b23b7aa7 authored by Omar Abdelmonem's avatar Omar Abdelmonem Committed by Android (Google) Code Review
Browse files

Merge "Change TouchpadDebugView color on touchpad button clicked" into main

parents 5fd3af3c 3ed2996c
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -2269,13 +2269,15 @@ public class InputManagerService extends IInputManager.Stub
    // Native callback.
    @SuppressWarnings("unused")
    private void notifyTouchpadHardwareState(TouchpadHardwareState hardwareStates, int deviceId) {
        // TODO(b/286551975): sent the touchpad hardware state data here to TouchpadDebugActivity
        Slog.d(TAG, "notifyTouchpadHardwareState: Time: "
                + hardwareStates.getTimestamp() + ", No. Buttons: "
                + hardwareStates.getButtonsDown() + ", No. Fingers: "
                + hardwareStates.getFingerCount() + ", No. Touch: "
                + hardwareStates.getTouchCount() + ", Id: "
                + deviceId);
        if (mTouchpadDebugViewController != null) {
            mTouchpadDebugViewController.updateTouchpadHardwareState(hardwareStates);
        }
    }

    // Native callback.
+44 −12
Original line number Diff line number Diff line
@@ -30,6 +30,9 @@ import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.android.server.input.TouchpadFingerState;
import com.android.server.input.TouchpadHardwareState;

import java.util.Objects;

public class TouchpadDebugView extends LinearLayout {
@@ -52,6 +55,10 @@ public class TouchpadDebugView extends LinearLayout {
    private int mScreenHeight;
    private int mWindowLocationBeforeDragX;
    private int mWindowLocationBeforeDragY;
    @NonNull
    private TouchpadHardwareState mLastTouchpadState =
            new TouchpadHardwareState(0, 0 /* buttonsDown */, 0, 0,
                    new TouchpadFingerState[0]);

    public TouchpadDebugView(Context context, int touchpadId) {
        super(context);
@@ -83,14 +90,14 @@ public class TouchpadDebugView extends LinearLayout {

    private void init(Context context) {
        setOrientation(VERTICAL);
        setLayoutParams(new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        setBackgroundColor(Color.TRANSPARENT);
        setLayoutParams(new LayoutParams(
                LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));
        setBackgroundColor(Color.RED);

        // TODO(b/286551975): Replace this content with the touchpad debug view.
        TextView textView1 = new TextView(context);
        textView1.setBackgroundColor(Color.parseColor("#FFFF0000"));
        textView1.setBackgroundColor(Color.TRANSPARENT);
        textView1.setTextSize(20);
        textView1.setText("Touchpad Debug View 1");
        textView1.setGravity(Gravity.CENTER);
@@ -98,7 +105,7 @@ public class TouchpadDebugView extends LinearLayout {
        textView1.setLayoutParams(new LayoutParams(1000, 200));

        TextView textView2 = new TextView(context);
        textView2.setBackgroundColor(Color.BLUE);
        textView2.setBackgroundColor(Color.TRANSPARENT);
        textView2.setTextSize(20);
        textView2.setText("Touchpad Debug View 2");
        textView2.setGravity(Gravity.CENTER);
@@ -126,9 +133,7 @@ public class TouchpadDebugView extends LinearLayout {
            case MotionEvent.ACTION_MOVE:
                deltaX = event.getRawX() - mWindowLayoutParams.x - mTouchDownX;
                deltaY = event.getRawY() - mWindowLayoutParams.y - mTouchDownY;
                Slog.d("TouchpadDebugView", "Slop = " + mTouchSlop);
                if (isSlopExceeded(deltaX, deltaY)) {
                    Slog.d("TouchpadDebugView", "Slop exceeded");
                    mWindowLayoutParams.x =
                            Math.max(0, Math.min((int) (event.getRawX() - mTouchDownX),
                                    mScreenWidth - this.getWidth()));
@@ -136,9 +141,6 @@ public class TouchpadDebugView extends LinearLayout {
                            Math.max(0, Math.min((int) (event.getRawY() - mTouchDownY),
                                    mScreenHeight - this.getHeight()));

                    Slog.d("TouchpadDebugView", "New position X: "
                            + mWindowLayoutParams.x + ", Y: " + mWindowLayoutParams.y);

                    mWindowManager.updateViewLayout(this, mWindowLayoutParams);
                }
                return true;
@@ -166,7 +168,7 @@ public class TouchpadDebugView extends LinearLayout {
    @Override
    public boolean performClick() {
        super.performClick();
        Slog.d("TouchpadDebugView", "You clicked me!");
        Slog.d("TouchpadDebugView", "You tapped the window!");
        return true;
    }

@@ -201,4 +203,34 @@ public class TouchpadDebugView extends LinearLayout {
    public WindowManager.LayoutParams getWindowLayoutParams() {
        return mWindowLayoutParams;
    }

    public void updateHardwareState(TouchpadHardwareState touchpadHardwareState) {
        if (mLastTouchpadState.getButtonsDown() == 0) {
            if (touchpadHardwareState.getButtonsDown() > 0) {
                onTouchpadButtonPress();
            }
        } else {
            if (touchpadHardwareState.getButtonsDown() == 0) {
                onTouchpadButtonRelease();
            }
        }
        mLastTouchpadState = touchpadHardwareState;
    }

    private void onTouchpadButtonPress() {
        Slog.d("TouchpadDebugView", "You clicked me!");

        // Iterate through all child views
        // Temporary demonstration for testing
        for (int i = 0; i < getChildCount(); i++) {
            getChildAt(i).setBackgroundColor(Color.BLUE);
        }
    }

    private void onTouchpadButtonRelease() {
        Slog.d("TouchpadDebugView", "You released the click");
        for (int i = 0; i < getChildCount(); i++) {
            getChildAt(i).setBackgroundColor(Color.RED);
        }
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.view.WindowManager;

import com.android.server.input.InputManagerService;
import com.android.server.input.TouchpadHardwareProperties;
import com.android.server.input.TouchpadHardwareState;

import java.util.Objects;

@@ -132,4 +133,10 @@ public class TouchpadDebugViewController implements InputManager.InputDeviceList
        mTouchpadDebugView = null;
        Slog.d(TAG, "Touchpad debug view removed.");
    }

    public void updateTouchpadHardwareState(TouchpadHardwareState touchpadHardwareState) {
        if (mTouchpadDebugView != null) {
            mTouchpadDebugView.updateHardwareState(touchpadHardwareState);
        }
    }
}
+36 −0
Original line number Diff line number Diff line
@@ -26,7 +26,9 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.testing.TestableContext;
import android.view.MotionEvent;
import android.view.View;
@@ -40,6 +42,8 @@ import androidx.test.runner.AndroidJUnit4;

import com.android.cts.input.MotionEventBuilder;
import com.android.cts.input.PointerBuilder;
import com.android.server.input.TouchpadFingerState;
import com.android.server.input.TouchpadHardwareState;

import org.junit.Before;
import org.junit.Test;
@@ -289,4 +293,36 @@ public class TouchpadDebugViewTest {
        assertEquals(initialX, mWindowLayoutParamsCaptor.getValue().x);
        assertEquals(initialY, mWindowLayoutParamsCaptor.getValue().y);
    }

    @Test
    public void testTouchpadClick() {
        View child;

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

        for (int i = 0; i < mTouchpadDebugView.getChildCount(); i++) {
            child = mTouchpadDebugView.getChildAt(i);
            assertEquals(((ColorDrawable) child.getBackground()).getColor(), Color.BLUE);
        }

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

        for (int i = 0; i < mTouchpadDebugView.getChildCount(); i++) {
            child = mTouchpadDebugView.getChildAt(i);
            assertEquals(((ColorDrawable) child.getBackground()).getColor(), Color.RED);
        }

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

        for (int i = 0; i < mTouchpadDebugView.getChildCount(); i++) {
            child = mTouchpadDebugView.getChildAt(i);
            assertEquals(((ColorDrawable) child.getBackground()).getColor(), Color.BLUE);
        }
    }
}