2020-01-10 23:35:41 +03:00
|
|
|
|
2019-02-22 22:51:45 +03:00
|
|
|
using System.ComponentModel;
|
|
|
|
using Android.Content;
|
|
|
|
using Android.Views;
|
|
|
|
using Android.Widget;
|
|
|
|
using Xamarin.Forms;
|
2019-02-28 02:48:45 +03:00
|
|
|
using Xamarin.Forms.Material.Android;
|
|
|
|
using Xamarin.Forms.Platform.Android;
|
2019-02-22 22:51:45 +03:00
|
|
|
using AButton = Android.Widget.Button;
|
2020-01-10 23:35:41 +03:00
|
|
|
#if __ANDROID_29__
|
|
|
|
using MButton = Google.Android.Material.Button.MaterialButton;
|
|
|
|
#else
|
2019-02-22 22:51:45 +03:00
|
|
|
using MButton = Android.Support.Design.Button.MaterialButton;
|
2020-01-10 23:35:41 +03:00
|
|
|
#endif
|
2019-02-22 22:51:45 +03:00
|
|
|
|
|
|
|
|
2019-02-28 02:48:45 +03:00
|
|
|
namespace Xamarin.Forms.Material.Android
|
2019-02-22 22:51:45 +03:00
|
|
|
{
|
|
|
|
public class MaterialStepperRenderer : ViewRenderer<Stepper, LinearLayout>, IStepperRenderer
|
|
|
|
{
|
|
|
|
const int DefaultButtonSpacing = 4;
|
|
|
|
|
|
|
|
MButton _downButton;
|
|
|
|
MButton _upButton;
|
2019-03-27 19:07:15 +03:00
|
|
|
bool _inputTransparent;
|
2019-02-22 22:51:45 +03:00
|
|
|
|
|
|
|
public MaterialStepperRenderer(Context context) : base(context)
|
|
|
|
{
|
|
|
|
AutoPackage = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override LinearLayout CreateNativeControl()
|
|
|
|
{
|
|
|
|
return new LinearLayout(Context)
|
|
|
|
{
|
|
|
|
Orientation = Orientation.Horizontal,
|
|
|
|
Focusable = true,
|
|
|
|
DescendantFocusability = DescendantFocusability.AfterDescendants
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnElementChanged(ElementChangedEventArgs<Stepper> e)
|
|
|
|
{
|
|
|
|
base.OnElementChanged(e);
|
|
|
|
|
|
|
|
if (e.OldElement == null)
|
|
|
|
{
|
|
|
|
if (Control == null)
|
|
|
|
{
|
|
|
|
var layout = CreateNativeControl();
|
|
|
|
StepperRendererManager.CreateStepperButtons(this, out _downButton, out _upButton);
|
|
|
|
layout.AddView(_downButton, new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.MatchParent)
|
|
|
|
{
|
|
|
|
Weight = 1,
|
|
|
|
RightMargin = (int)(Context.ToPixels(DefaultButtonSpacing) / 2),
|
|
|
|
});
|
|
|
|
layout.AddView(_upButton, new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.MatchParent)
|
|
|
|
{
|
|
|
|
Weight = 1,
|
|
|
|
LeftMargin = (int)(Context.ToPixels(DefaultButtonSpacing) / 2),
|
|
|
|
});
|
|
|
|
|
|
|
|
SetNativeControl(layout);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StepperRendererManager.UpdateButtons(this, _downButton, _upButton);
|
2019-03-27 19:07:15 +03:00
|
|
|
UpdateInputTransparent();
|
2019-02-22 22:51:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
|
|
{
|
|
|
|
base.OnElementPropertyChanged(sender, e);
|
|
|
|
|
|
|
|
StepperRendererManager.UpdateButtons(this, _downButton, _upButton, e);
|
2019-03-27 19:07:15 +03:00
|
|
|
|
|
|
|
if (e.PropertyName == VisualElement.InputTransparentProperty.PropertyName)
|
|
|
|
UpdateInputTransparent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void UpdateInputTransparent()
|
|
|
|
{
|
|
|
|
if (Element == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_inputTransparent = Element.InputTransparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool OnTouchEvent(MotionEvent e)
|
|
|
|
{
|
|
|
|
if (!Enabled || _inputTransparent)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return base.OnTouchEvent(e);
|
2019-02-22 22:51:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UpdateBackgroundColor()
|
|
|
|
{
|
|
|
|
// don't call base
|
|
|
|
}
|
|
|
|
|
|
|
|
// IStepperRenderer
|
|
|
|
|
|
|
|
Stepper IStepperRenderer.Element => Element;
|
|
|
|
|
|
|
|
AButton IStepperRenderer.UpButton => _upButton;
|
|
|
|
|
|
|
|
AButton IStepperRenderer.DownButton => _downButton;
|
|
|
|
|
|
|
|
AButton IStepperRenderer.CreateButton()
|
|
|
|
{
|
|
|
|
var button = new MButton(MaterialContextThemeWrapper.Create(Context), null, Resource.Attribute.materialOutlinedButtonStyle);
|
|
|
|
|
|
|
|
// the buttons are meant to be "square", but are usually wide,
|
|
|
|
// so, copy the vertical properties into the horizontal properties
|
|
|
|
button.SetMinimumWidth(button.MinimumHeight);
|
|
|
|
button.SetMinWidth(button.MinHeight);
|
|
|
|
button.SetPadding(button.PaddingTop, button.PaddingTop, button.PaddingBottom, button.PaddingBottom);
|
|
|
|
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|