Пример #1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            //this disables orientation changes while form loads, effectively ignoring the sensors
            RequestedOrientation = Android.Content.PM.ScreenOrientation.Locked;

            SetContentView(Resource.Layout.Form2);
            inflater = LayoutInflater.From(this);

            MainFormLayout = FindViewById <LinearLayout>(Resource.Id.mainFormView);
            MainScrollView = FindViewById <ScrollView>(Resource.Id.mainScrollView);

            progress = new ProgressDialog(this);
            progress.SetCanceledOnTouchOutside(false);
            progress.SetCancelable(false);
            progress.SetProgressStyle(ProgressDialogStyle.Spinner);
            progress.SetProgressNumberFormat(null);
            progress.SetProgressPercentFormat(null);
            progress.Indeterminate = true;


            //grab the form name from previous
            string item = Intent.GetStringExtra("form_name");

            //if we came from a page button, these values will have something in them
            int  groupId = Intent.GetIntExtra("groupId", -1);
            bool newForm = Intent.GetBooleanExtra("newForm", true);



            //get the form from the WS
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += delegate
            {
                if (newForm)
                {
                    RunOnUiThread(() =>
                    {
                        progress.SetMessage("Disposing tables...");
                        progress.Show();
                    });

                    if (XForm.instance == null)
                    {
                        DLL.DisposeTables();
                    }



                    RunOnUiThread(() => { progress.SetMessage("Downloading form..."); });

                    WebServerHelper.WebServiceResponse response =
                        JsonConvert.DeserializeObject <WebServerHelper.WebServiceResponse>(WebServerHelper.WebCall("https://macarthur.goget.co.nz:9725/apps/?getform=1", item));

                    string xform = response.data;

                    //puts it into the sqlite db
                    try
                    {
                        RunOnUiThread(() => { progress.SetMessage("Parsing form..."); });
                        Parser.Parse(xform, "Test Form");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }

                    form = DLL.GetForm(1);

                    isAssetForm = item.ToLower().Contains("asset") ? true : false;
                    if (XForm.instance == null)
                    {
                        XForm.instance = new Instance()
                        {
                            formid   = form.id,
                            instance = XForm.LoadInstance(form.instancexml),
                        };
                        DLL.InsertRow(XForm.instance);
                    }
                }


                try
                {
                    RunOnUiThread(() => { progress.SetMessage("Loading controls..."); });
                    //if we have a group id passed, this is a sub page
                    OrderLayouts = new List <LinearLayout>();

                    WidgetHelper.activity = this;
                    if (newForm)
                    {
                        XForm.LoadForm(null, this);
                    }
                    else
                    {
                        RunOnUiThread(() => {
                            progress.SetMessage($"Loading {item}...");
                            progress.Show();
                        });
                        XForm.LoadForm(groupId, this);
                        RunOnUiThread(() => { progress.Dismiss(); });
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                    progress.Dismiss();

                    AlertDialog alert = new AlertDialog.Builder(this).Create();
                    alert.SetTitle("Error");
                    alert.SetMessage($"An error occured while loading the form. If the issue persists, check your form is valid XML. \n\nError:\n {ex.ToString()}");
                    alert.SetButton("OK", delegate { Finish(); });
                }
            };


            bw.RunWorkerCompleted += delegate { RunOnUiThread(() => {
                    PageLoaded = true;
                    //this reenables the app listening to orientation sensors
                    RequestedOrientation = Android.Content.PM.ScreenOrientation.Sensor;

                    foreach (LinearLayout ol in OrderLayouts)
                    {
                        TextView label = ol.FindViewById <TextView>(Resource.Id.textLabel);
                        EditText edit  = ol.FindViewById <EditText>(Resource.Id.textEdit);

                        ol.Measure(0, 0);
                        int spec = MeasureSpec.MakeMeasureSpec(ol.MeasuredWidth, MeasureSpecMode.AtMost);

                        label.Measure(spec, spec);
                        edit.Measure(spec, spec);

                        Console.WriteLine(label.Text);

                        // if (label.MeasuredWidth > edit.MeasuredWidth)
                        //  ol.Orientation = Orientation.Vertical;
                    }

                    FireFormChangeEvent(null);
                    progress.Dismiss();
                }); };

            bw.RunWorkerAsync();

            MainFormLayout.ChildViewAdded += delegate
            {
                RunOnUiThread(() => {
                    progress.SecondaryProgress += 1;
                    progress.Progress++;
                });
            };
        }
Пример #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);


            progress = new ProgressDialog(this);
            progress.SetMessage("Loading...");
            progress.SetCanceledOnTouchOutside(false);
            progress.SetCancelable(false);
            progress.SetProgressStyle(ProgressDialogStyle.Spinner);
            progress.SetProgressNumberFormat(null);
            progress.SetProgressPercentFormat(null);
            progress.Indeterminate = true;

            SetContentView(Resource.Layout.Form);
            listView = FindViewById <ListView>(Resource.Id.controlList);



            //get the form from the WS
            BackgroundWorker bw = new BackgroundWorker();

            bw.DoWork += delegate
            {
                DLL.DisposeTables();

                RunOnUiThread(() =>
                {
                    progress.Show();
                });

                WebServerHelper.WebServiceResponse response =
                    JsonConvert.DeserializeObject <WebServerHelper.WebServiceResponse>(WebServerHelper.WebCall("https://macarthur.goget.co.nz:9725/apps/?getform=1"));

                string xform = response.data;

                //puts it into the sqlite db
                try
                {
                    Parser.Parse(xform, "Test Form");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                Forms form = DLL.GetForm(1);
                //this is where we put our filled out values back into
                instance = XForm.LoadInstance(form.instancexml);

                //the controls we put onto the UI
                FormControls = DLL.GetControls(1);

                foreach (Controls c in FormControls)
                {
                    Console.WriteLine(c.type);
                }

                RunOnUiThread(() => {
                    Title            = "Test Form";
                    listView.Adapter = new FormAdapter(FormControls, this);
                });
            };


            //setup ui now we are done
            bw.RunWorkerCompleted += delegate {
                RunOnUiThread(() => {
                    //trigger any show/hide stuff :D
                    FireFormChangeEvent(null);
                    progress.Dismiss();
                });
            };


            bw.RunWorkerAsync();
        }