Created
December 10, 2014 05:15
-
-
Save amay077/1d22ba8ffa8ad95e9393 to your computer and use it in GitHub Desktop.
simply_shape_moving_by_xamarin_with_rx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Android.App; | |
using Android.Content; | |
using Android.Runtime; | |
using Android.Views; | |
using Android.Widget; | |
using Android.OS; | |
using System.Reactive.Linq; | |
using NDebug = System.Diagnostics.Debug; | |
using Android.Graphics; | |
namespace DrawingTest | |
{ | |
[Activity(Label = "DrawingTest", MainLauncher = true, Icon = "@drawable/icon")] | |
public class MainActivity : Activity | |
{ | |
protected override void OnCreate(Bundle bundle) | |
{ | |
base.OnCreate(bundle); | |
// Set our view from the "main" layout resource | |
SetContentView(Resource.Layout.Main); | |
ActionBar.Hide(); | |
var rectangle = FindViewById<View>(Resource.Id.view1); | |
rectangle.DownEvent() | |
.SelectMany(rectangle.MoveEvent()) | |
.Subscribe(e => | |
{ | |
rectangle.SetX(e.RawX); | |
rectangle.SetY(e.RawY - 50f); | |
}); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using Android.Views; | |
using System.Reactive.Linq; | |
namespace DrawingTest | |
{ | |
public static class ViewExtensions | |
{ | |
public static IObservable<MotionEvent> DownEvent(this View v) | |
{ | |
return Observable.FromEventPattern<View.TouchEventArgs>(h => v.Touch += h, h => v.Touch -= h) | |
.Where(e => e.EventArgs.Event.Action == MotionEventActions.Down) | |
.Select(e => e.EventArgs.Event); | |
} | |
public static IObservable<MotionEvent> MoveEvent(this View v) | |
{ | |
return Observable.FromEventPattern<View.TouchEventArgs>(h => v.Touch += h, h => v.Touch -= h) | |
.Where(e => e.EventArgs.Event.Action == MotionEventActions.Move) | |
.Select(e => e.EventArgs.Event); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment