LCL-CustomDrawn-Android: Fixes a bug which prevented input of numbers in Android 4 and overall improves the key events for all devices

git-svn-id: trunk@37252 -
This commit is contained in:
sekelsenmat 2012-05-11 07:54:39 +00:00
parent 5faf1db14f
commit d2843b0d5c
2 changed files with 43 additions and 3 deletions

View File

@ -143,7 +143,7 @@ var
lForm: TCDNonNativeForm;
begin
lChar := Cardinal(AChar);
{$ifdef VerboseCDEvents}
{$ifdef VerboseCDKeyInput}
__android_log_write(ANDROID_LOG_INFO,'lclapp',PChar(
Format('[LCLOnKey] called AKind=%d AKeyCode=%x AChar=%s', [AKind, AKeyCode, UnicodeToUTF8(lChar)])));
{$endif}
@ -153,12 +153,41 @@ begin
lKey := CDWidgetset.AndroidKeyCodeToLCLKeyCode(AKeyCode);
case AKind of
ACTION_DOWN: CallbackKeyDown(lCurForm, lKey);
-1: // This indicates a key char event
ACTION_DOWN:
begin
CallbackKeyDown(lCurForm, lKey);
// Galaxy Nexus S with Android 4.0 sends numbers only as key down/up events,
// it doesn't send them to commit text
//
// Wildfire with Android 2.2 sends the numbers only to commit text
//
// So if we get any numbers here, generate KeyPress too
case lKey of
VK_0..VK_9:
begin
AUTF8Char := VK2Char(lKey);
CallbackKeyChar(lCurForm, lKey, AUTF8Char);
end;
end;
end;
// This indicates a key char event, created with commitText
// We don't get KeyDown/KeyUp when we get this, so generate them
-1:
begin
AUTF8Text := UnicodeToUTF8(lChar);
AUTF8Char := AUTF8Text;
if Length(AUTF8Text) = 1 then
begin
lKey := Char2VK(AUTF8Text[1]);
CallbackKeyDown(lCurForm, lKey);
end;
CallbackKeyChar(lCurForm, lKey, AUTF8Char);
if Length(AUTF8Text) = 1 then
CallbackKeyUp(lCurForm, lKey);
end;
ACTION_UP:
begin

View File

@ -2962,6 +2962,7 @@ function CS_To_String(CompStyle: Integer): String;
function HiWord(i: integer): word;
function LoWord(i: integer): word;
function Char2VK(C : Char) : Word;
function VK2Char(AVK: Word): Char;
function MathRound(AValue: ValReal): Int64;
function MulDiv(nNumber, nNumerator, nDenominator: Integer): Integer;
function KeyToShortCut(const Key: Word; const Shift: TShiftState): TShortCut;
@ -2993,6 +2994,16 @@ begin
end;
end;
function VK2Char(AVK: Word): Char;
begin
case AVK of
VK_0..VK_9: Result := chr(ord('0')+AVK-VK_0);
VK_A..VK_Z: Result := chr(ord('a')+AVK-VK_A);
else
Result:='?';
end;
end;
function MathRound(AValue: ValReal): Int64; inline;
begin
if AValue >= 0 then