1
0
mirror of https://github.com/bitwarden/mobile.git synced 2024-11-26 12:16:07 +01:00

OnComplete return type, autocorrect, and autocapitalize implemented for android.

This commit is contained in:
Kyle Spearrin 2016-05-23 22:50:32 -04:00
parent 7ce1eec96d
commit dd9463fca2
4 changed files with 76 additions and 5 deletions

View File

@ -3,8 +3,11 @@ using System.ComponentModel;
using Android.Graphics;
using Android.Text;
using Android.Text.Method;
using Android.Views.InputMethods;
using Android.Widget;
using Bit.Android.Controls;
using Bit.App.Controls;
using Bit.App.Enums;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
@ -27,6 +30,29 @@ namespace Bit.Android.Controls
SetBorder(view);
SetMaxLength(view);
SetReturnType(view);
// Editor Action is called when the return button is pressed
Control.EditorAction += (object sender, TextView.EditorActionEventArgs args) =>
{
if(view.ReturnType != ReturnType.Next)
{
view.Unfocus();
}
// Call all the methods attached to base_entry event handler Completed
view.InvokeCompleted();
};
if(view.DisableAutocapitalize)
{
Control.SetRawInputType(Control.InputType |= InputTypes.TextVariationEmailAddress);
}
if(view.Autocorrect.HasValue)
{
Control.SetRawInputType(Control.InputType |= InputTypes.TextFlagNoSuggestions);
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
@ -49,6 +75,35 @@ namespace Bit.Android.Controls
}
}
private void SetReturnType(ExtendedEntry view)
{
if(view.ReturnType.HasValue)
{
switch(view.ReturnType.Value)
{
case ReturnType.Go:
Control.ImeOptions = ImeAction.Go;
Control.SetImeActionLabel("Go", ImeAction.Go);
break;
case ReturnType.Next:
Control.ImeOptions = ImeAction.Next;
Control.SetImeActionLabel("Next", ImeAction.Next);
break;
case ReturnType.Search:
Control.ImeOptions = ImeAction.Search;
Control.SetImeActionLabel("Search", ImeAction.Search);
break;
case ReturnType.Send:
Control.ImeOptions = ImeAction.Send;
Control.SetImeActionLabel("Send", ImeAction.Send);
break;
default:
Control.SetImeActionLabel("Done", ImeAction.Done);
break;
}
}
}
private void SetBorder(ExtendedEntry view)
{
if(!view.HasBorder)

View File

@ -42,8 +42,17 @@ namespace Bit.App.Controls
set { SetValue(MaxLengthProperty, value); }
}
public ReturnType? ReturnType { get; set; }
public bool? Autocorrect { get; set; }
public bool DisableAutocapitalize { get; set; }
// Need to overwrite default handler because we cant Invoke otherwise
public new event EventHandler Completed;
public void InvokeCompleted()
{
Completed.Invoke(this, null);
}
}
}

View File

@ -2,10 +2,10 @@
{
public enum ReturnType
{
Return,
Done,
Go,
Next,
Search
Search,
Send
}
}

View File

@ -38,9 +38,6 @@ namespace Bit.iOS.Controls
{
switch(view.ReturnType.Value)
{
case App.Enums.ReturnType.Return:
Control.ReturnKeyType = UIReturnKeyType.Default;
break;
case App.Enums.ReturnType.Done:
Control.ReturnKeyType = UIReturnKeyType.Done;
break;
@ -53,10 +50,20 @@ namespace Bit.iOS.Controls
case App.Enums.ReturnType.Search:
Control.ReturnKeyType = UIReturnKeyType.Search;
break;
case App.Enums.ReturnType.Send:
Control.ReturnKeyType = UIReturnKeyType.Send;
break;
default:
Control.ReturnKeyType = UIReturnKeyType.Default;
break;
}
}
Control.ShouldReturn += (UITextField tf) =>
{
view.InvokeCompleted();
return true;
};
}
}