Exemple #1
1
        private ScrollView GenerateOptionLayout()
        {
            var stack = new StackLayout { Orientation = StackOrientation.Vertical };

            var peak = new Entry { Keyboard = Keyboard.Numeric, Placeholder = "Peak" };
            peak.SetBinding(Entry.TextProperty, OptionViewModel.PeakCommandPropertyName);
            stack.Children.Add(peak);

            var distance = new Entry { Keyboard = Keyboard.Numeric, Placeholder = "Distance" };
            distance.SetBinding(Entry.TextProperty, OptionViewModel.DistanceCommandPropertyName);
            stack.Children.Add(distance);

            var dogAllowed = new Switch();
            dogAllowed.SetBinding(Switch.IsToggledProperty, OptionViewModel.DogAllowedCommandPropertyName);
            stack.Children.Add(dogAllowed);

            var goodForKids = new Switch();
            goodForKids.SetBinding(Switch.IsToggledProperty, OptionViewModel.GoodForKidsCommandPropertyName);
            stack.Children.Add(goodForKids);

            var seasonStart = new Picker { Title = "SeasonStart" };
            foreach (var season in options.Seasons)
            {
                seasonStart.Items.Add(season.Value);
            }
            seasonStart.SetBinding(Picker.SelectedIndexProperty, OptionViewModel.SeasonStartCommandPropertyName);
            stack.Children.Add(seasonStart);

            var seasonEnd = new Picker { Title = "SeasonEnd" };
            foreach (var season in options.Seasons)
            {
                seasonEnd.Items.Add(season.Value);
            }
            seasonEnd.SetBinding(Picker.SelectedIndexProperty, OptionViewModel.SeasonEndCommandPropertyName);
            stack.Children.Add(seasonEnd);

            var trailType = new Picker() { Title = "Trail Type" };
            stack.Children.Add(trailType);
            foreach (var type in options.TrailsTypes)
            {
                trailType.Items.Add(type.Value);
            }
            trailType.SetBinding(Picker.SelectedIndexProperty, OptionViewModel.TypeCommandPropertyName);

            var trailDurationType = new Picker() { Title = "Trail Duration Type" };
            foreach (var durType in options.TrailsDurationTypes)
            {
                trailDurationType.Items.Add(durType.Value);
            }
            trailDurationType.SetBinding(Picker.SelectedIndexProperty, OptionViewModel.DurationTypeCommandPropertyName);
            stack.Children.Add(trailDurationType);

            var button = GenericsContent.GenerateDefaultButton("Update");
            button.SetBinding(Button.CommandProperty, OptionViewModel.UpdateCommandPropertyName);
            stack.Children.Add(button);

            return new ScrollView { Content = stack };
        }
		public TodoItemPage ()
		{
			this.SetBinding (ContentPage.TitleProperty, "Name");

			NavigationPage.SetHasNavigationBar (this, true);
			var nameLabel = new Label { Text = "Name" };
			var nameEntry = new Entry ();
			
			nameEntry.SetBinding (Entry.TextProperty, "Name");

			var notesLabel = new Label { Text = "Notes" };
			var notesEntry = new Entry ();
			notesEntry.SetBinding (Entry.TextProperty, "Notes");

			var doneLabel = new Label { Text = "Done" };
			var doneEntry = new Xamarin.Forms.Switch ();
			doneEntry.SetBinding (Xamarin.Forms.Switch.IsToggledProperty, "Done");

			var saveButton = new Button { Text = "Save" };
			saveButton.Clicked += (sender, e) => {
				var todoItem = (TodoItem)BindingContext;
				App.Database.SaveItem(todoItem);
				this.Navigation.PopAsync();
			};

			var deleteButton = new Button { Text = "Delete" };
			deleteButton.Clicked += (sender, e) => {
				var todoItem = (TodoItem)BindingContext;
				App.Database.DeleteItem(todoItem.ID);
                this.Navigation.PopAsync();
			};
							
			var cancelButton = new Button { Text = "Cancel" };
			cancelButton.Clicked += (sender, e) => {
				var todoItem = (TodoItem)BindingContext;
                this.Navigation.PopAsync();
			};


			var speakButton = new Button { Text = "Speak" };
			speakButton.Clicked += (sender, e) => {
				var todoItem = (TodoItem)BindingContext;
				DependencyService.Get<ITextToSpeech>().Speak(todoItem.Name + " " + todoItem.Notes);
			};

			Content = new StackLayout {
				VerticalOptions = LayoutOptions.StartAndExpand,
				Padding = new Thickness(20),
				Children = {
					nameLabel, nameEntry, 
					notesLabel, notesEntry,
					doneLabel, doneEntry,
					saveButton, deleteButton, cancelButton,
					speakButton
				}
			};
		}
Exemple #3
0
        public TodoItemPage()
        {
            this.SetBinding(ContentPage.TitleProperty, "Name");

            NavigationPage.SetHasNavigationBar(this, true);
            var nameLabel = new Label {
                Text = "Name"
            };
            var nameEntry = new Entry();

            nameEntry.SetBinding(Entry.TextProperty, "Name");

            var notesLabel = new Label {
                Text = "Notes"
            };
            var notesEntry = new Entry();

            notesEntry.SetBinding(Entry.TextProperty, "Notes");

            var doneLabel = new Label {
                Text = "Done"
            };
            var doneEntry = new Xamarin.Forms.Switch();

            doneEntry.SetBinding(Xamarin.Forms.Switch.IsToggledProperty, "Done");

            var saveButton = new Button {
                Text = "Save"
            };

            saveButton.Clicked += (sender, e) => {
                var todoItem = (TodoItem)BindingContext;
                App.Database.SaveItem(todoItem);
                this.Navigation.PopAsync();
            };

            var deleteButton = new Button {
                Text = "Delete"
            };

            deleteButton.Clicked += (sender, e) => {
                var todoItem = (TodoItem)BindingContext;
                App.Database.DeleteItem(todoItem._id);
                this.Navigation.PopAsync();
            };

            var cancelButton = new Button {
                Text = "Cancel"
            };

            cancelButton.Clicked += (sender, e) => {
                var todoItem = (TodoItem)BindingContext;
                this.Navigation.PopAsync();
            };


            var speakButton = new Button {
                Text = "Speak"
            };

            speakButton.Clicked += (sender, e) => {
                var todoItem = (TodoItem)BindingContext;
                DependencyService.Get <ITextToSpeech>().Speak(todoItem.Name + " " + todoItem.Notes);
            };

            Content = new StackLayout {
                VerticalOptions = LayoutOptions.StartAndExpand,
                Padding         = new Thickness(20),
                Children        =
                {
                    nameLabel,  nameEntry,
                    notesLabel, notesEntry,
                    doneLabel,  doneEntry,
                    saveButton, deleteButton,cancelButton,
                    speakButton
                }
            };
        }
Exemple #4
0
        private void ReadQuiz()
        {
            string jsonString = returnJsonString();

            //COnvert the JSON String into a list of objects
            List <RootObject> result = (List <RootObject>)JsonConvert.DeserializeObject(jsonString, typeof(List <RootObject>));

            foreach (var question in result)
            {
                //Only get the results from the corresponding quiz
                if (question.id == ChooseQuiz.quizIdClicked)
                {
                    //This foreach populates only the quesion header
                    foreach (var item in question.questions)
                    {
                        Label questionId = new Label();
                        questionId.Text           = ("Question: " + item.id + " - " + item.text).ToString();
                        questionId.FontSize       = Device.GetNamedSize(NamedSize.Medium, typeof(Label));
                        questionId.FontAttributes = FontAttributes.Bold;

                        Label help = new Label();
                        help.Text = ("Hint: " + item.help);

                        ViewCellHeader = new ViewCell()
                        {
                            View = new StackLayout
                            {
                                Margin          = new Thickness(0, 10, 0, 0),
                                Orientation     = StackOrientation.Vertical,
                                VerticalOptions = LayoutOptions.Center,
                                Children        =
                                {
                                    new StackLayout
                                    {
                                        Orientation = StackOrientation.Vertical,
                                        Children    =
                                        {
                                            questionId,
                                            help
                                        }
                                    }
                                }
                            }
                        };


                        //This manages the date fields and textboxes
                        if (item.type == "date" || item.type == "Date" || item.type == "textbox")
                        {
                            //For single Line entries
                            Entry singleLineEntry = new Entry();

                            //Get existing data from saved file (if it exists)
                            singleLineEntry.Text = myAnswerManager.ProvideAnswerText(item.id);

                            ViewCell ViewCellAnswer = new ViewCell()
                            {
                                View = new StackLayout
                                {
                                    Orientation     = StackOrientation.Vertical,
                                    VerticalOptions = LayoutOptions.Center,
                                    Children        =
                                    {
                                        singleLineEntry
                                    }
                                }
                            };

                            //Update the Answers if the user leaves the UI element
                            singleLineEntry.Unfocused += (sender, e) =>
                            {
                                myAnswerManager.UpdateAnswerList(item.id, false, false, singleLineEntry.Text);
                            };

                            section.Add(ViewCellHeader);
                            section.Add(ViewCellAnswer);
                        }

                        //this manages the textareas
                        if (item.type == "textarea")
                        {
                            //For single Line entries
                            Editor multilineEditor = new Editor {
                                HeightRequest = 50
                            };

                            //Get existing data from saved file (if it exists)
                            multilineEditor.Text = myAnswerManager.ProvideAnswerText(item.id);

                            ViewCell ViewCellAnswer = new ViewCell()
                            {
                                View = new StackLayout
                                {
                                    Orientation = StackOrientation.Vertical,
                                    Children    =
                                    {
                                        multilineEditor
                                    }
                                }
                            };

                            //Update the Answers if the user leaves the UI element
                            multilineEditor.Unfocused += (sender, e) =>
                            {
                                myAnswerManager.UpdateAnswerList(item.id, false, false, multilineEditor.Text);
                            };

                            section.Add(ViewCellHeader);
                            section.Add(ViewCellAnswer);
                        }



                        if (item.type == "choice" || item.type == "options")
                        {
                            Picker pickerView = new Picker
                            {
                                Title           = "Pick one",
                                BackgroundColor = Xamarin.Forms.Color.LightGray,
                                VerticalOptions = LayoutOptions.Center
                            };

                            foreach (var pickerItem in item.options)
                            {
                                pickerView.Items.Add(pickerItem);
                            }

                            //Get existing data from saved file (if it exists)
                            String answerText = myAnswerManager.ProvideAnswerText(item.id);

                            if (answerText != "")
                            {
                                pickerView.SelectedIndex = Convert.ToInt32(answerText);
                            }

                            ViewCell ViewCellAnswer = new ViewCell()
                            {
                                View = new StackLayout
                                {
                                    Orientation = StackOrientation.Vertical,
                                    Children    =
                                    {
                                        pickerView
                                    }
                                }
                            };

                            //Update the Answers if the user leaves the UI element
                            pickerView.Unfocused += (sender, e) =>
                            {
                                myAnswerManager.UpdateAnswerList(item.id, false, false, pickerView.SelectedIndex.ToString());
                            };

                            section.Add(ViewCellHeader);
                            section.Add(ViewCellAnswer);
                        }

                        if (item.type == "slidingoption")
                        {
                            //Get existing data from saved file (if it exists)
                            String answerText     = myAnswerManager.ProvideAnswerText(item.id);
                            float  answerPosition = 1.0f;

                            if (answerText != "")
                            {
                                answerPosition = float.Parse(answerText);
                            }

                            sliderView = new Slider
                            {
                                Minimum         = 0.0f,
                                Maximum         = 2.0f,
                                Value           = answerPosition,
                                VerticalOptions = LayoutOptions.Center
                            };

                            OptionItems      = new List <string>();
                            OptionItemsImage = new List <string>();

                            foreach (var optionItem in item.options)
                            {
                                OptionItems.Add(optionItem);
                            }

                            foreach (var optionItem in item.optionVisuals)
                            {
                                OptionItemsImage.Add(optionItem);
                            }

                            sliderPositionText = new Label
                            {
                                Text = OptionItems[Convert.ToInt32(sliderView.Value)]
                            };

                            sliderPositionImage = new Label
                            {
                                Text = OptionItemsImage[Convert.ToInt32(sliderView.Value)]
                            };

                            //Update the Answers if the user changes theslider value
                            sliderView.ValueChanged += (sender, e) =>
                            {
                                //https://forums.xamarin.com/discussion/22473/can-you-limit-a-slider-to-only-allow-integer-values-hopefully-snapping-to-the-next-integer
                                var newStep = Math.Round(e.NewValue / 1.0);

                                sliderView.Value = newStep * 1.0;

                                sliderPositionText.Text  = OptionItems[Convert.ToInt32(sliderView.Value)];
                                sliderPositionImage.Text = OptionItemsImage[Convert.ToInt32(sliderView.Value)];

                                myAnswerManager.UpdateAnswerList(item.id, false, false, sliderView.Value.ToString());
                            };

                            ViewCell ViewCellAnswer = new ViewCell()
                            {
                                View = new StackLayout
                                {
                                    Orientation = StackOrientation.Vertical,
                                    Children    =
                                    {
                                        sliderView,
                                        sliderPositionText,
                                        sliderPositionImage
                                    }
                                }
                            };

                            section.Add(ViewCellHeader);
                            section.Add(ViewCellAnswer);
                        }

                        if (item.type == "scale")
                        {
                            //Get existing data from saved file (if it exists)
                            String answerText     = myAnswerManager.ProvideAnswerText(item.id);
                            double answerPosition = Convert.ToDouble(item.end * 0.5f);

                            if (answerText != "")
                            {
                                answerPosition = double.Parse(answerText);
                            }

                            Stepper stepperView = new Stepper
                            {
                                Minimum         = Convert.ToDouble(item.start),
                                Maximum         = Convert.ToDouble(item.end),
                                Value           = answerPosition,
                                VerticalOptions = LayoutOptions.Center,
                                Increment       = Convert.ToDouble(item.increment)

                                                  //Here I was also wanting to utilise the colouring of the slider
                                                  //but I could not seem to bring up the MinimumTrackTintColor and
                                                  //MaximumTrackTintColor methods. If I could have done this then I
                                                  //would have applied the gradients.
                            };

                            Label stepperValue = new Label
                            {
                                Text = stepperView.Value.ToString()
                            };

                            StepperChange myStepperChange = new StepperChange();

                            myStepperChange.setLabel(stepperValue);

                            //This is a hack here. I did it this way so that multiple steppers do not interfere with each other
                            stepperView.ValueChanged += (sender, e) =>
                            {
                                //See how I have pased on (sender, e)
                                myStepperChange.OnStepperValueChanged(sender, e);
                                myAnswerManager.UpdateAnswerList(item.id, false, false, stepperView.Value.ToString());
                            };

                            ViewCell ViewCellAnswer = new ViewCell()
                            {
                                View = new StackLayout
                                {
                                    Orientation = StackOrientation.Vertical,
                                    Children    =
                                    {
                                        stepperView,
                                        stepperValue
                                    }
                                }
                            };

                            section.Add(ViewCellHeader);
                            section.Add(ViewCellAnswer);
                        }


                        if (item.type == "multiplechoice")
                        {
                            //This approach was referenced from http://proquestcombo.safaribooksonline.com.ezproxy-b.deakin.edu.au/video/programming/mobile/9781771373371#

                            multipleChoiceAnswers = new List <MultipleChoiceAnswer>();

                            //Get existing data from saved file (if it exists) and load into a List
                            foreach (var optionItem in item.options)
                            {
                                multipleChoiceAnswers.Add(new MultipleChoiceAnswer(optionItem, myAnswerManager.ProvideAnswerMultipleChoice(item.id, optionItem)));
                            }

                            ListView listView = new ListView
                            {
                                ItemsSource = multipleChoiceAnswers,

                                ItemTemplate = new DataTemplate(() => {
                                    Label lblDescription = new Label();
                                    lblDescription.SetBinding(Label.TextProperty, "Description");

                                    Label lblIsChecked = new Label();
                                    lblIsChecked.SetBinding(Label.TextProperty, "IsCheckedString");

                                    Xamarin.Forms.Switch swIsChecked = new Xamarin.Forms.Switch();
                                    swIsChecked.SetBinding(Xamarin.Forms.Switch.IsToggledProperty, "isChecked");

                                    //Update the Answers if the user changes the UI element
                                    swIsChecked.Toggled += (sender, e) => // I got this line from https://stackoverflow.com/questions/32975894/xamarin-forms-switch-sends-toggled-event-when-value-is-updated
                                    {
                                        if (e != null)
                                        {
                                            var optionText = lblDescription.Text;

                                            foreach (var multianswer in multipleChoiceAnswers)
                                            {
                                                if (multianswer.Description == optionText)
                                                {
                                                    if (multianswer.isChecked == true)
                                                    {
                                                        multianswer.isChecked = false;
                                                        //Save the toggle
                                                        myAnswerManager.UpdateAnswerList(item.id, true, false, lblDescription.Text);
                                                    }
                                                    else
                                                    {
                                                        multianswer.isChecked = true;
                                                        //Save the toggle
                                                        myAnswerManager.UpdateAnswerList(item.id, true, true, lblDescription.Text);
                                                    }
                                                    lblIsChecked.Text = multianswer.IsCheckedString;
                                                }
                                            }
                                        }
                                    };

                                    return(new ViewCell
                                    {
                                        Height = 100,
                                        View = new StackLayout
                                        {
                                            Orientation = StackOrientation.Horizontal,
                                            HorizontalOptions = LayoutOptions.StartAndExpand,
                                            Children =
                                            {
                                                new StackLayout {
                                                    VerticalOptions = LayoutOptions.Center,
                                                    Spacing = 0,
                                                    Children =
                                                    {
                                                        swIsChecked
                                                    }
                                                },
                                                new StackLayout {
                                                    VerticalOptions = LayoutOptions.Center,
                                                    Spacing = 0,
                                                    Children =
                                                    {
                                                        lblDescription,
                                                        lblIsChecked
                                                    }
                                                }
                                            }
                                        }
                                    });
                                }


                                                                )
                            };


                            ViewCell ViewCellAnswer = new ViewCell()
                            {
                                View = new StackLayout
                                {
                                    Orientation = StackOrientation.Vertical,
                                    Children    =
                                    {
                                        listView
                                    }
                                }
                            };

                            section.Add(ViewCellHeader);
                            section.Add(ViewCellAnswer);
                        }
                    }
                }
            }
            tblQuizes.Root.Add(section);
        }
		public TodoItemPage ()
		{
			this.SetBinding (ContentPage.TitleProperty, "Name");

			NavigationPage.SetHasNavigationBar (this, true);
			var nameLabel = new Label (); // no Text! localized later
			var nameEntry = new Entry ();
			
			nameEntry.SetBinding (Entry.TextProperty, "Name");

			var notesLabel = new Label (); // no Text! localized later
			var notesEntry = new Entry ();
			notesEntry.SetBinding (Entry.TextProperty, "Notes");

			var doneLabel = new Label (); // no Text! localized later
			var doneEntry = new Switch ();
			doneEntry.SetBinding (Switch.IsToggledProperty, "Done");

			var saveButton = new Button (); // no Text! localized later
			saveButton.Clicked += (sender, e) => {
				var todoItem = (TodoItem)BindingContext;
				App.Database.SaveItem(todoItem);
				this.Navigation.PopAsync();
			};

			var deleteButton = new Button (); // no Text! localized later
			deleteButton.Clicked += (sender, e) => {
				var todoItem = (TodoItem)BindingContext;
				App.Database.DeleteItem(todoItem.ID);
                this.Navigation.PopAsync();
			};
							
			var cancelButton = new Button (); // no Text! localized later
			cancelButton.Clicked += (sender, e) => {
                this.Navigation.PopAsync();
			};

			var speakButton = new Button (); // no Text! localized later
			speakButton.Clicked += (sender, e) => {
				var todoItem = (TodoItem)BindingContext;
				DependencyService.Get<ITextToSpeech>().Speak(todoItem.Name + " " + todoItem.Notes);
			};


			// TODO: Forms Localized text using two different methods:

			// refer to the codebehind for AppResources.resx.designer
			nameLabel.Text = AppResources.NameLabel;
			notesLabel.Text = AppResources.NotesLabel;
			doneLabel.Text = AppResources.DoneLabel;

			// using ResourceManager
			saveButton.Text = AppResources.SaveButton;
			deleteButton.Text = L10n.Localize ("DeleteButton", "Delete");
			cancelButton.Text = L10n.Localize ("CancelButton", "Cancel");
			speakButton.Text = L10n.Localize ("SpeakButton", "Speak");

			// HACK: included as a 'test' for localizing the picker
			// currently not saved to database
			//var dueDateLabel = new Label { Text = "Due" };
			//var dueDatePicker = new DatePicker ();

			Content = new StackLayout {
				VerticalOptions = LayoutOptions.StartAndExpand,
				Padding = new Thickness(20),
				Children = {
					nameLabel, nameEntry, 
					notesLabel, notesEntry,
					doneLabel, doneEntry,
					//dueDateLabel, dueDatePicker,
					saveButton, deleteButton, cancelButton, speakButton
				}
			};
		}
Exemple #6
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            idx        = ((Todo)this.BindingContext).Idx;
            projectIdx = ((Todo)BindingContext).ProjectIdx;
            dao        = new ProjectDao(projectIdx);

            Title = (idx == -1) ? "New Todo" : "Edit Todo";

            var nameLbl = new Label {
                Text = "Name"
            };
            var nameEntry = new Entry();

            nameEntry.SetBinding(Entry.TextProperty, "Name");

            var contentLbl = new Label {
                Text = "Content"
            };
            var contentEntry = new Editor();

            contentEntry.SetBinding(Editor.TextProperty, "Content");

            var deadlineLbl = new Label {
                Text = "Deadline"
            };
            var deadlinePicker = new DatePicker();

            deadlinePicker.SetBinding(DatePicker.DateProperty, "DeadLine");

            var essentialLbl = new Label {
                Text = "Essential"
            };
            var essentialEntry = new Xamarin.Forms.Switch();

            essentialEntry.SetBinding(Switch.IsToggledProperty, "IsEssential");

            var progressLbl = new Label {
                Text = "Progress"
            };

            progressEntry = new Xamarin.Forms.Picker()
            {
                Items =
                {
                    "Before Starting", "Proceeding", "END"
                }
            };
            if (idx != -1)
            {
                string tmp = ((Todo)BindingContext).Progress;

                progressEntry.SelectedIndex = (tmp == "B") ? 0 : (tmp == "P") ? 1 : 2;
            }

            var managerLbl = new Label {
                Text = "Manager"
            };

            getManagers();

            var saveButton = new Button {
                Text = "Save"
            };

            saveButton.Clicked += SaveButton_Clicked;

            var deleteButton = new Button {
                Text = "Delete"
            };

            deleteButton.Clicked += DeleteButton_Clicked;

            var cancelButton = new Button {
                Text = "Cancel"
            };

            cancelButton.Clicked += CancelButton_Clicked;

            var layout = new StackLayout
            {
                VerticalOptions = LayoutOptions.StartAndExpand,
//				Padding = new Thickness(20),
                Children =
                {
                    nameLbl,      nameEntry,
                    contentLbl,   contentEntry,
                    deadlineLbl,  deadlinePicker,
                    essentialLbl, essentialEntry,
                    progressLbl,  progressEntry,
                    managerLbl,   managerEntry,
                    saveButton,   cancelButton,
                }
            };

            if (idx != -1)
            {
                layout.Children.Add(deleteButton);
            }

            ScrollView scrollView = new ScrollView();

            scrollView.Content = layout;

            Content = scrollView;
        }