// make sure the app is still working while the phone is in sleeping mode protected override void OnSleep() { if (Application.Current.Properties.ContainsKey("map")) { map = (GMTEMap)Application.Current.Properties["map"]; } else { map = new GMTEMap() { IsShowingUser = true, HeightRequest = 100, WidthRequest = 960, VerticalOptions = LayoutOptions.FillAndExpand, HasZoomEnabled = true }; } // check geolocation CrossGeolocator.Current.PositionChanged += (o, args) => { // check campus 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"); }); onCampus = true; } 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 = ""; }); } // check parking lot if (map.CheckInLotGeofences(args.Position, mCurrentCampus) && (mParked == false) && (inLot == false)) { Device.BeginInvokeOnMainThread(() => { mCurrentLot = map.InWhichLot(args.Position, mCurrentCampus); //DisplayAlert("You are in lot " + mCurrentLot + "!", "We hope you find a spot!", "Okay"); }); inLot = true; } if ((mParked) && (mShown == false)) { Device.BeginInvokeOnMainThread(() => { //DisplayAlert("You Parked!", "We detected that you parked in " + mLotParked, "Okay"); }); mShown = true; } if ((map.InWhichLot(args.Position, mCurrentCampus) != mCurrentLot) && (mCurrentLot != "") && (mTimerStarted == false) && (mParked == false)) { Device.BeginInvokeOnMainThread(() => { //DisplayAlert("Now leaving " + mCurrentLot, "Start parking-detection algorithm", "Start"); }); mLotParked = mCurrentLot; mCurrentLot = ""; mTimerStarted = true; if (map.CheckInLotGeofences(args.Position, mCurrentCampus)) { inLot = true; } else { inLot = false; } //Device.StartTimer(TimeSpan.FromSeconds(.5), new Func<bool>(() => CheckSpeed(args.Position))); } if ((map.CheckInLotGeofences(args.Position, mCurrentCampus) == false) && (mParked == false)) { mCurrentLot = ""; inLot = false; } }; }
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]); }; }
public MapPage(string selectedRole, string buildingName, string campusName) { InitializeComponent(); mCampusName = campusName; mBuildingName = buildingName; mRole = selectedRole; this.Title = mBuildingName; if (Application.Current.Properties.ContainsKey("map")) { map = (GMTEMap)Application.Current.Properties["map"]; } else { // Creates campuses objects and draws them map.AddCampus(campusName); // Assigns title of page to building that is to be going to this.Title = buildingName; Task addBuild = map.DrawBuildings(campusName); map.DrawLots(campusName); } string font; switch (Device.RuntimePlatform) { case "iOS": font = "AppleSDGothicNeo-UltraLight"; break; case "Android": font = "Droid Sans Mono"; break; default: font = "Comic Sans MS"; break; } client = new HttpClient(); client.MaxResponseContentBufferSize = 256000; var lotTask = GetLotOrder(); var lotLabel = new Label { FontFamily = font, TextColor = Color.Blue }; var goingToLabel = new Label { FontFamily = font, TextColor = Color.Green, }; lotLabel.SetBinding(Label.TextProperty, new Binding("Lots", stringFormat: "{0}")); goingToLabel.SetBinding(Label.TextProperty, new Binding("GoingTo", stringFormat: "Going to: {0}")); var button = new Button() { Text = "Start Directions!", Font = Font.SystemFontOfSize(NamedSize.Large), FontFamily = font, CommandParameter = new double() }; button.Clicked += OnClicked; button.SetBinding(Button.CommandParameterProperty, new Binding("Pos")); stack.Children.Add(lotLabel); stack.Children.Add(goingToLabel); stack.Children.Add(map); stack.Children.Add(button); stack.BindingContext = new { Lots = "Retrieving closest lots..." }; stack.BindingContext = stack.Children[0].BindingContext; this.Content = stack; Task stackTask = ConvertLots(lotTask); AwaitTask(stackTask); map.SpanToBuilding(buildingName, campusName); 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; }); } 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 = ""; }); } if (map.CheckInLotGeofences(args.Position, mCurrentCampus) && (mParked == false) && (inLot == false)) { Device.BeginInvokeOnMainThread(() => { mCurrentLot = map.InWhichLot(args.Position, mCurrentCampus); DisplayAlert("You are in lot " + mCurrentLot + "!", "We hope you find a spot!", "Okay"); DependencyService.Get <ITextToSpeech>().Speak("You are in lot " + mCurrentLot); }); inLot = true; } if ((mParked) && (mShown == false)) { Device.BeginInvokeOnMainThread(() => { DisplayAlert("You Parked!", "We detected that you parked in " + mLotParked, "Okay"); DependencyService.Get <ITextToSpeech>().Speak("You Parked in " + mLotParked); }); mShown = true; } if ((map.InWhichLot(args.Position, mCurrentCampus) != mCurrentLot) && (mCurrentLot != "") && (mTimerStarted == false) && (mParked == false)) { Device.BeginInvokeOnMainThread(() => { DisplayAlert("Now leaving " + mCurrentLot, "Start parking-detection algorithm", "Start"); }); mLotParked = mCurrentLot; mCurrentLot = ""; mTimerStarted = true; if (map.CheckInLotGeofences(args.Position, mCurrentCampus)) { inLot = true; } else { inLot = false; } Device.StartTimer(TimeSpan.FromSeconds(.5), new Func <bool>(() => CheckSpeed(args.Position))); } if ((map.CheckInLotGeofences(args.Position, mCurrentCampus) == false) && (mParked == false)) { mCurrentLot = ""; inLot = false; } }; }