public QuestionsScreen()
        {
            //instantiates the camera class for use
            //to take images
            cameraOps = new Camera();

            //creating layouts to store each of the images within the grid
            //without this the background of the grid is white when we want
            //it to be black
            #region imageIconLayouts
 
            StackLayout logoLayout = new StackLayout
            {
                BackgroundColor = Color.Black,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Padding = new Thickness(4, 0, 0, 0)
            };

            StackLayout questionIconLayout = new StackLayout
            {
                BackgroundColor = Color.Black,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Padding = new Thickness(0, 2, 0, 0)
            };

            StackLayout triviaIconLayout = new StackLayout
            {
                BackgroundColor = Color.Black,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Padding = new Thickness(0, 2, 0, 0)
            };

            StackLayout taskIconLayout = new StackLayout
            {
                BackgroundColor = Color.Black,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Padding = new Thickness(0, 2, 0, 0)
            };

            StackLayout cameraIconLayout = new StackLayout
            {
                BackgroundColor = Color.Black,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Padding = new Thickness(0, 2, 0, 0)
            };

            #endregion

            //stacklayout to host the questions editor, and scrollview
            //this is necessary because without it the scrollview
            //will override the grid layout and flow out of the grid
            StackLayout questionContent = new StackLayout
            {
                Padding = new Thickness(3, 0, 4, 0),
                BackgroundColor = Color.Black
            };

            MyEditor questions = new MyEditor
            {
                Text = "",
                Keyboard = Keyboard.Default,
                BackgroundColor = Color.Black,
            };

            questionTypeLabel = new Label
            {
                Text = "Activity Tasks",
                TextColor = Color.White,
                BackgroundColor = Color.Black,
                FontSize = 20
            };

            //try load from file
            loadText(questions, currentFile);

            //when questions editor is unfocused save
            questions.Unfocused += (sender, e) =>
            {
                saveText(questions, currentFile);
            };

            //scrollview for the question editor
            ScrollView questionText = new ScrollView
            {
                IsClippedToBounds = true,
                Content = questions
            };

            questionContent.Children.Add(questionTypeLabel);
            questionContent.Children.Add(questionText);
            //questionContent.Children.Add(scrollViewFix);

            //creating each of the image icons for
            //the grid with their tap commands to load
            //correct file
            #region imageIcons

            Image logo = new Image
            {
                Source = "QutLogoWhite.png",
                HeightRequest = (App.screenHeight / 12) - 4,
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions = LayoutOptions.CenterAndExpand
            };

            Image cameraIcon = new Image
            {
                Source = "cameraIcon.png",
                HeightRequest = (App.screenHeight / 12) - 4,
                WidthRequest = 30
            };

            Image questionIcon = new Image
            {
                Source = "questionIcon.png",
                HeightRequest = (App.screenHeight / 12) - 4,
                WidthRequest = 30
            };

            Image triviaIcon = new Image
            {
                Source = "triviaIcon.png",
                BackgroundColor = Color.Black,
                HeightRequest = (App.screenHeight / 12) - 4,
                WidthRequest = 30
            };

            Image taskIcon = new Image
            {
                Source = "taskIcon.png",
                HeightRequest = (App.screenHeight / 12) - 4,
                WidthRequest = 30
            };

            questionIcon.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(() => loadText(questions, "activity" + App.currentActivity + "Questions.txt"))
            });

            triviaIcon.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(() => loadText(questions, "activity" + App.currentActivity + "Trivia.txt"))
            });

            taskIcon.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(() => loadText(questions, "activity" + App.currentActivity + "Tasks.txt")),
            });

            cameraIcon.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(() => takePicture()),
            });

            #endregion

            //adding each of the image icons to the relevant layout
            questionIconLayout.Children.Add(questionIcon);
            triviaIconLayout.Children.Add(triviaIcon);
            taskIconLayout.Children.Add(taskIcon);
            cameraIconLayout.Children.Add(cameraIcon);
            logoLayout.Children.Add(logo);

            //creating a new 5x8 grid
            Grid pageGrid = new Grid
            {
                VerticalOptions = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                BackgroundColor = Color.White,
                Opacity = 0.8,
                //row and column spacing creates a "bordered"
                //effect around each element
                RowSpacing = 2,
                ColumnSpacing = 2,
                IsClippedToBounds = true,
                Padding = new Thickness(.5, 1, .5, 0),
                //all row heights, and column widths are relative to
                //the devices screen size/resolution so they should
                //be an appropriate size on each type of device
                RowDefinitions = {
                    new RowDefinition {Height = 0},
                    new RowDefinition {Height = App.screenHeight / 12},
                    new RowDefinition {Height = App.screenHeight / 1.35},
                    new RowDefinition {Height = App.screenHeight / 12},
                    new RowDefinition {Height = 0}
                },
                ColumnDefinitions = 
                {
                    new ColumnDefinition {Width = 0},
                    new ColumnDefinition {Width = App.screenWidth / 10},
                    new ColumnDefinition {Width = App.screenWidth / 5 - 32},
                    new ColumnDefinition {Width = App.screenWidth / 5},
                    new ColumnDefinition {Width = App.screenWidth / 5},
                    new ColumnDefinition {Width = App.screenWidth / 5},
                    new ColumnDefinition {Width = App.screenWidth / 10},
                    new ColumnDefinition {Width = 0}
                }
            };

            Label backLbl = new Label
            {
                Text = "<",
                BackgroundColor = Color.Black,
                TextColor = Color.White,
                FontSize = 24,
                XAlign = TextAlignment.Center,
                YAlign = TextAlignment.Center
            };

            backLbl.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(() => goBack())
            }); 

            Label nextLbl = new Label
            {
                Text = ">",
                BackgroundColor = Color.Black,
                TextColor = Color.White,
                FontSize = 24,
                XAlign = TextAlignment.Center,
                YAlign = TextAlignment.Center
            };

            nextLbl.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(() => goToNextActivity()),
            }); 


            //adding each element to the grid
            pageGrid.Children.Add(backLbl, 1, 1); //back button

            pageGrid.Children.Add(logoLayout, 2, 7, 1, 2); //qut logo

            pageGrid.Children.Add(questionContent, 1, 7, 2, 3); //scrolling editor text

            pageGrid.Children.Add(questionIconLayout, 1, 3, 3, 4); //questions button

            pageGrid.Children.Add(triviaIconLayout, 3, 3); //trivia button

            pageGrid.Children.Add(taskIconLayout, 4, 3); //tasks button

            pageGrid.Children.Add(cameraIconLayout, 5, 3); //camera button

            pageGrid.Children.Add(nextLbl, 6, 3); //next activity button

            //creating a stacklayout and adding the grid to it
            StackLayout innerContent = new StackLayout
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.Center,
            };

            innerContent.Children.Add(pageGrid);

            //making the pages content the stacklayout with the grid
            this.Content = innerContent;

            //add padding to account for the iOS status bar
            this.Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);
            this.BackgroundImage = "background.png";

            //when the editor with the questions is unfocused
            //invalidate it so that it reformats the height
            questions.TextChanged += (s, e) =>
            {
                reformatEditorHeight(questions);
            };

            //on iOS when you click the text in the editor, it doesn't
            //automatically scroll the editor down to where the text is
            //with this added functionality when the question editor is
            //focused it should scroll to the position the user clicked
            //and when unfocused scroll back to the beginning of the
            //editor element.
            if (Device.OS == TargetPlatform.iOS)
            {
                questions.Focused += (s, e) =>
                {
                    double scrollPosition = questions.Y;
                    questionText.ScrollToAsync(0, scrollPosition, false);
                };

                questions.Unfocused += (s, e) =>
                {
                    questionText.ScrollToAsync(0, 0, false);
                };
            }
        }
Exemple #2
0
        public QuestionsScreen()
        {
            //instantiates the camera class for use
            //to take images
            cameraOps = new Camera();

            //creating layouts to store each of the images within the grid
            //without this the background of the grid is white when we want
            //it to be black
            #region imageIconLayouts
 
            StackLayout logoLayout = new StackLayout
            {
                BackgroundColor = App.QUTBlue,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Padding = new Thickness(4, 0, 0, 0)
            };

            StackLayout questionIconLayout = new StackLayout
            {
                BackgroundColor = Color.Black,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Padding = new Thickness(0, 2, 0, 0)
            };

            StackLayout triviaIconLayout = new StackLayout
            {
                BackgroundColor = Color.Black,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Padding = new Thickness(0, 2, 0, 0)
            };

            StackLayout taskIconLayout = new StackLayout
            {
                BackgroundColor = Color.Black,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Padding = new Thickness(0, 2, 0, 0)
            };

            StackLayout cameraIconLayout = new StackLayout
            {
                BackgroundColor = Color.Black,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions = LayoutOptions.FillAndExpand,
                Padding = new Thickness(0, 2, 0, 0)
            };

            #endregion

            //creating each of the image icons for
            //the grid with their tap commands to load
            //correct file
            #region imageIcons and gesture commands

            Image logo = new Image
            {
                Source = "QutLogoHeader.png",
                BackgroundColor = App.QUTBlue,
                HeightRequest = (App.screenHeight / 10) - 4,
                HorizontalOptions = LayoutOptions.StartAndExpand,
                VerticalOptions = LayoutOptions.CenterAndExpand
            };

            Image cameraIcon = new Image
            {
                Source = "cameraIcon.png",
                HeightRequest = (App.screenHeight / 12) - 4,
                WidthRequest = 30
            };

            Image questionIcon = new Image
            {
                Source = "questionIcon.png",
                HeightRequest = (App.screenHeight / 12) - 4,
                WidthRequest = 30
            };

            Image triviaIcon = new Image
            {
                Source = "triviaIcon.png",
                HeightRequest = (App.screenHeight / 12) - 4,
                WidthRequest = 30
            };

            Image taskIcon = new Image
            {
                Source = "taskIcon.png",
                HeightRequest = (App.screenHeight / 12) - 4,
                WidthRequest = 30
            };

            questionIcon.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(() => changeQuestions(1))
            });

            triviaIcon.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(() => changeQuestions(2))
            });

            taskIcon.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(() => changeQuestions(3)),
            });

            cameraIcon.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(() => takePicture()),
            });

            #endregion

            questionTypeLabel = new Label
            {
                Text = "Activity Tasks",
                TextColor = Color.White,
                BackgroundColor = Color.Black,
                FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label))
            };

            questionContent.Children.Add(questionTypeLabel);

            //adding each of the image icons to the relevant layout
            questionIconLayout.Children.Add(questionIcon);
            triviaIconLayout.Children.Add(triviaIcon);
            taskIconLayout.Children.Add(taskIcon);
            cameraIconLayout.Children.Add(cameraIcon);
            logoLayout.Children.Add(logo);

            //creating a new 5x8 grid
            Grid pageGrid = new Grid
            {
                VerticalOptions = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.CenterAndExpand,
                BackgroundColor = Color.White,
                Opacity = 0.8,
                //row and column spacing creates a "bordered"
                //effect around each element
                RowSpacing = 2,
                ColumnSpacing = 2,
                IsClippedToBounds = true,
                Padding = new Thickness(.5, 1, .5, 0),
                //all row heights, and column widths are relative to
                //the devices screen size/resolution so they should
                //be an appropriate size on each type of device
                RowDefinitions = {
                    new RowDefinition {Height = 0},
                    new RowDefinition {Height = App.screenHeight / 10},
                    new RowDefinition {Height = App.screenHeight / 1.35},
                    new RowDefinition {Height = App.screenHeight / 12},
                    new RowDefinition {Height = 0}
                },
                ColumnDefinitions = 
                {
                    new ColumnDefinition {Width = 0},
                    new ColumnDefinition {Width = App.screenWidth / 10},
                    new ColumnDefinition {Width = App.screenWidth / 5 - 32},
                    new ColumnDefinition {Width = App.screenWidth / 5},
                    new ColumnDefinition {Width = App.screenWidth / 5},
                    new ColumnDefinition {Width = App.screenWidth / 5},
                    new ColumnDefinition {Width = App.screenWidth / 10},
                    new ColumnDefinition {Width = 0}
                }
            };

            Label backLbl = new Label
            {
                Text = "<",
                BackgroundColor = App.QUTBlue,
                TextColor = Color.White,
                FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)) + 4,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment = TextAlignment.Center
            };

            backLbl.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(() => goBack())
            }); 

            Label nextLbl = new Label
            {
                Text = ">",
                BackgroundColor = Color.Black,
                TextColor = Color.White,
                FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)) + 4,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment = TextAlignment.Center
            };

            nextLbl.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(() => goToNextActivity()),
            });

            loadContentIntoStackLayout();
            questionContent.Children.Add(activitySetContent);

            //adding each element to the grid
            pageGrid.Children.Add(backLbl, 1, 1); //back button

            pageGrid.Children.Add(logoLayout, 2, 7, 1, 2); //qut logo

            pageGrid.Children.Add(questionContent, 1, 7, 2, 3); //stacklayout hosting the content scrollview

            pageGrid.Children.Add(questionIconLayout, 1, 3, 3, 4); //questions button

            pageGrid.Children.Add(triviaIconLayout, 3, 3); //trivia button

            pageGrid.Children.Add(taskIconLayout, 4, 3); //tasks button

            pageGrid.Children.Add(cameraIconLayout, 5, 3); //camera button

            pageGrid.Children.Add(nextLbl, 6, 3); //next activity button

            //creating a stacklayout and adding the grid to it
            StackLayout innerContent = new StackLayout
            {
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.Center,
            };

            innerContent.Children.Add(pageGrid);

            //making the pages content the stacklayout with the grid
            this.Content = innerContent;

            //add padding to account for the iOS status bar
            this.Padding = new Thickness(0, Device.OnPlatform(20, 0, 0), 0, 0);
            this.BackgroundImage = "background.png";
        }