Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 3fa7f59

Browse files
authored
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
1 parent 1481eb6 commit 3fa7f59

File tree

5 files changed

+57
-5
lines changed

5 files changed

+57
-5
lines changed

AccessibilityInsightsForAndroidService/app/src/main/java/com/microsoft/accessibilityinsightsforandroidservice/FocusElementHighlight.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class FocusElementHighlight {
2020
private HashMap<String, Paint> paints;
2121
private Rect rect;
2222
private View view;
23+
private boolean isCurrentElement;
2324
private static final String TAG = "FocusElementHighlight";
2425

2526
public FocusElementHighlight(
@@ -34,6 +35,7 @@ public FocusElementHighlight(
3435
this.radius = radius;
3536
this.rect = new Rect();
3637
this.paints = currentPaints;
38+
this.isCurrentElement = true;
3739
}
3840

3941
private void setCoordinates() {
@@ -54,10 +56,20 @@ public void drawElementHighlight(Canvas canvas) {
5456

5557
this.updateWithNewCoordinates();
5658

57-
this.drawInnerCircle(
58-
this.xCoordinate, this.yCoordinate, this.radius, this.paints.get("innerCircle"), canvas);
59-
this.drawNumberInCircle(
60-
this.xCoordinate, this.yCoordinate, this.tabStopCount, this.paints.get("number"), canvas);
59+
if (isCurrentElement) {
60+
this.drawInnerCircle(
61+
this.xCoordinate,
62+
this.yCoordinate,
63+
this.radius,
64+
this.paints.get("transparentInnerCircle"),
65+
canvas);
66+
} else {
67+
this.drawInnerCircle(
68+
this.xCoordinate, this.yCoordinate, this.radius, this.paints.get("innerCircle"), canvas);
69+
this.drawNumberInCircle(
70+
this.xCoordinate, this.yCoordinate, this.tabStopCount, this.paints.get("number"), canvas);
71+
}
72+
6173
this.drawOuterCircle(
6274
this.xCoordinate, this.yCoordinate, this.radius, this.paints.get("outerCircle"), canvas);
6375
}
@@ -85,6 +97,10 @@ public void setPaints(HashMap<String, Paint> paints) {
8597
this.paints = paints;
8698
}
8799

100+
public void setAsNonCurrentElement() {
101+
this.isCurrentElement = false;
102+
}
103+
88104
public AccessibilityNodeInfo getEventSource() {
89105
return this.eventSource;
90106
}

AccessibilityInsightsForAndroidService/app/src/main/java/com/microsoft/accessibilityinsightsforandroidservice/FocusVisualizer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ private void setPreviousLineNonCurrent(FocusElementLine line) {
5858
}
5959

6060
private void setPreviousElementHighlightNonCurrent(FocusElementHighlight focusElementHighlight) {
61+
focusElementHighlight.setAsNonCurrentElement();
6162
focusElementHighlight.setPaints(this.styles.getNonCurrentElementPaints());
6263
}
6364

AccessibilityInsightsForAndroidService/app/src/main/java/com/microsoft/accessibilityinsightsforandroidservice/FocusVisualizerStyles.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import android.graphics.Color;
77
import android.graphics.DashPathEffect;
88
import android.graphics.Paint;
9+
import android.graphics.PorterDuff;
10+
import android.graphics.PorterDuffXfermode;
911
import java.util.HashMap;
1012

1113
public class FocusVisualizerStyles {
@@ -17,6 +19,7 @@ public class FocusVisualizerStyles {
1719
private Paint numberPaint;
1820
private Paint currentBackgroundLinePaint;
1921
private Paint nonCurrentBackgroundLinePaint;
22+
private Paint transparentInnerCirclePaint;
2023

2124
private HashMap<String, Paint> currentElementPaints;
2225
private HashMap<String, Paint> nonCurrentElementPaints;
@@ -34,6 +37,7 @@ public FocusVisualizerStyles() {
3437
this.setNonCurrentOuterCirclePaint();
3538
this.setCurrentBackgroundLinePaint();
3639
this.setNonCurrentBackgroundLinePaint();
40+
this.setTransparentInnerCirclePaint();
3741

3842
this.setCurrentElementPaints();
3943
this.setNonCurrentElementPaints();
@@ -46,6 +50,7 @@ private void setCurrentElementPaints() {
4650
this.currentElementPaints.put("outerCircle", this.currentOuterCirclePaint);
4751
this.currentElementPaints.put("innerCircle", this.innerCirclePaint);
4852
this.currentElementPaints.put("number", this.numberPaint);
53+
this.currentElementPaints.put("transparentInnerCircle", this.transparentInnerCirclePaint);
4954
}
5055

5156
public HashMap<String, Paint> getCurrentElementPaints() {
@@ -141,4 +146,11 @@ private void setNonCurrentBackgroundLinePaint() {
141146
this.nonCurrentBackgroundLinePaint.setColor(Color.WHITE);
142147
this.nonCurrentBackgroundLinePaint.setStrokeWidth(12);
143148
}
149+
150+
private void setTransparentInnerCirclePaint() {
151+
this.transparentInnerCirclePaint = new Paint();
152+
this.transparentInnerCirclePaint.setStyle(Paint.Style.FILL);
153+
this.transparentInnerCirclePaint.setColor(Color.TRANSPARENT);
154+
this.transparentInnerCirclePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
155+
}
144156
}

AccessibilityInsightsForAndroidService/app/src/test/java/com/microsoft/accessibilityinsightsforandroidservice/FocusElementHighlightTest.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public void prepare() throws Exception {
4949
paintsStub.put("innerCircle", paintMock);
5050
paintsStub.put("outerCircle", paintMock);
5151
paintsStub.put("number", paintMock);
52+
paintsStub.put("transparentInnerCircle", paintMock);
5253

5354
when(viewMock.getResources()).thenReturn(resourcesMock);
5455
whenNew(Rect.class).withNoArguments().thenReturn(rectMock);
@@ -90,7 +91,22 @@ public void drawElementHighlightDoesNothingWhenEventSourceRefreshDoesNotWork() {
9091
}
9192

9293
@Test
93-
public void drawElementHighlightCallsAllRelevantDrawMethods() throws Exception {
94+
public void drawElementHighlightCallsAllRelevantDrawMethodsForCurrentElement() throws Exception {
95+
when(accessibilityNodeInfoMock.refresh()).thenReturn(true);
96+
FocusElementHighlight elementSpy = spy(testSubject);
97+
elementSpy.drawElementHighlight(canvasMock);
98+
verifyPrivate(elementSpy, times(1))
99+
.invoke(
100+
"drawInnerCircle", anyInt(), anyInt(), anyInt(), any(Paint.class), any(Canvas.class));
101+
verifyPrivate(elementSpy, times(1))
102+
.invoke(
103+
"drawOuterCircle", anyInt(), anyInt(), anyInt(), any(Paint.class), any(Canvas.class));
104+
}
105+
106+
@Test
107+
public void drawElementHighlightCallsAllRelevantDrawMethodsForNonCurrentElement()
108+
throws Exception {
109+
testSubject.setAsNonCurrentElement();
94110
when(accessibilityNodeInfoMock.refresh()).thenReturn(true);
95111
FocusElementHighlight elementSpy = spy(testSubject);
96112
elementSpy.drawElementHighlight(canvasMock);
@@ -114,4 +130,10 @@ public void drawElementHighlightCallsAllRelevantDrawMethods() throws Exception {
114130
public void getEventSourceReturnsAccessibilityNodeInfo() {
115131
Assert.assertEquals(testSubject.getEventSource(), accessibilityNodeInfoMock);
116132
}
133+
134+
@Test
135+
public void setAsNonCurrentElementFunctionsAsExpected() {
136+
testSubject.setAsNonCurrentElement();
137+
Assert.assertEquals(Whitebox.getInternalState(testSubject, "isCurrentElement"), false);
138+
}
117139
}

AccessibilityInsightsForAndroidService/app/src/test/java/com/microsoft/accessibilityinsightsforandroidservice/FocusVisualizerStylesTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public void getCurrentElementPaintsReturnsAllRelevantPaints() {
3636
Assert.assertNotNull(paints.get("outerCircle"));
3737
Assert.assertNotNull(paints.get("innerCircle"));
3838
Assert.assertNotNull(paints.get("number"));
39+
Assert.assertNotNull(paints.get("transparentInnerCircle"));
3940
}
4041

4142
@Test

0 commit comments

Comments
 (0)