protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);

            // Create the quote collection and display the current quote
            quoteCollection = new QuoteBank();
            quoteCollection.LoadQuotes();
            quoteCollection.GetNextQuote();

            quotationTextView      = FindViewById <TextView>(Resource.Id.quoteTextView);
            quotationTextView.Text = quoteCollection.CurrentQuote.Quotation;

            scoreTextView      = FindViewById <TextView>(Resource.Id.scoreTextView);
            scoreTextView.Text = score.ToString();

            authorName = FindViewById <EditText>(Resource.Id.authorNameBox);



            // Display another quote when the "Next Quote" button is tapped
            var nextButton = FindViewById <Button>(Resource.Id.nextButton);

            nextButton.Click += delegate
            {
                quoteCollection.GetNextQuote();
                quotationTextView.Text = quoteCollection.CurrentQuote.Quotation;
            };

            var enterButton = FindViewById <Button>(Resource.Id.enterButton);

            enterButton.Click += (object sender, System.EventArgs e) =>
            {
                //string author = authorName.ToString();

                if (authorName.Text == quoteCollection.CurrentQuote.Person) //author matches what the user input )
                {
                    //increase our score
                    ++score;
                    //write to the score box
                    scoreTextView.Text = score.ToString();
                    //say it was right
                    authorName.Text = "You're right, it was :" + quoteCollection.CurrentQuote.Person;
                }
                else // (author doesnt match) maybe just an else not an else/if
                {
                    //decrease score
                    --score;
                    //write to the score box
                    scoreTextView.Text = score.ToString();
                    //say it was wrong
                    authorName.Text = "You're wrong, it was :" + quoteCollection.CurrentQuote.Person; //quoteCollection.CurrentQuote.Person;
                }

                //authorName.Text = Resources.GetString(Resource.String.authorTextView, author);
            };
        }
Exemple #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);

            if (savedInstanceState != null)
            {
                // Deserialized the saved object state

                XmlSerializer x   = new XmlSerializer(typeof(QuoteBank));
                string        xml = savedInstanceState.GetString("Quotes");


                quoteCollection = (QuoteBank)x.Deserialize(new StringReader(xml));
            }
            else
            {
                // Create the quote collection and display the current quote
                quoteCollection = new QuoteBank();
                quoteCollection.LoadQuotes();
                quoteCollection.GetNextQuote();
            }
            quotationTextView      = FindViewById <TextView>(Resource.Id.quoteTextView);
            quotationTextView.Text = quoteCollection.CurrentQuote.Quotation;

            TextView authorTextView = FindViewById <TextView>(Resource.Id.quoteAuthorTextView);

            authorTextView.Text = quoteCollection.CurrentQuote.Person;



            // Display another quote when the "Next Quote" button is tapped
            var nextButton = FindViewById <Button>(Resource.Id.nextButton);

            nextButton.Click += delegate {
                quoteCollection.GetNextQuote();
                quotationTextView.Text = quoteCollection.CurrentQuote.Quotation;
                authorTextView.Text    = quoteCollection.CurrentQuote.Person;
            };

            var saveButton = FindViewById <Button>(Resource.Id.saveButton);

            saveButton.Click += delegate
            {
                Quote q = new Quote();
                q.Quotation = FindViewById <EditText>(Resource.Id.newQuoteText).Text;

                q.Person = FindViewById <EditText>(Resource.Id.newQuoteAuthor).Text;


                quoteCollection.Quotes.Add(q);

                FindViewById <EditText>(Resource.Id.newQuoteAuthor).Text = "";
                FindViewById <EditText>(Resource.Id.newQuoteText).Text   = "";
            };
        }
Exemple #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);

            if (savedInstanceState == null)     //if null, initialization
            {
                // Create the quote collection and load quotes
                quoteCollection = new QuoteBank();
                quoteCollection.LoadQuotes();
            }
            else       //not null, getting infromation from Bundle
            {
                // Deserialized the saved object state
                string        xmlQuoteCollection = savedInstanceState.GetString("Quotes");
                XmlSerializer x = new XmlSerializer(typeof(QuoteBank));
                quoteCollection = (QuoteBank)x.Deserialize(new StringReader(xmlQuoteCollection));
            }

            TextView quotationTextView = FindViewById <TextView>(Resource.Id.quoteTextView);

            quotationTextView.Text = quoteCollection.CurrentQuote.Quotation;
            DisplayScores();

            var whoEditText    = FindViewById <EditText>(Resource.Id.whoEditText);
            var answerTextView = FindViewById <TextView>(Resource.Id.answerTextView);

            // Display another quote when the "Next Quote" button is tapped
            var nextButton = FindViewById <Button>(Resource.Id.nextButton);

            nextButton.Click += delegate {
                quoteCollection.GetNextQuote();
                quotationTextView.Text = quoteCollection.CurrentQuote.Quotation;
            };

            // Enter button
            // Check the user's input with the answer and count scores
            var enterButton = FindViewById <Button>(Resource.Id.enterButton);

            enterButton.Click += delegate {
                if (!quoteCollection.CheckAnswer(whoEditText.Text))       // The answer is incorrect
                {
                    string person = quoteCollection.CurrentQuote.Person;
                    answerTextView.Text = "Wrong! The answer is " + person;

                    DisplayScores();
                    quoteCollection.GetNextQuote();
                    quotationTextView.Text = quoteCollection.CurrentQuote.Quotation;
                    whoEditText.Text       = "";
                }
                else
                {
                    answerTextView.Text = "Correct Answer!";                    // The answer is correct

                    DisplayScores();
                    quoteCollection.GetNextQuote();
                    quotationTextView.Text = quoteCollection.CurrentQuote.Quotation;
                    whoEditText.Text       = "";
                }
            };

            // Reset button
            // Set Scores as 0
            var resetButton = FindViewById <Button>(Resource.Id.resetButton);

            resetButton.Click += delegate
            {
                quoteCollection.ResetScores();
                DisplayScores();
            };
        }
Exemple #4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            // load quotes from bundle
            if (savedInstanceState != null)
            {
                // get string quotes
                string quotes = savedInstanceState.GetString(QUOTE_BUNDLE_KEY);
                // create serializer
                XmlSerializer cereal = new XmlSerializer(typeof(QuoteBank));
                // stringreader
                StringReader reader = new StringReader(quotes);
                // deserializer
                quoteCollection = (QuoteBank)cereal.Deserialize(reader);
            }
            else
            {
                // Create the quote collection and display the current quote
                quoteCollection = new QuoteBank();
                quoteCollection.LoadQuotes();
                quoteCollection.GetNextQuote();
            }

            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Main);


            // get quote text view
            quotationTextView = FindViewById <TextView>(Resource.Id.quoteTextView);
            // get author text view
            authorTextView = FindViewById <TextView>(Resource.Id.authorTextView);
            // initialize text views
            UpdateTextViews();

            // Display another quote when the "Next Quote" button is tapped
            var nextButton = FindViewById <Button>(Resource.Id.nextButton);

            nextButton.Click += delegate {
                quoteCollection.GetNextQuote();
                UpdateTextViews();
            };



            // get edittexts
            quoteEditText  = FindViewById <EditText>(Resource.Id.quoteEditText);
            authorEditText = FindViewById <EditText>(Resource.Id.authorEditText);

            // add new quote when "add new quote" button is pressed
            var addButton = FindViewById <Button>(Resource.Id.addButton);

            addButton.Click += delegate {
                // add new quote
                var newQuote = new Quote()
                {
                    Quotation = quoteEditText.Text, Person = authorEditText.Text
                };

                // stop if edittexts are empty
                if (newQuote.Person.Length < 1 || newQuote.Quotation.Length < 1)
                {
                    return;
                }

                quoteCollection.Quotes.Add(newQuote);
                // display new quote
                UpdateTextViews(newQuote);
                // clear adding edittexts
                quoteEditText.Text  = "";
                authorEditText.Text = "";
            };
        }
Exemple #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Main);

            answerTextView = FindViewById <TextView>(Resource.Id.answerTextView);
            guessEditText  = FindViewById <EditText>(Resource.Id.guessEditText);
            scoreTextView  = FindViewById <TextView>(Resource.Id.scoreTextView);

            if (savedInstanceState != null)
            {
                //Deserialize the QuoteBank object
                string        currentQuotes = savedInstanceState.GetString("QuoteCollection");
                XmlSerializer x             = new XmlSerializer(typeof(QuoteBank));
                quoteCollection = (QuoteBank)x.Deserialize(new StringReader(currentQuotes));

                //get the score from the bundle and display
                right = savedInstanceState.GetInt("Right", 0);
                wrong = savedInstanceState.GetInt("Wrong", 0);
                SetScore();
            }
            else
            {   // Create the quote collection and display the current quote
                quoteCollection = new QuoteBank();
                quoteCollection.LoadQuotes();
                quoteCollection.GetNextQuote();
            }

            quotationTextView      = FindViewById <TextView>(Resource.Id.quoteTextView);
            quotationTextView.Text = quoteCollection.CurrentQuote.Quotation;



            // Display another quote when the "Next Quote" button is tapped
            var nextButton = FindViewById <Button>(Resource.Id.nextButton);

            nextButton.Click += delegate {
                //clear the previous guess and answer
                guessEditText.Text  = "";
                answerTextView.Text = "";

                quoteCollection.GetNextQuote();
                quotationTextView.Text = quoteCollection.CurrentQuote.Quotation;
            };

            var enterButton = FindViewById <Button>(Resource.Id.enterButton);

            enterButton.Click += delegate {
                guess = guessEditText.Text;

                //check to see if correct answer
                Boolean answer = quoteCollection.CheckAnswer(quoteCollection.CurrentQuote, guess);

                //if correct
                if (answer)
                {
                    answerTextView.Text = GetString(Resource.String.CorrectAnswer);
                    right = quoteCollection.Right;
                    SetScore();
                }
                //if not correct
                else
                {
                    wrong = quoteCollection.Wrong;
                    SetScore();
                    person = quoteCollection.CurrentQuote.Person;
                    answerTextView.Text = GetString(Resource.String.IncorrectAnswer) + person;
                }
            };

            var restartButton = FindViewById <Button>(Resource.Id.restartButton);

            restartButton.Click += delegate
            {
                guessEditText.Text  = "";
                answerTextView.Text = "";
                scoreTextView.Text  = "";

                right = 0;
                wrong = 0;

                quoteCollection = new QuoteBank();
                quoteCollection.LoadQuotes();
                quoteCollection.GetNextQuote();
                quotationTextView.Text = quoteCollection.CurrentQuote.Quotation;
            };
        }