2020-05-19 03:56:25 +03:00
|
|
|
|
2018-11-23 20:40:15 +03:00
|
|
|
using Android.Content;
|
|
|
|
using Android.Util;
|
|
|
|
using Android.Views;
|
|
|
|
using Android.Widget;
|
2020-05-19 03:56:25 +03:00
|
|
|
using System.Maui;
|
|
|
|
using System.Maui.Material.Android;
|
|
|
|
using System.Maui.Platform.Android;
|
2019-03-27 19:07:15 +03:00
|
|
|
using AView = Android.Views.View;
|
2018-11-23 20:40:15 +03:00
|
|
|
|
2020-05-19 03:56:25 +03:00
|
|
|
namespace System.Maui.Material.Android
|
2018-11-23 20:40:15 +03:00
|
|
|
{
|
2019-07-09 02:17:05 +03:00
|
|
|
public class MaterialEntryRenderer : EntryRendererBase<MaterialFormsTextInputLayout>, ITabStop
|
2018-11-23 20:40:15 +03:00
|
|
|
{
|
2019-02-25 06:21:39 +03:00
|
|
|
MaterialFormsEditText _textInputEditText;
|
|
|
|
MaterialFormsTextInputLayout _textInputLayout;
|
2018-11-23 20:40:15 +03:00
|
|
|
|
2019-01-08 03:07:50 +03:00
|
|
|
public MaterialEntryRenderer(Context context) :
|
|
|
|
base(MaterialContextThemeWrapper.Create(context))
|
2018-11-23 20:40:15 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-03-27 19:07:15 +03:00
|
|
|
protected override AView ControlUsedForAutomation => EditText;
|
|
|
|
|
2019-01-08 03:07:50 +03:00
|
|
|
protected override MaterialFormsTextInputLayout CreateNativeControl()
|
2018-11-23 20:40:15 +03:00
|
|
|
{
|
2019-01-08 03:07:50 +03:00
|
|
|
LayoutInflater inflater = LayoutInflater.FromContext(Context);
|
|
|
|
var view = inflater.Inflate(Resource.Layout.TextInputLayoutFilledBox, null);
|
|
|
|
_textInputLayout = (MaterialFormsTextInputLayout)view;
|
|
|
|
_textInputEditText = _textInputLayout.FindViewById<MaterialFormsEditText>(Resource.Id.materialformsedittext);
|
2018-11-23 20:40:15 +03:00
|
|
|
|
2019-01-08 03:07:50 +03:00
|
|
|
return _textInputLayout;
|
2018-11-23 20:40:15 +03:00
|
|
|
}
|
|
|
|
|
2019-01-08 03:07:50 +03:00
|
|
|
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
|
2018-11-23 20:40:15 +03:00
|
|
|
{
|
2019-01-08 03:07:50 +03:00
|
|
|
base.OnElementChanged(e);
|
2018-11-23 20:40:15 +03:00
|
|
|
UpdateBackgroundColor();
|
|
|
|
}
|
|
|
|
|
2019-03-02 06:15:08 +03:00
|
|
|
protected override void UpdateColor() => ApplyTheme();
|
2018-11-23 20:40:15 +03:00
|
|
|
|
2019-01-08 03:07:50 +03:00
|
|
|
protected override void UpdateBackgroundColor()
|
2018-11-23 20:40:15 +03:00
|
|
|
{
|
2019-01-08 03:07:50 +03:00
|
|
|
if (_textInputLayout == null)
|
2018-11-23 20:40:15 +03:00
|
|
|
return;
|
|
|
|
|
2019-01-31 00:44:34 +03:00
|
|
|
_textInputLayout.BoxBackgroundColor = MaterialColors.CreateEntryFilledInputBackgroundColor(Element.BackgroundColor, Element.TextColor);
|
2018-11-23 20:40:15 +03:00
|
|
|
}
|
|
|
|
|
2019-03-02 06:15:08 +03:00
|
|
|
protected override void UpdatePlaceHolderText() => _textInputLayout.SetHint(Element.Placeholder, Element);
|
2019-02-28 02:48:45 +03:00
|
|
|
protected override EditText EditText => _textInputEditText;
|
2019-02-25 06:21:39 +03:00
|
|
|
protected override void UpdatePlaceholderColor() => ApplyTheme();
|
2019-03-02 06:15:08 +03:00
|
|
|
void ApplyTheme(Color textColor) => _textInputLayout?.ApplyTheme(textColor, Element.PlaceholderColor);
|
|
|
|
void ApplyTheme() => ApplyTheme(Element.TextColor);
|
2018-11-23 20:40:15 +03:00
|
|
|
|
2019-03-02 06:15:08 +03:00
|
|
|
protected override void UpdateTextColor(Color color)
|
|
|
|
{
|
|
|
|
ApplyTheme(color);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UpdateFont()
|
2018-11-23 20:40:15 +03:00
|
|
|
{
|
2019-01-08 03:07:50 +03:00
|
|
|
base.UpdateFont();
|
|
|
|
_textInputLayout.Typeface = Element.ToTypeface();
|
|
|
|
_textInputEditText.SetTextSize(ComplexUnitType.Sp, (float)Element.FontSize);
|
2018-11-23 20:40:15 +03:00
|
|
|
}
|
2019-03-02 06:15:08 +03:00
|
|
|
|
2019-07-09 02:17:05 +03:00
|
|
|
AView ITabStop.TabStop => EditText;
|
2018-11-23 20:40:15 +03:00
|
|
|
}
|
|
|
|
}
|