diff options
author | Kangho <rookiejava+github@gmail.com> | 2017-02-03 03:23:31 +0900 |
---|---|---|
committer | Kangho Hur <kangho.hur@samsung.com> | 2017-03-24 13:18:57 +0900 |
commit | b50a12b136ef17b0bf46103821481d92ec3b2dae (patch) | |
tree | cf08b146a0f545ff920774196b124807b312ec6b /Xamarin.Forms.Platform.Android | |
parent | 3b608a3a5e9b5739014a60995c31dbf610b61de4 (diff) | |
download | xamarin-forms-b50a12b136ef17b0bf46103821481d92ec3b2dae.tar.gz xamarin-forms-b50a12b136ef17b0bf46103821481d92ec3b2dae.tar.bz2 xamarin-forms-b50a12b136ef17b0bf46103821481d92ec3b2dae.zip |
Add pressed and released events to Button (#446)
* Add pressed and released events to Button
* Update ButtonRenderer.cs
* Apply safely casting to android button renderer
* Use safety casting for Android buttin renderer
* [Windows] Fix modal pages being laid out below soft buttons (#395)
* Add sample HanselForms and TwitterDemo to ControlGallery (#651)
* [Controls] Add Hanselforms sample
* Remove extra twitter sample
* [Controls]Add TwitterDemo sample
* [Controls] Fix build
* Slider should show user-set value on initial load (#378)
* [UWP] Use toolbar foreground color on primary items (#640)
* Avoid duplicating code in OmPlatform (#591)
* [iOS] Entry should not pass a newline to the next responder (#397)
* UITextField should not return so that the next field does not get passed a newline
* Added code sample
* [XamlC] import members on x:Static and factories (#642)
* [Xaml] support short Properties for PropertyCondition (#645)
* Xamlc compile data triggers (#648)
* [Xaml] DataTrigger and PropertyCondition no longer use a ServiceProvider
* [XamlC] avoid generating ServiceProvider for unused ProvideValue
* fix tests
* Fix comment typo
* [UWP] Fix TextBox style for foreground focus color (#618)
* Adding image to use for CellsGalleryImageUrlCellList UI test
* Update ImageCellListPage to use an image we control;
Update CellsGalleryImageUrlCellList test to wait longer than 1s for images
to load if necessary
* fix nre when changing content in datepickerselected (#494)
* Make CellsGalleryImageUrlCellList test finish early if possible
* [iOS] Change keyboard type while keyboard is visible (#443)
* Change keyboard while changing text
* add sample code
* [Android] Fix NavigationPage dispose crash when it parents a MasterDetailPage (#577)
* fix navigation page dispose crash
* changes after review
* [XamlC] detect duplicate x:Name at compile time (#655)
* [XamlC] detect duplicate x:Name at compile time
* invoking methods with the right arguments produces better results
* Make UWP toolbar display rules consistent with other platforms (#638)
* Allow subscriber to be collected if MessagingCenter is the only reference to it (#617)
* Repro
* Make messaging center callbacks weak references
* Preserve attribute
* Fix test method name
* Watch for collection of actual delegate target instead of wrapper delegate
* Preserve the original platform instance when changing main page
* Better tests for lambda situations
* Update tests, make callback target a weakreference if it's the subscriber
* Ensure old Platform MessagingCenter subs are gone before creating new Platform
* [iOS] Prevent multiple ListView cells from being swiped simultaneously (#578)
* disable multiple cell swipe
* add sample code
* refactored
* convert to weakreference
* remove null setting
* change weakreference setting place
* remove if
* revert isopen changes
* add instructions
* [WinRT/UWP] Apply BackgroundColor to Stepper buttons (#581)
* [WinRT/UWP] Apply BackgroundColor to Stepper buttons
* Add explanatory text; use nameof
* Move explanatory text to a label
* Return group instead of internal class (#461)
* [iOS/Android] Move Map camera to correct region on layout change (#548)
* Move to region on layout change
* remove visibility check
* [iOS] Platform specifics for controlling Picker SelectedIndex change behavior (#540)
* picker selected index could change when picker view is dismissed
* use enum
* [iOS] Ignore intermittent failing test on XTC (#666)
* [UITest] Update to UITest 2.0.5 (#665)
* Rebase the current branch onto upstream latest
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r-- | Xamarin.Forms.Platform.Android/AppCompat/ButtonRenderer.cs | 38 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.Android/Renderers/ButtonRenderer.cs | 26 |
2 files changed, 59 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 +} diff --git a/Xamarin.Forms.Platform.Android/Renderers/ButtonRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/ButtonRenderer.cs index 4f384b3b..e07a2be5 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/ButtonRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/ButtonRenderer.cs @@ -7,6 +7,8 @@ using Android.Util; using static System.String; using AButton = Android.Widget.Button; using AView = Android.Views.View; +using AMotionEvent = Android.Views.MotionEvent; +using AMotionEventActions = Android.Views.MotionEventActions; using Object = Java.Lang.Object; namespace Xamarin.Forms.Platform.Android @@ -96,6 +98,7 @@ namespace Xamarin.Forms.Platform.Android { button = CreateNativeControl(); button.SetOnClickListener(ButtonClickListener.Instance.Value); + button.SetOnTouchListener(ButtonTouchListener.Instance.Value); button.Tag = this; SetNativeControl(button); _textColorSwitcher = new TextColorSwitcher(button.TextColors); @@ -303,5 +306,28 @@ namespace Xamarin.Forms.Platform.Android ((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 |