Category Archives: Monotouch

Monotouch development

MonoDroid: How to determine if you are on a phone or tablet

In a recent Android based mobile application using Mono, our customer requirements dictated two sets of screen layouts: one for Android phones and one for Android tablets.

Easy right?

Well… No.  The requirement statement “detect if the device is a tablet or phone using MonoDroid and display the appropriate layout” turned out to not be as trivial as we originally suspected.

A quick Google search turned up several solutions using screen size and density to determine the answer to the phone vs. tablet question.  While workable, these solutions were far from fool proof due to the vast array of sizes and densities available on various Android devices.

Ugh.

During an offsite Red Solo cup session, the answer occurred to one of our senior developers:  Ask about IMEI!  If the device has an IMEI, its gotta be a phone (or a tablet with suspiciously phone like qualities).

Our Solution
A property exposed on a helper class which probes the IMEI and determines phone vs. tablet.

EDIT 02/27/2012: Code updated to reflect API support for 4G phones

public bool IsPhone
{
  get
  {
    return ((this.GetSystemService(Context.TelephonyService) as
                TelephonyManager).PhoneType != PhoneType.None);

   }
}

 

Quick, simple, solved!

Monotouch iPhone – Showing activity to the end (or how to create an iPhone wait cursor)

One of AIS’s recent projects involved development of an iPhone application using MonoTouch. This application made significant use of web services, some of which could take 10’s of seconds to return (Yes, we were moving a lot of data for this particular application… there is just no easy way to deal with “historical data”).

Rather than just locking the UI for the duration of the activity, we wanted to display a user notification that something was actually happening in the background. In addition, we wanted to disable the UI so the user did not inadvertently believe they could tap anything.

Our goals:

1. Display a “long running operation” notification to the user

2. Lock the primary UI to prevent unwanted unexpected user interactions

3. The component must be reusable

To accomplish this feat of programming, we decided to use a UIAlertView with a UIActivityIndicatorView on it. We created the ActivityAlertView class to manage this for us. It allows you to use it in one of 2 ways:

  1. In a using statement. This will display the ActivityAlertView for the duration that the using statement is in scope:
  2. using(ActivityAlertView alert
              = new ActivityAlertView("Logging in, Please wait"))
    {
          //Code to do while ActivityAlertView is displayed to user
    }

  3. Normal instantiation
  4. ActivityAlertView alert = new ActivityAlertView;
    alert.Show("Logging in, Please wait");
    //Code to do while ActivityAlertView is displayed to user
    alert.Dismiss();

Here are a few screenshots of the attached demo project.

imageimageimage
(Click image to enlarge)

Download the sample project and source code from this link