Skip to content

Commit

Permalink
Merge pull request #184 from DK99/AddPrimitiveDataTypes
Browse files Browse the repository at this point in the history
AdvancedEntry addprimitive Data Types as Annotation
  • Loading branch information
enisn authored Mar 2, 2020
2 parents 3262dd6 + b05ed36 commit e101ccb
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 6 deletions.
70 changes: 65 additions & 5 deletions InputKit/Shared/Controls/AdvancedEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,16 @@ public bool IsAnnotated
return true;

if (String.IsNullOrEmpty(Text))
return false;
{
if (Nullable)
{
return true;
}
else
{
return false;
}
}

if (Text.Length < MinLength)
return false;
Expand Down Expand Up @@ -275,7 +284,42 @@ public bool IsAnnotated

case AnnotationType.Phone:
return Regex.Match(Text, REGEX_PHONE).Success;

case AnnotationType.ShortType:
return short.TryParse(Text, out _);

case AnnotationType.IntType:
return int.TryParse(Text, out _);

case AnnotationType.LongType:
return long.TryParse(Text, out _);

case AnnotationType.FloatType:
return float.TryParse(Text, out _);

case AnnotationType.DoubleType:
return double.TryParse(Text, out _);

case AnnotationType.DecimalType:
return decimal.TryParse(Text, out _);

case AnnotationType.ByteType:
return byte.TryParse(Text, out _);

case AnnotationType.SByteType:
return sbyte.TryParse(Text, out _);

case AnnotationType.CharType:
return char.TryParse(Text, out _);

case AnnotationType.UIntType:
return uint.TryParse(Text, out _);

case AnnotationType.ULongType:
return ulong.TryParse(Text, out _);

case AnnotationType.UShortType:
return ushort.TryParse(Text, out _);

case AnnotationType.RegexPattern:
return Regex.Match(Text, RegexPattern).Success;
Expand Down Expand Up @@ -349,6 +393,11 @@ public LabelPosition ValidationPosition
get => (LabelPosition)GetValue(ValidationPositionProperty);
set => SetValue(ValidationPositionProperty, value);
}
//----------------------------------------- -------------------------------
/// <summary>
/// Sets if an Empty Entry is Valid
/// </summary>
public bool Nullable { get => (bool)GetValue(NullableProperty); set => SetValue(NullableProperty, value); }
#endregion

//--------------------------------------------------------------------------------------------------------------------------------------------------
Expand All @@ -372,6 +421,7 @@ public LabelPosition ValidationPosition
public static readonly BindableProperty RegexPatternProperty = BindableProperty.Create(nameof(RegexPattern), typeof(string), typeof(AdvancedEntry), "", propertyChanged: (bo, ov, nv) => { (bo as AdvancedEntry).DisplayValidation(); (bo as AdvancedEntry).UpdateWarning(); });
public static readonly BindableProperty TextFontSizeProperty = BindableProperty.Create(nameof(TextFontSize), typeof(double), typeof(AdvancedEntry), Device.GetNamedSize(NamedSize.Default, typeof(Label)), propertyChanged: (bo, ov, nv) => (bo as AdvancedEntry).txtInput.FontSize = (double)nv);
public static readonly BindableProperty TextColorProperty = BindableProperty.Create(nameof(TextColor), typeof(Color), typeof(AdvancedEntry), Entry.TextColorProperty.DefaultValue , propertyChanged: (bo, ov, nv) => (bo as AdvancedEntry).txtInput.TextColor = (Color)nv);
public static readonly BindableProperty NullableProperty = BindableProperty.Create(nameof(Nullable), typeof(bool), typeof(AdvancedEntry), false, propertyChanged: (bo, ov, nv) => (bo as AdvancedEntry).Nullable = (bool)nv);
public static readonly new BindableProperty BackgroundColorProperty = BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(AdvancedEntry), GlobalSetting.BackgroundColor, propertyChanged: (bo, ov, nv) => (bo as AdvancedEntry).BackgroundColor = (Color)nv);
public static readonly BindableProperty ValidationPositionProperty = BindableProperty.Create(
propertyName: nameof(ValidationPosition), declaringType: typeof(AdvancedEntry),
Expand Down Expand Up @@ -454,14 +504,24 @@ public void UpdateKeyboard(AnnotationType annotation)
txtInput.Keyboard = Keyboard.Plain;
break;
case AnnotationType.DigitsOnly:
case AnnotationType.ShortType:
case AnnotationType.IntType:
case AnnotationType.LongType:
case AnnotationType.FloatType:
case AnnotationType.DoubleType:
case AnnotationType.DecimalType:
case AnnotationType.ByteType:
case AnnotationType.SByteType:
case AnnotationType.CharType:
case AnnotationType.UIntType:
case AnnotationType.ULongType:
case AnnotationType.UShortType:
case AnnotationType.Decimal:
txtInput.Keyboard = Keyboard.Numeric;
break;
case AnnotationType.NonDigitsOnly:
txtInput.Keyboard = Keyboard.Text;
break;
case AnnotationType.Decimal:
txtInput.Keyboard = Keyboard.Numeric;
break;
case AnnotationType.Email:
txtInput.Keyboard = Keyboard.Email;
break;
Expand Down Expand Up @@ -524,4 +584,4 @@ private protected virtual Entry GetInputEntry()
}
#endregion
}
}
}
50 changes: 49 additions & 1 deletion InputKit/Shared/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,55 @@ public enum AnnotationType
/// <summary>
/// You need to set RegexPattern property as your regex query to use this.
/// </summary>
RegexPattern
RegexPattern,
/// <summary>
/// Short Type only
/// </summary>
ShortType,
/// <summary>
/// Int Type only
/// </summary>
IntType,
/// <summary>
/// Long Type only
/// </summary>
LongType,
/// <summary>
/// Float Type only
/// </summary>
FloatType,
/// <summary>
/// Double Type only
/// </summary>
DoubleType,
/// <summary>
/// Decimal Type only
/// </summary>
DecimalType,
/// <summary>
/// Byte Type only
/// </summary>
ByteType,
/// <summary>
/// SByte Type only
/// </summary>
SByteType,
/// <summary>
/// Char Type only
/// </summary>
CharType,
/// <summary>
/// UInt Type only
/// </summary>
UIntType,
/// <summary>
/// ULong Type only
/// </summary>
ULongType,
/// <summary>
/// UShort Type only
/// </summary>
UShortType
}

public enum LabelPosition
Expand Down

0 comments on commit e101ccb

Please sign in to comment.