From 3fa7f59b2788a757968c7592426c327e668c71ba Mon Sep 17 00:00:00 2001 From: Brock Taylor <13286385+brocktaylor7@users.noreply.github.com> Date: Thu, 1 Apr 2021 12:30:55 -0700 Subject: [PATCH] feat(focus-mvp-android-device): current focus element highlight transparent inner circle (#92) * current focus element highlight always has transparent inner circle * added if/else for clarity --- .../FocusElementHighlight.java | 24 +++++++++++++++---- .../FocusVisualizer.java | 1 + .../FocusVisualizerStyles.java | 12 ++++++++++ .../FocusElementHighlightTest.java | 24 ++++++++++++++++++- .../FocusVisualizerStylesTest.java | 1 + 5 files changed, 57 insertions(+), 5 deletions(-) diff --git a/AccessibilityInsightsForAndroidService/app/src/main/java/com/microsoft/accessibilityinsightsforandroidservice/FocusElementHighlight.java b/AccessibilityInsightsForAndroidService/app/src/main/java/com/microsoft/accessibilityinsightsforandroidservice/FocusElementHighlight.java index e598c533..03d764d3 100644 --- a/AccessibilityInsightsForAndroidService/app/src/main/java/com/microsoft/accessibilityinsightsforandroidservice/FocusElementHighlight.java +++ b/AccessibilityInsightsForAndroidService/app/src/main/java/com/microsoft/accessibilityinsightsforandroidservice/FocusElementHighlight.java @@ -20,6 +20,7 @@ public class FocusElementHighlight { private HashMap paints; private Rect rect; private View view; + private boolean isCurrentElement; private static final String TAG = "FocusElementHighlight"; public FocusElementHighlight( @@ -34,6 +35,7 @@ public FocusElementHighlight( this.radius = radius; this.rect = new Rect(); this.paints = currentPaints; + this.isCurrentElement = true; } private void setCoordinates() { @@ -54,10 +56,20 @@ public void drawElementHighlight(Canvas canvas) { this.updateWithNewCoordinates(); - this.drawInnerCircle( - this.xCoordinate, this.yCoordinate, this.radius, this.paints.get("innerCircle"), canvas); - this.drawNumberInCircle( - this.xCoordinate, this.yCoordinate, this.tabStopCount, this.paints.get("number"), canvas); + if (isCurrentElement) { + this.drawInnerCircle( + this.xCoordinate, + this.yCoordinate, + this.radius, + this.paints.get("transparentInnerCircle"), + canvas); + } else { + this.drawInnerCircle( + this.xCoordinate, this.yCoordinate, this.radius, this.paints.get("innerCircle"), canvas); + this.drawNumberInCircle( + this.xCoordinate, this.yCoordinate, this.tabStopCount, this.paints.get("number"), canvas); + } + this.drawOuterCircle( this.xCoordinate, this.yCoordinate, this.radius, this.paints.get("outerCircle"), canvas); } @@ -85,6 +97,10 @@ public void setPaints(HashMap paints) { this.paints = paints; } + public void setAsNonCurrentElement() { + this.isCurrentElement = false; + } + public AccessibilityNodeInfo getEventSource() { return this.eventSource; } diff --git a/AccessibilityInsightsForAndroidService/app/src/main/java/com/microsoft/accessibilityinsightsforandroidservice/FocusVisualizer.java b/AccessibilityInsightsForAndroidService/app/src/main/java/com/microsoft/accessibilityinsightsforandroidservice/FocusVisualizer.java index dae2e74d..0ed084ed 100644 --- a/AccessibilityInsightsForAndroidService/app/src/main/java/com/microsoft/accessibilityinsightsforandroidservice/FocusVisualizer.java +++ b/AccessibilityInsightsForAndroidService/app/src/main/java/com/microsoft/accessibilityinsightsforandroidservice/FocusVisualizer.java @@ -58,6 +58,7 @@ private void setPreviousLineNonCurrent(FocusElementLine line) { } private void setPreviousElementHighlightNonCurrent(FocusElementHighlight focusElementHighlight) { + focusElementHighlight.setAsNonCurrentElement(); focusElementHighlight.setPaints(this.styles.getNonCurrentElementPaints()); } diff --git a/AccessibilityInsightsForAndroidService/app/src/main/java/com/microsoft/accessibilityinsightsforandroidservice/FocusVisualizerStyles.java b/AccessibilityInsightsForAndroidService/app/src/main/java/com/microsoft/accessibilityinsightsforandroidservice/FocusVisualizerStyles.java index 2f6be048..d54ae137 100644 --- a/AccessibilityInsightsForAndroidService/app/src/main/java/com/microsoft/accessibilityinsightsforandroidservice/FocusVisualizerStyles.java +++ b/AccessibilityInsightsForAndroidService/app/src/main/java/com/microsoft/accessibilityinsightsforandroidservice/FocusVisualizerStyles.java @@ -6,6 +6,8 @@ import android.graphics.Color; import android.graphics.DashPathEffect; import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffXfermode; import java.util.HashMap; public class FocusVisualizerStyles { @@ -17,6 +19,7 @@ public class FocusVisualizerStyles { private Paint numberPaint; private Paint currentBackgroundLinePaint; private Paint nonCurrentBackgroundLinePaint; + private Paint transparentInnerCirclePaint; private HashMap currentElementPaints; private HashMap nonCurrentElementPaints; @@ -34,6 +37,7 @@ public FocusVisualizerStyles() { this.setNonCurrentOuterCirclePaint(); this.setCurrentBackgroundLinePaint(); this.setNonCurrentBackgroundLinePaint(); + this.setTransparentInnerCirclePaint(); this.setCurrentElementPaints(); this.setNonCurrentElementPaints(); @@ -46,6 +50,7 @@ private void setCurrentElementPaints() { this.currentElementPaints.put("outerCircle", this.currentOuterCirclePaint); this.currentElementPaints.put("innerCircle", this.innerCirclePaint); this.currentElementPaints.put("number", this.numberPaint); + this.currentElementPaints.put("transparentInnerCircle", this.transparentInnerCirclePaint); } public HashMap getCurrentElementPaints() { @@ -141,4 +146,11 @@ private void setNonCurrentBackgroundLinePaint() { this.nonCurrentBackgroundLinePaint.setColor(Color.WHITE); this.nonCurrentBackgroundLinePaint.setStrokeWidth(12); } + + private void setTransparentInnerCirclePaint() { + this.transparentInnerCirclePaint = new Paint(); + this.transparentInnerCirclePaint.setStyle(Paint.Style.FILL); + this.transparentInnerCirclePaint.setColor(Color.TRANSPARENT); + this.transparentInnerCirclePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); + } } diff --git a/AccessibilityInsightsForAndroidService/app/src/test/java/com/microsoft/accessibilityinsightsforandroidservice/FocusElementHighlightTest.java b/AccessibilityInsightsForAndroidService/app/src/test/java/com/microsoft/accessibilityinsightsforandroidservice/FocusElementHighlightTest.java index 9cb37557..fa22373a 100644 --- a/AccessibilityInsightsForAndroidService/app/src/test/java/com/microsoft/accessibilityinsightsforandroidservice/FocusElementHighlightTest.java +++ b/AccessibilityInsightsForAndroidService/app/src/test/java/com/microsoft/accessibilityinsightsforandroidservice/FocusElementHighlightTest.java @@ -49,6 +49,7 @@ public void prepare() throws Exception { paintsStub.put("innerCircle", paintMock); paintsStub.put("outerCircle", paintMock); paintsStub.put("number", paintMock); + paintsStub.put("transparentInnerCircle", paintMock); when(viewMock.getResources()).thenReturn(resourcesMock); whenNew(Rect.class).withNoArguments().thenReturn(rectMock); @@ -90,7 +91,22 @@ public void drawElementHighlightDoesNothingWhenEventSourceRefreshDoesNotWork() { } @Test - public void drawElementHighlightCallsAllRelevantDrawMethods() throws Exception { + public void drawElementHighlightCallsAllRelevantDrawMethodsForCurrentElement() throws Exception { + when(accessibilityNodeInfoMock.refresh()).thenReturn(true); + FocusElementHighlight elementSpy = spy(testSubject); + elementSpy.drawElementHighlight(canvasMock); + verifyPrivate(elementSpy, times(1)) + .invoke( + "drawInnerCircle", anyInt(), anyInt(), anyInt(), any(Paint.class), any(Canvas.class)); + verifyPrivate(elementSpy, times(1)) + .invoke( + "drawOuterCircle", anyInt(), anyInt(), anyInt(), any(Paint.class), any(Canvas.class)); + } + + @Test + public void drawElementHighlightCallsAllRelevantDrawMethodsForNonCurrentElement() + throws Exception { + testSubject.setAsNonCurrentElement(); when(accessibilityNodeInfoMock.refresh()).thenReturn(true); FocusElementHighlight elementSpy = spy(testSubject); elementSpy.drawElementHighlight(canvasMock); @@ -114,4 +130,10 @@ public void drawElementHighlightCallsAllRelevantDrawMethods() throws Exception { public void getEventSourceReturnsAccessibilityNodeInfo() { Assert.assertEquals(testSubject.getEventSource(), accessibilityNodeInfoMock); } + + @Test + public void setAsNonCurrentElementFunctionsAsExpected() { + testSubject.setAsNonCurrentElement(); + Assert.assertEquals(Whitebox.getInternalState(testSubject, "isCurrentElement"), false); + } } diff --git a/AccessibilityInsightsForAndroidService/app/src/test/java/com/microsoft/accessibilityinsightsforandroidservice/FocusVisualizerStylesTest.java b/AccessibilityInsightsForAndroidService/app/src/test/java/com/microsoft/accessibilityinsightsforandroidservice/FocusVisualizerStylesTest.java index 71772497..9af46092 100644 --- a/AccessibilityInsightsForAndroidService/app/src/test/java/com/microsoft/accessibilityinsightsforandroidservice/FocusVisualizerStylesTest.java +++ b/AccessibilityInsightsForAndroidService/app/src/test/java/com/microsoft/accessibilityinsightsforandroidservice/FocusVisualizerStylesTest.java @@ -36,6 +36,7 @@ public void getCurrentElementPaintsReturnsAllRelevantPaints() { Assert.assertNotNull(paints.get("outerCircle")); Assert.assertNotNull(paints.get("innerCircle")); Assert.assertNotNull(paints.get("number")); + Assert.assertNotNull(paints.get("transparentInnerCircle")); } @Test