1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-23 11:45:38 +01:00

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.Linq;
using Android.Content;
using Android.Content.Res;
using Android.Graphics;
using Android.OS;
using Android.Provider;
@ -11,7 +10,6 @@ using Android.Views.Accessibility;
using Android.Widget;
using Bit.App.Resources;
using Bit.Core;
using Plugin.CurrentActivity;
namespace Bit.Droid.Accessibility
{
@ -368,8 +366,8 @@ namespace Bit.Droid.Accessibility
return layoutParams;
}
public static Point GetOverlayAnchorPosition(AccessibilityNodeInfo anchorView, int overlayViewHeight,
bool isOverlayAboveAnchor)
public static Point GetOverlayAnchorPosition(AccessibilityService service, AccessibilityNodeInfo anchorView,
int overlayViewHeight, bool isOverlayAboveAnchor)
{
var anchorViewRect = new Rect();
anchorView.GetBoundsInScreen(anchorViewRect);
@ -381,13 +379,14 @@ namespace Bit.Droid.Accessibility
{
anchorViewY -= overlayViewHeight;
}
anchorViewY -= GetStatusBarHeight();
anchorViewY -= GetStatusBarHeight(service);
return new Point(anchorViewX, anchorViewY);
}
public static Point GetOverlayAnchorPosition(AccessibilityNodeInfo anchorNode, AccessibilityNodeInfo root,
IEnumerable<AccessibilityWindowInfo> windows, int overlayViewHeight, bool isOverlayAboveAnchor)
public static Point GetOverlayAnchorPosition(AccessibilityService service, AccessibilityNodeInfo anchorNode,
AccessibilityNodeInfo root, IEnumerable<AccessibilityWindowInfo> windows, int overlayViewHeight,
bool isOverlayAboveAnchor)
{
Point point = null;
if (anchorNode != null)
@ -420,9 +419,10 @@ namespace Bit.Droid.Accessibility
{
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 (isOverlayAboveAnchor)
@ -502,6 +502,11 @@ namespace Bit.Droid.Accessibility
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)
{
if (node == null)
@ -515,26 +520,24 @@ namespace Bit.Droid.Accessibility
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 barHeight = 0;
var resourceId = activity.Resources.GetIdentifier(resName, "dimen", "android");
var resourceId = service.Resources.GetIdentifier(resName, "dimen", "android");
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 Android.App;
using Android.Content;
using Android.Graphics;
using Android.OS;
using Android.Provider;
using Android.Runtime;
using Android.Views;
using Android.Views.Accessibility;
@ -15,7 +13,6 @@ using Bit.App.Resources;
using Bit.Core;
using Bit.Core.Abstractions;
using Bit.Core.Utilities;
using Java.Util;
namespace Bit.Droid.Accessibility
{
@ -249,6 +246,12 @@ namespace Bit.Droid.Accessibility
private void OverlayPromptToAutofill(AccessibilityNodeInfo root, AccessibilityEvent e)
{
if (Java.Lang.JavaSystem.CurrentTimeMillis() - _lastAutoFillTime < 1000 ||
AccessibilityHelpers.IsAutofillServicePromptVisible(Windows))
{
return;
}
if (!AccessibilityHelpers.OverlayPermitted())
{
if (!AccessibilityHelpers.IsAutofillTileAdded)
@ -267,11 +270,6 @@ namespace Bit.Droid.Accessibility
CancelOverlayPrompt();
}
if (Java.Lang.JavaSystem.CurrentTimeMillis() - _lastAutoFillTime < 1000)
{
return;
}
var uri = AccessibilityHelpers.GetUri(root);
var fillable = !string.IsNullOrWhiteSpace(uri);
if (fillable)
@ -309,8 +307,8 @@ namespace Bit.Droid.Accessibility
};
var layoutParams = AccessibilityHelpers.GetOverlayLayoutParams();
var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(e.Source, _overlayViewHeight,
_isOverlayAboveAnchor);
var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(this, e.Source,
_overlayViewHeight, _isOverlayAboveAnchor);
layoutParams.X = anchorPosition.X;
layoutParams.Y = anchorPosition.Y;
@ -353,7 +351,8 @@ namespace Bit.Droid.Accessibility
private void AdjustOverlayForScroll()
{
if (_overlayView == null || _anchorNode == null)
if (_overlayView == null || _anchorNode == null ||
AccessibilityHelpers.IsAutofillServicePromptVisible(Windows))
{
CancelOverlayPrompt();
return;
@ -366,8 +365,8 @@ namespace Bit.Droid.Accessibility
windows = Windows;
}
var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(_anchorNode, root, windows,
_overlayViewHeight, _isOverlayAboveAnchor);
var anchorPosition = AccessibilityHelpers.GetOverlayAnchorPosition(this, _anchorNode, root,
windows, _overlayViewHeight, _isOverlayAboveAnchor);
if (anchorPosition == null)
{
CancelOverlayPrompt();