Exemplo n.º 1
0
        public MainPage()
        {
            FoundBeacon      = false;
            Title            = "Available Items";
            CurrentARViewId  = "0";
            beaconLocater    = DependencyService.Get <IBeaconLocater>();
            beaconCollection = new ObservableCollection <BeaconItem>();

            //Debug Button to start a AR View
            Button arButton = new Button {
                HorizontalOptions = LayoutOptions.Center,
                Text = "Debug ID " + debug
            };

            arButton.Clicked += (sender, e) => {
                arPage = new ARPage(debug);
                Navigation.PushAsync(arPage);
            };

            listView = new ListView {
                RowHeight = 100,
            };
            listView.ItemTemplate = new DataTemplate(typeof(BeaconCell));
            listView.ItemsSource  = beaconCollection;
            listView.ItemTapped  += (sender, e) => {
                BeaconFound(((BeaconItem)e.Item));
            };

            tableLayout = new StackLayout {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children        =
                {
                    listView
                }
            };

            searchingLabel = new Label {
                Text   = "Please get closer to a picture",
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center
            };

            spinner = new ActivityIndicator {
                IsRunning = true,
                Color     = Color.Gray,
            };

            searchingLayout = new StackLayout {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                Children          =
                {
                    spinner,
                    searchingLabel,
                    arButton
                }
            };

            Content = searchingLayout;
        }
Exemplo n.º 2
0
        public MainPage()
        {
            Title = "Available Beacons";

            trackingPage = new TrackingPage();

            listView = new ListView
            {
                RowHeight = 100,
            };
            listView.ItemTemplate = new DataTemplate(typeof(BeaconCell));

            beaconLocater        = DependencyService.Get <IBeaconLocater>();
            beaconCollection     = new ObservableCollection <BeaconItem>();
            listView.ItemsSource = beaconCollection;

            var trackingButton = new Button
            {
                Text = "Start Tracking",
                HorizontalOptions = LayoutOptions.Center
            };

            trackingButton.Clicked += (sender, args) =>
            {
                Navigation.PushAsync(trackingPage);
            };

            tableLayout = new StackLayout
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children        = { trackingButton, listView }
            };

            searchingLabel = new Label
            {
                Text = "Searching for beacons",
                VerticalTextAlignment   = TextAlignment.Center,
                HorizontalTextAlignment = TextAlignment.Center
            };

            spinner = new ActivityIndicator
            {
                IsRunning = true,
                Color     = Color.Gray,
            };

            searchingLayout = new StackLayout
            {
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                Children          = { spinner, searchingLabel }
            };

            Content = searchingLayout;
        }
Exemplo n.º 3
0
        public MainPage()
        {
            Title = "Available Beacons";

            trackingPage = new TrackingPage ();

            listView = new ListView {
                RowHeight = 100,
            };
            listView.ItemTemplate = new DataTemplate (typeof(BeaconCell));

            beaconLocater = DependencyService.Get<IBeaconLocater> ();
            beaconCollection = new ObservableCollection<BeaconItem> ();
            listView.ItemsSource = beaconCollection;

            var trackingButton = new Button {
                Text = "Start Tracking",
                HorizontalOptions = LayoutOptions.Center
            };

            trackingButton.Clicked += (sender, args) => {
                Navigation.PushAsync(trackingPage);
            };

            tableLayout = new StackLayout {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children = {trackingButton, listView}
            };

            searchingLabel = new Label {
                Text = "Searching for beacons",
                YAlign = TextAlignment.Center,
                XAlign = TextAlignment.Center
            };

            spinner = new ActivityIndicator {
                IsRunning = true,
                Color = Color.Gray,
            };

            searchingLayout = new StackLayout {
                VerticalOptions = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.Center,
                Children = {spinner, searchingLabel}
            };

            Content = searchingLayout;
        }
Exemplo n.º 4
0
        public static void Start()
        {
            IsBusy = false;

            try
            {
                Device.BeginInvokeOnMainThread(async() =>
                {
                    beaconLocater    = DependencyService.Get <IBeaconLocater>();
                    beaconCollection = new ObservableCollection <BeaconItem>();

                    PermissionStatus status = PermissionStatus.Unknown;
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        status = await CrossPermissions.Current
                                 .CheckPermissionStatusAsync(Permission.Location);

                        if (status != PermissionStatus.Granted)
                        {
                            if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location))
                            {
                                await App.Current.MainPage.DisplayAlert("Location", "Please switch on Location", "OK");
                            }

                            var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location);
                            status      = results[Permission.Location];
                        }
                    }
                    else if (Device.RuntimePlatform == Device.Android)
                    {
                        status = await CrossPermissions.Current
                                 .CheckPermissionStatusAsync(Permission.Bluetooth);

                        if (status != PermissionStatus.Granted)
                        {
                            if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Bluetooth))
                            {
                                await App.Current.MainPage.DisplayAlert("Bluetooth", "Please switch on Bluetooth", "OK");
                            }

                            var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Bluetooth);
                            status      = results[Permission.Bluetooth];
                        }

                        if (!CrossPermissions.Current.IsBluetoothEnabled())
                        {
                            Device.BeginInvokeOnMainThread(async() =>
                            {
                                var canBluetoothEnabled = await App.Current.MainPage.DisplayAlert("Bluetooth", "Please enable device Bluetooth to locate Beacons", "OK", "Cancel");
                                if (canBluetoothEnabled)
                                {
                                    CrossPermissions.Current.OpenBluetoothSettings();
                                }
                            });
                        }
                    }

                    if (status == PermissionStatus.Granted)
                    {
                        startTimer?.Stop();
                        startTimer = new TimerHolder(1000, () =>
                        {
                            try
                            {
                                var beaconCollection = beaconLocater.GetAvailableBeacons();
                                var _BaseViewModel   = Application.Current.MainPage.BindingContext as BaseViewModel;


                                if (beaconCollection != null && beaconCollection.Count() > 0 &&
                                    (
                                        Helpers.Settings.SubCategorySettings == "Neuro" ||
                                        Helpers.Settings.SubCategorySettings == "Emergency"

                                    ))
                                {
                                    // _BaseViewModel.ImageName = "hospitalMap.png";

                                    var closestBeacon = ((List <BeaconItem>)beaconCollection).OrderBy(b => b.CurrentDistance).First();
                                    CrossLocalNotifications.Current.Show("PathFinder", "Wrong Direction", 101);
                                    CrossVibrate.Current.Vibration(TimeSpan.FromSeconds(1));
                                }
                                else if (beaconCollection != null && beaconCollection.Count() > 0)
                                {
                                    var closestBeacon = ((List <BeaconItem>)beaconCollection).OrderBy(b => b.CurrentDistance).First();
                                    if (closestBeacon != null)
                                    {
                                        switch (closestBeacon.Minor)
                                        {
                                        case "10":

                                            if (LastLocation != "10")
                                            {
                                                CrossLocalNotifications.Current.Show("PathFinder", "You are at conference room projector", 101);

                                                Helpers.Settings.CurrentLocation = "projector";
                                                _BaseViewModel.ImageName         = "pj.png";
                                            }
                                            LastLocation = "10";
                                            break;

                                        case "15":

                                            if (LastLocation != "15")
                                            {
                                                CrossLocalNotifications.Current.Show("PathFinder", "You are at conference room tv", 101);

                                                Helpers.Settings.CurrentLocation = "tv";
                                                _BaseViewModel.ImageName         = "tv.png";
                                            }
                                            LastLocation = "15";
                                            break;

                                        case "20":

                                            if (LastLocation != "20")
                                            {
                                                CrossLocalNotifications.Current.Show("PathFinder", "You are at server room", 101);

                                                Helpers.Settings.CurrentLocation = "server";
                                                _BaseViewModel.ImageName         = "sr.png";
                                            }
                                            LastLocation = "20";
                                            break;
                                        }
                                    }
                                    // CrossVibrate.Current.Vibration(TimeSpan.FromSeconds(1));
                                }
                                else
                                {
                                    // _BaseViewModel.ImageName = "hospitalMap.png";
                                    CrossLocalNotifications.Current.Cancel(101);
                                    CrossVibrate.Current.Vibration(TimeSpan.FromSeconds(0));
                                }
                            }
                            catch (Exception)
                            {
                                BeaconService.IsBusy = false;
                            }
                        });
                        startTimer.Start();
                    }
                });
            }
            catch (Exception)
            {
            }
        }