forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeyboardExtensions.cs
85 lines (76 loc) · 2.29 KB
/
KeyboardExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using Windows.UI.Xaml.Input;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms.Platform.UWP
{
public static class KeyboardExtensions
{
public static InputScope ToInputScope(this Keyboard self)
{
if (self == null)
throw new ArgumentNullException("self");
var result = new InputScope();
var name = new InputScopeName();
if (self == Keyboard.Default)
{
name.NameValue = InputScopeNameValue.Default;
}
else if (self == Keyboard.Chat)
{
name.NameValue = InputScopeNameValue.Chat;
}
else if (self == Keyboard.Email)
{
name.NameValue = InputScopeNameValue.EmailSmtpAddress;
}
else if (self == Keyboard.Numeric)
{
name.NameValue = InputScopeNameValue.Number;
}
else if (self == Keyboard.Telephone)
{
name.NameValue = InputScopeNameValue.TelephoneNumber;
}
else if (self == Keyboard.Text)
{
name.NameValue = InputScopeNameValue.Default;
}
else if (self == Keyboard.Url)
{
name.NameValue = InputScopeNameValue.Url;
}
else
{
var custom = (CustomKeyboard)self;
var capitalizedSentenceEnabled = (custom.Flags & KeyboardFlags.CapitalizeSentence) == KeyboardFlags.CapitalizeSentence;
var capitalizedWordsEnabled = (custom.Flags & KeyboardFlags.CapitalizeWord) == KeyboardFlags.CapitalizeWord;
var capitalizedCharacterEnabled = (custom.Flags & KeyboardFlags.CapitalizeCharacter) == KeyboardFlags.CapitalizeCharacter;
var spellcheckEnabled = (custom.Flags & KeyboardFlags.Spellcheck) == KeyboardFlags.Spellcheck;
var suggestionsEnabled = (custom.Flags & KeyboardFlags.Suggestions) == KeyboardFlags.Suggestions;
InputScopeNameValue nameValue = InputScopeNameValue.Default;
if (capitalizedSentenceEnabled)
{
if (!spellcheckEnabled)
{
Log.Warning(null, "CapitalizeSentence only works when spell check is enabled");
}
}
else if (capitalizedWordsEnabled)
{
if (!spellcheckEnabled)
{
Log.Warning(null, "CapitalizeWord only works when spell check is enabled");
}
nameValue = InputScopeNameValue.NameOrPhoneNumber;
}
if (capitalizedCharacterEnabled)
{
Log.Warning(null, "UWP does not support CapitalizeCharacter");
}
name.NameValue = nameValue;
}
result.Names.Add(name);
return result;
}
}
}