コード例 #1
0
        public StartPage()
        {
            Title = "Job Search Scorecard";

            NavigationPage.SetHasBackButton (this, false);  // no back button from this screen!

            App.AppSettings = App.Database.GetSettings ();
            if (App.AppSettings == null) {
                App.AppSettings = new Settings ();
                App.Database.SaveSettings (App.AppSettings);
                _settingsPage = new SettingsPage (true);  // tell Settings that it's Name-entry only
                _settingsPage.BindingContext = App.AppSettings;  // first time Settings (no Cancel)
                this.Navigation.PushModalAsync (_settingsPage);
            } else {
                _settingsPage = new SettingsPage (false);
            }
            ;

            welcomeLabel = new Label () {
                FontSize = 22,
                FontAttributes = FontAttributes.Italic,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
            };
            welcomeLabel.Text = String.Format ("Welcome to Job Seeker Scorecard, friend!");

            MessagingCenter.Subscribe<SettingsPage> (this, "popped", (sender) => {
                OnAppearing();
            });

            if (firstTime) {  // first time in this screen for this execution, but not necessarily first time in app
                firstTime = false;
                ActivityTable.BuildActivitiesDictionary ();  // build the table of potential tasks (aka Activity list)
                //currentTasks = MockUpTasks ();  // if you wish to mock-up some completed tasks
                Debug.WriteLine ("Built Activities Dictionary with : " + Activity.UniqueCode + " unique entries");
                Debug.WriteLine ("Database Table Counts at Start-Up:");
                Debug.WriteLine ("[Task] has " + App.Database.GetTasks ().Count () + " rows");
                Debug.WriteLine ("[Period] has " + App.Database.GetPeriods ().Count () + " rows");

            }  // first-time

            scoreBox = new Label () {
                Text = "No Score",
                FontSize = 55,
                FontAttributes = FontAttributes.Bold,
                HorizontalOptions = LayoutOptions.Center
            };  // Text set in the OnAppearing override in order to grab latest total score

            scorePeriod = new Label () {
                Text = "for Unknown Period",
                FontAttributes = FontAttributes.Italic,
                FontSize = 12,
            };

            var buttonStyle = new Style (typeof(Button)) {
                Setters = {
                    new Setter { Property = Button.TextColorProperty, Value = Color.White, },
                    new Setter { Property = Button.BackgroundColorProperty, Value = Color.Teal, },
                    new Setter { Property = Button.BorderRadiusProperty, Value = 5 },
                    new Setter { Property = Button.HeightRequestProperty, Value = 50 }
                }
            };

            var btnShowSteps = new Button {
                Text = "Earn points using Job Search Steps",
                Style = buttonStyle,
            };
            btnShowSteps.Clicked += async (sender, e) => {
                await this.Navigation.PushAsync (new MainStepsPage ());
            };

            var btnSpeak = new Button {
                Text = "Hear some Encouraging Words",
                Style = buttonStyle,
            };
            btnSpeak.Clicked += (sender, e) => {
                encourage = encouragements [myRandom.Next (0, encouragements.Length)];
                DependencyService.Get<ITextToSpeech> ().Speak (
                    string.Format("{0}, {1}. You have {2}",  App.AppSettings.Name, encourage, scoreBox.Text));
            };

            // Two buttons: one for starting a new period, the other for wiping-out the database
            var btnNewPeriod = new Button {
                Text = "Start New Scoring Period",
                Style = buttonStyle,
            };
            btnNewPeriod.Clicked += async(sender, e) => {
                var action = await DisplayActionSheet ("Start a new period?", "No", "Yes");
                if (action.StartsWith ("N"))
                    return;
                if (App.Database.SavePeriod () != 1) {
                    throw new Exception ("Cannot create new Period!");
                }
                this.OnAppearing ();
            };

            var btnPeriods = new Button {
                Text = "Show Score Period History",
                Style = buttonStyle,
            };
            btnPeriods.Clicked += async (sender, e) => {
                await this.Navigation.PushAsync (new HistoryPage ());
            };

            //			var btnFb = new Button {
            //				Text = "Share my Score on Facebook",
            //				Style = buttonStyle,
            //			};
            //			btnFb.Clicked  += (sender, e) => {
            //				Device.OpenUri(new Uri("http://jobtransition.net"));
            //			};

            var btnLaunchJTSG = new Button {
                Text = "Take me to Job Transition Website",
                Style = buttonStyle,
            };
            btnLaunchJTSG.Clicked += (sender, e) => {
                Device.OpenUri (new Uri ("http://jobtransition.net"));
            };

            var btnSettings = new Button {
                Text = "Update Settings",
                Style = buttonStyle,
            };
            btnSettings.Clicked += async (sender, e) => {
                _settingsPage.BindingContext = App.AppSettings;
                await this.Navigation.PushModalAsync (_settingsPage);
            };

            ScrollView scrollView = new ScrollView ();
            var stackLayout = new StackLayout {
                Padding = new Thickness (8, 8),
                Children = {
                    welcomeLabel,
                    scoreBox,
                    scorePeriod,
                    btnShowSteps,
                    btnSpeak,
                    btnNewPeriod,
                    btnPeriods,
            //					btnFb,
                    btnLaunchJTSG,
                    btnSettings,
                }
            };
            scrollView.Content = stackLayout;
            this.Content = scrollView;
        }
コード例 #2
0
        public StartPage()
        {
            Title = "Job Search Scorecard";

            NavigationPage.SetHasBackButton(this, false);               // no back button from this screen!

            App.AppSettings = App.Database.GetSettings();
            if (App.AppSettings == null)
            {
                App.AppSettings = new Settings();
                App.Database.SaveSettings(App.AppSettings);
                _settingsPage = new SettingsPage(true);                   // tell Settings that it's Name-entry only
                _settingsPage.BindingContext = App.AppSettings;           // first time Settings (no Cancel)
                this.Navigation.PushModalAsync(_settingsPage);
            }
            else
            {
                _settingsPage = new SettingsPage(false);
            }
            ;

            welcomeLabel = new Label()
            {
                FontSize          = 22,
                FontAttributes    = FontAttributes.Italic,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
            };
            welcomeLabel.Text = String.Format("Welcome to Job Seeker Scorecard, friend!");


            MessagingCenter.Subscribe <SettingsPage> (this, "popped", (sender) => {
                OnAppearing();
            });

            if (firstTime)                // first time in this screen for this execution, but not necessarily first time in app
            {
                firstTime = false;
                ActivityTable.BuildActivitiesDictionary();                   // build the table of potential tasks (aka Activity list)
                //currentTasks = MockUpTasks ();  // if you wish to mock-up some completed tasks
                Debug.WriteLine("Built Activities Dictionary with : " + Activity.UniqueCode + " unique entries");
                Debug.WriteLine("Database Table Counts at Start-Up:");
                Debug.WriteLine("[Task] has " + App.Database.GetTasks().Count() + " rows");
                Debug.WriteLine("[Period] has " + App.Database.GetPeriods().Count() + " rows");
            }              // first-time

            scoreBox = new Label()
            {
                Text              = "No Score",
                FontSize          = 55,
                FontAttributes    = FontAttributes.Bold,
                HorizontalOptions = LayoutOptions.Center
            };              // Text set in the OnAppearing override in order to grab latest total score

            scorePeriod = new Label()
            {
                Text           = "for Unknown Period",
                FontAttributes = FontAttributes.Italic,
                FontSize       = 12,
            };

            var buttonStyle = new Style(typeof(Button))
            {
                Setters =
                {
                    new Setter {
                        Property = Button.TextColorProperty, Value = Color.White,
                    },
                    new Setter {
                        Property = Button.BackgroundColorProperty, Value = Color.Teal,
                    },
                    new Setter {
                        Property = Button.BorderRadiusProperty, Value = 5
                    },
                    new Setter {
                        Property = Button.HeightRequestProperty, Value = 50
                    }
                }
            };

            var btnShowSteps = new Button {
                Text  = "Earn points using Job Search Steps",
                Style = buttonStyle,
            };

            btnShowSteps.Clicked += async(sender, e) => {
                await this.Navigation.PushAsync(new MainStepsPage());
            };

            var btnSpeak = new Button {
                Text  = "Hear some Encouraging Words",
                Style = buttonStyle,
            };

            btnSpeak.Clicked += (sender, e) => {
                encourage = encouragements [myRandom.Next(0, encouragements.Length)];
                DependencyService.Get <ITextToSpeech> ().Speak(
                    string.Format("{0}, {1}. You have {2}", App.AppSettings.Name, encourage, scoreBox.Text));
            };

            // Two buttons: one for starting a new period, the other for wiping-out the database
            var btnNewPeriod = new Button {
                Text  = "Start New Scoring Period",
                Style = buttonStyle,
            };

            btnNewPeriod.Clicked += async(sender, e) => {
                var action = await DisplayActionSheet("Start a new period?", "No", "Yes");

                if (action.StartsWith("N"))
                {
                    return;
                }
                if (App.Database.SavePeriod() != 1)
                {
                    throw new Exception("Cannot create new Period!");
                }
                this.OnAppearing();
            };

            var btnPeriods = new Button {
                Text  = "Show Score Period History",
                Style = buttonStyle,
            };

            btnPeriods.Clicked += async(sender, e) => {
                await this.Navigation.PushAsync(new HistoryPage());
            };


//			var btnFb = new Button {
//				Text = "Share my Score on Facebook",
//				Style = buttonStyle,
//			};
//			btnFb.Clicked  += (sender, e) => {
//				Device.OpenUri(new Uri("http://jobtransition.net"));
//			};

            var btnLaunchJTSG = new Button {
                Text  = "Take me to Job Transition Website",
                Style = buttonStyle,
            };

            btnLaunchJTSG.Clicked += (sender, e) => {
                Device.OpenUri(new Uri("http://jobtransition.net"));
            };

            var btnSettings = new Button {
                Text  = "Update Settings",
                Style = buttonStyle,
            };

            btnSettings.Clicked += async(sender, e) => {
                _settingsPage.BindingContext = App.AppSettings;
                await this.Navigation.PushModalAsync(_settingsPage);
            };

            ScrollView scrollView  = new ScrollView();
            var        stackLayout = new StackLayout {
                Padding  = new Thickness(8, 8),
                Children =
                {
                    welcomeLabel,
                    scoreBox,
                    scorePeriod,
                    btnShowSteps,
                    btnSpeak,
                    btnNewPeriod,
                    btnPeriods,
//					btnFb,
                    btnLaunchJTSG,
                    btnSettings,
                }
            };

            scrollView.Content = stackLayout;
            this.Content       = scrollView;
        }