Exemplo n.º 1
0
        private void PerformUpdate()
        {
            EdiabasInit();
            Android.App.ProgressDialog progress = new Android.App.ProgressDialog(this);
            progress.SetCancelable(false);
            progress.SetMessage(GetString(Resource.String.can_adapter_fw_update_active));
            progress.Show();

            _adapterThread = new Thread(() =>
            {
                bool updateOk  = false;
                bool connectOk = false;
                try
                {
                    connectOk = !InterfacePrepare();
                    BluetoothSocket bluetoothSocket = EdBluetoothInterface.BluetoothSocket;
                    if (bluetoothSocket == null)
                    {
                        connectOk = false;
                    }
                    else
                    {
                        connectOk = true;
                        updateOk  = PicBootloader.FwUpdate(bluetoothSocket);
                    }
                }
                catch (Exception)
                {
                    updateOk = false;
                }
                RunOnUiThread(() =>
                {
                    if (IsJobRunning())
                    {
                        _adapterThread.Join();
                    }
                    progress.Hide();
                    progress.Dispose();
                    string message;
                    if (updateOk)
                    {
                        message = GetString(Resource.String.can_adapter_fw_update_ok);
                    }
                    else
                    {
                        message = connectOk
                            ? GetString(Resource.String.can_adapter_fw_update_failed)
                            : GetString(Resource.String.can_adapter_fw_update_conn_failed);
                    }
                    _activityCommon.ShowAlert(message, updateOk ? Resource.String.alert_title_info : Resource.String.alert_title_error);
                    UpdateDisplay();
                    if (updateOk)
                    {
                        PerformRead();
                    }
                });
            });
            _adapterThread.Start();
            UpdateDisplay();
        }
Exemplo n.º 2
0
        //public override void OnActivityCreated(Bundle savedInstanceState)
        //{
        //    base.OnActivityCreated(savedInstanceState);
        //    DoWork();
        //}

        private async void DoWork()
        {
            var pr = new Android.App.ProgressDialog(globalContext);

            pr.SetMessage("Loading data");
            pr.SetCancelable(false);
            pr.Show();

            var repository = new Respository();
            //var channel = await await Task.Factory.StartNew(async() =>await repository.ReadPsi());//repository.ReadPsi();
            //var channel = await await await Task.Factory.StartNew(() =>repository.ReadPsi().ContinueWith<Task<Channel>>(t=>t,TaskContinuationOptions.OnlyOnFaulted));
            await Task.Factory.StartNew(() => BigLongImportantMethodAsync());

            var channel      = _channelResult;
            var psiInfo      = PsiInformation.Parse(channel);
            var view         = globalView;
            var foundTextbox = view.FindViewById <TextView>(Resource.Id.textViewUpdateTime);

            foundTextbox.Text = psiInfo.DisplayUpdateTime;
            foundTextbox      = view.FindViewById <TextView>(Resource.Id.textView3hrPsi);
            foundTextbox.Text = psiInfo.Psi3Hour;
            foundTextbox      = view.FindViewById <TextView>(Resource.Id.textView24hrPsi);
            foundTextbox.Text = psiInfo.Psi24Hour;

            var root = view.FindViewById <LinearLayout>(Resource.Id.linearLayoutRoot);

            root.Visibility = ViewStates.Visible;

            pr.Hide();
        }
Exemplo n.º 3
0
 private void HideProgressDialog()
 {
     Activity.RunOnUiThread(() =>
     {
         progress.Hide();
         progress.Dismiss();
     });
 }
Exemplo n.º 4
0
        private void CheckUploadResult(object state)
        {
            Activity.RunOnUiThread(() =>
            {
                progress.Hide();
                progress.Dismiss();
            });

            if (Core.Globals.UploadAuditDBResult == UploadDBResultType.Success)
            {
                // Upload Successful
                Activity.RunOnUiThread(() =>
                {
                    ShowSuccessToast("Uploaded Successfully");

                    BtnUpload.Enabled = false;
                    BtnUpload.Click  += null;

                    GlobalsAndroid.DeleteAuditDB();
                });
            }
            else if (Core.Globals.UploadAuditDBResult == UploadDBResultType.BadRequestError || Core.Globals.UploadAuditDBResult == UploadDBResultType.NetworkError)
            {
                // Bad Request Error / Network Error
                Activity.RunOnUiThread(() =>
                {
                    ShowErrorDialog("Something went wrong. Please try it later.");
                });
            }
            else
            {
                // Error
                Activity.RunOnUiThread(() =>
                {
                    ShowErrorDialog("It looks like you are in an error that does not have the data service or something went wrong.");
                });
            }
        }
Exemplo n.º 5
0
        private async void LoginButton_Click(object sender, EventArgs e)
        {
            _loginButton.Enabled = false;

            var pr = new Android.App.ProgressDialog(_context);

            pr.SetMessage("Login...");
            pr.SetCancelable(false);
            pr.Show();

            await Task.Factory.StartNew(() => BigLongImportantMethodAsync());

            pr.Hide();
            _loginButton.Enabled = true;
        }
Exemplo n.º 6
0
 public void LoadingHide()
 {
     progress.Hide();
 }
Exemplo n.º 7
0
        /// <summary>
        /// Start adapter detection
        /// </summary>
        /// <param name="deviceAddress">Device Bluetooth address</param>
        /// <param name="deviceName">Device Bleutooth name</param>
        private void DetectAdapter(string deviceAddress, string deviceName)
        {
            Android.App.ProgressDialog progress = new Android.App.ProgressDialog(this);
            progress.SetCancelable(false);
            progress.SetMessage(GetString(Resource.String.detect_adapter));
            progress.Show();

            _sbLog.Clear();

            Thread detectThread = new Thread(() =>
            {
                AdapterType adapterType = AdapterType.Unknown;
                try
                {
                    BluetoothDevice device = _btAdapter.GetRemoteDevice(deviceAddress);
                    if (device != null)
                    {
                        BluetoothSocket bluetoothSocket = null;

                        adapterType = AdapterType.ConnectionFailed;
                        if (adapterType == AdapterType.ConnectionFailed)
                        {
                            try
                            {
                                bluetoothSocket = device.CreateRfcommSocketToServiceRecord(SppUuid);
                                if (bluetoothSocket != null)
                                {
                                    try
                                    {
                                        bluetoothSocket.Connect();
                                    }
                                    catch (Exception)
                                    {
                                        // sometimes the second connect is working
                                        bluetoothSocket.Connect();
                                    }
                                    adapterType = AdapterTypeDetection(bluetoothSocket);
                                }
                            }
                            catch (Exception)
                            {
                                adapterType = AdapterType.ConnectionFailed;
                            }
                            finally
                            {
                                bluetoothSocket?.Close();
                            }
                        }

                        if (adapterType == AdapterType.ConnectionFailed)
                        {
                            try
                            {
                                // this socket sometimes looses data for long telegrams
                                IntPtr createRfcommSocket = Android.Runtime.JNIEnv.GetMethodID(device.Class.Handle,
                                                                                               "createRfcommSocket", "(I)Landroid/bluetooth/BluetoothSocket;");
                                if (createRfcommSocket == IntPtr.Zero)
                                {
                                    throw new Exception("No createRfcommSocket");
                                }
                                IntPtr rfCommSocket = Android.Runtime.JNIEnv.CallObjectMethod(device.Handle,
                                                                                              createRfcommSocket, new Android.Runtime.JValue(1));
                                if (rfCommSocket == IntPtr.Zero)
                                {
                                    throw new Exception("No rfCommSocket");
                                }
                                bluetoothSocket = GetObject <BluetoothSocket>(rfCommSocket, Android.Runtime.JniHandleOwnership.TransferLocalRef);
                                if (bluetoothSocket != null)
                                {
                                    bluetoothSocket.Connect();
                                    adapterType = AdapterTypeDetection(bluetoothSocket);
                                }
                            }
                            catch (Exception)
                            {
                                adapterType = AdapterType.ConnectionFailed;
                            }
                            finally
                            {
                                bluetoothSocket?.Close();
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    adapterType = AdapterType.ConnectionFailed;
                }

                RunOnUiThread(() =>
                {
                    progress.Hide();
                    progress.Dispose();
                    switch (adapterType)
                    {
                    case AdapterType.ConnectionFailed:
                        _altertInfoDialog = new AlertDialog.Builder(this)
                                            .SetPositiveButton(Resource.String.button_yes, (sender, args) =>
                        {
                            ReturnDeviceType(deviceAddress, deviceName);
                        })
                                            .SetNegativeButton(Resource.String.button_no, (sender, args) =>
                        {
                        })
                                            .SetCancelable(true)
                                            .SetMessage(Resource.String.adapter_connection_failed)
                                            .SetTitle(Resource.String.alert_title_error)
                                            .Show();
                        _altertInfoDialog.DismissEvent += (sender, args) =>
                        {
                            _altertInfoDialog = null;
                        };
                        break;

                    case AdapterType.Unknown:
                        {
                            bool yesSelected  = false;
                            _altertInfoDialog = new AlertDialog.Builder(this)
                                                .SetPositiveButton(Resource.String.button_yes, (sender, args) =>
                            {
                                yesSelected = true;
                            })
                                                .SetNegativeButton(Resource.String.button_no, (sender, args) =>
                            {
                            })
                                                .SetCancelable(true)
                                                .SetMessage(Resource.String.unknown_adapter_type)
                                                .SetTitle(Resource.String.alert_title_error)
                                                .Show();
                            _altertInfoDialog.DismissEvent += (sender, args) =>
                            {
                                _altertInfoDialog = null;
                                _activityCommon.RequestSendMessage(_appDataDir, _sbLog.ToString(),
                                                                   PackageManager.GetPackageInfo(PackageName, 0), GetType(), (o, eventArgs) =>
                                {
                                    if (yesSelected)
                                    {
                                        ReturnDeviceType(deviceAddress, deviceName);
                                    }
                                });
                            };
                            break;
                        }

                    case AdapterType.Elm327:
                        {
                            _altertInfoDialog = new AlertDialog.Builder(this)
                                                .SetNeutralButton(Resource.String.button_ok, (sender, args) =>
                            {
                                ReturnDeviceType(deviceAddress + ";" + EdBluetoothInterface.Elm327Tag, deviceName);
                            })
                                                .SetCancelable(true)
                                                .SetMessage(Resource.String.adapter_elm_replacement)
                                                .SetTitle(Resource.String.alert_title_info)
                                                .Show();
                            _altertInfoDialog.DismissEvent += (sender, args) =>
                            {
                                _altertInfoDialog = null;
                            };
                            TextView messageView = _altertInfoDialog.FindViewById <TextView>(Android.Resource.Id.Message);
                            if (messageView != null)
                            {
                                messageView.MovementMethod = new LinkMovementMethod();
                            }
                            break;
                        }

                    case AdapterType.Elm327Invalid:
                    case AdapterType.Elm327Fake21:
                        {
                            string message =
                                GetString(adapterType == AdapterType.Elm327Fake21
                                    ? Resource.String.fake_elm_adapter_type
                                    : Resource.String.invalid_adapter_type);
                            message          += "<br>" + GetString(Resource.String.recommened_adapter_type);
                            _altertInfoDialog = new AlertDialog.Builder(this)
                                                .SetNeutralButton(Resource.String.button_ok, (sender, args) =>
                            {
                            })
                                                .SetCancelable(true)
                                                .SetMessage(Html.FromHtml(message))
                                                .SetTitle(Resource.String.alert_title_error)
                                                .Show();
                            _altertInfoDialog.DismissEvent += (sender, args) =>
                            {
                                _altertInfoDialog = null;
                                _activityCommon.RequestSendMessage(_appDataDir, _sbLog.ToString(), PackageManager.GetPackageInfo(PackageName, 0), GetType());
                            };
                            TextView messageView = _altertInfoDialog.FindViewById <TextView>(Android.Resource.Id.Message);
                            if (messageView != null)
                            {
                                messageView.MovementMethod = new LinkMovementMethod();
                            }
                            break;
                        }

                    case AdapterType.Custom:
                    case AdapterType.CustomUpdate:
                        _altertInfoDialog = new AlertDialog.Builder(this)
                                            .SetPositiveButton(Resource.String.button_yes, (sender, args) =>
                        {
                            ReturnDeviceType(deviceAddress, deviceName, true);
                        })
                                            .SetNegativeButton(Resource.String.button_no, (sender, args) =>
                        {
                            ReturnDeviceType(deviceAddress, deviceName);
                        })
                                            .SetCancelable(true)
                                            .SetMessage(adapterType == AdapterType.CustomUpdate ? Resource.String.adapter_fw_update : Resource.String.adapter_cfg_required)
                                            .SetTitle(Resource.String.alert_title_info)
                                            .Show();
                        _altertInfoDialog.DismissEvent += (sender, args) =>
                        {
                            _altertInfoDialog = null;
                        };
                        break;

                    default:
                        {
                            ReturnDeviceType(deviceAddress, deviceName);
                            break;
                        }
                    }
                });
            })
            {
                Priority = System.Threading.ThreadPriority.Highest
            };

            detectThread.Start();
        }
        private void ExecuteTestFormat()
        {
            _textViewTestFormatOutput.Text = string.Empty;
            if ((_selectedJob == null) || (_selectedResult == null))
            {
                return;
            }

            Android.App.ProgressDialog progress = new Android.App.ProgressDialog(this);
            progress.SetCancelable(false);
            progress.SetMessage(GetString(Resource.String.xml_tool_execute_test_job));
            progress.Show();

            string resultText    = string.Empty;
            bool   executeFailed = false;
            Thread jobThread     = new Thread(() =>
            {
                try
                {
                    _ediabas.ResolveSgbdFile(_ecuInfo.Sgbd);

                    _ediabas.ArgString       = string.Empty;
                    _ediabas.ArgBinaryStd    = null;
                    _ediabas.ResultsRequests = string.Empty;
                    _ediabas.ExecuteJob(_selectedJob.Name);

                    List <Dictionary <string, EdiabasNet.ResultData> > resultSets = _ediabas.ResultSets;
                    if (resultSets != null && resultSets.Count >= 2)
                    {
                        int dictIndex = 0;
                        foreach (Dictionary <string, EdiabasNet.ResultData> resultDict in resultSets)
                        {
                            if (dictIndex == 0)
                            {
                                dictIndex++;
                                continue;
                            }
                            EdiabasNet.ResultData resultData;
                            if (resultDict.TryGetValue(_selectedResult.Name, out resultData))
                            {
                                resultText = EdiabasNet.FormatResult(resultData, _selectedResult.Format) ?? string.Empty;
                                break;
                            }
                            dictIndex++;
                        }
                    }
                }
                catch (Exception)
                {
                    executeFailed = true;
                }

                RunOnUiThread(() =>
                {
                    progress.Hide();
                    progress.Dispose();
                    _textViewTestFormatOutput.Text = resultText;

                    if (executeFailed)
                    {
                        _activityCommon.ShowAlert(GetString(Resource.String.xml_tool_read_test_job_failed), Resource.String.alert_title_error);
                    }
                });
            });

            jobThread.Start();
        }