|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MaxBeckers\AmazonAlexa\Response\Directives\APL\Component; |
|
6
|
|
|
|
|
7
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\APLComponentType; |
|
8
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\FontStyle; |
|
9
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\FontWeight; |
|
10
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\KeyboardType; |
|
11
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\SecureInputType; |
|
12
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\Document\SubmitKeyType; |
|
13
|
|
|
use MaxBeckers\AmazonAlexa\Response\Directives\APL\StandardCommand\AbstractStandardCommand; |
|
14
|
|
|
|
|
15
|
|
|
class EditTextComponent extends ActionableComponent implements \JsonSerializable |
|
16
|
|
|
{ |
|
17
|
|
|
public const TYPE = APLComponentType::EDIT_TEXT; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param string|null $borderColor Color of the border around the text box |
|
21
|
|
|
* @param string|null $borderStrokeWidth Width of the border stroke around the text box |
|
22
|
|
|
* @param string $borderWidth Width of the border |
|
23
|
|
|
* @param string|null $color Color of the text the user enters |
|
24
|
|
|
* @param string $fontFamily The name of the font family |
|
25
|
|
|
* @param string $fontSize The size of the text |
|
26
|
|
|
* @param FontStyle|null $fontStyle The style of the font |
|
27
|
|
|
* @param FontWeight|null $fontWeight The weight of the font |
|
28
|
|
|
* @param string|null $highlightColor The highlight color to show behind selected text |
|
29
|
|
|
* @param string $hint Hint text to display when no text has been entered |
|
30
|
|
|
* @param string|null $hintColor The color of the hint text |
|
31
|
|
|
* @param FontStyle|null $hintStyle The style of the hint font |
|
32
|
|
|
* @param FontWeight|null $hintWeight The weight of the hint font |
|
33
|
|
|
* @param KeyboardType|null $keyboardType The type of keyboard to display |
|
34
|
|
|
* @param string $lang The language of the text |
|
35
|
|
|
* @param int $maxLength The maximum number of characters the user can enter |
|
36
|
|
|
* @param AbstractStandardCommand[]|null $onTextChange Commands to run when the text changes |
|
37
|
|
|
* @param AbstractStandardCommand[]|null $onSubmit Commands to run when the user submits |
|
38
|
|
|
* @param SecureInputType|null $secureInput Hide characters as they are typed if specified |
|
39
|
|
|
* @param bool $selectOnFocus When true, select the text when the EditText component gets focus |
|
40
|
|
|
* @param int $size Specifies approximately the number of characters to display |
|
41
|
|
|
* @param SubmitKeyType|null $submitKeyType The type of the return key |
|
42
|
|
|
* @param string $text The text to display |
|
43
|
|
|
* @param string $validCharacters Restrict the characters that can be entered |
|
44
|
|
|
*/ |
|
45
|
7 |
|
public function __construct( |
|
46
|
|
|
public ?string $borderColor = null, |
|
47
|
|
|
public ?string $borderStrokeWidth = null, |
|
48
|
|
|
public string $borderWidth = '0', |
|
49
|
|
|
public ?string $color = null, |
|
50
|
|
|
public string $fontFamily = 'sans-serif', |
|
51
|
|
|
public string $fontSize = '40dp', |
|
52
|
|
|
public ?FontStyle $fontStyle = null, |
|
53
|
|
|
public ?FontWeight $fontWeight = null, |
|
54
|
|
|
public ?string $highlightColor = null, |
|
55
|
|
|
public string $hint = '', |
|
56
|
|
|
public ?string $hintColor = null, |
|
57
|
|
|
public ?FontStyle $hintStyle = null, |
|
58
|
|
|
public ?FontWeight $hintWeight = null, |
|
59
|
|
|
public ?KeyboardType $keyboardType = null, |
|
60
|
|
|
public string $lang = '', |
|
61
|
|
|
public int $maxLength = 0, |
|
62
|
|
|
public ?array $onTextChange = null, |
|
63
|
|
|
public ?array $onSubmit = null, |
|
64
|
|
|
public ?SecureInputType $secureInput = null, |
|
65
|
|
|
public bool $selectOnFocus = false, |
|
66
|
|
|
public int $size = 8, |
|
67
|
|
|
public ?SubmitKeyType $submitKeyType = null, |
|
68
|
|
|
public string $text = '', |
|
69
|
|
|
public string $validCharacters = '', |
|
70
|
|
|
) { |
|
71
|
7 |
|
parent::__construct(self::TYPE); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
5 |
|
public function jsonSerialize(): array |
|
75
|
|
|
{ |
|
76
|
5 |
|
$data = parent::jsonSerialize(); |
|
77
|
|
|
|
|
78
|
5 |
|
if ($this->borderColor !== null) { |
|
79
|
1 |
|
$data['borderColor'] = $this->borderColor; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
5 |
|
if ($this->borderStrokeWidth !== null) { |
|
83
|
|
|
$data['borderStrokeWidth'] = $this->borderStrokeWidth; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
5 |
|
if ($this->borderWidth !== '0') { |
|
87
|
1 |
|
$data['borderWidth'] = $this->borderWidth; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
5 |
|
if ($this->color !== null) { |
|
91
|
1 |
|
$data['color'] = $this->color; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
5 |
|
if ($this->fontFamily !== 'sans-serif') { |
|
95
|
1 |
|
$data['fontFamily'] = $this->fontFamily; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
5 |
|
if ($this->fontSize !== '40dp') { |
|
99
|
1 |
|
$data['fontSize'] = $this->fontSize; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
5 |
|
if ($this->fontStyle !== null) { |
|
103
|
1 |
|
$data['fontStyle'] = $this->fontStyle->value; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
5 |
|
if ($this->fontWeight !== null) { |
|
107
|
1 |
|
$data['fontWeight'] = $this->fontWeight->value; |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
5 |
|
if ($this->highlightColor !== null) { |
|
111
|
|
|
$data['highlightColor'] = $this->highlightColor; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
5 |
|
if ($this->hint !== '') { |
|
115
|
1 |
|
$data['hint'] = $this->hint; |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
5 |
|
if ($this->hintColor !== null) { |
|
119
|
|
|
$data['hintColor'] = $this->hintColor; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
5 |
|
if ($this->hintStyle !== null) { |
|
123
|
1 |
|
$data['hintStyle'] = $this->hintStyle->value; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
5 |
|
if ($this->hintWeight !== null) { |
|
127
|
|
|
$data['hintWeight'] = $this->hintWeight->value; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
5 |
|
if ($this->keyboardType !== null) { |
|
131
|
|
|
$data['keyboardType'] = $this->keyboardType->value; |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
5 |
|
if ($this->lang !== '') { |
|
135
|
|
|
$data['lang'] = $this->lang; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
5 |
|
if ($this->maxLength !== 0) { |
|
139
|
1 |
|
$data['maxLength'] = $this->maxLength; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
5 |
|
if ($this->onTextChange !== null && !empty($this->onTextChange)) { |
|
143
|
|
|
$data['onTextChange'] = $this->onTextChange; |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
5 |
|
if ($this->onSubmit !== null && !empty($this->onSubmit)) { |
|
147
|
1 |
|
$data['onSubmit'] = $this->onSubmit; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
5 |
|
if ($this->secureInput !== null) { |
|
151
|
|
|
$data['secureInput'] = $this->secureInput->value; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
5 |
|
if ($this->selectOnFocus) { |
|
155
|
1 |
|
$data['selectOnFocus'] = $this->selectOnFocus; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
5 |
|
if ($this->size !== 8) { |
|
159
|
1 |
|
$data['size'] = $this->size; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
5 |
|
if ($this->submitKeyType !== null) { |
|
163
|
1 |
|
$data['submitKeyType'] = $this->submitKeyType->value; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
5 |
|
if ($this->text !== '') { |
|
167
|
1 |
|
$data['text'] = $this->text; |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
5 |
|
if ($this->validCharacters !== '') { |
|
171
|
|
|
$data['validCharacters'] = $this->validCharacters; |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
5 |
|
return $data; |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
|