maui-linux/System.Maui.Material.Android/MaterialEntryRenderer.cs

72 строки
2.2 KiB
C#
Исходник Обычный вид История

2020-05-19 03:56:25 +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;
using AView = Android.Views.View;
2020-05-19 03:56:25 +03:00
namespace System.Maui.Material.Android
{
public class MaterialEntryRenderer : EntryRendererBase<MaterialFormsTextInputLayout>, ITabStop
{
MaterialFormsEditText _textInputEditText;
MaterialFormsTextInputLayout _textInputLayout;
Material Design Renderers for the Material Visual (#4733) * Use the auto-generated constants * [Visual] Work on the Material Frame * Improving the code for the sample * Added a controller to help with frames that have additional padding - Android MaterialCardView does not use the default padding to determine where the content starts, rather it uses the content padding of the view because there is a border that does not affect the content * [Visual] Added a few extra checks on Android to reduce unnecessary interop * [Visual] A few more frame changes and some button tweaks * [Visual] use the themers on iOS and save default properties * [Visual] Add placeholders for themer and cache defaults * [Visual] Added the material slider for iOS - Android does not have a custom control, so uses the existing renderer * [enhancements] Move from duplicate LoadImageAsync code to GetNativeImageAsync * [visual] Updated the controls to use the new iOS bits * [visual] some fixes for material components * [visual] Added hacks for material alerts * [visual] removing the alert changes for the main branch * [visual] Update the MaterialComponents NuGet * [visual] Rework the theming/customization of Material controls on iOS * [visual] fix the places where the user colors were being changed * [visual] Improve the ColorStateList management for Android * [visual] Re-implemented the Android ProgressBar as a fast, material renderer * Material Entry * [visual] Add Android ActivityIndicator * filter out material layouts for 8.1 * remove folder * fix __ANDROID_28__ * MaterialContextThemeWrapper * [visual] remove the `IFrameController` interface * [visual] reverting the changes to the Frame layout * [visual] reverting whitespace * [visual] make sure to raise both property changed * formatting changes * fixing colors on android to match with ios themes * Update Xamarin.Forms.Platform.Android/Material/MaterialButtonRenderer.cs Co-Authored-By: mattleibow <mattleibow@live.com> * fix sizing of entry with infinite width size request * update to release 28 of support * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * PR Comment changes
2019-01-08 03:07:50 +03:00
public MaterialEntryRenderer(Context context) :
base(MaterialContextThemeWrapper.Create(context))
{
}
protected override AView ControlUsedForAutomation => EditText;
Material Design Renderers for the Material Visual (#4733) * Use the auto-generated constants * [Visual] Work on the Material Frame * Improving the code for the sample * Added a controller to help with frames that have additional padding - Android MaterialCardView does not use the default padding to determine where the content starts, rather it uses the content padding of the view because there is a border that does not affect the content * [Visual] Added a few extra checks on Android to reduce unnecessary interop * [Visual] A few more frame changes and some button tweaks * [Visual] use the themers on iOS and save default properties * [Visual] Add placeholders for themer and cache defaults * [Visual] Added the material slider for iOS - Android does not have a custom control, so uses the existing renderer * [enhancements] Move from duplicate LoadImageAsync code to GetNativeImageAsync * [visual] Updated the controls to use the new iOS bits * [visual] some fixes for material components * [visual] Added hacks for material alerts * [visual] removing the alert changes for the main branch * [visual] Update the MaterialComponents NuGet * [visual] Rework the theming/customization of Material controls on iOS * [visual] fix the places where the user colors were being changed * [visual] Improve the ColorStateList management for Android * [visual] Re-implemented the Android ProgressBar as a fast, material renderer * Material Entry * [visual] Add Android ActivityIndicator * filter out material layouts for 8.1 * remove folder * fix __ANDROID_28__ * MaterialContextThemeWrapper * [visual] remove the `IFrameController` interface * [visual] reverting the changes to the Frame layout * [visual] reverting whitespace * [visual] make sure to raise both property changed * formatting changes * fixing colors on android to match with ios themes * Update Xamarin.Forms.Platform.Android/Material/MaterialButtonRenderer.cs Co-Authored-By: mattleibow <mattleibow@live.com> * fix sizing of entry with infinite width size request * update to release 28 of support * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * PR Comment changes
2019-01-08 03:07:50 +03:00
protected override MaterialFormsTextInputLayout CreateNativeControl()
{
Material Design Renderers for the Material Visual (#4733) * Use the auto-generated constants * [Visual] Work on the Material Frame * Improving the code for the sample * Added a controller to help with frames that have additional padding - Android MaterialCardView does not use the default padding to determine where the content starts, rather it uses the content padding of the view because there is a border that does not affect the content * [Visual] Added a few extra checks on Android to reduce unnecessary interop * [Visual] A few more frame changes and some button tweaks * [Visual] use the themers on iOS and save default properties * [Visual] Add placeholders for themer and cache defaults * [Visual] Added the material slider for iOS - Android does not have a custom control, so uses the existing renderer * [enhancements] Move from duplicate LoadImageAsync code to GetNativeImageAsync * [visual] Updated the controls to use the new iOS bits * [visual] some fixes for material components * [visual] Added hacks for material alerts * [visual] removing the alert changes for the main branch * [visual] Update the MaterialComponents NuGet * [visual] Rework the theming/customization of Material controls on iOS * [visual] fix the places where the user colors were being changed * [visual] Improve the ColorStateList management for Android * [visual] Re-implemented the Android ProgressBar as a fast, material renderer * Material Entry * [visual] Add Android ActivityIndicator * filter out material layouts for 8.1 * remove folder * fix __ANDROID_28__ * MaterialContextThemeWrapper * [visual] remove the `IFrameController` interface * [visual] reverting the changes to the Frame layout * [visual] reverting whitespace * [visual] make sure to raise both property changed * formatting changes * fixing colors on android to match with ios themes * Update Xamarin.Forms.Platform.Android/Material/MaterialButtonRenderer.cs Co-Authored-By: mattleibow <mattleibow@live.com> * fix sizing of entry with infinite width size request * update to release 28 of support * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * PR Comment changes
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);
Material Design Renderers for the Material Visual (#4733) * Use the auto-generated constants * [Visual] Work on the Material Frame * Improving the code for the sample * Added a controller to help with frames that have additional padding - Android MaterialCardView does not use the default padding to determine where the content starts, rather it uses the content padding of the view because there is a border that does not affect the content * [Visual] Added a few extra checks on Android to reduce unnecessary interop * [Visual] A few more frame changes and some button tweaks * [Visual] use the themers on iOS and save default properties * [Visual] Add placeholders for themer and cache defaults * [Visual] Added the material slider for iOS - Android does not have a custom control, so uses the existing renderer * [enhancements] Move from duplicate LoadImageAsync code to GetNativeImageAsync * [visual] Updated the controls to use the new iOS bits * [visual] some fixes for material components * [visual] Added hacks for material alerts * [visual] removing the alert changes for the main branch * [visual] Update the MaterialComponents NuGet * [visual] Rework the theming/customization of Material controls on iOS * [visual] fix the places where the user colors were being changed * [visual] Improve the ColorStateList management for Android * [visual] Re-implemented the Android ProgressBar as a fast, material renderer * Material Entry * [visual] Add Android ActivityIndicator * filter out material layouts for 8.1 * remove folder * fix __ANDROID_28__ * MaterialContextThemeWrapper * [visual] remove the `IFrameController` interface * [visual] reverting the changes to the Frame layout * [visual] reverting whitespace * [visual] make sure to raise both property changed * formatting changes * fixing colors on android to match with ios themes * Update Xamarin.Forms.Platform.Android/Material/MaterialButtonRenderer.cs Co-Authored-By: mattleibow <mattleibow@live.com> * fix sizing of entry with infinite width size request * update to release 28 of support * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * PR Comment changes
2019-01-08 03:07:50 +03:00
return _textInputLayout;
}
Material Design Renderers for the Material Visual (#4733) * Use the auto-generated constants * [Visual] Work on the Material Frame * Improving the code for the sample * Added a controller to help with frames that have additional padding - Android MaterialCardView does not use the default padding to determine where the content starts, rather it uses the content padding of the view because there is a border that does not affect the content * [Visual] Added a few extra checks on Android to reduce unnecessary interop * [Visual] A few more frame changes and some button tweaks * [Visual] use the themers on iOS and save default properties * [Visual] Add placeholders for themer and cache defaults * [Visual] Added the material slider for iOS - Android does not have a custom control, so uses the existing renderer * [enhancements] Move from duplicate LoadImageAsync code to GetNativeImageAsync * [visual] Updated the controls to use the new iOS bits * [visual] some fixes for material components * [visual] Added hacks for material alerts * [visual] removing the alert changes for the main branch * [visual] Update the MaterialComponents NuGet * [visual] Rework the theming/customization of Material controls on iOS * [visual] fix the places where the user colors were being changed * [visual] Improve the ColorStateList management for Android * [visual] Re-implemented the Android ProgressBar as a fast, material renderer * Material Entry * [visual] Add Android ActivityIndicator * filter out material layouts for 8.1 * remove folder * fix __ANDROID_28__ * MaterialContextThemeWrapper * [visual] remove the `IFrameController` interface * [visual] reverting the changes to the Frame layout * [visual] reverting whitespace * [visual] make sure to raise both property changed * formatting changes * fixing colors on android to match with ios themes * Update Xamarin.Forms.Platform.Android/Material/MaterialButtonRenderer.cs Co-Authored-By: mattleibow <mattleibow@live.com> * fix sizing of entry with infinite width size request * update to release 28 of support * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * PR Comment changes
2019-01-08 03:07:50 +03:00
protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
{
Material Design Renderers for the Material Visual (#4733) * Use the auto-generated constants * [Visual] Work on the Material Frame * Improving the code for the sample * Added a controller to help with frames that have additional padding - Android MaterialCardView does not use the default padding to determine where the content starts, rather it uses the content padding of the view because there is a border that does not affect the content * [Visual] Added a few extra checks on Android to reduce unnecessary interop * [Visual] A few more frame changes and some button tweaks * [Visual] use the themers on iOS and save default properties * [Visual] Add placeholders for themer and cache defaults * [Visual] Added the material slider for iOS - Android does not have a custom control, so uses the existing renderer * [enhancements] Move from duplicate LoadImageAsync code to GetNativeImageAsync * [visual] Updated the controls to use the new iOS bits * [visual] some fixes for material components * [visual] Added hacks for material alerts * [visual] removing the alert changes for the main branch * [visual] Update the MaterialComponents NuGet * [visual] Rework the theming/customization of Material controls on iOS * [visual] fix the places where the user colors were being changed * [visual] Improve the ColorStateList management for Android * [visual] Re-implemented the Android ProgressBar as a fast, material renderer * Material Entry * [visual] Add Android ActivityIndicator * filter out material layouts for 8.1 * remove folder * fix __ANDROID_28__ * MaterialContextThemeWrapper * [visual] remove the `IFrameController` interface * [visual] reverting the changes to the Frame layout * [visual] reverting whitespace * [visual] make sure to raise both property changed * formatting changes * fixing colors on android to match with ios themes * Update Xamarin.Forms.Platform.Android/Material/MaterialButtonRenderer.cs Co-Authored-By: mattleibow <mattleibow@live.com> * fix sizing of entry with infinite width size request * update to release 28 of support * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * PR Comment changes
2019-01-08 03:07:50 +03:00
base.OnElementChanged(e);
UpdateBackgroundColor();
}
protected override void UpdateColor() => ApplyTheme();
Material Design Renderers for the Material Visual (#4733) * Use the auto-generated constants * [Visual] Work on the Material Frame * Improving the code for the sample * Added a controller to help with frames that have additional padding - Android MaterialCardView does not use the default padding to determine where the content starts, rather it uses the content padding of the view because there is a border that does not affect the content * [Visual] Added a few extra checks on Android to reduce unnecessary interop * [Visual] A few more frame changes and some button tweaks * [Visual] use the themers on iOS and save default properties * [Visual] Add placeholders for themer and cache defaults * [Visual] Added the material slider for iOS - Android does not have a custom control, so uses the existing renderer * [enhancements] Move from duplicate LoadImageAsync code to GetNativeImageAsync * [visual] Updated the controls to use the new iOS bits * [visual] some fixes for material components * [visual] Added hacks for material alerts * [visual] removing the alert changes for the main branch * [visual] Update the MaterialComponents NuGet * [visual] Rework the theming/customization of Material controls on iOS * [visual] fix the places where the user colors were being changed * [visual] Improve the ColorStateList management for Android * [visual] Re-implemented the Android ProgressBar as a fast, material renderer * Material Entry * [visual] Add Android ActivityIndicator * filter out material layouts for 8.1 * remove folder * fix __ANDROID_28__ * MaterialContextThemeWrapper * [visual] remove the `IFrameController` interface * [visual] reverting the changes to the Frame layout * [visual] reverting whitespace * [visual] make sure to raise both property changed * formatting changes * fixing colors on android to match with ios themes * Update Xamarin.Forms.Platform.Android/Material/MaterialButtonRenderer.cs Co-Authored-By: mattleibow <mattleibow@live.com> * fix sizing of entry with infinite width size request * update to release 28 of support * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * PR Comment changes
2019-01-08 03:07:50 +03:00
protected override void UpdateBackgroundColor()
{
Material Design Renderers for the Material Visual (#4733) * Use the auto-generated constants * [Visual] Work on the Material Frame * Improving the code for the sample * Added a controller to help with frames that have additional padding - Android MaterialCardView does not use the default padding to determine where the content starts, rather it uses the content padding of the view because there is a border that does not affect the content * [Visual] Added a few extra checks on Android to reduce unnecessary interop * [Visual] A few more frame changes and some button tweaks * [Visual] use the themers on iOS and save default properties * [Visual] Add placeholders for themer and cache defaults * [Visual] Added the material slider for iOS - Android does not have a custom control, so uses the existing renderer * [enhancements] Move from duplicate LoadImageAsync code to GetNativeImageAsync * [visual] Updated the controls to use the new iOS bits * [visual] some fixes for material components * [visual] Added hacks for material alerts * [visual] removing the alert changes for the main branch * [visual] Update the MaterialComponents NuGet * [visual] Rework the theming/customization of Material controls on iOS * [visual] fix the places where the user colors were being changed * [visual] Improve the ColorStateList management for Android * [visual] Re-implemented the Android ProgressBar as a fast, material renderer * Material Entry * [visual] Add Android ActivityIndicator * filter out material layouts for 8.1 * remove folder * fix __ANDROID_28__ * MaterialContextThemeWrapper * [visual] remove the `IFrameController` interface * [visual] reverting the changes to the Frame layout * [visual] reverting whitespace * [visual] make sure to raise both property changed * formatting changes * fixing colors on android to match with ios themes * Update Xamarin.Forms.Platform.Android/Material/MaterialButtonRenderer.cs Co-Authored-By: mattleibow <mattleibow@live.com> * fix sizing of entry with infinite width size request * update to release 28 of support * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * PR Comment changes
2019-01-08 03:07:50 +03:00
if (_textInputLayout == null)
return;
_textInputLayout.BoxBackgroundColor = MaterialColors.CreateEntryFilledInputBackgroundColor(Element.BackgroundColor, Element.TextColor);
}
protected override void UpdatePlaceHolderText() => _textInputLayout.SetHint(Element.Placeholder, Element);
protected override EditText EditText => _textInputEditText;
protected override void UpdatePlaceholderColor() => ApplyTheme();
void ApplyTheme(Color textColor) => _textInputLayout?.ApplyTheme(textColor, Element.PlaceholderColor);
void ApplyTheme() => ApplyTheme(Element.TextColor);
protected override void UpdateTextColor(Color color)
{
ApplyTheme(color);
}
protected override void UpdateFont()
{
Material Design Renderers for the Material Visual (#4733) * Use the auto-generated constants * [Visual] Work on the Material Frame * Improving the code for the sample * Added a controller to help with frames that have additional padding - Android MaterialCardView does not use the default padding to determine where the content starts, rather it uses the content padding of the view because there is a border that does not affect the content * [Visual] Added a few extra checks on Android to reduce unnecessary interop * [Visual] A few more frame changes and some button tweaks * [Visual] use the themers on iOS and save default properties * [Visual] Add placeholders for themer and cache defaults * [Visual] Added the material slider for iOS - Android does not have a custom control, so uses the existing renderer * [enhancements] Move from duplicate LoadImageAsync code to GetNativeImageAsync * [visual] Updated the controls to use the new iOS bits * [visual] some fixes for material components * [visual] Added hacks for material alerts * [visual] removing the alert changes for the main branch * [visual] Update the MaterialComponents NuGet * [visual] Rework the theming/customization of Material controls on iOS * [visual] fix the places where the user colors were being changed * [visual] Improve the ColorStateList management for Android * [visual] Re-implemented the Android ProgressBar as a fast, material renderer * Material Entry * [visual] Add Android ActivityIndicator * filter out material layouts for 8.1 * remove folder * fix __ANDROID_28__ * MaterialContextThemeWrapper * [visual] remove the `IFrameController` interface * [visual] reverting the changes to the Frame layout * [visual] reverting whitespace * [visual] make sure to raise both property changed * formatting changes * fixing colors on android to match with ios themes * Update Xamarin.Forms.Platform.Android/Material/MaterialButtonRenderer.cs Co-Authored-By: mattleibow <mattleibow@live.com> * fix sizing of entry with infinite width size request * update to release 28 of support * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * Update Xamarin.Forms.Platform.Android/Resources/values/styles.xml Co-Authored-By: PureWeen <shane94@hotmail.com> * PR Comment changes
2019-01-08 03:07:50 +03:00
base.UpdateFont();
_textInputLayout.Typeface = Element.ToTypeface();
_textInputEditText.SetTextSize(ComplexUnitType.Sp, (float)Element.FontSize);
}
AView ITabStop.TabStop => EditText;
}
}