コード例 #1
0
        public Main(string campusName)
        {
            InitializeComponent();

            client = new HttpClient();
            client.MaxResponseContentBufferSize = 256000;

            mCurrentCampus = campusName;
            Title          = campusName;
            Application.Current.Properties["map"] = map;
            Refresh();

            var    scroll = new ScrollView();
            string font;

            switch (Device.RuntimePlatform)
            {
            case "iOS":
                font = "AppleSDGothicNeo-UltraLight";
                break;

            case "Android":
                font = "Droid Sans Mono";
                break;

            default:
                font = "Comic Sans MS";
                break;
            }

            // Assigns title of page to building that is to be going to

            //display user prefernece info
            Label cName = new Label
            {
                Text            = "Campus: N/A",
                TextColor       = Color.White,
                BackgroundColor = Color.FromRgb(104, 151, 243),
                FontFamily      = font
            };
            Label r = new Label
            {
                Text            = "Role: N/A",
                TextColor       = Color.White,
                BackgroundColor = Color.FromRgb(104, 151, 243),
                FontFamily      = font
            };
            Label b = new Label
            {
                Text            = "Building: N/A",
                TextColor       = Color.White,
                BackgroundColor = Color.FromRgb(104, 151, 243),
                FontFamily      = font
            };

            l = new Label
            {
                Text            = "Lot: N/A",
                TextColor       = Color.White,
                BackgroundColor = Color.FromRgb(104, 151, 243),
                FontFamily      = font
            };

            // All function buttons
            var nd = new Button()
            {
                Text = "New Destination",
                //TextColor = Color.Red,
                Font       = Font.SystemFontOfSize(NamedSize.Large),
                FontFamily = font
            };

            nd.Clicked += newdes;

            var go = new Button()
            {
                Text       = "Go!",
                TextColor  = Color.Red,
                Font       = Font.SystemFontOfSize(NamedSize.Large),
                FontFamily = font
            };

            go.IsEnabled = false;

            var call = new Button()
            {
                Text       = "Call",
                Font       = Font.SystemFontOfSize(NamedSize.Large),
                FontFamily = font
            };

            call.Clicked += callnum;

            // display the user's preference that stored in their phone
            if (Application.Current.Properties.ContainsKey(campusName + "campus"))
            {
                cName.Text = "Campus: " + Application.Current.Properties[campusName + "campus"];
            }
            if (Application.Current.Properties.ContainsKey(campusName + "role"))
            {
                r.Text = "Role: " + Application.Current.Properties[campusName + "role"];
            }
            if (Application.Current.Properties.ContainsKey(campusName + "building"))
            {
                b.Text = "Building: " + Application.Current.Properties[campusName + "building"];
            }

            // Go button is not clickable if their no user's preference stored
            if ((Application.Current.Properties.ContainsKey(campusName + "building")) &&
                (Application.Current.Properties.ContainsKey(campusName + "role")) &&
                (Application.Current.Properties.ContainsKey(campusName + "campus")) &&
                (campusName == (string)Application.Current.Properties[campusName + "campus"]))
            {
                go.IsEnabled = true;
            }

            else
            {
                go.IsEnabled = false;
            }

            // all elements
            var stack = new StackLayout {
                Spacing = 0, VerticalOptions = LayoutOptions.FillAndExpand
            };

            stack.Children.Add(cName);
            stack.Children.Add(r);
            stack.Children.Add(b);
            stack.Children.Add(l);
            stack.Children.Add(map);
            stack.Children.Add(nd);
            stack.Children.Add(go);
            stack.Children.Add(call);

            scroll.Content = stack;
            Content        = scroll;

            NavigationPage.SetBackButtonTitle(this, "");

            // Geofencing
            AwaitSingle(StartGeoLocation());

            CrossGeolocator.Current.PositionChanged += (o, args) =>
            {
                if ((map.CheckInGeofences(args.Position)) &&
                    (onCampus == false))
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        mCurrentCampus = map.InWhichGeofences(args.Position);
                        DisplayAlert("Welcome to " + mCurrentCampus + "!", "We hope you find your way around!", "Okay");
                        DependencyService.Get <ITextToSpeech>().Speak("Welcome to " + mCurrentCampus);
                        onCampus = true;
                        Application.Current.Properties["notification"] = 1;
                    });
                }

                else if ((map.CheckInGeofences(args.Position) == false) &&
                         (onCampus == true))
                {
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        DisplayAlert("Now leaving " + mCurrentCampus, "Did you mean to do that?", "Maybe?");
                        onCampus       = false;
                        mCurrentCampus = "";
                        Application.Current.Properties["notification"] = 0;
                    });
                }
            };

            // Preference button
            ToolbarItems.Add(new ToolbarItem("Preference", "preference.png", () =>
            {
                Navigation.PushAsync(new EnterUserInfoPage(this.Title));
            }));

            map.SpanToCampus(campusName);

            go.Clicked += async(sender, e) =>
            {
                map.NavigateToLot(this.Title, mLotOrder[mLotToGo]);
            };
        }
コード例 #2
0
 async void OnClicked(object sender, EventArgs args)
 {
     map.NavigateToLot(mCampusName, mLotOrder[0]);
 }