public override void ViewDidLoad() { base.ViewDidLoad(); viewModel = new GameCompleteViewModel(); scanner = new ZXing.Mobile.MobileBarcodeScanner(); ButtonShare.Layer.CornerRadius = 5; scanButton = new UIBarButtonItem("Scan", UIBarButtonItemStyle.Plain, async(sender, args) => { var result = await scanner.Scan(true); if (result == null) { return; } Console.WriteLine("Scanned Barcode: " + result.Text); viewModel.CheckBanana(result.Text); }); NavigationItem.RightBarButtonItem = scanButton; viewModel.PropertyChanged += HandlePropertyChanged; manager = new CLLocationManager(); manager.DidRangeBeacons += (sender2, e) => { if (e.Beacons == null) { return; } foreach (var beacon in e.Beacons) { if (beacon.Proximity != CLProximity.Immediate) { return; } if (beacon.Accuracy > .1)//close, but not close enough. { return; } viewModel.CheckBanana(beacon.Major.Int32Value, beacon.Minor.Int32Value); } }; viewModel.LoadGameCommand.Execute(null); }
public override bool OnOptionsItemSelected(IMenuItem item) { switch (item.ItemId) { case Resource.Id.action_scan: { scanner.Scan().ContinueWith(result => { if (result.Result == null) { return; } Console.WriteLine("Scanned Barcode: " + result.Result.Text); viewModel.CheckBanana(result.Result.Text); }); } break; case Android.Resource.Id.Home: Finish(); OverridePendingTransition(Resource.Animation.slide_in_right, Resource.Animation.slide_out_right); break; } return(base.OnOptionsItemSelected(item)); }
private async void AppBarScan_Click(object sender, EventArgs e) { var result = await scanner.Scan(); if (result != null) { Console.WriteLine("Scanned Barcode: " + result.Text); Deployment.Current.Dispatcher.BeginInvoke(() => viewModel.CheckBanana(result.Text)); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); App.CurrentActivity = this; ActionBar.SetDisplayHomeAsUpEnabled(true); ActionBar.SetHomeButtonEnabled(true); viewModel = new GameCompleteViewModel(); SetContentView(Resource.Layout.game_complete); viewModel.PropertyChanged += HandlePropertyChanged; mainImage = FindViewById <ImageView>(Resource.Id.main_image); progressBar = FindViewById <ProgressBar>(Resource.Id.progressBar); beaconManager = new BeaconManager(this); scanner = new ZXing.Mobile.MobileBarcodeScanner(); var shareButton = FindViewById <Button>(Resource.Id.share_success); shareButton.Click += (sender, e) => { var intent = new Intent(Intent.ActionSend); intent.SetType("text/plain"); intent.PutExtra(Intent.ExtraText, Resources.GetString(Resource.String.success_tweet)); StartActivity(Intent.CreateChooser(intent, Resources.GetString(Resource.String.share_success))); }; beaconManager.Ranging += (sender, e) => { if (e.Beacons == null) { return; } foreach (var beacon in e.Beacons) { var proximity = Utils.ComputeProximity(beacon); if (proximity != Utils.Proximity.Immediate) { continue; } var accuracy = Utils.ComputeAccuracy(beacon); if (accuracy > .06) { continue; } viewModel.CheckBanana(beacon.Major, beacon.Minor); } }; viewModel.LoadGameCommand.Execute(null); }