Saturday, January 19, 2013

Login for Mono Touch.


So folks.  Looks like making good code still has some worth.  Ipad / Iphone app, with Login functionality now.  This code is placed in the AppDelegate.cs in Mono Touch for the interface on app start.


            RootElement re = new RootElement("Login");
            Section creds = new Section("Credentials");
            Section welcome = new Section("Welcome to Youth Impact!");
            UIImageView ie;
            if(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) ie = new UIImageView(UIImage.FromBundle("resized.png"));
            else ie = new UIImageView(UIImage.FromBundle("small2.png"));
            welcome.Add(ie);
            login = new EntryElement("Login","Enter your Email", "");
            password = new EntryElement("Password","","",true);

            creds.Add(login);
            creds.Add(password);
            Section button = new Section();
            button.Add(new StringElement("Sign In",delegate { Validate();}));

            re.Add(welcome);
            re.Add(creds);
            re.Add(button);

            window = new UIWindow (UIScreen.MainScreen.Bounds);
            DialogViewController dialog = new DialogViewController(re);


            window.RootViewController = new DialogViewController(re);

I only put in a bit of logic for swapping the image out for IPhone / Ipad.  There is some code to do for when the app shifts Orientation.  As your properly sized image needs to be replaced with an image with the proper width / height due to the orientation change.

Using that if(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone), should provide you the ability to handle that.. and maybe I'll just update this post later.

In the Validate method, I check the two Entries, one for password, and one for Login.. and use my web service call to validate the user.. if the response comes back as valid credentials, then I load the default ViewController that was generated when you create a "Universal" iphone / ipad app in Mono Touch.

Most of this code was taken as ill-gotten gains from this great recipe on Xamarin:

Xamarin Login Window Recipe.


Friday, January 18, 2013

Monotouch Development.


Yeah, if you've been here because of my links, you'll notice that the title of the blog changed.

Mobile Development.  Started working a bit in Mono Touch.

The great thing about working in Xamarin, is that you can re-use almost all your data access, if you started in Android.

I imported my model classes.  I imported my service call methods.



Made a nice little MasterViewController, and a DetailView where I could render custom data from the data made in my calls. Sorry, I had to blur the names.. because those kids don't deserve to have some stupid developer expose the fact that they are in a program at an address that can be found pretty easily.

Creating this app, took about 30 minutes.   (I had to read a little).  I can actually say nowadays, that my new personality is stronger / faster / happier, than I can easily explain and I'm going to take advantage of that.