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

Commit

Permalink
feat(focus-mvp-android-device): current focus element highlight trans…
Browse files Browse the repository at this point in the history
…parent inner circle (#92)

* current focus element highlight always has transparent inner circle

* added if/else for clarity
  • Loading branch information
brocktaylor7 authored Apr 1, 2021
1 parent 1481eb6 commit 3fa7f59
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class FocusElementHighlight {
private HashMap<String, Paint> paints;
private Rect rect;
private View view;
private boolean isCurrentElement;
private static final String TAG = "FocusElementHighlight";

public FocusElementHighlight(
Expand All @@ -34,6 +35,7 @@ public FocusElementHighlight(
this.radius = radius;
this.rect = new Rect();
this.paints = currentPaints;
this.isCurrentElement = true;
}

private void setCoordinates() {
Expand All @@ -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);
}
Expand Down Expand Up @@ -85,6 +97,10 @@ public void setPaints(HashMap<String, Paint> paints) {
this.paints = paints;
}

public void setAsNonCurrentElement() {
this.isCurrentElement = false;
}

public AccessibilityNodeInfo getEventSource() {
return this.eventSource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ private void setPreviousLineNonCurrent(FocusElementLine line) {
}

private void setPreviousElementHighlightNonCurrent(FocusElementHighlight focusElementHighlight) {
focusElementHighlight.setAsNonCurrentElement();
focusElementHighlight.setPaints(this.styles.getNonCurrentElementPaints());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -17,6 +19,7 @@ public class FocusVisualizerStyles {
private Paint numberPaint;
private Paint currentBackgroundLinePaint;
private Paint nonCurrentBackgroundLinePaint;
private Paint transparentInnerCirclePaint;

private HashMap<String, Paint> currentElementPaints;
private HashMap<String, Paint> nonCurrentElementPaints;
Expand All @@ -34,6 +37,7 @@ public FocusVisualizerStyles() {
this.setNonCurrentOuterCirclePaint();
this.setCurrentBackgroundLinePaint();
this.setNonCurrentBackgroundLinePaint();
this.setTransparentInnerCirclePaint();

this.setCurrentElementPaints();
this.setNonCurrentElementPaints();
Expand All @@ -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<String, Paint> getCurrentElementPaints() {
Expand Down Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3fa7f59

Please sign in to comment.