mirror of
https://github.com/bitwarden/android.git
synced 2024-12-24 18:08:26 +03:00
accessibility settings page
This commit is contained in:
parent
7ed45c3535
commit
22f16ea514
8 changed files with 216 additions and 2 deletions
|
@ -512,6 +512,35 @@ namespace Bit.Droid.Services
|
||||||
return afm.IsEnabled && afm.HasEnabledAutofillServices;
|
return afm.IsEnabled && afm.HasEnabledAutofillServices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void OpenAccessibilitySettings()
|
||||||
|
{
|
||||||
|
var activity = (MainActivity)CrossCurrentActivity.Current.Activity;
|
||||||
|
var intent = new Intent(Settings.ActionAccessibilitySettings);
|
||||||
|
activity.StartActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenAutofillSettings()
|
||||||
|
{
|
||||||
|
var activity = (MainActivity)CrossCurrentActivity.Current.Activity;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var intent = new Intent(Settings.ActionRequestSetAutofillService);
|
||||||
|
intent.SetData(Android.Net.Uri.Parse("package:com.x8bit.bitwarden"));
|
||||||
|
activity.StartActivity(intent);
|
||||||
|
}
|
||||||
|
catch(ActivityNotFoundException)
|
||||||
|
{
|
||||||
|
var alertBuilder = new AlertDialog.Builder(activity);
|
||||||
|
alertBuilder.SetMessage(AppResources.BitwardenAutofillGoToSettings);
|
||||||
|
alertBuilder.SetCancelable(true);
|
||||||
|
alertBuilder.SetPositiveButton(AppResources.Ok, (sender, args) =>
|
||||||
|
{
|
||||||
|
(sender as AlertDialog)?.Cancel();
|
||||||
|
});
|
||||||
|
alertBuilder.Create().Show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private bool DeleteDir(Java.IO.File dir)
|
private bool DeleteDir(Java.IO.File dir)
|
||||||
{
|
{
|
||||||
if(dir != null && dir.IsDirectory)
|
if(dir != null && dir.IsDirectory)
|
||||||
|
|
|
@ -31,5 +31,7 @@ namespace Bit.App.Abstractions
|
||||||
bool AutofillAccessibilityServiceRunning();
|
bool AutofillAccessibilityServiceRunning();
|
||||||
bool AutofillServiceEnabled();
|
bool AutofillServiceEnabled();
|
||||||
string GetBuildNumber();
|
string GetBuildNumber();
|
||||||
|
void OpenAccessibilitySettings();
|
||||||
|
void OpenAutofillSettings();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,9 @@
|
||||||
<Compile Update="Pages\Settings\OptionsPage.xaml.cs">
|
<Compile Update="Pages\Settings\OptionsPage.xaml.cs">
|
||||||
<DependentUpon>OptionsPage.xaml</DependentUpon>
|
<DependentUpon>OptionsPage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Update="Pages\Settings\AccessibilityServicePage.xaml.cs">
|
||||||
|
<DependentUpon>AccessibilityServicePage.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Update="Pages\Settings\SyncPage.xaml.cs">
|
<Compile Update="Pages\Settings\SyncPage.xaml.cs">
|
||||||
<DependentUpon>SyncPage.xaml</DependentUpon>
|
<DependentUpon>SyncPage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|
85
src/App/Pages/Settings/AccessibilityServicePage.xaml
Normal file
85
src/App/Pages/Settings/AccessibilityServicePage.xaml
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<pages:BaseContentPage
|
||||||
|
xmlns="http://xamarin.com/schemas/2014/forms"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||||
|
x:Class="Bit.App.Pages.AccessibilityServicePage"
|
||||||
|
xmlns:pages="clr-namespace:Bit.App.Pages"
|
||||||
|
xmlns:u="clr-namespace:Bit.App.Utilities"
|
||||||
|
x:DataType="pages:AccessibilityServicePageViewModel"
|
||||||
|
Title="{Binding PageTitle}">
|
||||||
|
<ContentPage.BindingContext>
|
||||||
|
<pages:AccessibilityServicePageViewModel />
|
||||||
|
</ContentPage.BindingContext>
|
||||||
|
|
||||||
|
<ContentPage.Resources>
|
||||||
|
<ResourceDictionary>
|
||||||
|
<u:InverseBoolConverter x:Key="inverseBool" />
|
||||||
|
</ResourceDictionary>
|
||||||
|
</ContentPage.Resources>
|
||||||
|
|
||||||
|
<ScrollView>
|
||||||
|
<StackLayout Spacing="20"
|
||||||
|
Padding="10, 30"
|
||||||
|
VerticalOptions="FillAndExpand">
|
||||||
|
<Label Text="{u:I18n AutofillAccessibilityDescription}"
|
||||||
|
VerticalOptions="Start"
|
||||||
|
HorizontalTextAlignment="Center"
|
||||||
|
LineBreakMode="WordWrap" />
|
||||||
|
<StackLayout IsVisible="{Binding Enabled, Converter={StaticResource inverseBool}}"
|
||||||
|
VerticalOptions="CenterAndExpand"
|
||||||
|
HorizontalOptions="Center">
|
||||||
|
<StackLayout Orientation="Horizontal" HorizontalOptions="CenterAndExpand">
|
||||||
|
<Label Text="{u:I18n Status}" />
|
||||||
|
<Label Text="{u:I18n Disabled}"
|
||||||
|
StyleClass="text-danger, text-bold" />
|
||||||
|
</StackLayout>
|
||||||
|
<Image Source="accessibility_step1.png"
|
||||||
|
HorizontalOptions="Center"
|
||||||
|
Margin="0, 20, 0, 0"
|
||||||
|
WidthRequest="300"
|
||||||
|
HeightRequest="98" />
|
||||||
|
<Label Text="{u:I18n BitwardenAutofillServiceStep1}"
|
||||||
|
HorizontalTextAlignment="Center"
|
||||||
|
LineBreakMode="WordWrap"
|
||||||
|
StyleClass="text-sm" />
|
||||||
|
<Image Source="accessibility_step2.png"
|
||||||
|
HorizontalOptions="Center"
|
||||||
|
Margin="0, 20, 0, 0"
|
||||||
|
WidthRequest="300"
|
||||||
|
HeightRequest="67" />
|
||||||
|
<Label Text="{u:I18n BitwardenAutofillServiceStep2}"
|
||||||
|
HorizontalTextAlignment="Center"
|
||||||
|
LineBreakMode="WordWrap"
|
||||||
|
StyleClass="text-sm" />
|
||||||
|
</StackLayout>
|
||||||
|
<StackLayout IsVisible="{Binding Enabled}"
|
||||||
|
VerticalOptions="CenterAndExpand"
|
||||||
|
HorizontalOptions="Center">
|
||||||
|
<StackLayout Orientation="Horizontal" HorizontalOptions="Center">
|
||||||
|
<Label Text="{u:I18n Status}" />
|
||||||
|
<Label Text="{u:I18n Enabled}"
|
||||||
|
StyleClass="text-success, text-bold" />
|
||||||
|
</StackLayout>
|
||||||
|
<Image Source="accessibility_notification_icon.png"
|
||||||
|
HorizontalOptions="Center"
|
||||||
|
Margin="0, 20, 0, 0"
|
||||||
|
WidthRequest="300"
|
||||||
|
HeightRequest="54" />
|
||||||
|
<Image Source="accessibility_notification.png"
|
||||||
|
HorizontalOptions="Center"
|
||||||
|
Margin="0, 20, 0, 0"
|
||||||
|
WidthRequest="300"
|
||||||
|
HeightRequest="74" />
|
||||||
|
<Label Text="{u:I18n BitwardenAutofillServiceNotification}"
|
||||||
|
HorizontalTextAlignment="Center"
|
||||||
|
LineBreakMode="WordWrap"
|
||||||
|
StyleClass="text-sm" />
|
||||||
|
</StackLayout>
|
||||||
|
<Button Text="{u:I18n BitwardenAutofillServiceOpenAccessibilitySettings}"
|
||||||
|
Clicked="Settings_Clicked"
|
||||||
|
HorizontalOptions="Fill"
|
||||||
|
VerticalOptions="End"></Button>
|
||||||
|
</StackLayout>
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
</pages:BaseContentPage>
|
52
src/App/Pages/Settings/AccessibilityServicePage.xaml.cs
Normal file
52
src/App/Pages/Settings/AccessibilityServicePage.xaml.cs
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
using System;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
|
||||||
|
namespace Bit.App.Pages
|
||||||
|
{
|
||||||
|
public partial class AccessibilityServicePage : BaseContentPage
|
||||||
|
{
|
||||||
|
private readonly AccessibilityServicePageViewModel _vm;
|
||||||
|
private readonly SettingsPage _settingsPage;
|
||||||
|
private DateTime? _timerStarted = null;
|
||||||
|
private TimeSpan _timerMaxLength = TimeSpan.FromMinutes(5);
|
||||||
|
|
||||||
|
public AccessibilityServicePage(SettingsPage settingsPage)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_vm = BindingContext as AccessibilityServicePageViewModel;
|
||||||
|
_vm.Page = this;
|
||||||
|
_settingsPage = settingsPage;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnAppearing()
|
||||||
|
{
|
||||||
|
_vm.UpdateEnabled();
|
||||||
|
_timerStarted = DateTime.UtcNow;
|
||||||
|
Device.StartTimer(new TimeSpan(0, 0, 3), () =>
|
||||||
|
{
|
||||||
|
if(_timerStarted == null || (DateTime.UtcNow - _timerStarted) > _timerMaxLength)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_vm.UpdateEnabled();
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
base.OnAppearing();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnDisappearing()
|
||||||
|
{
|
||||||
|
_timerStarted = null;
|
||||||
|
_settingsPage.BuildList();
|
||||||
|
base.OnDisappearing();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Settings_Clicked(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if(DoOnce())
|
||||||
|
{
|
||||||
|
_vm.OpenSettings();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
38
src/App/Pages/Settings/AccessibilityServicePageViewModel.cs
Normal file
38
src/App/Pages/Settings/AccessibilityServicePageViewModel.cs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
using Bit.App.Abstractions;
|
||||||
|
using Bit.App.Resources;
|
||||||
|
using Bit.Core.Abstractions;
|
||||||
|
using Bit.Core.Utilities;
|
||||||
|
|
||||||
|
namespace Bit.App.Pages
|
||||||
|
{
|
||||||
|
public class AccessibilityServicePageViewModel : BaseViewModel
|
||||||
|
{
|
||||||
|
private readonly IDeviceActionService _deviceActionService;
|
||||||
|
private readonly IPlatformUtilsService _platformUtilsService;
|
||||||
|
|
||||||
|
private bool _enabled;
|
||||||
|
|
||||||
|
public AccessibilityServicePageViewModel()
|
||||||
|
{
|
||||||
|
_deviceActionService = ServiceContainer.Resolve<IDeviceActionService>("deviceActionService");
|
||||||
|
_platformUtilsService = ServiceContainer.Resolve<IPlatformUtilsService>("platformUtilsService");
|
||||||
|
PageTitle = AppResources.AutofillAccessibilityService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Enabled
|
||||||
|
{
|
||||||
|
get => _enabled;
|
||||||
|
set => SetProperty(ref _enabled, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenSettings()
|
||||||
|
{
|
||||||
|
_deviceActionService.OpenAccessibilitySettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void UpdateEnabled()
|
||||||
|
{
|
||||||
|
Enabled = _deviceActionService.AutofillAccessibilityServiceRunning();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,11 @@ namespace Bit.App.Pages
|
||||||
await _vm.InitAsync();
|
await _vm.InitAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void BuildList()
|
||||||
|
{
|
||||||
|
_vm.BuildList();
|
||||||
|
}
|
||||||
|
|
||||||
protected override bool OnBackButtonPressed()
|
protected override bool OnBackButtonPressed()
|
||||||
{
|
{
|
||||||
if(Device.RuntimePlatform == Device.Android && _tabsPage != null)
|
if(Device.RuntimePlatform == Device.Android && _tabsPage != null)
|
||||||
|
@ -54,7 +59,7 @@ namespace Bit.App.Pages
|
||||||
}
|
}
|
||||||
else if(item.Name == AppResources.AutofillAccessibilityService)
|
else if(item.Name == AppResources.AutofillAccessibilityService)
|
||||||
{
|
{
|
||||||
// await Navigation.PushModalAsync(new NavigationPage(new OptionsPage()));
|
await Navigation.PushModalAsync(new NavigationPage(new AccessibilityServicePage(this)));
|
||||||
}
|
}
|
||||||
else if(item.Name == AppResources.AutofillService)
|
else if(item.Name == AppResources.AutofillService)
|
||||||
{
|
{
|
||||||
|
|
|
@ -270,7 +270,7 @@ namespace Bit.App.Pages
|
||||||
BuildList();
|
BuildList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BuildList()
|
public void BuildList()
|
||||||
{
|
{
|
||||||
var doUpper = Device.RuntimePlatform != Device.Android;
|
var doUpper = Device.RuntimePlatform != Device.Android;
|
||||||
var autofillItems = new List<SettingsPageListItem>();
|
var autofillItems = new List<SettingsPageListItem>();
|
||||||
|
|
Loading…
Reference in a new issue