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

Commit ce15a76c authored by Omar Abdelmonem's avatar Omar Abdelmonem Committed by Abdelrahman Awadalla
Browse files

Added new custom View to TouchpadDebugView

Added custom View that will contain the representation of the fingers.
Fetched the touchpad name inside the TouchpadDebugView

Bug: 364547682

Test: presubmit
flag: com.android.hardware.input.touchpad_visualizer
Change-Id: I24047ff0ba4167c1a16b361d853a90a28d207070
parent 3575d886
Loading
Loading
Loading
Loading
+34 −32
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.hardware.input.InputManager;
import android.util.Slog;
import android.view.Gravity;
import android.view.MotionEvent;
@@ -65,7 +66,7 @@ public class TouchpadDebugView extends LinearLayout {
        mTouchpadId = touchpadId;
        mWindowManager =
                Objects.requireNonNull(getContext().getSystemService(WindowManager.class));
        init(context);
        init(context, touchpadId);
        mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

        // TODO(b/360137366): Use the hardware properties to initialise layout parameters.
@@ -88,32 +89,40 @@ public class TouchpadDebugView extends LinearLayout {
        mWindowLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    }

    private void init(Context context) {
    private void init(Context context, int touchpadId) {
        setOrientation(VERTICAL);
        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.TRANSPARENT);
        textView1.setTextSize(20);
        textView1.setText("Touchpad Debug View 1");
        textView1.setGravity(Gravity.CENTER);
        textView1.setTextColor(Color.WHITE);
        textView1.setLayoutParams(new LayoutParams(1000, 200));

        TextView textView2 = new TextView(context);
        textView2.setBackgroundColor(Color.TRANSPARENT);
        textView2.setTextSize(20);
        textView2.setText("Touchpad Debug View 2");
        textView2.setGravity(Gravity.CENTER);
        textView2.setTextColor(Color.WHITE);
        textView2.setLayoutParams(new LayoutParams(1000, 200));

        addView(textView1);
        addView(textView2);
        setBackgroundColor(Color.TRANSPARENT);

        TextView nameView = new TextView(context);
        nameView.setBackgroundColor(Color.RED);
        nameView.setTextSize(20);
        nameView.setText(Objects.requireNonNull(Objects.requireNonNull(
                        mContext.getSystemService(InputManager.class))
                .getInputDevice(touchpadId)).getName());
        nameView.setGravity(Gravity.CENTER);
        nameView.setTextColor(Color.WHITE);
        nameView.setLayoutParams(new LayoutParams(1000, 200));

        TouchpadVisualisationView touchpadVisualisationView =
                new TouchpadVisualisationView(context);
        touchpadVisualisationView.setBackgroundColor(Color.WHITE);
        touchpadVisualisationView.setLayoutParams(new LayoutParams(1000, 200));

        //TODO(b/365562952): Add a display for recognized gesture info here
        TextView gestureInfoView = new TextView(context);
        gestureInfoView.setBackgroundColor(Color.GRAY);
        gestureInfoView.setTextSize(20);
        gestureInfoView.setText("Touchpad Debug View 3");
        gestureInfoView.setGravity(Gravity.CENTER);
        gestureInfoView.setTextColor(Color.BLACK);
        gestureInfoView.setLayoutParams(new LayoutParams(1000, 200));

        addView(nameView);
        addView(touchpadVisualisationView);
        addView(gestureInfoView);

        updateScreenDimensions();
    }
@@ -219,18 +228,11 @@ public class TouchpadDebugView extends LinearLayout {

    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);
        }
        getChildAt(0).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);
        }
        getChildAt(0).setBackgroundColor(Color.RED);
    }
}
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.input.debug;

import android.content.Context;
import android.view.View;

public class TouchpadVisualisationView extends View {
    public TouchpadVisualisationView(Context context) {
        super(context);
    }
}
+4 −13
Original line number Diff line number Diff line
@@ -296,33 +296,24 @@ public class TouchpadDebugViewTest {

    @Test
    public void testTouchpadClick() {
        View child;
        View child = mTouchpadDebugView.getChildAt(0);

        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);
    }
}
}