Esempio n. 1
0
 private async void RefreshCheckPic()
 {
     Stream stream;
     const int MAX_RETRY = 3;
     Exception ex = null;
     for (int i = 0; i < MAX_RETRY; i++)
     {
         try
         {
             stream = await helper.GetCheckPicAsync();
             Bitmap bitmap = BitmapFactory.DecodeStream(stream);
             randBox.Measure(0, 0);
             randImage.LayoutParameters = new LinearLayout.LayoutParams(
                 randBox.MeasuredHeight * bitmap.Width / bitmap.Height,
                 randImage.LayoutParameters.Height);
             randImage.SetImageBitmap(bitmap);
             ex = null;
             break;
         }
         catch (Exception exception)
         {
             ex = exception;
         }
     }
     if (ex != null)
     {
         randImage.SetImageDrawable(
             GetDrawable(Android.Resource.Drawable.IcMenuGallery));
     }
 }
Esempio n. 2
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++;
                });
            };
        }