private bool EditFieldOptionIsValid(SettingEditType editType, string value, SettingEditOptions option) { bool isValid = false; switch (editType) { case SettingEditType.TEXT: case SettingEditType.PASSWORD: case SettingEditType.IP_ADDRESS_LIST: { if (value.Length > 0 || option == SettingEditOptions.ALLOW_EMPTY_FIELD) { isValid = true; } else { isValid = false; } } break; case SettingEditType.NUMERIC: case SettingEditType.IP_PORT: { long tVal = 0; try { tVal = long.Parse(value); } catch (System.FormatException) { tVal = 0; } if (tVal > 0 || option == SettingEditOptions.ALLOW_ZERO_VALUE) { isValid = true; } else { isValid = false; } } break; } return(isValid); }
private long GetNumericOptionDialog(int resTitle, long selectedValue, SettingEditOptions editOption = SettingEditOptions.DO_NOT_ALLOW_ZERO_VALUE) { string value = ""; long retVal = 0; value = EditOptionDialog(resTitle, selectedValue.ToString(), SettingEditType.NUMERIC, editOption); try { retVal = long.Parse(value); } catch (System.FormatException) { retVal = 0; } return(retVal); }
private string GetPasswordOptionDialog(int resTitle, string selectedValue, SettingEditOptions editOption = SettingEditOptions.DO_NOT_ALLOW_EMPTY_FIELD) { return(EditOptionDialog(resTitle, selectedValue, SettingEditType.PASSWORD, editOption)); }
private string GetTextOptionDialog(int resTitle, string selectedValue, SettingEditOptions editOption = SettingEditOptions.DO_NOT_ALLOW_EMPTY_FIELD) { return(EditOptionDialog(resTitle, selectedValue, SettingEditType.TEXT, editOption)); }
private bool EditFieldIsValid(SettingEditType editType, string value, SettingEditOptions editOption = SettingEditOptions.DO_NOT_ALLOW_EMPTY_FIELD) { bool isValid = false; long tVal = 0; switch (editType) { case SettingEditType.TEXT: { isValid = true; } break; case SettingEditType.PASSWORD: { isValid = true; } break; case SettingEditType.NUMERIC: { isValid = true; } break; case SettingEditType.IP_ADDRESS_LIST: { string[] octect = null; isValid = true; string[] ipAdrressArray = value.Split(SettingsManager.DEFAULT_SPLIT_SEPARATOR); foreach (string ipAddress in ipAdrressArray) { octect = ipAddress.Split('.'); if (octect.Length != 4) { isValid = false; } foreach (string val in octect) { try { tVal = long.Parse(val); } catch (System.FormatException) { tVal = 0; isValid = false; } if (tVal < 0 || tVal > 255) { isValid = false; } } } if (value.Length == 0 && editOption == SettingEditOptions.ALLOW_EMPTY_FIELD) { isValid = true; } } break; case SettingEditType.IP_PORT: { try { tVal = long.Parse(value); } catch (System.FormatException) { tVal = 0; isValid = false; } if (tVal >= 1 && tVal <= 65535) { isValid = true; } else { isValid = false; } if (tVal == 0 && editOption == SettingEditOptions.ALLOW_ZERO_VALUE) { isValid = true; } } break; default: { isValid = false; } break; } return(isValid); }
private string EditOptionDialog(int resTitle, string selectedValue, SettingEditType editType = SettingEditType.TEXT, SettingEditOptions editOption = SettingEditOptions.DO_NOT_ALLOW_EMPTY_FIELD) { btnOk = null; btnCancel = null; dialogHandler = new Handler(m => { throw new Java.Lang.RuntimeException(); }); dialogBuilder = new AlertDialog.Builder(this); View content = LayoutInflater.From(this).Inflate(Resource.Layout.edit_option_dialog, null); edtKey = content.FindViewById <EditText>(Resource.Id.key); edtKey.Text = selectedValue; if (editType == SettingEditType.NUMERIC || editType == SettingEditType.IP_PORT) { edtKey.SetRawInputType(InputTypes.ClassNumber | InputTypes.NumberFlagSigned); edtKey.Gravity = GravityFlags.Right; edtKey.SetSelection(edtKey.Text.Length); } if (editType == SettingEditType.PASSWORD) { edtKey.InputType = InputTypes.TextVariationPassword | InputTypes.ClassText; } btnOk = content.FindViewById <Button>(Resource.Id.btn_ok); btnCancel = content.FindViewById <Button>(Resource.Id.btn_cancel); btnOk.Enabled = EditFieldOptionIsValid(editType, selectedValue, editOption); btnCancel.Enabled = true; btnOk.Click += delegate { int errMsgResource = 0; if (EditFieldIsValid(editType, edtKey.Text, editOption) == false) { switch (editType) { case SettingEditType.IP_ADDRESS_LIST: { errMsgResource = Resource.String.settings_ip_address_warning; } break; case SettingEditType.IP_PORT: { errMsgResource = Resource.String.settings_ip_port_warning; } break; default: { errMsgResource = Resource.String.settings_value_warning; } break; } supportTools.InfoDialog(errMsgResource); return; } if (edtKey.Text.Length > 0 || editOption == SettingEditOptions.ALLOW_EMPTY_FIELD || editOption == SettingEditOptions.ALLOW_ZERO_VALUE) { dialogReturnStringValue = edtKey.Text; } settingDialog.Dismiss(); dialogHandler.SendMessage(dialogHandler.ObtainMessage()); }; btnCancel.Click += delegate { dialogReturnStringValue = selectedValue; settingDialog.Dismiss(); dialogHandler.SendMessage(dialogHandler.ObtainMessage()); }; edtKey.TextChanged += (sender, e) => { btnOk.Enabled = EditFieldOptionIsValid(editType, e.Text.ToString(), editOption); }; dialogBuilder.SetTitle(Resources.GetString(resTitle)); dialogBuilder.SetView(content); settingDialog = dialogBuilder.Create(); settingDialog.Show(); try { Looper.Loop(); } catch (Java.Lang.RuntimeException) { } return(dialogReturnStringValue.Trim()); }
private string GetIpAddressOptionDialog(int resTitle, string selectedValue, SettingEditOptions editOption = SettingEditOptions.DO_NOT_ALLOW_EMPTY_FIELD) { return(EditOptionDialog(resTitle, selectedValue, SettingEditType.IP_ADDRESS_LIST, editOption)); }