Repository navigation
Expand file tree
/
Copy pathKeyPanel.cs
More file actions
6676 lines (5886 loc) · 285 KB
/
Copy pathKeyPanel.cs
File metadata and controls
6676 lines (5886 loc) · 285 KB
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
using System.Globalization;
using Android.Content;
using Android.Content.Res;
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.OS;
using Android.Util;
using Android.Views;
using Android.Widget;
using Orientation = Android.Widget.Orientation;
namespace Berpiztu.KeyPlus;
/// <summary>
/// The keys, as a small window: a title bar that moves it, with ABC to turn
/// it into a whole Spanish keyboard and Keys to turn it back, A− and A+ for
/// smaller or larger labels on the keys that type characters and A↺ for the
/// keys and labels at their usual size, ⤓ to dock it
/// above the keyboard again (while it floats), – to minimize it into the ⌨
/// icon, which a tap opens again and a drag moves, and ✕ to close KeyPlus,
/// once the title bar has asked whether to; the keys, the shortcuts'
/// row and the terminal's two or the whole keyboard; the window resized with
/// the frame its resize lays over the keys (<see cref="KeyboardFrame"/>), or
/// a long press near a corner. Where the window stands is
/// the popup's service's (KeyPlusService): the title bar, the icon and the corners only
/// say how far they were dragged.
/// Ctrl, Alt and AltGr are held as Termux holds them: pressed once they stay
/// down, filled, for the next key, here or typed on the phone's keyboard
/// (<see cref="TakeHeldForTyped"/>), and are let go after it; pressed again
/// they let go at once. Shift stays down for the strip's keys, so Shift and
/// the arrows select, and is let go after a character typed; Caps Lock stays
/// until pressed again. A dead key (´ ` ^ ¨) waits for the next character
/// and puts its accent on it. Keys act on the touch, not on its release, and
/// the arrows, the pages and the deleting keys repeat while held.
/// </summary>
public sealed class KeyPanel
{
/// <summary>The phase of a drag on the title bar, the icon or a grip.</summary>
public enum Drag
{
Start,
Move,
End,
}
/// <summary>The corner a grip resizes from; the opposite one stays where it is.</summary>
[Flags]
public enum Corner
{
BottomRight = 0,
Left = 1,
Top = 2,
BottomLeft = Left,
TopRight = Top,
TopLeft = Left | Top,
}
private const string FoldedPreference = "folded";
private const string WholeKeyboardPreference = "wholeKeyboard";
private const string CompactPreference = "compact";
private const string LabelScalePreference = "labelScale";
/// <summary>How much A− and A+ change the labels' size at a press, and how far.</summary>
private const float LabelScaleStep = 0.1f;
private const float SmallestLabelScale = 0.5f;
private const float LargestLabelScale = 5f;
internal const int RepeatDelayMs = 400;
internal const int RepeatIntervalMs = 50;
/// <summary>How long a touch is held still before it moves or resizes the window.</summary>
private const int LongPressMs = 450;
/// <summary>How near a corner of the window a long press starts to resize it rather than move it.</summary>
private const int CornerReachDp = 48;
/// <summary>The icon's label, in sp.</summary>
private const float LabelSize = 16f;
/// <summary>
/// The room around a key, and inside it around its labels, in dp: one
/// each, so the labels have the key almost whole.
/// </summary>
private const int KeyMarginDp = 1;
private const int KeyPaddingDp = 1;
/// <summary>The most of its key's width the word of a key that types no character takes: three quarters, the rest room at its sides.</summary>
private const float WordShare = 0.75f;
/// <summary>The least the words' one size is of the legends': below it, a word that does not fit is made smaller alone.</summary>
private const float WordFloor = 0.7f;
/// <summary>The least room between two legends of a key, in dp.</summary>
private const int LegendGapDp = 2;
/// <summary>The title bar's height, in dp: enough to hold and move the window by, no more.</summary>
private const int TitleBarDp = 32;
/// <summary>The least the title bar's height goes down to with the keys, in dp: room for a finger to hold it.</summary>
private const int LeastTitleBarDp = 24;
/// <summary>A swipe's trail's width where the finger is, in dp: Gboard's line.</summary>
private const int SwipeTrailDp = 5;
// Opaque, the keys well apart from the ground: the window looks the same
// over a white screen as over a black one.
internal static readonly Color PanelColor = Color.Argb(0xFF, 0x12, 0x12, 0x12);
internal static readonly Color KeyColor = Color.Argb(0xFF, 0x42, 0x42, 0x42);
internal static readonly Color HeldColor = Color.Argb(0xFF, 0x4F, 0xC3, 0xF7);
internal static readonly Color HeldTextColor = Color.Argb(0xFF, 0x10, 0x10, 0x10);
internal static readonly Color RippleColor = Color.Argb(0x55, 0xFF, 0xFF, 0xFF);
private static readonly Color DimTextColor = Color.Argb(0xFF, 0x9E, 0x9E, 0x9E);
/// <summary>The copied things' cards, the menu held on one and the editor: a ground a little lighter than the window's.</summary>
private static readonly Color CardColor = Color.Argb(0xFF, 0x2C, 0x2C, 0x2C);
/// <summary>The title bar's height where what was copied stands in it as chips, in dp: Gboard's, room for a chip to read and tap.</summary>
private const int ChipBarDp = 44;
/// <summary>The copied things', their menu's and the editor's words, in sp: a list's, not the keys'.</summary>
private const float CardTextSp = 15f;
private const float MenuTextSp = 16f;
/// <summary>A key's legend it sends now, strong, and the ones it does not, weak.</summary>
private static readonly Color SentLegendColor = Color.White;
private static readonly Color OtherLegendColor = Color.Argb(0xFF, 0xA8, 0xA8, 0xA8);
private readonly Context context;
private readonly Action<Keycode, MetaKeyStates> sendOut;
private readonly Action<string> typeOut;
private readonly ISharedPreferences preferences;
private readonly Handler handler = new(Looper.MainLooper!);
private readonly int touchSlop;
private readonly List<(Held Modifier, TextView View)> modifierKeys = [];
/// <summary>The keys that type characters, whose legends are drawn on the table of three by three.</summary>
private readonly List<(PanelKey Key, KeyLegends Legends, TextView View)> characterKeys = [];
/// <summary>The keys that type no character but read another label with Fn held: the arrows.</summary>
/// <summary>The keys that type no character but read another label with Fn or Shift held: the arrows, ⌫.</summary>
private readonly List<(PanelKey Key, TextView View)> fnKeys = [];
/// <summary>The keys that type no character, whose one label is sized as the legends are, and how much larger it is drawn.</summary>
private readonly List<(TextView View, float Factor, string Label)> labelKeys = [];
/// <summary>The title bar's words and signs, and the largest each is drawn, in sp: never larger than the keys' words.</summary>
private readonly List<(TextView View, int LargestSp)> titleTexts = [];
/// <summary>The title bar's pieces but the title, and each one's width in dp at its full size.</summary>
private readonly List<(View View, int WidthDp)> titleParts = [];
/// <summary>The rows and the side column's keys, whose heights follow <see cref="Scale"/> and nothing else.</summary>
private readonly List<View> rowViews = [];
private readonly List<View> sideKeys = [];
/// <summary>The whole keyboard's column at its right (ImpPnt, Inicio, Fin, RePág, AvPág).</summary>
private View? sideColumn;
private readonly FrameLayout root;
private readonly LinearLayout strip;
/// <summary>Keys: the terminal's two rows; empty until their mode is first shown (<see cref="MakeKeys"/>).</summary>
private LinearLayout terminal;
/// <summary>The whole keyboard (ABC): as made, or as the screen's design has it, made again when it changes; empty until first shown.</summary>
private LinearLayout wholeKeyboard;
/// <summary>Which of the modes' keys are made: Keys, the whole keyboard, two rows.</summary>
private bool terminalMade, wholeKeyboardMade, compactMade;
/// <summary>The keyboard of the list this screen shows in the keyboard's language (Ajustes › Tema); none in the popup.</summary>
private KeyboardEntry? keyboard;
/// <summary>The screen the keyboards of the list are chosen for; none in the popup and the headset's box.</summary>
private readonly KeyPlusPreferences.Screen? keyboardScreen;
/// <summary>Whether the keyboard floats: its floating design shown, and designed.</summary>
public bool ShowsFloating { get; set; }
/// <summary>The keyboard of the list shown, as it is now; none in the popup.</summary>
public KeyboardEntry? Keyboard => keyboard;
/// <summary>The whole keyboard's design: a keyboard saved keeps its own; the popup's, the screen's.</summary>
private KeyboardDesign? ReadDesign() =>
keyboard is null ? KeyboardDesign.Read(preferences) : KeyboardDesign.FromText(keyboard.Design);
/// <summary>The design kept where it belongs: in the keyboard saved; the popup's, the screen's. None, the keyboard as made again.</summary>
private void KeepDesign(KeyboardDesign? kept)
{
if (keyboard is { } made)
{
Keyboards.SetDesign(context, made.Id, kept?.Text, floating: false);
}
else if (kept is not null)
{
kept.Save(preferences);
}
else
{
KeyboardDesign.Forget(preferences);
}
}
/// <summary>The screen's design of the whole keyboard; none, the keyboard as made (KeyboardDesign).</summary>
private KeyboardDesign? design;
/// <summary>Whether the whole keyboard's keys are being dragged into place (⚙ → Diseñar) rather than typed with.</summary>
private bool designing;
/// <summary>Every key and hole the design shows, with its id (a hole's negative), its row and its place in it: Entrar standing tall is there for both of its rows; the keys aside in row -1.</summary>
private readonly List<(int Id, int Row, int Index, View View)> designKeys = [];
/// <summary>The design's rows as shown, each with its index, to find the row a key is let go on: Entrar's two rows each by their own views.</summary>
private readonly List<(int Row, View View)> designRows = [];
/// <summary>
/// Each key of the design made once and moved from row to row as it is
/// dragged: made again at every drop, seventy keys a time, the views and
/// their listeners left for the collector between Java and .NET held the
/// keyboard still past Android's five seconds.
/// </summary>
private readonly Dictionary<int, TextView> designViews = [];
/// <summary>While designing, above the keys: what to do, Restablecer and Hecho.</summary>
private readonly LinearLayout designBar;
/// <summary>The key being dragged, the picture of it that follows the finger or pointer, and where it was taken within it.</summary>
private (int Id, View Key, ImageView Picture, float GrabX, float GrabY)? dragged;
/// <summary>Whether the key held has moved further than a tap: let go, it is put there; else it is marked.</summary>
private bool dragMoved;
/// <summary>Where the key held was touched, on the screen.</summary>
private (float X, float Y) dragStart;
/// <summary>The key marked by a tap while designing, which − and + make narrower or wider.</summary>
private int? selectedKey;
/// <summary>Keys made small: two rows, no title bar; empty until first shown.</summary>
private LinearLayout compact;
/// <summary>
/// The standard keyboard, Gboard's (Berpiztu AI Keyboard on a phone),
/// beside PC, which is the strip's keys and the whole keyboard with its
/// designs; none in the popup and on a headset.
/// </summary>
private readonly StandardKeyboard? standard;
private readonly TextView makeSmall;
/// <summary>The title bar's resize, the keyboard's sign: the frame over the keys to size them (<see cref="ResizeRequested"/>), where the window shows it (<see cref="ShowsResizeButton"/>).</summary>
private readonly ImageView resizeButton;
private readonly TextView tab;
private readonly LinearLayout titleBar;
private readonly LinearLayout closeBar;
/// <summary>The question shown in place of the title bar, and what Sí does.</summary>
private readonly TextView question;
private Action? asked;
private bool iconOnly;
private readonly TextView dock;
private readonly TextView switchKeys;
/// <summary>The texts copied lately, and 📋, which shows them in the keys' place to paste one.</summary>
private readonly ClipboardHistory clipboard;
private readonly View clipboardButton;
private readonly ScrollView clipboardView;
/// <summary>
/// A thing copied seen whole in the keys' place (its menu's Preview), an image or a text that scrolls, and which one
/// it is.
/// </summary>
private readonly FrameLayout previewView;
private readonly ImageView imageViewer;
private readonly ScrollView textPreview;
private readonly TextView previewText;
private ClipboardHistory.Entry? previewed;
private readonly LinearLayout clipboardRows;
/// <summary>The copied texts side by side in one row above the keys (<see cref="ClipboardAbove"/>).</summary>
private readonly HorizontalScrollView clipboardLine;
private readonly LinearLayout clipboardItems;
/// <summary>The keys a view stands in place of (the copied texts, the settings), with the button that shows it; none while the keys show.</summary>
private (View Keys, View Cover, View Button)? covered;
/// <summary>
/// The editor above the keys for a copied text, Cancelar and Guardar under
/// it, and the text edited: the keys type into it meanwhile, not into the
/// field; none, no editor.
/// </summary>
private readonly LinearLayout editorBar;
private readonly TextView editorTitle;
private readonly LinearLayout editorButtons;
private readonly View editorGap;
private readonly EditText editor;
private ClipboardHistory.Entry? edited;
/// <summary>Test on a headset: ⌨ hides the keyboard and shows it again; the line says what Android tells of the keyboard's window.</summary>
private readonly TextView keyboardButton;
private readonly TextView infoLine;
private Action? keyboardToggle;
/// <summary>✕, which closes the popup once asked; a keyboard has none (<see cref="Settings"/>).</summary>
private readonly TextView closeButton;
/// <summary>⚙, and the settings it shows in the keys' place, each a row that does what it says.</summary>
private readonly TextView settingsButton;
private readonly ScrollView settingsView;
private readonly LinearLayout settingsRows;
private IReadOnlyList<Setting> settings = [];
/// <summary>
/// What was copied as chips in the title bar's middle (<see cref="CopiedInTitleBar"/>),
/// a bar of its own in the title bar's place, with ⚙ at its right.
/// </summary>
private readonly LinearLayout chipBar;
private readonly LinearLayout chipItems;
/// <summary>ABC or Keys in the chips' bar, as in the title bar.</summary>
private readonly TextView chipSwitchKeys;
private readonly HorizontalScrollView chipScroll;
private bool copiedInTitleBar;
/// <summary>The chips wait to be made again, what was copied having changed while they were out of sight.</summary>
private bool chipsStale = true;
/// <summary>
/// Berpiztu AI Keyboard on a phone (<see cref="CopiedInTitleBar"/>), as
/// Gboard's toolbar: ⚙ at the left and the rest of it what was copied
/// last while it is recent, else 📋, or a swipe's other words; one height
/// and one size of words, whatever the keys' size, and nothing drawn over
/// anything else. Keys and ABC switch from ⚙'s tiles.
/// </summary>
private readonly LinearLayout toolbar;
/// <summary>⚙'s tiles or the copied things in the keys' place: ✕ and 📋 across the toolbar's place.</summary>
private readonly LinearLayout menuBar;
/// <summary>The toolbar's middle: the recent copy's chip, or 📋.</summary>
private readonly FrameLayout toolbarMiddle;
private readonly View toolbarClipboard;
/// <summary>The toolbar's and the menu bar's height, in dp: Gboard's.</summary>
internal const int ToolbarDp = 48;
/// <summary>
/// The standard keyboard's toolbar, as Gboard's on the emulator (pixels
/// over 2.625): each end's sign 59 px in, so its place 118 px wide; a
/// circle 89 px across; ⊞ drawn 40 px wide, of the 720 its 960 box fills;
/// the words 19 sp (a capital 35 px tall over Roboto's 0.711); the lines
/// between them 3 px wide and 63 px tall.
/// </summary>
private readonly LinearLayout standardBar;
private readonly StandardColors? standardColors;
/// <summary>
/// The standard keyboard floating in a window, as Gboard's (on the
/// emulator, pixels over 2.625): a card with corners 55 px round and a
/// shadow, under the keys a bar 104 px tall with ∨ (hide) at its left,
/// its centre 90 px in, drawn 29 px wide (480 of its 960), and in the
/// middle a handle 188 × 10 px that moves the window.
/// </summary>
private readonly FrameLayout? floatingBar;
private bool inWindow;
private const float CardCornerDp = 55 / 2.625f;
private const float CardShadowDp = 8;
private const float FloatingBarDp = 104 / 2.625f;
private const float HideCentreDp = 90 / 2.625f;
private const float HideDp = 29 / (480f / 960) / 2.625f;
private const float HandleWidthDp = 188 / 2.625f;
private const float HandleHeightDp = 10 / 2.625f;
/// <summary>
/// The floating card being resized, as Gboard's, a tap on its bar beside
/// the handle: its outline 4 px, its corners 8 px and 38 px past their
/// curve; a corner held anywhere within <see cref="CornerReachDp"/>;
/// Reset, 207 × 74 px, 105 px from the card's right. It ends by itself
/// <see cref="CardResizeMs"/> after the last touch, or as the card is moved.
/// </summary>
private bool cardResizing;
private readonly List<View> cardCorners = [];
private View? cardReset;
private Java.Lang.Runnable? endCardResize;
private const float CardLineDp = 4 / 2.625f;
private const float CardMarkDp = 8 / 2.625f;
private const float CardMarkReachDp = 38 / 2.625f;
private const float ResetWidthDp = 207 / 2.625f;
private const float ResetHeightDp = 74 / 2.625f;
private const float ResetRightDp = 105 / 2.625f;
private const int CardResizeMs = 3000;
/// <summary>Berpiztu AI Keyboard's ⌨ icon, in dp: a finger's; and the room around it its shadow is drawn in.</summary>
private const int IconDp = 48;
private const int IconShadowDp = 12;
/// <summary>The standard keyboard's grid (⊞), Gboard's, in the keys' place; none without the standard keyboard.</summary>
private readonly StandardGrid? standardGrid;
/// <summary>The standard keyboard's emoji (the comma held, ⊞'s Emojis), in the keys' and the toolbar's place; and those typed lately, over the toolbar.</summary>
private readonly EmojiPanel? emojiPanel;
private readonly LinearLayout emojiRow;
private readonly LinearLayout emojiRowItems;
/// <summary>The row of those typed lately, as Gboard's on the Fold: 100 px tall, each 83 px apart, 48 px wide.</summary>
private const float EmojiRowDp = 100 / 2.25f;
private const float EmojiRowCellDp = 83 / 2.25f;
private const float EmojiRowShare = 48f / 83;
/// <summary>An emoji's width in its cell: its ink 60% of the row's height, measured on the Fold (the owner, 2026-11-03).</summary>
private const float EmojiCellShare = 0.82f;
/// <summary>A toolbar button's circle and its sign's box, as shares of the toolbar's height: the sign's ink 60% of it, measured on the Fold (the owner, 2026-11-03).</summary>
private const float ToolCircleShare = 0.85f;
private const float ToolSignShare = 0.646f;
/// <summary>The most of a circle its sign's box takes, for a circle lit to show around the sign.</summary>
private const float ToolSignInCircle = 0.88f;
/// <summary>The least height of the toolbar and the row of those typed lately: a row of keys at half its size, as on Windows, below which their buttons could not be hit.</summary>
private const float LeastLineDp = StandardKeyboard.LetterRowDp / 2;
private bool? headset;
private bool Headset => headset ??= KeyPlusPreferences.IsHeadset(context);
/// <summary>
/// The share of their sizes the toolbar and the row of those typed lately are made: as tall as a row of keys up to the
/// toolbar's own height, taller keys leaving them there (the owner, 2026-11-03); on a headset, whole, as it fills its window.
/// </summary>
private float LineShare => Headset
? 1f
: Math.Min(1f, Math.Max(StandardKeyboard.LetterRowDp * scale, LeastLineDp) / ToolbarDp);
/// <summary>The toolbar's share: while designing or customising, whole, for what those show in it.</summary>
private float BarShare => designingStandard || editingTools ? 1f : LineShare;
/// <summary>The row of those typed lately as tall as the toolbar, up to its own height.</summary>
private int EmojiRowHeight => Dp(Math.Min(ToolbarDp * LineShare, EmojiRowDp));
/// <summary>The toolbar and the row of those typed lately as tall as the keys make them; set only what changed.</summary>
private bool SizeBars()
{
var (bar, row) = (Dp(ToolbarDp * BarShare), EmojiRowHeight);
if (standardBar.LayoutParameters!.Height == bar && emojiRow.LayoutParameters!.Height == row)
{
return false;
}
standardBar.LayoutParameters.Height = bar;
emojiRow.LayoutParameters!.Height = row;
standardBar.RequestLayout();
emojiRow.RequestLayout();
return true;
}
/// <summary>The grid's buttons the keyboard gives, Gboard's, before the panel's own (the other standard keyboard, Minimizar).</summary>
private IReadOnlyList<GridTile> gridTiles = [];
/// <summary>The toolbar's own buttons, Gboard's, in Gboard's order: where they stand until placed elsewhere (⊞ › ✏).</summary>
private static readonly string[] BarFirst = ["clipboard", "resize", "settings"];
private const string OtherStandardId = "otherStandard";
/// <summary>
/// Customising, on the Fold: the toolbar's buttons in a blue outline 85 px
/// tall, Gboard's 8 px inside it above and below, each a circle as tall as
/// that leaves (<see cref="ToolDiameter"/>); side by side they all but
/// touch, <see cref="ToolGapDp"/> apart, as the glyph inside each circle
/// keeps its own margin, so that as many fit as can be.
/// </summary>
private const float EditBarDp = 85 / 2.25f;
private const float EditToolGapDp = 8 / 2.25f;
private const float ToolGapDp = 1;
/// <summary>While the grid is customised (⊞ › ✏): the toolbar's buttons and the grid's, by their ids, as they are being placed.</summary>
private bool editingTools;
private List<string> barTools = [];
private List<string> gridTools = [];
/// <summary>
/// The button dragged while customising: it and where it was taken from,
/// its picture under the finger, and where it would go, on the toolbar
/// or in the grid (-1, neither).
/// </summary>
private (GridTile Tool, bool FromBar, int From)? lifted;
private View? liftedView;
private int barGap = -1;
private int gridGap = -1;
/// <summary>The toolbar's places while customising, in order, a gap's among them.</summary>
private List<View> barSlots = [];
private const float ToolSlotDp = 118 / 2.625f;
internal const float ToolCircleDp = 89 / 2.625f;
private const float ToolIconDp = 40 / (720f / 960) / 2.625f;
private const float SuggestionSp = 35 / 0.711f / 2.625f;
private const float SuggestionLineDp = 3 / 2.625f;
private const float SuggestionLineHeightDp = 63 / 2.625f;
/// <summary>How long a copy shows as a chip in the toolbar, as Gboard shows the one just copied.</summary>
private static readonly TimeSpan RecentCopyTime = TimeSpan.FromMinutes(5);
/// <summary>What was copied last, by its text or image, and when: the toolbar's chip while it is recent.</summary>
private (string? Text, string? Image)? recentCopy;
private DateTime recentCopyAt;
/// <summary>Whether 📋 asked for the things copied in the line over the toolbar, until it is tapped again.</summary>
private bool copiesAsked;
/// <summary>How far the chips of the things copied are scrolled across, from the start once they show anew.</summary>
private int copiesScroll;
/// <summary>What the clipboard's list held, to tell a new copy from a pin, an edit or a removal.</summary>
private HashSet<(string? Text, string? Image)> knownCopies = [];
/// <summary>The whole keyboard's letters a swipe is read over, in the order their centres are handed with it: Spanish's.</summary>
private static string SwipeLetters => StandardKeys.Spanish.SwipeLetters;
/// <summary>
/// A swipe over the whole keyboard's letters: its points and their
/// times in milliseconds from its start, and each letter's centre (in
/// <see cref="SwipeLetters"/>' order), all from 0 to 1 over the room the
/// letters take, as FUTO Swipe reads them; and the language it is read in.
/// </summary>
public sealed record SwipePath(float[] X, float[] Y, float[] T, float[] KeyX, float[] KeyY, StandardLanguage Language);
/// <summary>
/// Reads a swipe over the letters as words, the likeliest first
/// (Berpiztu AI Keyboard's FUTO Swipe); none, the letters are only
/// tapped and type on the touch.
/// </summary>
public Func<SwipePath, Task<IReadOnlyList<string>>>? Swiping { get; set; }
/// <summary>Whether a language is swiped in: its Glide typing on, with its word list and the model downloaded (the keyboard's LanguageChoices); none, every language is.</summary>
public Func<StandardLanguage, bool>? GlidesFor { get; set; }
/// <summary>A swipe's words in the order to offer them, what was learnt first (<see cref="PersonalWords.Ordered"/>); none, as read.</summary>
public Func<StandardLanguage, IReadOnlyList<string>, IReadOnlyList<string>>? OrderSwiped { get; set; }
/// <summary>A word of the toolbar taken in place of a swiped one: the language, the word the swipe read first, the word taken (<see cref="PersonalWords.Chose"/>).</summary>
public Action<StandardLanguage, string, string>? SwipeChosen { get; set; }
/// <summary>The text just before the caret, to tell whether a swiped word needs a space before it.</summary>
public Func<string?>? TextBeforeCaret { get; set; }
/// <summary>The text just before the caret, the sentence being written, for Spelling to mend it (<see cref="SpanishMarks"/>).</summary>
public Func<string?>? RecentText { get; set; }
/// <summary>
/// The text right before the caret, so many characters, replaced with
/// another in one edit of the field: ⌫ keys and the text typed after
/// them reach the field out of order (the text first), so the keys took
/// the new word away. None, ⌫ keys then the text.
/// </summary>
public Action<int, string>? ReplaceBeforeCaret { get; set; }
/// <summary>A finger on a letter while swiping is on: its points on the screen and times, and whether it left the letter's touch.</summary>
private sealed class SwipeTrace(PanelKey key, long start)
{
public PanelKey Key { get; } = key;
public long Start { get; } = start;
public List<(float X, float Y, float T)> Points { get; } = [];
public bool Moved { get; set; }
}
private SwipeTrace? swipeTrace;
/// <summary>The line the swiping finger draws over the whole keyboard, once it left its first letter.</summary>
private SwipeTrail? swipeTrail;
/// <summary>What the last swipe typed, which a word in the toolbar replaces; none once anything else is typed.</summary>
private string? swipedText;
/// <summary>The last swipe's words, the likeliest first, in the toolbar's middle as Gboard's suggestions.</summary>
private IReadOnlyList<string> swipeWords = [];
/// <summary>Which of the last swipe's words is typed now: the toolbar's centre.</summary>
private string? swipedWord;
/// <summary>The words offered for the word being typed letter by letter, the likeliest first, in the toolbar's middle as Gboard's; and that word as it stands before the caret, which the one taken replaces.</summary>
private IReadOnlyList<string> typingWords = [];
private string typingWord = "";
/// <summary>Whether the toolbar's middle shows words: a swipe's, or those offered for the word being typed.</summary>
private bool OffersWords => swipeWords.Count > 0 || typingWords.Count > 0 || learnable || inHunspellAlone;
/// <summary>Whether the word being typed is one no list has, offered as typed at the toolbar's left to be learnt with a tap (<see cref="Learnable"/>).</summary>
private bool learnable;
/// <summary>Whether only Hunspell knows the word being typed: offered as typed at the toolbar's left too, not to be learnt (<see cref="OnlyInHunspell"/>).</summary>
private bool inHunspellAlone;
/// <summary>Whether only Hunspell knows a word, no list nor the personal dictionary (the keyboard's SpellingEngine.OnlyInHunspell).</summary>
public Func<StandardLanguage, string, bool>? OnlyInHunspell { get; set; }
/// <summary>Whether the debug window is to be shown (the toolbar's Debug).</summary>
public Func<bool>? ModelWindowOn { get; set; }
/// <summary>What the debug window says where no context model is on (the keyboard's ContextCorrector.Said, which the popup has not).</summary>
public Func<StandardLanguage, string, string>? SaidWithoutModel { get; set; }
private PopupWindow? modelWindow;
private TextView? modelWindowText;
private (int X, int Y) modelWindowAt = (24, 240);
/// <summary>
/// What the context model gave put in the debug window, which never takes the focus and is moved with a finger; gone
/// where it is turned off. Called from any thread.
/// </summary>
public void ShowModelWindow(string said) => handler.Post(() =>
{
if (ModelWindowOn?.Invoke() != true)
{
HideModelWindow();
return;
}
if (modelWindow is null)
{
modelWindowText = new TextView(context) { Background = new ColorDrawable(Color.Argb(235, 20, 20, 20)) };
modelWindowText.SetTextColor(Color.White);
modelWindowText.SetTextSize(ComplexUnitType.Sp, 13);
modelWindowText.SetPadding(Dp(8), Dp(6), Dp(8), Dp(6));
modelWindow = new PopupWindow(modelWindowText, ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent, false)
{
OutsideTouchable = false,
Touchable = true,
ClippingEnabled = false,
Elevation = Dp(8),
};
modelWindow.SetBackgroundDrawable(new ColorDrawable(Color.Transparent));
(float X, float Y, int FromX, int FromY) grabbed = default;
modelWindowText.Touch += (_, touch) =>
{
if (touch.Event is not { } moved)
{
return;
}
if (moved.ActionMasked == MotionEventActions.Down)
{
grabbed = (moved.RawX, moved.RawY, modelWindowAt.X, modelWindowAt.Y);
}
else if (moved.ActionMasked == MotionEventActions.Move)
{
modelWindowAt = (grabbed.FromX + (int)(moved.RawX - grabbed.X), grabbed.FromY + (int)(moved.RawY - grabbed.Y));
modelWindow?.Update(modelWindowAt.X, modelWindowAt.Y, -1, -1);
}
};
}
modelWindowText!.Text = said;
if (!modelWindow.IsShowing && root.WindowToken is not null)
{
modelWindow.ShowAtLocation(root, GravityFlags.NoGravity, modelWindowAt.X, modelWindowAt.Y);
}
});
/// <summary>The debug window gone, while no keyboard is shown or it is turned off.</summary>
public void HideModelWindow()
{
if (modelWindow?.IsShowing == true)
{
modelWindow.Dismiss();
}
}
private PopupWindow? voiceHelp;
private TextView? voiceHelpTitle;
private TextView[] voiceHelpColumns = [];
private (int X, int Y) voiceHelpAt = (8, 8);
/// <summary>The commands' window's size, set once whatever it lists: as many columns of one width as the screen has room for, three at most, so all is seen at once where it can be, and its list scrolling inside it where it cannot.</summary>
private const int VoiceHelpColumnDp = 230;
private const int VoiceHelpHeightDp = 380;
private const int VoiceHelpMostColumns = 3;
/// <summary>
/// The dictation's commands listed in a window over the keyboard, asked
/// for by voice ("comando ayuda"), part by part in columns, each part's
/// name in bold: of one size; it never takes the focus nor writes in the
/// field, is moved with a finger by its top line and closed by its ✕.
/// </summary>
public void ShowVoiceHelp(string title, IReadOnlyList<VoiceHelpSection> sections)
{
if (voiceHelp is null)
{
var close = new TextView(context) { Text = "✕", Gravity = GravityFlags.Center };
close.SetTextColor(Color.White);
close.SetTextSize(ComplexUnitType.Sp, 18);
close.Click += (_, _) => HideVoiceHelp();
voiceHelpTitle = new TextView(context) { Gravity = GravityFlags.CenterVertical };
voiceHelpTitle.SetTextColor(Color.White);
voiceHelpTitle.SetTextSize(ComplexUnitType.Sp, 14);
voiceHelpTitle.SetTypeface(null, TypefaceStyle.Bold);
voiceHelpTitle.SetSingleLine(true);
voiceHelpTitle.SetPadding(Dp(8), 0, 0, 0);
var top = new LinearLayout(context) { Orientation = Orientation.Horizontal };
top.AddView(voiceHelpTitle, new LinearLayout.LayoutParams(0, Dp(40), 1));
top.AddView(close, new LinearLayout.LayoutParams(Dp(40), Dp(40)));
var metrics = context.Resources!.DisplayMetrics!;
var count = Math.Clamp((int)(metrics.WidthPixels / metrics.Density) / VoiceHelpColumnDp, 1, VoiceHelpMostColumns);
var columns = new LinearLayout(context) { Orientation = Orientation.Horizontal };
voiceHelpColumns = new TextView[count];
for (var at = 0; at < count; at++)
{
var column = new TextView(context);
column.SetTextColor(Color.White);
column.SetTextSize(ComplexUnitType.Sp, 13);
column.SetPadding(Dp(8), 0, 0, Dp(8));
column.SetHorizontallyScrolling(true);
voiceHelpColumns[at] = column;
columns.AddView(column, new LinearLayout.LayoutParams(Dp(VoiceHelpColumnDp), ViewGroup.LayoutParams.WrapContent));
}
var list = new ScrollView(context);
list.AddView(columns);
var box = new LinearLayout(context) { Orientation = Orientation.Vertical, Background = new ColorDrawable(Color.Argb(235, 20, 20, 20)) };
box.AddView(top);
box.AddView(list, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, 0, 1));
voiceHelp = new PopupWindow(box, Dp(VoiceHelpColumnDp * count), Dp(VoiceHelpHeightDp), false)
{
OutsideTouchable = false,
Touchable = true,
ClippingEnabled = false,
Elevation = Dp(8),
};
voiceHelp.SetBackgroundDrawable(new ColorDrawable(Color.Transparent));
(float X, float Y, int FromX, int FromY) grabbed = default;
voiceHelpTitle.Touch += (_, touch) =>
{
if (touch.Event is not { } moved)
{
return;
}
if (moved.ActionMasked == MotionEventActions.Down)
{
grabbed = (moved.RawX, moved.RawY, voiceHelpAt.X, voiceHelpAt.Y);
}
else if (moved.ActionMasked == MotionEventActions.Move)
{
voiceHelpAt = (grabbed.FromX + (int)(moved.RawX - grabbed.X), grabbed.FromY + (int)(moved.RawY - grabbed.Y));
voiceHelp?.Update(voiceHelpAt.X, voiceHelpAt.Y, -1, -1);
}
};
}
voiceHelpTitle!.Text = title;
var laid = VoiceCommands.InColumns(sections, voiceHelpColumns.Length);
for (var at = 0; at < voiceHelpColumns.Length; at++)
{
var listed = new Android.Text.SpannableStringBuilder();
foreach (var section in at < laid.Count ? laid[at] : [])
{
if (listed.Length() > 0)
{
listed.Append("\n\n");
}
var from = listed.Length();
listed.Append(section.Title);
listed.SetSpan(new Android.Text.Style.StyleSpan(TypefaceStyle.Bold), from, listed.Length(), Android.Text.SpanTypes.ExclusiveExclusive);
foreach (var line in section.Lines)
{
listed.Append("\n");
listed.Append(line);
}
}
voiceHelpColumns[at].SetText(listed, TextView.BufferType.Spannable);
}
if (!voiceHelp.IsShowing && root.WindowToken is not null)
{
voiceHelp.ShowAtLocation(root, GravityFlags.NoGravity, voiceHelpAt.X, voiceHelpAt.Y);
}
}
/// <summary>The commands' window gone: its ✕, or no keyboard shown.</summary>
public void HideVoiceHelp()
{
if (voiceHelp?.IsShowing == true)
{
voiceHelp.Dismiss();
}
}
/// <summary>The word the one typed surely meant, of those offered (the keyboard's SpellingEngine.Sure); none where it is not clear.</summary>
public Func<StandardLanguage, string, IReadOnlyList<string>, string?>? Sure { get; set; }
/// <summary>The word a misspelling means, among those the context model offered (the keyboard's SpellingEngine.SureOfModel); none where it is no misspelling or not clear.</summary>
public Func<StandardLanguage, string, IReadOnlyList<string>, string?>? SureOfModel { get; set; }
/// <summary>The word it is sure the one typed meant: in bold in the toolbar's centre and what a space writes, as Gboard's (the owner, 2026-11-01); none, nothing in bold and nothing written.</summary>
private (string Word, string Sure)? surely;
/// <summary>The words to offer for a word being typed in a language, the likeliest first (<see cref="WordSuggestions"/>); none, nothing is offered as letters are typed.</summary>
public Func<StandardLanguage, string, IReadOnlyList<string>>? Suggesting { get; set; }
/// <summary>
/// The words the language's context model offers for the sentence typed so far, its last word being typed (the
/// keyboard's ContextCorrector.Suggest, which the popup has not); none where it has no model on. Asked at each
/// letter, the newest only: a letter typed before it answers cancels the question before it.
/// </summary>
public Func<StandardLanguage, string, CancellationToken, Task<IReadOnlyList<string>>>? ModelSuggesting { get; set; }
/// <summary>The question to the context model for the words being offered, cancelled by the next letter's.</summary>
private CancellationTokenSource? modelAsked;
/// <summary>The last words offered, the context model's or the word list's, and the word typed they were for: their first, the toolbar's centre, is what a space takes.</summary>
private (string Word, IReadOnlyList<string> Offered)? modelOffer;
/// <summary>Whether the language's context model gives the words offered as a word is typed, the word list's then never shown.</summary>
public Func<StandardLanguage, bool>? ModelOffers { get; set; }
/// <summary>Whether a word is one the language's word lists or the personal dictionary have (the keyboard's SpellingEngine).</summary>
public Func<StandardLanguage, string, bool>? KnownWord { get; set; }
/// <summary>What a word no list nor dictionary has may have meant (the keyboard's SpellingEngine.Meant): offered where nothing else is.</summary>
public Func<StandardLanguage, string, IReadOnlyList<string>>? Meaning { get; set; }
/// <summary>Whether a word is a word as it is written, its accents too (the keyboard's SpellingEngine.IsWord).</summary>
public Func<StandardLanguage, string, bool>? IsWord { get; set; }
/// <summary>The letters right before the caret, the word being typed; none or empty where there is none.</summary>
public Func<string?>? WordBeforeCaret { get; set; }
/// <summary>The settings ⚙ shows now: on a phone, the panel's own tiles first.</summary>
private IReadOnlyList<Setting> shownSettings = [];
/// <summary>The editor's card stands outside the panel, where its host puts it (<see cref="EditorOutside"/>).</summary>
private bool editorOutside;
/// <summary>The question the title bar's place asks (<see cref="Ask"/>); none, the bar.</summary>
private string? asking;
/// <summary>The height the copied texts keep above the keys all the time (<see cref="ClipboardAbove"/>); 0, none.</summary>
private int clipboardAbove;
private Java.Lang.Runnable? repeat;
private Held held;
private string? deadAccent;
private float scale = 1f;
/// <summary>The labels' size the user chose with A− and A+, 1 for the usual one.</summary>
private float labelScale;
/// <summary>The legends' one size, in pixels, as the keys in sight allow (<see cref="FitLegends"/>); none until they are laid out.</summary>
private float legendSize;
/// <summary>A fitting is waiting for the keys to be laid out.</summary>
private bool fitPending;
/// <summary>The window is being moved or resized, and the labels wait for it to end to be fitted (<see cref="NoteDrag"/>).</summary>
private bool dragging;
private bool fitAfterDrag;
/// <summary>A headset (Android XR), whose touches give their raw place from the window (<see cref="OnScreen"/>).</summary>
private readonly bool onHeadset;
/// <param name="send">Sends a key with the meta state of the modifiers held for it.</param>
/// <param name="type">Types text, as the phone's keyboard does.</param>
/// <param name="preferences">The layout of the display the panel is on.</param>
/// <param name="clipboard">The texts copied lately, which 📋 lists.</param>
/// <param name="lettersFirst">Whether a screen with no mode kept opens on the whole keyboard (ABC), as a keyboard opens on its letters, rather than on Keys.</param>
/// <param name="keyboardScreen">Berpiztu AI Keyboard on a phone's screen: the keyboards of the list (Estándar, Estándar PC, those saved), the one the screen shows in the keyboard's language; none, the popup's and the headset's keys.</param>
/// <param name="floating">Whether the keyboard floats, which shows its floating design.</param>
public KeyPanel(Context context, ISharedPreferences preferences, ClipboardHistory clipboard, Action<Keycode, MetaKeyStates> send, Action<string> type, bool lettersFirst = false, KeyPlusPreferences.Screen? keyboardScreen = null, bool floating = false)
{
this.context = context;
this.clipboard = clipboard;
#if KEYBOARD
onHeadset = KeyPlusPreferences.HeadsetKeyboard(context);
#else
onHeadset = KeyPlusPreferences.IsHeadset(context);
#endif
sendOut = send;
typeOut = type;
this.preferences = preferences;
touchSlop = ViewConfiguration.Get(context)!.ScaledTouchSlop;
// No name in the title bar, so its buttons have the room: what is
// left between them is the place to drag the window by.
var title = new View(context) { ContentDescription = "Drag to move the keys" };
// The bar's free room is dragged at once, as a window's title is: a
// headset's pinch (Galaxy XR) never holds still enough for a long press.
Draggable(title, ReportMoving, tapped: null);
dock = TitleButton("⤓", "Docked: the keys show while a keyboard is open, where you left them; pressed again, they float, in sight all the time", () => DockRequested?.Invoke());
var minimize = TitleButton("–", "Minimize the keys into an icon", () => SetFolded(true));
closeButton = TitleButton("✕", "Close KeyPlus", () => Ask(context.GetString(Resource.String.close_keyplus_ask)!, () => CloseRequested?.Invoke()));
var smaller = TitleButton("A−", "Smaller labels", () => SetLabelScale(labelScale - LabelScaleStep));
var larger = TitleButton("A+", "Larger labels", () => SetLabelScale(labelScale + LabelScaleStep));
// A↺ undoes every size made by hand, so it asks first, as ✕ does.
var usual = TitleButton("A↺", "Keys and labels at their usual size", () => Ask(context.GetString(Resource.String.usual_size_ask)!, () =>
{
SetLabelScale(1f);
UsualSizeRequested?.Invoke();
}));
switchKeys = TitleButton("ABC", "Switch between the keys and a whole keyboard", () => SetWholeKeyboard(wholeKeyboard!.Visibility != ViewStates.Visible));
clipboardButton = ClipboardTitleButton("Texts copied lately: tap one to paste it");
settingsButton = TitleButton("⚙", "Settings", () => Toggle(settingsView!, ShowSettings));
keyboardButton = TitleButton("⌨", "Hide the keyboard, or show it again", () => keyboardToggle?.Invoke());
keyboardButton.Visibility = ViewStates.Gone;
settingsButton.Visibility = ViewStates.Gone;
makeSmall = TitleButton("▭", "Two rows: the keys made small, with no title bar; hold PgUp to open them again", () => SetCompact(true));
resizeButton = TitleIcon(Resource.Drawable.ic_tool_resize, "Resize the keys", () => ResizeRequested?.Invoke());
resizeButton.Visibility = ViewStates.Gone;
titleBar = new LinearLayout(context) { Orientation = Orientation.Horizontal };
titleBar.AddView(title, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MatchParent, 1f));
AddToTitleBar(resizeButton, 36);
AddToTitleBar(smaller, 36);
AddToTitleBar(larger, 36);
AddToTitleBar(usual, 36);
AddToTitleBar(makeSmall, 36);
AddToTitleBar(keyboardButton, 36);
AddToTitleBar(clipboardButton, 36);
AddToTitleBar(switchKeys, 44);
AddToTitleBar(dock, 36);
AddToTitleBar(minimize, 36);
AddToTitleBar(closeButton, 36);
AddToTitleBar(settingsButton, 36);
// A window narrower than the title bar's buttons: they all narrow
// alike, and their words with them, rather than any going out of sight.
titleBar.LayoutChange += (_, e) =>
{
if (e.Right - e.Left != e.OldRight - e.OldLeft)
{
FitTitleBar(e.Right - e.Left);
}
};
question = new TextView(context) { Gravity = GravityFlags.CenterVertical };
question.SetTextColor(Color.White);
Shrinkable(question, 13);
question.SetPadding(Dp(4), 0, Dp(4), 0);
var yes = TitleButton(context.GetString(Resource.String.yes)!, "Yes", () =>
{
var confirmed = asked;
Ask(null, null);
confirmed?.Invoke();
});
var no = TitleButton(context.GetString(Resource.String.no)!, "No", () => Ask(null, null));
closeBar = new LinearLayout(context) { Orientation = Orientation.Horizontal, Visibility = ViewStates.Gone };
closeBar.AddView(question, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MatchParent, 1f));
closeBar.AddView(yes, new LinearLayout.LayoutParams(Dp(36), ViewGroup.LayoutParams.MatchParent));
closeBar.AddView(no, new LinearLayout.LayoutParams(Dp(36), ViewGroup.LayoutParams.MatchParent));
// As Gboard's: buttons at both ends, what was copied between them. The
// room the chips leave free is held, as the buttons are, to move the
// window.
chipItems = new LinearLayout(context) { Orientation = Orientation.Horizontal };
HoldToMove(chipItems, resizes: false);
chipScroll = new HorizontalScrollView(context) { HorizontalScrollBarEnabled = false, FillViewport = true };
chipScroll.AddView(chipItems, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.MatchParent));
chipSwitchKeys = TitleButton("ABC", "Switch between the keys and a whole keyboard", () => SetWholeKeyboard(wholeKeyboard!.Visibility != ViewStates.Visible));
chipBar = new LinearLayout(context) { Orientation = Orientation.Horizontal, Visibility = ViewStates.Gone };
chipBar.AddView(ClipboardTitleButton("Everything copied lately"), new LinearLayout.LayoutParams(Dp(44), ViewGroup.LayoutParams.MatchParent));
chipBar.AddView(chipScroll, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MatchParent, 1f));
chipBar.AddView(chipSwitchKeys, new LinearLayout.LayoutParams(Dp(52), ViewGroup.LayoutParams.MatchParent));
chipBar.AddView(TitleButton("⚙", "Settings", () => Toggle(settingsView!, ShowSettings)), new LinearLayout.LayoutParams(Dp(44), ViewGroup.LayoutParams.MatchParent));
toolbarClipboard = ToolIcon(Resource.Drawable.ic_clipboard, "Everything copied lately", () => Toggle(clipboardView!, ShowClipboard));
toolbarMiddle = new FrameLayout(context);
HoldToMove(toolbarMiddle, resizes: false);
toolbarMiddle.AddView(toolbarClipboard, new FrameLayout.LayoutParams(Dp(56), ViewGroup.LayoutParams.MatchParent, GravityFlags.Center));
toolbar = new LinearLayout(context) { Orientation = Orientation.Horizontal, Visibility = ViewStates.Gone };
// ⚙ as wide as its sign and a finger's margin: the room left is the words'.
var toolbarSettings = ToolButton("⚙", "Settings: sizes, moving, designing, the keyboard's app", 20, () => Toggle(settingsView!, ShowSettings));
toolbarSettings.SetPadding(Dp(8), 0, Dp(8), 0);
toolbar.AddView(toolbarSettings, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.MatchParent));
toolbar.AddView(toolbarMiddle, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MatchParent, 1f));
var standardKeys = keyboardScreen is not null;
standardColors = standardKeys ? StandardColors.Read(context) : null;
standardBar = new LinearLayout(context) { Orientation = Orientation.Horizontal, Visibility = ViewStates.Gone };
// A keyboard made narrower or wider (a window resized): its toolbar's places again for that width.
standardBar.LayoutChange += (_, e) =>
{
if (e.Right - e.Left != e.OldRight - e.OldLeft)
{
standardBar.Post(ShowBars);
}
};
menuBar = new LinearLayout(context) { Orientation = Orientation.Horizontal, Visibility = ViewStates.Gone };
foreach (var button in new View[]
{
ToolButton("✕", "The keys again", 20, Uncover),
ToolIcon(Resource.Drawable.ic_clipboard, "Everything copied lately", () => Toggle(clipboardView!, ShowClipboard)),
})
{
menuBar.AddView(button, new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MatchParent, 1f));
}
strip = new LinearLayout(context) { Orientation = Orientation.Vertical };
strip.SetBackgroundColor(PanelColor);
strip.SetPadding(Dp(KeyMarginDp), 0, Dp(KeyMarginDp), 0);
infoLine = new TextView(context) { Visibility = ViewStates.Gone };
infoLine.SetTextColor(Color.Yellow);