Additional accessibility tweaks (#825)

* Additional accessibility tweaks

* Cleanup
This commit is contained in:
Matt Portune 2020-04-09 14:57:06 -04:00 committed by GitHub
parent 78cfd82fdd
commit d66eaf8855
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 32 deletions

View file

@ -2,7 +2,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Android.Content; using Android.Content;
using Android.Content.Res;
using Android.Graphics; using Android.Graphics;
using Android.OS; using Android.OS;
using Android.Provider; using Android.Provider;
@ -11,7 +10,6 @@ using Android.Views.Accessibility;
using Android.Widget; using Android.Widget;
using Bit.App.Resources; using Bit.App.Resources;
using Bit.Core; using Bit.Core;
using Plugin.CurrentActivity;
namespace Bit.Droid.Accessibility namespace Bit.Droid.Accessibility
{ {
@ -368,8 +366,8 @@ namespace Bit.Droid.Accessibility
return layoutParams; return layoutParams;
} }
public static Point GetOverlayAnchorPosition(AccessibilityNodeInfo anchorView, int overlayViewHeight, public static Point GetOverlayAnchorPosition(AccessibilityService service, AccessibilityNodeInfo anchorView,
bool isOverlayAboveAnchor) int overlayViewHeight, bool isOverlayAboveAnchor)
{ {
var anchorViewRect = new Rect(); var anchorViewRect = new Rect();
anchorView.GetBoundsInScreen(anchorViewRect); anchorView.GetBoundsInScreen(anchorViewRect);
@ -381,13 +379,14 @@ namespace Bit.Droid.Accessibility
{ {
anchorViewY -= overlayViewHeight; anchorViewY -= overlayViewHeight;
} }
anchorViewY -= GetStatusBarHeight(); anchorViewY -= GetStatusBarHeight(service);
return new Point(anchorViewX, anchorViewY); return new Point(anchorViewX, anchorViewY);
} }
public static Point GetOverlayAnchorPosition(AccessibilityNodeInfo anchorNode, AccessibilityNodeInfo root, public static Point GetOverlayAnchorPosition(AccessibilityService service, AccessibilityNodeInfo anchorNode,
IEnumerable<AccessibilityWindowInfo> windows, int overlayViewHeight, bool isOverlayAboveAnchor) AccessibilityNodeInfo root, IEnumerable<AccessibilityWindowInfo> windows, int overlayViewHeight,
bool isOverlayAboveAnchor)
{ {
Point point = null; Point point = null;
if (anchorNode != null) if (anchorNode != null)
@ -420,9 +419,10 @@ namespace Bit.Droid.Accessibility
{ {
return null; return null;
} }
var maxY = rootNodeHeight - GetNavigationBarHeight() - GetStatusBarHeight() - inputMethodHeight; var maxY = rootNodeHeight - GetNavigationBarHeight(service) - GetStatusBarHeight(service) -
inputMethodHeight;
point = GetOverlayAnchorPosition(anchorNode, overlayViewHeight, isOverlayAboveAnchor); point = GetOverlayAnchorPosition(service, anchorNode, overlayViewHeight, isOverlayAboveAnchor);
if (point.Y < minY) if (point.Y < minY)
{ {
if (isOverlayAboveAnchor) if (isOverlayAboveAnchor)
@ -502,6 +502,11 @@ namespace Bit.Droid.Accessibility
return inputMethodWindowHeight; return inputMethodWindowHeight;
} }
public static bool IsAutofillServicePromptVisible(IEnumerable<AccessibilityWindowInfo> windows)
{
return windows?.Any(w => w.Title?.ToLower().Contains("autofill") ?? false) ?? false;
}
public static int GetNodeHeight(AccessibilityNodeInfo node) public static int GetNodeHeight(AccessibilityNodeInfo node)
{ {
if (node == null) if (node == null)
@ -515,26 +520,24 @@ namespace Bit.Droid.Accessibility
return nodeRectHeight; return nodeRectHeight;
} }
private static int GetStatusBarHeight() private static int GetStatusBarHeight(AccessibilityService service)
{ {
return GetSystemResourceDimenPx("status_bar_height"); return GetSystemResourceDimenPx(service, "status_bar_height");
} }
private static int GetNavigationBarHeight() private static int GetNavigationBarHeight(AccessibilityService service)
{ {
return GetSystemResourceDimenPx("navigation_bar_height"); return GetSystemResourceDimenPx(service, "navigation_bar_height");
} }
private static int GetSystemResourceDimenPx(string resName) private static int GetSystemResourceDimenPx(AccessibilityService service, string resName)
{ {
var activity = (MainActivity)CrossCurrentActivity.Current.Activity; var resourceId = service.Resources.GetIdentifier(resName, "dimen", "android");
var barHeight = 0;
var resourceId = activity.Resources.GetIdentifier(resName, "dimen", "android");
if (resourceId > 0) if (resourceId > 0)
{ {
barHeight = activity.Resources.GetDimensionPixelSize(resourceId); return service.Resources.GetDimensionPixelSize(resourceId);
} }
return barHeight; return 0;
} }
} }
} }

View file

@ -4,9 +4,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Android.App; using Android.App;
using Android.Content; using Android.Content;
using Android.Graphics;
using Android.OS; using Android.OS;
using Android.Provider;
using Android.Runtime; using Android.Runtime;
using Android.Views; using Android.Views;
using Android.Views.Accessibility; using Android.Views.Accessibility;
@ -15,7 +13,6 @@ using Bit.App.Resources;
using Bit.Core; using Bit.Core;
using Bit.Core.Abstractions; using Bit.Core.Abstractions;
using Bit.Core.Utilities; using Bit.Core.Utilities;
using Java.Util;
namespace Bit.Droid.Accessibility namespace Bit.Droid.Accessibility
{ {
@ -249,6 +246,12 @@ namespace Bit.Droid.Accessibility
private void OverlayPromptToAutofill(AccessibilityNodeInfo root, AccessibilityEvent e) private void OverlayPromptToAutofill(AccessibilityNodeInfo root, AccessibilityEvent e)
{ {
if (Java.Lang.JavaSystem.CurrentTimeMillis() - _lastAutoFillTime < 1000 ||
AccessibilityHelpers.IsAutofillServicePromptVisible(Windows))
{
return;
}
if (!AccessibilityHelpers.OverlayPermitted()) if (!AccessibilityHelpers.OverlayPermitted())
{ {
if (!AccessibilityHelpers.IsAutofillTileAdded) if (!AccessibilityHelpers.IsAutofillTileAdded)
@ -267,11 +270,6 @@ namespace Bit.Droid.Accessibility
CancelOverlayPrompt(); CancelOverlayPrompt();
} }
if (Java.Lang.JavaSystem.CurrentTimeMillis() - _lastAutoFillTime < 1000)
{
return;
}
var uri = AccessibilityHelpers.GetUri(root); var uri = AccessibilityHelpers.GetUri(root);
var fillable = !string.IsNullOrWhiteSpace(uri); var fillable = !string.IsNullOrWhiteSpace(uri);
if (fillable) if (fillable)
@ -309,8 +307,8 @@ namespace Bit.Droid.Accessibility
}; };
var layoutParams = AccessibilityHelpers.GetOverlayLayoutParams(); var layoutParams = AccessibilityHelpers.GetOverlayLayoutParams();
var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(e.Source, _overlayViewHeight, var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(this, e.Source,
_isOverlayAboveAnchor); _overlayViewHeight, _isOverlayAboveAnchor);
layoutParams.X = anchorPosition.X; layoutParams.X = anchorPosition.X;
layoutParams.Y = anchorPosition.Y; layoutParams.Y = anchorPosition.Y;
@ -353,7 +351,8 @@ namespace Bit.Droid.Accessibility
private void AdjustOverlayForScroll() private void AdjustOverlayForScroll()
{ {
if (_overlayView == null || _anchorNode == null) if (_overlayView == null || _anchorNode == null ||
AccessibilityHelpers.IsAutofillServicePromptVisible(Windows))
{ {
CancelOverlayPrompt(); CancelOverlayPrompt();
return; return;
@ -366,8 +365,8 @@ namespace Bit.Droid.Accessibility
windows = Windows; windows = Windows;
} }
var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(_anchorNode, root, windows, var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(this, _anchorNode, root,
_overlayViewHeight, _isOverlayAboveAnchor); windows, _overlayViewHeight, _isOverlayAboveAnchor);
if (anchorPosition == null) if (anchorPosition == null)
{ {
CancelOverlayPrompt(); CancelOverlayPrompt();