summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/AppCompat/ButtonRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.Android/AppCompat/ButtonRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.Android/AppCompat/ButtonRenderer.cs38
1 files changed, 33 insertions, 5 deletions
diff --git a/Xamarin.Forms.Platform.Android/AppCompat/ButtonRenderer.cs b/Xamarin.Forms.Platform.Android/AppCompat/ButtonRenderer.cs
index 4c33df85..aef56e11 100644
--- a/Xamarin.Forms.Platform.Android/AppCompat/ButtonRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/AppCompat/ButtonRenderer.cs
@@ -9,11 +9,14 @@ using Android.Support.V7.Widget;
using Android.Util;
using GlobalResource = Android.Resource;
using Object = Java.Lang.Object;
+using AView = Android.Views.View;
+using AMotionEvent = Android.Views.MotionEvent;
+using AMotionEventActions = Android.Views.MotionEventActions;
using static System.String;
namespace Xamarin.Forms.Platform.Android.AppCompat
{
- public class ButtonRenderer : ViewRenderer<Button, AppCompatButton>, global::Android.Views.View.IOnAttachStateChangeListener
+ public class ButtonRenderer : ViewRenderer<Button, AppCompatButton>, AView.IOnAttachStateChangeListener
{
TextColorSwitcher _textColorSwitcher;
float _defaultFontSize;
@@ -28,12 +31,12 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
global::Android.Widget.Button NativeButton => Control;
- void IOnAttachStateChangeListener.OnViewAttachedToWindow(global::Android.Views.View attachedView)
+ void IOnAttachStateChangeListener.OnViewAttachedToWindow(AView attachedView)
{
UpdateText();
}
- void IOnAttachStateChangeListener.OnViewDetachedFromWindow(global::Android.Views.View detachedView)
+ void IOnAttachStateChangeListener.OnViewDetachedFromWindow(AView detachedView)
{
}
@@ -74,6 +77,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
if (Control != null)
{
Control.SetOnClickListener(null);
+ Control.SetOnTouchListener(null);
Control.RemoveOnAttachStateChangeListener(this);
Control.Tag = null;
_textColorSwitcher = null;
@@ -98,6 +102,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
AppCompatButton button = CreateNativeControl();
button.SetOnClickListener(ButtonClickListener.Instance.Value);
+ button.SetOnTouchListener(ButtonTouchListener.Instance.Value);
button.Tag = this;
_textColorSwitcher = new TextColorSwitcher(button.TextColors);
SetNativeControl(button);
@@ -292,11 +297,34 @@ namespace Xamarin.Forms.Platform.Android.AppCompat
#endregion
- public void OnClick(global::Android.Views.View v)
+ public void OnClick(AView v)
{
var renderer = v.Tag as ButtonRenderer;
((IButtonController)renderer?.Element)?.SendClicked();
}
}
+
+ class ButtonTouchListener : Object, IOnTouchListener
+ {
+ public static readonly Lazy<ButtonTouchListener> Instance = new Lazy<ButtonTouchListener>(() => new ButtonTouchListener());
+
+ public bool OnTouch(AView v, AMotionEvent e)
+ {
+ var renderer = v.Tag as ButtonRenderer;
+ if (renderer != null)
+ {
+ var buttonController = renderer.Element as IButtonController;
+ if (e.Action == AMotionEventActions.Down)
+ {
+ buttonController?.SendPressed();
+ }
+ else if (e.Action == AMotionEventActions.Up)
+ {
+ buttonController?.SendReleased();
+ }
+ }
+ return false;
+ }
+ }
}
-} \ No newline at end of file
+}