Sunday, December 23, 2012

Simple Mono Droid Entry point for new features.


One of the things I've needed, in order to create a rapid development environment, is an entry point that is extensible.    Using this setup, I was able to easily throw in new features at a running pace.


public static class Selector
    {
        public static void Selected (string component,Activity act,int Id)
        {
            switch (component) 
            {
                case "Participant List":
                    var intent = new Intent();
                    intent.SetClass(act, typeof (ParticipantListActivity));
                    intent.PutExtra("Type","");
                    intent.PutExtra("Id","");
                    act.StartActivity(intent);
                break;
                case "Child Detail":
                    var childintent = new Intent();
                    childintent.SetClass(act, typeof (ChildDetailsActivity));
                    childintent.PutExtra("currentChildId",Id);
                    act.StartActivity(childintent);
                break;
                case "Parent List":
                    var parentintent = new Intent();
                    parentintent.SetClass(act, typeof (ParentListActivity));
                    act.StartActivity(parentintent);
                break;
                case "Scanner":
                var scannerintent = new Intent();
                scannerintent.SetClass(act,typeof(ScannerActivity));
                act.StartActivity(scannerintent);
                break;
                case "School List":
                    var schoolintent = new Intent();
                    schoolintent.SetClass(act,typeof(SchoolListActivity));
                    act.StartActivity (schoolintent);
                break;
                case "Kiosk":
                var kioskintent = new Intent();
                kioskintent.SetClass(act,typeof(LocationListActivity));
                act.StartActivity(kioskintent);
                break;
                default:
                break;


            }
        }
    }


public class Main : ListActivity
    {
        ProgressDialog progress;

        string[] Entries = { "Participant List","Parent List","Scanner","Kiosk"};

        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);
            SetContentView (Resource.Layout.TextViewItem);

            this.ListAdapter = new ArrayAdapter<string>(this,Android.Resource.Layout.SimpleListItem1,Entries);

        }

        protected override void OnStart ()
        {
            base.OnStart ();
        }

        protected override void OnResume ()
        {
            base.OnResume();
        }

        protected override void OnListItemClick (ListView l, View v, int position, long id)
        {

            string place = ((ArrayAdapter<string>)this.ListAdapter).GetItem(position);
        
            Selector.Selected(place,this,0);
        }
    }

No comments:

Post a Comment