2020-06-16 17:09:26 +02:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using Android.Content;
|
2021-10-08 14:47:40 +02:00
|
|
|
|
using Android.Content.Res;
|
2020-06-16 17:09:26 +02:00
|
|
|
|
using Android.Graphics;
|
|
|
|
|
using Android.Text;
|
2019-05-31 22:47:54 +02:00
|
|
|
|
using Android.Views.InputMethods;
|
2020-06-16 17:09:26 +02:00
|
|
|
|
using Android.Widget;
|
2019-05-13 21:25:20 +02:00
|
|
|
|
using Bit.Droid.Renderers;
|
2021-10-08 14:47:40 +02:00
|
|
|
|
using Bit.Droid.Utilities;
|
2019-05-08 05:22:25 +02:00
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
using Xamarin.Forms.Platform.Android;
|
|
|
|
|
|
2019-05-08 21:00:45 +02:00
|
|
|
|
[assembly: ExportRenderer(typeof(Entry), typeof(CustomEntryRenderer))]
|
2019-05-13 21:25:20 +02:00
|
|
|
|
namespace Bit.Droid.Renderers
|
2019-05-08 05:22:25 +02:00
|
|
|
|
{
|
2019-05-08 21:00:45 +02:00
|
|
|
|
public class CustomEntryRenderer : EntryRenderer
|
2019-05-08 05:22:25 +02:00
|
|
|
|
{
|
2019-05-08 21:00:45 +02:00
|
|
|
|
public CustomEntryRenderer(Context context)
|
2019-05-08 05:22:25 +02:00
|
|
|
|
: base(context)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
|
|
|
|
|
{
|
|
|
|
|
base.OnElementChanged(e);
|
2021-10-08 14:47:40 +02:00
|
|
|
|
UpdateBorderColor();
|
2020-03-28 14:16:28 +01:00
|
|
|
|
if (Control != null && e.NewElement != null)
|
2019-05-08 05:22:25 +02:00
|
|
|
|
{
|
|
|
|
|
Control.SetPadding(Control.PaddingLeft, Control.PaddingTop - 10, Control.PaddingRight,
|
|
|
|
|
Control.PaddingBottom + 20);
|
2019-06-03 23:23:50 +02:00
|
|
|
|
Control.ImeOptions = Control.ImeOptions | (ImeAction)ImeFlags.NoPersonalizedLearning |
|
|
|
|
|
(ImeAction)ImeFlags.NoExtractUi;
|
2019-05-08 05:22:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-06-16 17:09:26 +02:00
|
|
|
|
|
|
|
|
|
// Workaround for failure to disable text prediction on non-password fields
|
|
|
|
|
// see https://github.com/xamarin/Xamarin.Forms/issues/10857
|
|
|
|
|
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnElementPropertyChanged(sender, e);
|
|
|
|
|
|
|
|
|
|
// Check if changed property is "IsPassword", otherwise ignore
|
|
|
|
|
if (e.PropertyName == Entry.IsPasswordProperty.PropertyName)
|
|
|
|
|
{
|
|
|
|
|
// Check if field type is text, otherwise ignore (numeric passwords, etc.)
|
|
|
|
|
EditText.InputType = Element.Keyboard.ToInputType();
|
2020-07-30 19:46:06 +02:00
|
|
|
|
bool isText = (EditText.InputType & InputTypes.ClassText) == InputTypes.ClassText,
|
|
|
|
|
isNumber = (EditText.InputType & InputTypes.ClassNumber) == InputTypes.ClassNumber;
|
|
|
|
|
if (isText || isNumber)
|
2020-06-16 17:09:26 +02:00
|
|
|
|
{
|
|
|
|
|
if (Element.IsPassword)
|
|
|
|
|
{
|
|
|
|
|
// Element is a password field, set inputType to TextVariationPassword which disables
|
|
|
|
|
// predictive text by default
|
2020-07-30 19:46:06 +02:00
|
|
|
|
EditText.InputType = EditText.InputType |
|
|
|
|
|
(isText ? InputTypes.TextVariationPassword : InputTypes.NumberVariationPassword);
|
2020-06-16 17:09:26 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Element is not a password field, set inputType to TextVariationVisiblePassword to
|
|
|
|
|
// disable predictive text while still displaying the content.
|
2020-07-30 19:46:06 +02:00
|
|
|
|
EditText.InputType = EditText.InputType |
|
|
|
|
|
(isText ? InputTypes.TextVariationVisiblePassword : InputTypes.NumberVariationNormal);
|
2020-06-16 17:09:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// The workaround above forces a reset of the style properties, so we need to re-apply the font.
|
|
|
|
|
// see https://xamarin.github.io/bugzilla-archives/33/33666/bug.html
|
|
|
|
|
var typeface = Typeface.CreateFromAsset(Context.Assets, "RobotoMono_Regular.ttf");
|
|
|
|
|
if (Control is TextView label)
|
|
|
|
|
{
|
|
|
|
|
label.Typeface = typeface;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-08 14:47:40 +02:00
|
|
|
|
else if (e.PropertyName == Entry.TextColorProperty.PropertyName)
|
|
|
|
|
{
|
|
|
|
|
UpdateBorderColor();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateBorderColor()
|
|
|
|
|
{
|
|
|
|
|
if (Control != null)
|
|
|
|
|
{
|
|
|
|
|
var states = new[]
|
|
|
|
|
{
|
|
|
|
|
new[] { Android.Resource.Attribute.StateFocused }, // focused
|
|
|
|
|
new[] { -Android.Resource.Attribute.StateFocused }, // unfocused
|
|
|
|
|
};
|
|
|
|
|
var colors = new int[]
|
|
|
|
|
{
|
|
|
|
|
ThemeHelpers.PrimaryColor,
|
|
|
|
|
ThemeHelpers.MutedColor
|
|
|
|
|
};
|
|
|
|
|
Control.BackgroundTintList = new ColorStateList(states, colors);
|
|
|
|
|
}
|
2020-06-16 17:09:26 +02:00
|
|
|
|
}
|
2019-05-08 05:22:25 +02:00
|
|
|
|
}
|
|
|
|
|
}
|