forked from MagicFoundation/Alcinoe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathALFmxEdit.pas
2399 lines (2155 loc) · 101 KB
/
ALFmxEdit.pas
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit ALFmxEdit;
interface
{$I Alcinoe.inc}
uses
System.Types,
system.Classes,
System.UITypes,
{$IF defined(android)}
System.Messaging,
Androidapi.JNI.GraphicsContentViewText,
Androidapi.JNIBridge,
Androidapi.JNI.Widget,
Androidapi.JNI.JavaTypes,
ALAndroidNativeView,
ALAndroidApi,
{$ELSEIF defined(IOS)}
System.TypInfo,
iOSapi.Foundation,
iOSapi.UIKit,
Macapi.ObjectiveC,
Macapi.ObjCRuntime,
ALIosNativeView,
{$ELSE}
FMX.Edit,
{$ENDIF}
FMX.types,
Fmx.Graphics,
Fmx.controls,
ALFmxObjects;
Type
{**********************************}
TALAutoCapitalizationType = (acNone, // Specifies that there is no automatic text capitalization.
acWords, // Specifies automatic capitalization of the first letter of each word.
acSentences, // Specifies automatic capitalization of the first letter of each sentence.
acAllCharacters); // Specifies automatic capitalization of all characters, such as for entry of two-character state abbreviations for the United States.
{$REGION ' ANDROID'}
{$IF defined(android)}
type
{*********************}
TALAndroidEdit = class;
{**********************************************}
TALAndroidEditText = class(TALAndroidNativeView)
private
type
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
TALTextWatcher = class(TJavaLocal, JTextWatcher)
private
[Weak] FEditText: TALAndroidEditText;
public
constructor Create(const aEditText: TALAndroidEditText);
procedure afterTextChanged(s: JEditable); cdecl;
procedure beforeTextChanged(s: JCharSequence; start: Integer; count: Integer; after: Integer); cdecl;
procedure onTextChanged(s: JCharSequence; start: Integer; before: Integer; count: Integer); cdecl;
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
TALEditorActionListener = class(TJavaLocal, JTextView_OnEditorActionListener)
private
fIsMultiLineEditText: Boolean;
[Weak] FEditText: TALAndroidEditText;
public
constructor Create(const aEditText: TALAndroidEditText; const aIsMultiLineEditText: Boolean = false);
function onEditorAction(v: JTextView; actionId: Integer; event: JKeyEvent): Boolean; cdecl;
end;
{~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
TALKeyPreImeListener = class(TJavaLocal, JALKeyPreImeListener)
private
[Weak] FEditText: TALAndroidEditText;
public
constructor Create(const aEditText: TALAndroidEditText);
function onKeyPreIme(keyCode: Integer; event: JKeyEvent): Boolean; cdecl;
end;
private
fIsMultiline: boolean;
fDefStyleAttr: String;
fDefStyleRes: String;
FTextWatcher: TALTextWatcher;
FEditorActionListener: TALEditorActionListener;
FKeyPreImeListener: TALKeyPreImeListener;
[Weak] FEditControl: TALAndroidEdit;
function GetView: JALEditText;
protected
function CreateView: JView; override;
procedure InitView; override;
public
constructor Create(const AControl: TalAndroidEdit; Const aIsMultiline: Boolean = False; const aDefStyleAttr: String = ''; const aDefStyleRes: String = ''); reintroduce;
destructor Destroy; override;
property View: JALEditText read GetView;
end;
{****************************************************************}
// the design of the androidText can be done in the res/styles.xml
// please see the example of the demos\AlFmxcontrols.dproj
TALAndroidEdit = class(TControl)
private
FEditText: TALAndroidEditText;
FPadding: TBounds;
fOnChangeTracking: TNotifyEvent;
fOnReturnKey: TNotifyEvent;
FScreenScale: single;
FTextSettings: TTextSettings;
fMaxLength: integer;
fApplicationEventMessageID: integer;
fReturnKeyType: TReturnKeyType;
fKeyboardType: TVirtualKeyboardType;
fPassword: boolean;
fCheckSpelling: boolean;
fIsMultiline: Boolean;
procedure DoSetInputType(const aKeyboardType: TVirtualKeyboardType;
const aPassword: Boolean;
const aCheckSpelling: Boolean;
const aIsMultiline: Boolean);
procedure setKeyboardType(const Value: TVirtualKeyboardType);
function GetKeyboardType: TVirtualKeyboardType;
procedure setPassword(const Value: Boolean);
function GetPassword: Boolean;
procedure setCheckSpelling(const Value: Boolean);
function GetCheckSpelling: Boolean;
procedure DoSetReturnKeyType(const aReturnKeyType: TReturnKeyType);
procedure setReturnKeyType(const Value: TReturnKeyType);
function GetReturnKeyType: TReturnKeyType;
function GetTextPrompt: String;
procedure setTextPrompt(const Value: String);
function GetTextPromptColor: TAlphaColor;
procedure setTextPromptColor(const Value: TAlphaColor);
function GetTextSettings: TTextSettings;
procedure SetTextSettings(const Value: TTextSettings);
function getText: String;
procedure SetText(const Value: String);
function GetLineSpacingMultiplier: single;
procedure SetLineSpacingMultiplier(const Value: single);
function GetLineSpacingExtra: single;
procedure SetLineSpacingExtra(const Value: single);
procedure SetPadding(const Value: TBounds);
function GetPadding: TBounds;
procedure OnFontChanged(Sender: TObject);
procedure SetMaxLength(const Value: integer);
function GetMaxLength: integer;
procedure ApplicationEventHandler(const Sender: TObject; const M : TMessage);
protected
procedure AncestorVisibleChanged(const Visible: Boolean); override;
procedure AncestorParentChanged; override;
procedure ParentChanged; override;
procedure ClipChildrenChanged; override;
procedure DoAbsoluteChanged; override;
procedure DoRootChanged; override;
procedure Resize; override;
procedure VisibleChanged; override;
procedure ChangeOrder; override;
procedure DoEnter; override;
procedure DoExit; override;
procedure DoEndUpdate; override;
public
constructor Create(const AOwner: TComponent; Const aIsMultiline: Boolean = False; const aDefStyleAttr: String = ''; const aDefStyleRes: String = ''); reintroduce; virtual;
destructor Destroy; override;
procedure RecalcOpacity; override;
procedure RecalcEnabled; override;
Procedure AddNativeView;
Procedure RemoveNativeView;
Procedure setSelection(const aStart: integer; const aStop: Integer); overload;
Procedure setSelection(const aindex: integer); overload;
function getLineHeight: Single; // << it's include the line spacing
function getLineCount: integer;
function PointInObjectLocal(X: Single; Y: Single): Boolean; override;
property OnChangeTracking: TNotifyEvent read fOnChangeTracking write fOnChangeTracking;
property OnReturnKey: TNotifyEvent read fOnReturnKey write fOnReturnKey;
property ReturnKeyType: TReturnKeyType read GetReturnKeyType write SetReturnKeyType;
property KeyboardType: TVirtualKeyboardType read GetKeyboardType write SetKeyboardType;
property Password: Boolean read GetPassword write SetPassword default False;
property TextPrompt: String read GetTextPrompt write setTextPrompt;
property TextPromptColor: TAlphaColor read GetTextPromptColor write setTextPromptColor default TalphaColorRec.null; // << null mean use the default color
property MaxLength: integer read GetMaxLength write SetMaxLength default 0;
property Text: String read getText write SetText;
property TextSettings: TTextSettings read GetTextSettings write SetTextSettings;
property CheckSpelling: Boolean read GetCheckSpelling write SetCheckSpelling default true;
property EditText: TALAndroidEditText read FEditText;
property LineSpacingMultiplier: single read GetLineSpacingMultiplier write SetLineSpacingMultiplier; // << Each line will have its height multiplied by LineSpacingMultiplier
property LineSpacingExtra: single read GetLineSpacingExtra write SetLineSpacingExtra; // << Each line will have its height added by LineSpacingExtra
property Padding: TBounds read GetPadding write SetPadding;
end;
{$endif}
{$ENDREGION}
{$REGION ' IOS'}
{$IF defined(ios)}
type
{*************************************}
IALUITextField = interface(UITextField)
['{E4E67240-F15A-444F-8CE1-A3A830C023E8}']
procedure touchesBegan(touches: NSSet; withEvent: UIEvent); cdecl;
procedure touchesCancelled(touches: NSSet; withEvent: UIEvent); cdecl;
procedure touchesEnded(touches: NSSet; withEvent: UIEvent); cdecl;
procedure touchesMoved(touches: NSSet; withEvent: UIEvent); cdecl;
procedure ControlEventEditingChanged; cdecl;
procedure ControlEventEditingDidEnd; cdecl;
function canBecomeFirstResponder: Boolean; cdecl;
function canPerformAction(action: SEL; withSender: Pointer): Boolean; cdecl;
end;
{******************************}
TALIosTextFieldDelegate = class;
TALIosEdit = class;
{***************************************}
TALIosTextField = class(TALIosNativeView)
private
[Weak] FEditControl: TALIosEdit;
FTextFieldDelegate: TALIosTextFieldDelegate;
function GetView: UITextField;
protected
function GetObjectiveCClass: PTypeInfo; override;
public
constructor Create; overload; override;
constructor Create(const AControl: TControl); overload; override;
destructor Destroy; override;
procedure ControlEventEditingChanged; cdecl;
procedure ControlEventEditingDidEnd; cdecl;
function canPerformAction(action: SEL; withSender: Pointer): Boolean; cdecl;
function canBecomeFirstResponder: Boolean; cdecl;
property View: UITextField read GetView;
end;
{************************************************************}
TALIosTextFieldDelegate = class(TOCLocal, UITextFieldDelegate)
private
[Weak] FTextField: TALIosTextField;
public
constructor Create(const ATextField: TALIosTextField);
function textField(textField: UITextField; shouldChangeCharactersInRange: NSRange; replacementString: NSString): Boolean; cdecl; // << this work even without [MethodName('textField:shouldChangeCharactersInRange:replacementString:')] - better name would be textFieldShouldChangeCharactersInRange but i prefer to keep the name given by Delphi
procedure textFieldDidBeginEditing(textField: UITextField); cdecl;
procedure textFieldDidEndEditing(textField: UITextField); cdecl;
function textFieldShouldBeginEditing(textField: UITextField): Boolean; cdecl;
function textFieldShouldClear(textField: UITextField): Boolean; cdecl;
function textFieldShouldEndEditing(textField: UITextField): Boolean; cdecl;
function textFieldShouldReturn(textField: UITextField): Boolean; cdecl;
end;
{**************************}
TALIosEdit = class(TControl)
private
FTextField: TALIosTextField;
fTextPromptColor: TalphaColor;
fOnChangeTracking: TNotifyEvent;
fOnReturnKey: TNotifyEvent;
FTextSettings: TTextSettings;
fMaxLength: integer;
procedure setKeyboardType(const Value: TVirtualKeyboardType);
function GetKeyboardType: TVirtualKeyboardType;
procedure setAutoCapitalizationType(const Value: TALAutoCapitalizationType);
function GetAutoCapitalizationType: TALAutoCapitalizationType;
procedure setPassword(const Value: Boolean);
function GetPassword: Boolean;
procedure setCheckSpelling(const Value: Boolean);
function GetCheckSpelling: Boolean;
procedure setReturnKeyType(const Value: TReturnKeyType);
function GetReturnKeyType: TReturnKeyType;
function GetTextPrompt: String;
procedure setTextPrompt(const Value: String);
function GetTextPromptColor: TAlphaColor;
procedure setTextPromptColor(const Value: TAlphaColor);
procedure applyTextPromptWithColor(const aStr: String; const aColor: TAlphaColor);
function GetTintColor: TAlphaColor;
procedure setTintColor(const Value: TAlphaColor);
function GetTextSettings: TTextSettings;
procedure SetTextSettings(const Value: TTextSettings);
function getText: String;
procedure SetText(const Value: String);
procedure DoFontChanged;
procedure OnFontChanged(Sender: TObject);
protected
procedure AncestorVisibleChanged(const Visible: Boolean); override;
procedure AncestorParentChanged; override;
procedure ParentChanged; override;
procedure ClipChildrenChanged; override;
procedure DoAbsoluteChanged; override;
procedure DoRootChanged; override;
procedure Resize; override;
procedure VisibleChanged; override;
procedure ChangeOrder; override;
procedure DoEnter; override;
procedure DoExit; override;
procedure DoEndUpdate; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure RecalcOpacity; override;
procedure RecalcEnabled; override;
Procedure AddNativeView;
Procedure RemoveNativeView;
function PointInObjectLocal(X: Single; Y: Single): Boolean; override;
property OnChangeTracking: TNotifyEvent read fOnChangeTracking write fOnChangeTracking;
property OnReturnKey: TNotifyEvent read fOnReturnKey write fOnReturnKey;
property ReturnKeyType: TReturnKeyType read GetReturnKeyType write SetReturnKeyType;
property KeyboardType: TVirtualKeyboardType read GetKeyboardType write SetKeyboardType;
property AutoCapitalizationType: TALAutoCapitalizationType read GetAutoCapitalizationType write SetAutoCapitalizationType;
property Password: Boolean read GetPassword write SetPassword default False;
property TextPrompt: String read GetTextPrompt write setTextPrompt;
property TextPromptColor: TAlphaColor read GetTextPromptColor write setTextPromptColor default TalphaColorRec.null; // << null mean use the default color
property TintColor: TAlphaColor read GetTintColor write setTintColor; // << null mean use the default color
property MaxLength: integer read fMaxLength write fMaxLength default 0;
property Text: String read getText write SetText;
property TextSettings: TTextSettings read GetTextSettings write SetTextSettings;
property CheckSpelling: Boolean read GetCheckSpelling write SetCheckSpelling default true;
property TextField: TALIosTextField read FTextField;
end;
{$endif}
{$ENDREGION}
type
{*************************}
[ComponentPlatforms($FFFF)]
TALEdit = class(TALRectangle)
private
fDefStyleAttr: String;
fDefStyleRes: String;
FAutoTranslate: Boolean;
FAutoConvertFontFamily: boolean;
fOnChangeTracking: TNotifyEvent;
fOnReturnKey: TNotifyEvent;
fOnEnter: TNotifyEvent;
fOnExit: TNotifyEvent;
FTextSettings: TTextSettings;
{$IF defined(android)}
fTintColor: TalphaColor;
fAutoCapitalizationType: TALAutoCapitalizationType;
fEditControl: TALAndroidEdit;
function GetAndroidEditText: TALAndroidEditText;
{$ELSEIF defined(IOS)}
fEditControl: TALIosEdit;
function GetIosTextField: TALIosTextField;
{$ELSE}
fTintColor: TalphaColor;
fAutoCapitalizationType: TALAutoCapitalizationType;
fTextPromptColor: TalphaColor;
fEditControl: TEdit;
{$ENDIF}
function GetTextPrompt: String;
procedure setTextPrompt(const Value: String);
function GetTextPromptColor: TAlphaColor;
procedure setTextPromptColor(const Value: TAlphaColor);
function GetTintColor: TAlphaColor;
procedure setTintColor(const Value: TAlphaColor);
function GetTextSettings: TTextSettings;
procedure SetTextSettings(const Value: TTextSettings);
procedure OnFontChanged(Sender: TObject);
function getText: String;
procedure SetText(const Value: String);
procedure OnChangeTrackingImpl(Sender: TObject);
{$IF defined(ios) OR defined(android)}
procedure OnReturnKeyImpl(Sender: TObject);
{$ENDIF}
procedure SetOnReturnKey(const Value: TNotifyEvent);
{$IF (not defined(ios)) and (not defined(android))}
procedure OnKeyDownImpl(Sender: TObject; var Key: Word; var KeyChar: WideChar; Shift: TShiftState);
{$ENDIF}
procedure OnEnterImpl(Sender: TObject);
procedure OnExitImpl(Sender: TObject);
procedure SetKeyboardType(Value: TVirtualKeyboardType);
function GetKeyboardType: TVirtualKeyboardType;
procedure setAutoCapitalizationType(const Value: TALAutoCapitalizationType);
function GetAutoCapitalizationType: TALAutoCapitalizationType;
procedure SetPassword(const Value: Boolean);
function GetPassword: Boolean;
procedure SetCheckSpelling(const Value: Boolean);
function GetCheckSpelling: Boolean;
procedure SetReturnKeyType(const Value: TReturnKeyType);
function GetReturnKeyType: TReturnKeyType;
procedure SetDefStyleAttr(const Value: String);
procedure SetDefStyleRes(const Value: String);
procedure CreateEditControl;
function GetContainFocus: Boolean;
procedure SetMaxLength(const Value: integer);
function GetMaxLength: integer;
protected
function GetDefaultSize: TSizeF; override;
procedure Loaded; override;
procedure StrokeChanged(Sender: TObject); override;
procedure SetSides(const Value: TSides); override;
function GetCanFocus: Boolean; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{$IF defined(android)}
property AndroidEditText: TALAndroidEditText read GetAndroidEditText;
{$ELSEIF defined(IOS)}
property IosTextField: TALIosTextField read GetIosTextField;
{$ENDIF}
Procedure AddNativeView;
Procedure RemoveNativeView;
Procedure setSelection(const aStart: integer; const aStop: Integer); overload;
Procedure setSelection(const aindex: integer); overload;
property ContainFocus: Boolean read GetContainFocus;
published
property DefStyleAttr: String read fDefStyleAttr write SetDefStyleAttr; // << android only - the name of an attribute in the current theme that contains a reference to
// << a style resource that supplies defaults style values
// << exemple of use: https://stackoverflow.com/questions/5051753/how-do-i-apply-a-style-programmatically
// << NOTE: !!IMPORTANT!! This properties must be defined the very first because the stream system
// << must load it the very first
property DefStyleRes: String read fDefStyleRes write SetDefStyleRes; // << android only - the name of a style resource that supplies default style values
// << NOTE: !!IMPORTANT!! This properties must be defined the very first because the stream system
// << must load it the very first
property TabOrder;
property TabStop;
property Cursor default crIBeam;
property CanFocus default True;
//property CanParentFocus;
property DisableFocusEffect;
property KeyboardType: TVirtualKeyboardType read GetKeyboardType write SetKeyboardType default TVirtualKeyboardType.Default;
property AutoCapitalizationType: TALAutoCapitalizationType read GetAutoCapitalizationType write SetAutoCapitalizationType default TALAutoCapitalizationType.acNone;
property ReturnKeyType: TReturnKeyType read GetReturnKeyType write SetReturnKeyType default TReturnKeyType.Default;
property Password: Boolean read GetPassword write SetPassword default False;
//property ReadOnly;
property MaxLength: integer read GetMaxLength write SetMaxLength default 0;
//property FilterChar;
property Text: String read getText write SetText;
property TextSettings: TTextSettings read GetTextSettings write SetTextSettings;
property Hint;
property TextPrompt: String read GetTextPrompt write setTextPrompt;
property TextPromptColor: TAlphaColor read GetTextPromptColor write setTextPromptColor default TalphaColorRec.null; // << null mean use the default TextPromptColor
property TintColor: TAlphaColor read GetTintColor write setTintColor default TalphaColorRec.null; // << IOS only - the color of the cursor caret and the text selection handles. null mean use the default TintColor
property AutoTranslate: Boolean read FAutoTranslate write FAutoTranslate default true; // << just the TextPrompt
property AutoConvertFontFamily: Boolean read FAutoConvertFontFamily write fAutoConvertFontFamily default true;
property TouchTargetExpansion;
//property Caret;
//property KillFocusByReturn; => always true
property CheckSpelling: Boolean read GetCheckSpelling write SetCheckSpelling default true;
property ParentShowHint;
property ShowHint;
//property OnChange;
property OnChangeTracking: TNotifyEvent read fOnChangeTracking write fOnChangeTracking;
property OnReturnKey: TNotifyEvent read fOnReturnKey write SetOnReturnKey;
//property OnTyping;
//property OnValidating;
//property OnValidate;
//property OnKeyDown; // << not work under android - it's like this with their @{[^# virtual keyboard :(
//property OnKeyUp; // << not work under android - it's like this with their @{[^# virtual keyboard :(
property OnEnter: TnotifyEvent Read fOnEnter Write fOnEnter;
property OnExit: TnotifyEvent Read fOnExit Write fOnExit;
end;
procedure Register;
implementation
uses
{$IF defined(android)}
System.SysUtils,
Androidapi.Helpers,
Androidapi.Input,
Androidapi.KeyCodes,
Androidapi.JNI.App,
Androidapi.JNI.Util,
Androidapi.JNI.Os,
FMX.VirtualKeyboard,
FMX.Platform,
FMX.Platform.Android,
FMX.Helpers.Android,
FMX.Forms,
{$ELSEIF defined(IOS)}
System.SysUtils,
Macapi.CoreFoundation,
iOSapi.CoreGraphics,
iOSapi.CocoaTypes,
Macapi.Helpers,
iOSapi.CoreText,
FMX.Helpers.iOS,
FMX.Consts,
{$endif}
ALCommon,
ALString,
AlFmxCommon;
{**}
type
TALEditTextSettings = class(TTextSettings)
public
constructor Create(const AOwner: TPersistent); override;
published
property Font;
property FontColor;
property HorzAlign default TTextAlign.Leading;
property VertAlign default TTextAlign.Center;
end;
{****************************************************************}
constructor TALEditTextSettings.Create(const AOwner: TPersistent);
begin
inherited;
HorzAlign := TTextAlign.Leading;
VertAlign := TTextAlign.Center;
end;
{$REGION ' ANDROID'}
{$IF defined(android)}
{**********************************************************************************************}
constructor TALAndroidEditText.TALKeyPreImeListener.Create(const aEditText: TALAndroidEditText);
begin
inherited Create;
FEditText := aEditText;
end;
{********************************************************************************************************}
function TALAndroidEditText.TALKeyPreImeListener.onKeyPreIme(keyCode: Integer; event: JKeyEvent): Boolean;
begin
{$IF defined(DEBUG)}
if event <> nil then ALLog('TALAndroidEditText.TALKeyPreImeListener.onKeyPreIme', 'control.name: ' + FEditText.FEditControl.parent.Name +
' - keyCode: ' + inttostr(keyCode) +
' - event: ' + JstringToString(event.toString) +
' - ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.VERBOSE)
else ALLog('TALAndroidEditText.TALKeyPreImeListener.onKeyPreIme', 'control.name: ' + FEditText.FEditControl.parent.Name +
' - keyCode: ' + inttostr(keyCode) +
' - ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.VERBOSE);
{$ENDIF}
if ((event = nil) or (event.getAction = AKEY_EVENT_ACTION_UP)) and
(keyCode = AKEYCODE_BACK) then begin
result := true;
FEditText.FEditcontrol.resetfocus;
end
else result := false;
end;
{****************************************************************************************}
constructor TALAndroidEditText.TALTextWatcher.Create(const aEditText: TALAndroidEditText);
begin
inherited Create;
FEditText := aEditText;
end;
{*************************************************************************}
procedure TALAndroidEditText.TALTextWatcher.afterTextChanged(s: JEditable);
begin
{$IF defined(DEBUG)}
ALLog('TALAndroidEditText.TALTextWatcher.afterTextChanged', 'control.name: ' + FEditText.FEditControl.parent.Name +
' - ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.VERBOSE);
{$ENDIF}
if assigned(FEditText.fEditControl.fOnChangeTracking) then
FEditText.fEditControl.fOnChangeTracking(fEditText.fEditControl);
end;
{******************************************************************************************************************************}
procedure TALAndroidEditText.TALTextWatcher.beforeTextChanged(s: JCharSequence; start: Integer; count: Integer; after: Integer);
begin
//nothing to do
end;
{***************************************************************************************************************************}
procedure TALAndroidEditText.TALTextWatcher.onTextChanged(s: JCharSequence; start: Integer; before: Integer; count: Integer);
begin
//nothing to do
end;
{**********************************************************************************************************************************************}
constructor TALAndroidEditText.TALEditorActionListener.Create(const aEditText: TALAndroidEditText; const aIsMultiLineEditText: Boolean = false);
begin
inherited Create;
FEditText := aEditText;
fIsMultiLineEditText := aIsMultiLineEditText;
end;
{*****************************************************************************************************************************}
function TALAndroidEditText.TALEditorActionListener.onEditorAction(v: JTextView; actionId: Integer; event: JKeyEvent): Boolean;
begin
{$IF defined(DEBUG)}
if event <> nil then ALLog('TALAndroidEditText.TALEditorActionListener.onEditorAction', 'control.name: ' + FEditText.FEditControl.parent.Name +
' - actionId: ' + inttostr(actionId) +
' - event: ' + JstringToString(event.toString) +
' - ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.VERBOSE)
else ALLog('TALAndroidEditText.TALEditorActionListener.onEditorAction', 'control.name: ' + FEditText.FEditControl.parent.Name +
' - actionId: ' + inttostr(actionId) +
' - ThreadID: ' + alIntToStrU(TThread.Current.ThreadID) + '/' + alIntToStrU(MainThreadID), TalLogType.VERBOSE);
{$ENDIF}
//IME_ACTION_DONE: the action key performs a "done" operation, typically meaning there is nothing more to input and the IME will be closed.
//IME_ACTION_GO: the action key performs a "go" operation to take the user to the target of the text they typed. Typically used, for example, when entering a URL.
//IME_ACTION_NEXT: the action key performs a "next" operation, taking the user to the next field that will accept text.
//IME_ACTION_NONE: there is no available action.
//IME_ACTION_PREVIOUS: like IME_ACTION_NEXT, but for moving to the previous field. This will normally not be used to specify an action (since it precludes IME_ACTION_NEXT), but can be returned to the app if it sets IME_FLAG_NAVIGATE_PREVIOUS.
//IME_ACTION_SEARCH: the action key performs a "search" operation, taking the user to the results of searching for the text they have typed (in whatever context is appropriate).
//IME_ACTION_SEND: the action key performs a "send" operation, delivering the text to its target. This is typically used when composing a message in IM or SMS where sending is immediate.
//IME_ACTION_UNSPECIFIED: no specific action has been associated with this editor, let the editor come up with its own if it can.
if (assigned(FEditText.FEditControl.fOnReturnKey)) and
(((actionId = TJEditorInfo.javaClass.IME_ACTION_UNSPECIFIED) and // IME_ACTION_UNSPECIFIED = the return key
(not fIsMultiLineEditText)) or
(actionId = TJEditorInfo.javaClass.IME_ACTION_DONE) or
(actionId = TJEditorInfo.javaClass.IME_ACTION_GO) or
(actionId = TJEditorInfo.javaClass.IME_ACTION_NEXT) or
(actionId = TJEditorInfo.javaClass.IME_ACTION_SEARCH) or
(actionId = TJEditorInfo.javaClass.IME_ACTION_SEND)) then begin
result := true;
FEditText.FEditControl.fOnReturnKey(fEditText.fEditControl);
end
else result := false;
end;
{****************************************************************************************************************************************************************************}
constructor TALAndroidEditText.Create(const AControl: TalAndroidEdit; Const aIsMultiline: Boolean = False; const aDefStyleAttr: String = ''; const aDefStyleRes: String = '');
begin
fIsMultiline := aIsMultiline;
fDefStyleAttr := aDefStyleAttr;
fDefStyleRes := aDefStyleRes;
FTextWatcher := TALTextWatcher.Create(self);
FEditorActionListener := TALEditorActionListener.Create(self, aIsMultiline);
FKeyPreImeListener := TALKeyPreImeListener.Create(self);
fEditControl := TalAndroidEdit(AControl);
inherited create(AControl); // << this will call InitView
end;
{************************************}
destructor TALAndroidEditText.Destroy;
begin
View.setVisibility(TJView.JavaClass.INVISIBLE);
View.RemoveTextChangedListener(FTextWatcher);
View.setOnEditorActionListener(nil);
View.SetKeyPreImeListener(nil);
alfreeandNil(FTextWatcher);
alfreeandNil(fEditorActionListener);
alfreeandNil(FKeyPreImeListener);
inherited;
end;
{********************************************}
function TALAndroidEditText.CreateView: JView;
Var LSDKVersion: integer;
begin
LSDKVersion := TJBuild_VERSION.JavaClass.SDK_INT;
//-----
if (fDefStyleAttr = '') and
((LSDKVersion < 22{lollipop}) or (fDefStyleRes='')) then
Result := TJALEditText.JavaClass.init(TAndroidHelper.Activity)
//-----
else if (LSDKVersion < 22{lollipop}) or (fDefStyleRes='') then
Result := TJALEditText.JavaClass.init(
TAndroidHelper.Activity, // context: JContext;
nil, // attrs: JAttributeSet;
TAndroidHelper. // defStyleAttr: Integer
Context.
getResources().
getIdentifier(StringToJstring(fDefStyleAttr), // name String: The name of the desired resource.
StringToJstring('attr'), // String: Optional default resource type to find, if "type/" is not included in the name. Can be null to require an explicit type.
TAndroidHelper.Context.getPackageName())) // String: Optional default package to find, if "package:" is not included in the name. Can be null to require an explicit package.
//-----
else if (fDefStyleAttr = '') then
Result := TJALEditText.JavaClass.init(
TAndroidHelper.Activity, // context: JContext;
nil, // attrs: JAttributeSet;
0, // defStyleAttr: Integer
TAndroidHelper. // defStyleRes: Integer
Context.
getResources().
getIdentifier(StringToJstring(fDefStyleRes), // name String: The name of the desired resource.
StringToJstring('style'), // String: Optional default resource type to find, if "type/" is not included in the name. Can be null to require an explicit type.
TAndroidHelper.Context.getPackageName())) // String: Optional default package to find, if "package:" is not included in the name. Can be null to require an explicit package.
//-----
else
Result := TJALEditText.JavaClass.init(
TAndroidHelper.Activity, // context: JContext;
nil, // attrs: JAttributeSet;
TAndroidHelper. // defStyleAttr: Integer
Context.
getResources().
getIdentifier(StringToJstring(fDefStyleAttr), // name String: The name of the desired resource.
StringToJstring('attr'), // String: Optional default resource type to find, if "type/" is not included in the name. Can be null to require an explicit type.
TAndroidHelper.Context.getPackageName()), // String: Optional default package to find, if "package:" is not included in the name. Can be null to require an explicit package.
TAndroidHelper. // defStyleRes: Integer
Context.
getResources().
getIdentifier(StringToJstring(fDefStyleRes), // name String: The name of the desired resource.
StringToJstring('style'), // String: Optional default resource type to find, if "type/" is not included in the name. Can be null to require an explicit type.
TAndroidHelper.Context.getPackageName())) // String: Optional default package to find, if "package:" is not included in the name. Can be null to require an explicit package.
end;
{************************************}
procedure TALAndroidEditText.InitView;
begin
inherited;
//-----
if fIsMultiline then View.setSingleLine(False)
else View.setSingleLine(True);
View.setClickable(True);
View.setFocusable(True);
View.setFocusableInTouchMode(True);
//-----
View.addTextChangedListener(fTextWatcher);
View.setOnEditorActionListener(fEditorActionListener);
View.SetKeyPreImeListener(fKeyPreImeListener);
end;
{***********************************************}
function TALAndroidEditText.GetView: JALEditText;
begin
Result := inherited GetView<JALEditText>;
end;
{******************************************************************************************************************************************************************}
constructor TalAndroidEdit.Create(const AOwner: TComponent; Const aIsMultiline: Boolean = False; const aDefStyleAttr: String = ''; const aDefStyleRes: String = '');
var LScreenSrv: IFMXScreenService;
begin
{$IF defined(DEBUG)}
ALLog('TALAndroidEdit.Create', 'start', TalLogType.VERBOSE);
{$ENDIF}
//-----
inherited create(AOwner);
//-----
if TPlatformServices.Current.SupportsPlatformService(IFMXScreenService, LScreenSrv) then FScreenScale := LScreenSrv.GetScreenScale
else FScreenScale := 1;
//-----
FPadding := TBounds.Create(TRectF.Empty);
fMaxLength := 0;
CanFocus := True;
fOnChangeTracking := nil;
FOnReturnKey := nil;
fApplicationEventMessageID := TMessageManager.DefaultManager.SubscribeToMessage(TApplicationEventMessage, ApplicationEventHandler);
FTextSettings := TALEditTextSettings.Create(Self);
FTextSettings.OnChanged := OnFontChanged;
fReturnKeyType := tReturnKeyType.Default;
fKeyboardType := TVirtualKeyboardType.default;
fPassword := false;
fCheckSpelling := true;
fIsMultiline := aIsMultiline;
FEditText := TALAndroidEditText.create(self, aIsMultiline, aDefStyleAttr, aDefStyleRes);
DoSetReturnKeyType(fReturnKeyType);
DoSetInputType(fKeyboardType, fPassword, fCheckSpelling, fIsMultiline);
//-----
{$IF defined(DEBUG)}
ALLog('TALAndroidEdit.Create', 'end', TalLogType.VERBOSE);
{$ENDIF}
end;
{********************************}
destructor TalAndroidEdit.Destroy;
begin
{$IF defined(DEBUG)}
ALLog('TALAndroidEdit.Destroy', 'start', TalLogType.VERBOSE);
{$ENDIF}
TMessageManager.DefaultManager.Unsubscribe(TApplicationEventMessage, fApplicationEventMessageID);
ALfreeandNil(FEditText);
ALFreeAndNil(FTextSettings);
ALFreeAndNil(FPadding);
inherited Destroy;
{$IF defined(DEBUG)}
ALLog('TALAndroidEdit.Destroy', 'end', TalLogType.VERBOSE);
{$ENDIF}
end;
{********************************************************************************}
procedure TALAndroidEdit.DoSetInputType(const aKeyboardType: TVirtualKeyboardType;
const aPassword: Boolean;
const aCheckSpelling: Boolean;
const aIsMultiline: Boolean);
var LInputType: integer;
begin
// TYPE_CLASS_DATETIME: Class for dates and times.
// TYPE_CLASS_NUMBER: Class for numeric text.
// TYPE_CLASS_PHONE: Class for a phone number.
// TYPE_CLASS_TEXT: Class for normal text.
// TYPE_DATETIME_VARIATION_DATE: Default variation of TYPE_CLASS_DATETIME: allows entering only a date.
// TYPE_DATETIME_VARIATION_NORMAL: Default variation of TYPE_CLASS_DATETIME: allows entering both a date and time.
// TYPE_DATETIME_VARIATION_TIME: Default variation of TYPE_CLASS_DATETIME: allows entering only a time.
// TYPE_MASK_CLASS: Mask of bits that determine the overall class of text being given.
// TYPE_MASK_FLAGS: Mask of bits that provide addition bit flags of options.
// TYPE_MASK_VARIATION: Mask of bits that determine the variation of the base content class.
// TYPE_NULL: Special content type for when no explicit type has been specified.
// TYPE_NUMBER_FLAG_DECIMAL: Flag of TYPE_CLASS_NUMBER: the number is decimal, allowing a decimal point to provide fractional values.
// TYPE_NUMBER_FLAG_SIGNED: Flag of TYPE_CLASS_NUMBER: the number is signed, allowing a positive or negative sign at the start.
// TYPE_NUMBER_VARIATION_NORMAL: Default variation of TYPE_CLASS_NUMBER: plain normal numeric text.
// TYPE_NUMBER_VARIATION_PASSWORD: Variation of TYPE_CLASS_NUMBER: entering a numeric password.
// TYPE_TEXT_FLAG_AUTO_COMPLETE: Flag for TYPE_CLASS_TEXT: the text editor (which means the application) is performing auto-completion of the text being entered based on its own semantics, which it will present to the user as they type.
// TYPE_TEXT_FLAG_AUTO_CORRECT: Flag for TYPE_CLASS_TEXT: the user is entering free-form text that should have auto-correction applied to it.
// TYPE_TEXT_FLAG_CAP_CHARACTERS: Flag for TYPE_CLASS_TEXT: capitalize all characters.
// TYPE_TEXT_FLAG_CAP_SENTENCES: Flag for TYPE_CLASS_TEXT: capitalize the first character of each sentence.
// TYPE_TEXT_FLAG_CAP_WORDS: Flag for TYPE_CLASS_TEXT: capitalize the first character of every word.
// TYPE_TEXT_FLAG_IME_MULTI_LINE: Flag for TYPE_CLASS_TEXT: the regular text view associated with this should not be multi-line, but when a fullscreen input method is providing text it should use multiple lines if it can.
// TYPE_TEXT_FLAG_MULTI_LINE: Flag for TYPE_CLASS_TEXT: multiple lines of text can be entered into the field.
// TYPE_TEXT_FLAG_NO_SUGGESTIONS: Flag for TYPE_CLASS_TEXT: the input method does not need to display any dictionary-based candidates.
// TYPE_TEXT_VARIATION_EMAIL_ADDRESS: Variation of TYPE_CLASS_TEXT: entering an e-mail address.
// TYPE_TEXT_VARIATION_EMAIL_SUBJECT: Variation of TYPE_CLASS_TEXT: entering the subject line of an e-mail.
// TYPE_TEXT_VARIATION_FILTER: Variation of TYPE_CLASS_TEXT: entering text to filter contents of a list etc.
// TYPE_TEXT_VARIATION_LONG_MESSAGE: Variation of TYPE_CLASS_TEXT: entering the content of a long, possibly formal message such as the body of an e-mail.
// TYPE_TEXT_VARIATION_NORMAL: Default variation of TYPE_CLASS_TEXT: plain old normal text.
// TYPE_TEXT_VARIATION_PASSWORD: Variation of TYPE_CLASS_TEXT: entering a password.
// TYPE_TEXT_VARIATION_PERSON_NAME: Variation of TYPE_CLASS_TEXT: entering the name of a person.
// TYPE_TEXT_VARIATION_PHONETIC: Variation of TYPE_CLASS_TEXT: entering text for phonetic pronunciation, such as a phonetic name field in contacts.
// TYPE_TEXT_VARIATION_POSTAL_ADDRESS: Variation of TYPE_CLASS_TEXT: entering a postal mailing address.
// TYPE_TEXT_VARIATION_SHORT_MESSAGE: Variation of TYPE_CLASS_TEXT: entering a short, possibly informal message such as an instant message or a text message.
// TYPE_TEXT_VARIATION_URI: Variation of TYPE_CLASS_TEXT: entering a URI.
// TYPE_TEXT_VARIATION_VISIBLE_PASSWORD: Variation of TYPE_CLASS_TEXT: entering a password, which should be visible to the user.
// TYPE_TEXT_VARIATION_WEB_EDIT_TEXT: Variation of TYPE_CLASS_TEXT: entering text inside of a web form.
// TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS: Variation of TYPE_CLASS_TEXT: entering e-mail address inside of a web form.
// TYPE_TEXT_VARIATION_WEB_PASSWORD: Variation of TYPE_CLASS_TEXT: entering password inside of a web form.
case aKeyboardType of
TVirtualKeyboardType.Alphabet: LInputType := TJInputType.JavaClass.TYPE_CLASS_TEXT or TJInputType.JavaClass.TYPE_TEXT_FLAG_NO_SUGGESTIONS;
TVirtualKeyboardType.URL: LInputType := TJInputType.JavaClass.TYPE_CLASS_TEXT or TJInputType.JavaClass.TYPE_TEXT_VARIATION_URI;
TVirtualKeyboardType.NamePhonePad: LInputType := TJInputType.JavaClass.TYPE_CLASS_TEXT;
TVirtualKeyboardType.EmailAddress: LInputType := TJInputType.JavaClass.TYPE_CLASS_TEXT or TJInputType.JavaClass.TYPE_TEXT_VARIATION_EMAIL_ADDRESS;
TVirtualKeyboardType.NumbersAndPunctuation: LInputType := TJInputType.JavaClass.TYPE_CLASS_NUMBER or TJInputType.JavaClass.TYPE_NUMBER_FLAG_DECIMAL;
TVirtualKeyboardType.NumberPad: LInputType := TJInputType.JavaClass.TYPE_CLASS_NUMBER;
TVirtualKeyboardType.PhonePad: LInputType := TJInputType.JavaClass.TYPE_CLASS_PHONE;
else {TVirtualKeyboardType.Default} LInputType := TJInputType.JavaClass.TYPE_CLASS_TEXT;
end;
if aPassword then begin
case aKeyboardType of
TVirtualKeyboardType.NumbersAndPunctuation: LInputType := LInputType or TJInputType.JavaClass.TYPE_NUMBER_VARIATION_PASSWORD;
TVirtualKeyboardType.NumberPad: LInputType := LInputType or TJInputType.JavaClass.TYPE_NUMBER_VARIATION_PASSWORD;
TVirtualKeyboardType.PhonePad:;
TVirtualKeyboardType.Alphabet: LInputType := LInputType or TJInputType.JavaClass.TYPE_TEXT_VARIATION_PASSWORD;
TVirtualKeyboardType.URL: LInputType := LInputType or TJInputType.JavaClass.TYPE_TEXT_VARIATION_PASSWORD;
TVirtualKeyboardType.NamePhonePad: LInputType := LInputType or TJInputType.JavaClass.TYPE_TEXT_VARIATION_PASSWORD;
TVirtualKeyboardType.EmailAddress: LInputType := LInputType or TJInputType.JavaClass.TYPE_TEXT_VARIATION_PASSWORD;
else {TVirtualKeyboardType.Default} LInputType := LInputType or TJInputType.JavaClass.TYPE_TEXT_VARIATION_PASSWORD;
end;
end
else if not aCheckSpelling then begin
// https://stackoverflow.com/questions/61704644/why-type-text-flag-no-suggestions-is-not-working-to-disable-auto-corrections
case aKeyboardType of
TVirtualKeyboardType.Alphabet: LInputType := LInputType or TJInputType.JavaClass.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
TVirtualKeyboardType.URL:;
TVirtualKeyboardType.NamePhonePad: LInputType := LInputType or TJInputType.JavaClass.TYPE_TEXT_FLAG_NO_SUGGESTIONS or TJInputType.JavaClass.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
TVirtualKeyboardType.EmailAddress:;
TVirtualKeyboardType.NumbersAndPunctuation:;
TVirtualKeyboardType.NumberPad:;
TVirtualKeyboardType.PhonePad:;
else {TVirtualKeyboardType.Default} LInputType := LInputType or TJInputType.JavaClass.TYPE_TEXT_FLAG_NO_SUGGESTIONS or TJInputType.JavaClass.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
end;
end;
if aIsMultiline then LInputType := LInputType or TJInputType.JavaClass.TYPE_TEXT_FLAG_MULTI_LINE;
fEditText.view.setInputType(LInputType);
end;
{**************************************************************************}
procedure TALAndroidEdit.setKeyboardType(const Value: TVirtualKeyboardType);
begin
if (value <> fKeyboardType) then begin
fKeyboardType := Value;
DoSetInputType(Value, fPassword, fCheckSpelling, fIsMultiLine);
end;
end;
{************************************************************}
function TALAndroidEdit.GetKeyboardType: TVirtualKeyboardType;
begin
result := fKeyboardType;
end;
{*********************************************************}
procedure TALAndroidEdit.setPassword(const Value: Boolean);
begin
if (value <> fPassword) then begin
fPassword := Value;
DoSetInputType(fKeyboardType, Value, fCheckSpelling, fIsMultiLine);
end;
end;
{*******************************************}
function TALAndroidEdit.GetPassword: Boolean;
begin
result := fPassword;
end;
{**************************************************************}
procedure TalAndroidEdit.SetCheckSpelling(const Value: Boolean);
begin
if (value <> fCheckSpelling) then begin
fCheckSpelling := Value;
DoSetInputType(fKeyboardType, fPassword, Value, fIsMultiLine);
end;
end;
{************************************************}
function TalAndroidEdit.GetCheckSpelling: Boolean;
begin
result := fCheckSpelling;
end;
{*********************************************************************************}
procedure TALAndroidEdit.DoSetReturnKeyType(const aReturnKeyType: TReturnKeyType);
var LImeOptions: integer;
begin
case aReturnKeyType of
TReturnKeyType.Done: LImeOptions := TJEditorInfo.JavaClass.IME_ACTION_DONE;
TReturnKeyType.Go: LImeOptions := TJEditorInfo.JavaClass.IME_ACTION_NONE; // TJEditorInfo.JavaClass.IME_ACTION_GO; => https://stackoverflow.com/questions/44708338/setimeactionlabel-or-setimeoptions-not-work-i-always-have-caption-done-on-the
TReturnKeyType.Next: LImeOptions := TJEditorInfo.JavaClass.IME_ACTION_NONE; // TJEditorInfo.JavaClass.IME_ACTION_NEXT; => https://stackoverflow.com/questions/44708338/setimeactionlabel-or-setimeoptions-not-work-i-always-have-caption-done-on-the
TReturnKeyType.Search: LImeOptions := TJEditorInfo.JavaClass.IME_ACTION_NONE; // TJEditorInfo.JavaClass.IME_ACTION_SEARCH; => https://stackoverflow.com/questions/44708338/setimeactionlabel-or-setimeoptions-not-work-i-always-have-caption-done-on-the
TReturnKeyType.Send: LImeOptions := TJEditorInfo.JavaClass.IME_ACTION_NONE; // TJEditorInfo.JavaClass.IME_ACTION_SEND; => https://stackoverflow.com/questions/44708338/setimeactionlabel-or-setimeoptions-not-work-i-always-have-caption-done-on-the
else {TReturnKeyType.Default} LImeOptions := TJEditorInfo.JavaClass.IME_ACTION_NONE;
end;
fEditText.view.setImeOptions(LImeOptions);
end;
{*********************************************************************}
procedure TALAndroidEdit.setReturnKeyType(const Value: TReturnKeyType);
begin
if (value <> fReturnKeyType) then begin
fReturnKeyType := Value;
DoSetReturnKeyType(Value);
end;
end;
{*******************************************************}
function TALAndroidEdit.GetReturnKeyType: TReturnKeyType;
begin
result := fReturnKeyType;
end;
{*******************************************************}
function TALAndroidEdit.GetLineSpacingMultiplier: single;
begin
result := FEditText.view.getLineSpacingMultiplier;
end;
{*********************************************************************}
procedure TALAndroidEdit.SetLineSpacingMultiplier(const Value: single);
begin
fEditText.view.setLineSpacing(fEditText.view.getLineSpacingExtra, Value);
end;
{**************************************************}
function TALAndroidEdit.GetLineSpacingExtra: single;
begin
result := FEditText.view.getLineSpacingExtra;
end;
{****************************************************************}
procedure TALAndroidEdit.SetLineSpacingExtra(const Value: single);
begin
fEditText.view.setLineSpacing(Value, fEditText.view.getLineSpacingMultiplier);
end;
{********************************************************}
procedure TALAndroidEdit.SetPadding(const Value: TBounds);
begin
FPadding.Assign(Value);
fEditText.view.setPadding(round(Value.Left * fScreenScale), round(Value.Top * fScreenScale), round(Value.Right * fScreenScale), round(Value.Bottom * fScreenScale));
end;
{******************************************}
function TALAndroidEdit.GetPadding: TBounds;
begin
result := FPadding;
end;
{**********************************************************}
procedure TALAndroidEdit.SetMaxLength(const Value: integer);
begin
if value <> FMaxLength then
fEditText.View.setMaxLength(Value);
end;
{********************************************}
function TALAndroidEdit.GetMaxLength: integer;
begin
result := FMaxLength;
end;
{********************************************}
function TalAndroidEdit.GetTextPrompt: String;
begin
result := JCharSequenceToStr(fEditText.View.getHint);
end;
{**********************************************************}
procedure TalAndroidEdit.setTextPrompt(const Value: String);
begin
fEditText.View.setHint(StrToJCharSequence(Value));