
using System;
using System.Collections.Generic;
using System.Linq;
using MonoTouch.Foundation;
using MonoTouch.UIKit;

namespace HelloWorld
{
	public class Application
	{
		static void Main (string[] args)
		{
			UIApplication.Main (args);
		}
	}

	// The name AppDelegate is referenced in the MainWindow.xib file.
	public partial class AppDelegate : UIApplicationDelegate
	{
		private void InfoAlert (string msg)
		{
			using (UIAlertView av = new UIAlertView ("Info", msg, null, "OK", null)) {
				av.Show ();
			}
		}

		// This method is invoked when the application has loaded its UI and its ready to run
		public override bool FinishedLaunching (UIApplication app, NSDictionary options)
		{
			//Since the background of the page is black, let's make the status bar black as well
			UIApplication.SharedApplication.StatusBarStyle = UIStatusBarStyle.BlackOpaque;
			//To have it definitively black, open the project's info.plist (double-click it in MonoDevelop).
			//In the Property List Editor select Information Property List and press Add Child...
			//Note that the above works, though the status bar briefly displays as grey
			//Now add the key UIStatusBarStyle and the Value UIStatusBarStyleBlackOpaque
			//Save and close the property List editor
			
			//Initialise output label to blank
			myLabel.Text = "";
			//Update button's caption at runtime
			myButton.SetTitle (myButton.Title (UIControlState.Normal) + "!", UIControlState.Normal);
			//Button's 2nd event handler
			myButton.TouchUpInside += (s, e) => { InfoAlert ("Hello " + myTextBox.Text); };
			//Hide keyboard
			//1) Anonymous method
			//myTextBox.ShouldReturn = delegate(UITextField textField) { return textField.ResignFirstResponder(); };
			//2) Lambda
			//myTextBox.ShouldReturn = textField => { return textField.ResignFirstResponder(); };
			//3) Concise lambda
			myTextBox.ShouldReturn = textField => textField.ResignFirstResponder ();
			
			window.MakeKeyAndVisible ();
			
			return true;
		}

		// This method is required in iPhoneOS 3.0
		public override void OnActivated (UIApplication application)
		{
		}

		//Button's first event handler
		partial void myButtonPressed (MonoTouch.UIKit.UIButton sender)
		{
			if (myTextBox.IsFirstResponder)
				myTextBox.ResignFirstResponder ();
			
			myLabel.Text = "Hello world! Erm, I mean Hello " + myTextBox.Text + "!";
		}
	}
}


