diff options
| author | 2024-09-09 09:49:52 +0000 | |
|---|---|---|
| committer | 2024-09-09 09:49:52 +0000 | |
| commit | b23b7aa7891e8cdf4d190526ef61722c96c2d0b7 (patch) | |
| tree | 75b56f53e47cba221867b7b6efa1b241ad884231 | |
| parent | 5fd3af3c4a843efb035ea7978faec6d10c08eaca (diff) | |
| parent | 3ed2996cf30c37172521eeafa26ed54c89ef72f5 (diff) | |
Merge "Change TouchpadDebugView color on touchpad button clicked" into main
4 files changed, 90 insertions, 13 deletions
diff --git a/services/core/java/com/android/server/input/InputManagerService.java b/services/core/java/com/android/server/input/InputManagerService.java index 84cee7ecbd05..1285a61d08f2 100644 --- a/services/core/java/com/android/server/input/InputManagerService.java +++ b/services/core/java/com/android/server/input/InputManagerService.java @@ -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. diff --git a/services/core/java/com/android/server/input/debug/TouchpadDebugView.java b/services/core/java/com/android/server/input/debug/TouchpadDebugView.java index 7785ffb4b17a..ba56ad073e6a 100644 --- a/services/core/java/com/android/server/input/debug/TouchpadDebugView.java +++ b/services/core/java/com/android/server/input/debug/TouchpadDebugView.java @@ -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); + } + } } diff --git a/services/core/java/com/android/server/input/debug/TouchpadDebugViewController.java b/services/core/java/com/android/server/input/debug/TouchpadDebugViewController.java index c28e74a02071..bc53c4947a71 100644 --- a/services/core/java/com/android/server/input/debug/TouchpadDebugViewController.java +++ b/services/core/java/com/android/server/input/debug/TouchpadDebugViewController.java @@ -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); + } + } } diff --git a/tests/Input/src/com/android/server/input/debug/TouchpadDebugViewTest.java b/tests/Input/src/com/android/server/input/debug/TouchpadDebugViewTest.java index ad0ef1b3a37f..0f08be215033 100644 --- a/tests/Input/src/com/android/server/input/debug/TouchpadDebugViewTest.java +++ b/tests/Input/src/com/android/server/input/debug/TouchpadDebugViewTest.java @@ -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); + } + } } |