public void OnBeaconsDiscovered(Region region, IList<Beacon> beacons) { Log.Debug(Tag, "Ranged beacons: " + beacons.Count); if (beacons.Count != 0) { foreach (var b in beacons) { var distance = Utils.ComputeAccuracy(b); Log.Debug("BeaconDetails:", b.MacAddress + " distance: " + distance); dis[macToName[b.MacAddress]] = distance; } } var text = string.Empty; var keys = dis.Keys.ToList(); keys.Sort(); foreach (var k in keys) { text += k + " " + dis[k] + "\n"; } CloudBlockBlob blob = this.container.GetBlockBlobReference("DistanceInfo"); Task.Run(async () => { MemoryStream msWrite = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(dis))); msWrite.Position = 0; using (msWrite) { await blob.UploadFromStreamAsync(msWrite); } }).ConfigureAwait(false); FindViewById<TextView>(Resource.Id.textView1).Text = text; }
protected void InitilizeRegions() { _regionBeacons = new EstimoteSdk.Region(Constants.BEACON_REGIONS_IDENTIFIER, "B9407F30-F5F8-466E-AFF9-25556B57FE6D"); _region1 = new EstimoteSdk.Region(Constants.REGION1_IDENTIFIER, "B9407F30-F5F8-466E-AFF9-25556B57FE6D", 1564, 34409); _region2 = new EstimoteSdk.Region(Constants.REGION2_IDENTIFIER, "B9407F30-F5F8-466E-AFF9-25556B57FE6D", 15212, 31506); _region3 = new EstimoteSdk.Region(Constants.REGION3_IDENTIFIER, "B9407F30-F5F8-466E-AFF9-25556B57FE6D", 26535, 44799); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); Tuple<Beacon, Region> stuff = this.GetBeaconAndRegion(); _beacon = stuff.Item1; _region = stuff.Item2; ActionBar.SetDisplayHomeAsUpEnabled(true); SetContentView(Resource.Layout.distance_view); _dotView = FindViewById(Resource.Id.dot); _sonar = FindViewById(Resource.Id.sonar); _sonar.ViewTreeObserver.AddOnGlobalLayoutListener(this); _findBeacon = new FindSpecificBeacon(this); _findBeacon.BeaconFound += (sender, e) => RunOnUiThread(() =>{ Log.Debug(Tag, "Found the beacon!"); if (_segmentLength == -1) { return; } _dotView.Animate().TranslationY(ComputeDotPosY(e.FoundBeacon)).Start(); }); }
public void OnServiceReady() { if (region != null) { beaconManager.StopRanging(region); beaconManager.StopMonitoring(region); region = null; } if (secretRegion != null) { beaconManager.StopRanging(secretRegion); } else { secretRegion = new EstimoteSdk.Region(BeaconId, ViewModel.UUID, new Java.Lang.Integer(9999), null); } if (ViewModel.Quest.Major >= 0) { region = new EstimoteSdk.Region(BeaconId, ViewModel.UUID, new Java.Lang.Integer(ViewModel.Quest.Major), null); // This method is called when BeaconManager is up and running. beaconManager.StartRanging(region); beaconManager.StartMonitoring(region); } beaconManager.StartRanging(secretRegion); connected = true; }
protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.Main); progressBar = FindViewById<ProgressBar> (Resource.Id.progressBar); noBeacons = FindViewById<TextView> (Resource.Id.no_beacons); ListAdapter = new BeaconAdapter (this); //create a new beacon manager to handle starting and stopping ranging beaconManager = new BeaconManager (this); //manually check for BLE var ble = Android.Content.PM.PackageManager.FeatureBluetoothLe; if (PackageManager.HasSystemFeature(ble)) { Toast.MakeText(this, "BLE not supported", ToastLength.Short).Show(); } //Validation checks if (!beaconManager.HasBluetooth) { //no bluetooth :( DisplayMessage ("No bluetooth on your device.", ":("); beaconsEnabled = false; } else if (!beaconManager.IsBluetoothEnabled) { //bluetooth is not enabled DisplayMessage ("Please turn on bluetooth.", ":("); beaconsEnabled = false; } else if (!beaconManager.CheckPermissionsAndService ()) { //issues with permissions and service DisplayMessage ("Issues with service and persmissions.", ":("); beaconsEnabled = false; } //major and minor are optional, pass in null if you don't need them beaconRegion = new Region (beaconId, uuid, major, null); //Event for when ranging happens beaconManager.Ranging += (object sender, BeaconManager.RangingEventArgs e) => RunOnUiThread (() => { if (e.Beacons.Count == 0) noBeacons.Visibility = ViewStates.Visible; else if(noBeacons.Visibility == ViewStates.Visible) noBeacons.Visibility = ViewStates.Gone; if (progressBar.Visibility == ViewStates.Visible) progressBar.Visibility = ViewStates.Invisible; ((BeaconAdapter)ListAdapter).Beacons.Clear (); ((BeaconAdapter)ListAdapter).Beacons.AddRange (e.Beacons); ((BeaconAdapter)ListAdapter).NotifyDataSetChanged (); }); //estimote loggin, optional #if DEBUG EstimoteSdk.Utility.L.EnableDebugLogging (true); #endif }
public void OnBeaconsDiscovered(Region region, IList<Beacon> beacons) { Log.Debug(Tag, "Found {0} beacons", beacons.Count); Beacon foundBeacon = (from b in beacons where b.MacAddress.Equals(_beacon.MacAddress) select b).FirstOrDefault(); if (foundBeacon != null) { BeaconFound(this, new BeaconFoundEventArgs(foundBeacon)); } }
public override void Stop() { if (_isSearching) { BeaconManager.StopRanging(_region); base.Stop(); _region = null; _beacon = null; _isSearching = false; } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); //create a new beacon manager to handle starting and stopping ranging beaconManager = new BeaconManager(this); //major and minor are optional, pass in null if you don't need them beaconRegion = new EstimoteSdk.Region(beaconId, uuid, null, null); var v = FindViewById <WatchViewStub> (Resource.Id.watch_view_stub); v.LayoutInflated += delegate { // Get our button from the layout resource, // and attach an event to it background = FindViewById <View> (Resource.Id.main); count = FindViewById <TextView>(Resource.Id.text); }; beaconManager.Ranging += (object sender, BeaconManager.RangingEventArgs e) => RunOnUiThread(() => { background.SetBackgroundColor(Color.Black); count.Text = e.Beacons.Count.ToString(); if (e.Beacons.Count == 0) { return; } var prox = Utils.ComputeProximity(e.Beacons[0]); if (prox == Utils.Proximity.Far) { background.SetBackgroundColor(Color.Blue); } else if (prox == Utils.Proximity.Near) { background.SetBackgroundColor(Color.Yellow); } else if (prox == Utils.Proximity.Immediate) { background.SetBackgroundColor(Color.Green); } else { background.SetBackgroundColor(Color.Black); } }); }
public void AddRegion(string id, string uuid, int major = -1, int minor = -1) { Region regionItem = null; if (major == -1 && minor == -1) regionItem = new Region(id, uuid); else if (major != -1 && minor != -1) regionItem = new Region(id, uuid, major, minor); else if (major != -1 && minor == -1) regionItem = new Region(id, uuid, major); if(regionItem != null) _itemsList.Add(regionItem); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); //create a new beacon manager to handle starting and stopping ranging beaconManager = new BeaconManager(this); //major and minor are optional, pass in null if you don't need them beaconRegion = new EstimoteSdk.Region(beaconId, uuid, null, null); var background = FindViewById <LinearLayout> (Resource.Id.background); var beaconsFound = FindViewById <TextView> (Resource.Id.beacons_found); var accuracy = FindViewById <TextView> (Resource.Id.accuracy); beaconManager.Ranging += (object sender, BeaconManager.RangingEventArgs e) => RunOnUiThread(() => { background.SetBackgroundColor(Color.White); beaconsFound.Text = e.Beacons.Count.ToString(); if (e.Beacons.Count == 0) { return; } var prox = Utils.ComputeProximity(e.Beacons [0]); if (prox == Utils.Proximity.Far) { background.SetBackgroundColor(Color.Blue); } else if (prox == Utils.Proximity.Near) { background.SetBackgroundColor(Color.Yellow); } else if (prox == Utils.Proximity.Immediate) { background.SetBackgroundColor(Color.Green); } else { background.SetBackgroundColor(Color.Black); } var distance = Utils.ComputeAccuracy(e.Beacons [0]); accuracy.Text = distance.ToString("##.0000000"); }); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); ActionBar.SetDisplayHomeAsUpEnabled(true); SetContentView(Resource.Layout.notify_demo); _region = this.GetBeaconAndRegion().Item2; _notificationManager = (NotificationManager)GetSystemService(NotificationService); _beaconManager = new BeaconManager(this); // Default values are 5s of scanning and 25s of waiting time to save CPU cycles. // In order for this demo to be more responsive and immediate we lower down those values. _beaconManager.SetBackgroundScanPeriod(TimeUnit.Seconds.ToMillis(1), 0); _beaconManager.EnteredRegion += (sender, e) => PostNotification("Entered region"); _beaconManager.ExitedRegion += (sender, e) => PostNotification("Exited region"); }
protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); //create a new beacon manager to handle starting and stopping ranging beaconManager = new BeaconManager (this); //major and minor are optional, pass in null if you don't need them beaconRegion = new EstimoteSdk.Region (beaconId, uuid, null, null); var v = FindViewById<WatchViewStub> (Resource.Id.watch_view_stub); v.LayoutInflated += delegate { // Get our button from the layout resource, // and attach an event to it background = FindViewById<View> (Resource.Id.main); count = FindViewById<TextView>(Resource.Id.text); }; beaconManager.Ranging += (object sender, BeaconManager.RangingEventArgs e) => RunOnUiThread (() => { background.SetBackgroundColor(Color.Black); count.Text = e.Beacons.Count.ToString(); if(e.Beacons.Count == 0) return; var prox = Utils.ComputeProximity(e.Beacons[0]); if(prox == Utils.Proximity.Far) background.SetBackgroundColor(Color.Blue); else if(prox == Utils.Proximity.Near) background.SetBackgroundColor(Color.Yellow); else if(prox == Utils.Proximity.Immediate) background.SetBackgroundColor(Color.Green); else background.SetBackgroundColor(Color.Black); }); }
void InitMonitoring() { _beaconManager = new BeaconManager(this); // Default values are 5s of scanning and 25s of waiting time to save CPU cycles. // In order for this demo to be more responsive and immediate we lower down those values. _beaconManager.SetBackgroundScanPeriod(TimeUnit.Seconds.ToMillis(1), 0); _beaconManager.EnteredRegion += (sender, e) => { PostNotification("Benvenuti alla sessione sui Beacon"); _beaconManager.StartRanging(_region); }; _beaconManager.ExitedRegion += (sender, e) => { PostNotification("Non dimenticate di dare il vostro feedback"); _beaconManager.StopRanging(_region); _layout.SetBackgroundColor(Color.Black); }; _beaconManager.Ranging += (sender, e) => { //Beacons in range var beacon = e.Beacons.FirstOrDefault(); if (beacon != null) { var accuracy = Utils.ComputeAccuracy(beacon); _layout.SetBackgroundColor(ColorFromDistance(accuracy)); PostNotification($"Distance to beacon\n{accuracy:N1}m"); } else { PostNotification("Non dimenticate di dare il vostro feedback"); _layout.SetBackgroundColor(Color.Black); } }; _region = new EstimoteSdk.Region("community_days_id", "B9407F30-F5F8-466E-AFF9-25556B57FE6D", 24986); }
protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); //create a new beacon manager to handle starting and stopping ranging beaconManager = new BeaconManager (this); //major and minor are optional, pass in null if you don't need them beaconRegion = new EstimoteSdk.Region (beaconId, uuid, null, null); var background = FindViewById<LinearLayout> (Resource.Id.background); var beaconsFound = FindViewById<TextView> (Resource.Id.beacons_found); var accuracy = FindViewById<TextView> (Resource.Id.accuracy); beaconManager.Ranging += (object sender, BeaconManager.RangingEventArgs e) => RunOnUiThread (() => { background.SetBackgroundColor(Color.White); beaconsFound.Text = e.Beacons.Count.ToString(); if(e.Beacons.Count == 0) return; var prox = Utils.ComputeProximity(e.Beacons[0]); if(prox == Utils.Proximity.Far) background.SetBackgroundColor(Color.Blue); else if(prox == Utils.Proximity.Near) background.SetBackgroundColor(Color.Yellow); else if(prox == Utils.Proximity.Immediate) background.SetBackgroundColor(Color.Green); else background.SetBackgroundColor(Color.Black); var distance = Utils.ComputeAccuracy(e.Beacons[0]); accuracy.Text = distance.ToString("##.0000000"); }); }
private void InitBeacon() { if (!beaconsEnabled) return; secretRegion = new Region(BeaconId, viewModel.UUID, new Java.Lang.Integer(9999), new Java.Lang.Integer(9999)); beaconManager.Connect(this); }
public void OnServiceReady() { if (region != null) { beaconManager.StopRanging(region); beaconManager.StopMonitoring(region); region = null; } if (secretRegion != null) beaconManager.StopRanging(secretRegion); else secretRegion = new EstimoteSdk.Region(BeaconId, ViewModel.UUID, new Java.Lang.Integer(9999), null); if (ViewModel.Quest.Major >= 0) { region = new EstimoteSdk.Region(BeaconId, ViewModel.UUID, new Java.Lang.Integer(ViewModel.Quest.Major), null); // This method is called when BeaconManager is up and running. beaconManager.StartRanging(region); beaconManager.StartMonitoring(region); } beaconManager.StartRanging(secretRegion); connected = true; }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); this.RequestWindowFeature(WindowFeatures.NoTitle); SetContentView(Resource.Layout.gruppeRom); menuButton = FindViewById<ImageButton>(Resource.Id.menuButton); mainPage = FindViewById<ImageButton>(Resource.Id.westerdalsLogo); infoText = FindViewById<TextView>(Resource.Id.ingenInfo); hjelpButton = FindViewById<Button>(Resource.Id.HjelpButton); hjelpButton.Visibility = ViewStates.Gone; infoText.Visibility = ViewStates.Gone; swiperefresh = FindViewById<SwipeRefreshLayout>(Resource.Id.swiperefresh); swiperefresh.Refresh += Swiperefresh_Refresh; menuButton.Click += delegate { StartActivity(typeof(Menu)); }; mainPage.Click += delegate { StartActivity(typeof(Menu)); }; _beaconManager = new BeaconManager(this); _region = new Region("SomeBeaconIdentifier", "b9407f30-f5f8-466e-aff9-25556b57fe6d"); romListView = FindViewById<ListView>(Resource.Id.romListe1); roomClient = new WebClient(); servURL = new Uri("http://pj3100.somee.com/GetRooms.php"); romListe = new List<RomBeacon>(); romListeDB = new List<RomBeacon>(); _beaconManager.SetBackgroundScanPeriod(2000, 0); _beaconManager.EnteredRegion += (sender, e) => { int numberOfBeacons = e.Beacons.Count; for (int i = 0; i < numberOfBeacons; i++) { romListe.Add(new RomBeacon { BeaconUUID = e.Beacons[i].ProximityUUID.ToString(), BeaconMajor = e.Beacons[i].Major, BeaconMinor = e.Beacons[i].Minor, distance = calculateDistance(e.Beacons[i].MeasuredPower, e.Beacons[i].Rssi).ToString() }); } }; roomClient.DownloadDataAsync(servURL); roomClient.DownloadDataCompleted += roomClient_DownloadDataCompleted; if (romListeDB.Count == 0) { infoText.Visibility = ViewStates.Visible; infoText.Text = "Ingenting her, swipe ned for å fornye."; } else { infoText.Visibility = ViewStates.Gone; } }
public void LookForBeacon(Region region, Beacon beacon) { _beacon = beacon; _region = region; BeaconManager.Connect(this); }
public void StartScanning(int milliSecond = 0) { BeaconManager = new BeaconManager(context); if (CheckForBluetooth()) { BeaconRegion = new Region("rid", App.Self.BEACON_ID); BeaconManager.SetBackgroundScanPeriod(TimeUnit.Seconds.ToMillis(milliSecond), 0); BeaconManager.Connect(this); BeaconManager.Ranging += (object sender, BeaconManager.RangingEventArgs e) => { foreach (var beacon in App.Self.Beacons) { var found = e.Beacons.FirstOrDefault(t => t.MacAddress.ToString() == beacon.MacAddress); var idx = e.Beacons.IndexOf(found); if (found != null) { if (idx < App.Self.Beacons.Count) { App.Self.Beacons[idx].Rssi = found.Rssi; } } } }; BeaconManager.EnteredRegion += (sender, e) => { if (App.Self.Beacons.Count != 0) { var exists = (from beacon in App.Self.Beacons from ebeacon in e.Beacons where beacon.Major == ebeacon.Major select beacon).FirstOrDefault(); //var exists = App.Self.Beacons.FirstOrDefault(t => t.Major == e.Beacons.FirstOrDefault(w => w.Major)); if (exists == null) App.Self.Beacons.Add(exists); else { var index = App.Self.Beacons.IndexOf(exists); if (index != -1) App.Self.Beacons[index] = exists; } } else { foreach (var beacon in e.Beacons) { App.Self.Beacons.Add(new BeaconData { MacAddress = beacon.MacAddress.ToString(), Major = beacon.Major, MeasuredPower = beacon.MeasuredPower, Minor = beacon.Minor, Name = beacon.Name, Rssi = beacon.Rssi, ProximityUUID = beacon.ProximityUUID.ToString(), Region = new RegionData { Major = e.Region.Major, Minor = e.Region.Minor, Identifier = e.Region.Identifier, ProximityUUID = e.Region.ProximityUUID.ToString() } }); } } }; BeaconManager.ExitedRegion += (sender, e) => { if (App.Self.Beacons.Count != 0) { var exists = (from b in App.Self.Beacons let reg = b.Region where reg.Identifier == e.Region.Identifier select reg).FirstOrDefault(); if (exists != null) { var index = App.Self.Beacons.IndexOf(App.Self.Beacons.FirstOrDefault(t => t.Region.Major == e.Region.Major)); App.Self.Beacons.RemoveAt(index); } } }; } }
public void OnServiceReady () { region = new Region(beaconId, uuid, null, null); beaconManager.StartRanging (region); beaconManager.StartMonitoring (region); }
protected virtual BeaconRegion FromNative(Region native) { return new BeaconRegion( native.Identifier, native.ProximityUUID, this.FromInteger(native.Major), this.FromInteger(native.Minor) ); }