mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-22 15:29:35 +01:00
Android: Starts improving the key input. Now it gets real unicode chars instead of the key name
git-svn-id: trunk@34509 -
This commit is contained in:
parent
98159ea9e5
commit
b106f80cb9
@ -44,7 +44,7 @@ function UTF8Length(p: PChar; ByteCount: PtrInt): PtrInt;
|
|||||||
function UTF8CharacterToUnicode(p: PChar; out CharLen: integer): Cardinal;
|
function UTF8CharacterToUnicode(p: PChar; out CharLen: integer): Cardinal;
|
||||||
function UnicodeToUTF8(u: cardinal; Buf: PChar): integer; inline;
|
function UnicodeToUTF8(u: cardinal; Buf: PChar): integer; inline;
|
||||||
function UnicodeToUTF8SkipErrors(u: cardinal; Buf: PChar): integer;
|
function UnicodeToUTF8SkipErrors(u: cardinal; Buf: PChar): integer;
|
||||||
function UnicodeToUTF8(u: cardinal): shortstring; inline;
|
function UnicodeToUTF8(u: cardinal): string;
|
||||||
function UTF8ToDoubleByteString(const s: string): string;
|
function UTF8ToDoubleByteString(const s: string): string;
|
||||||
function UTF8ToDoubleByte(UTF8Str: PChar; Len: PtrInt; DBStr: PByte): PtrInt;
|
function UTF8ToDoubleByte(UTF8Str: PChar; Len: PtrInt; DBStr: PByte): PtrInt;
|
||||||
function UTF8FindNearestCharStart(UTF8Str: PChar; Len: integer;
|
function UTF8FindNearestCharStart(UTF8Str: PChar; Len: integer;
|
||||||
@ -340,9 +340,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function UnicodeToUTF8(u: cardinal): shortstring;
|
function UnicodeToUTF8(u: cardinal): string;
|
||||||
|
var
|
||||||
|
Buf: array[0..6] of Char;
|
||||||
begin
|
begin
|
||||||
Result[0]:=chr(UnicodeToUTF8(u,@Result[1]));
|
UnicodeToUTF8SkipErrors(u, @Buf[0]);
|
||||||
|
Result := StrPas(@Buf[0]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function UTF8ToDoubleByteString(const s: string): string;
|
function UTF8ToDoubleByteString(const s: string): string;
|
||||||
|
|||||||
@ -76,12 +76,9 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
@Override public boolean onKeyUp (int keyCode, KeyEvent event)
|
@Override public boolean onKeyUp (int keyCode, KeyEvent event)
|
||||||
{
|
{
|
||||||
// First handle the KeyUp event
|
// First handle the KeyUp event
|
||||||
int eventResult = LCLOnKey(KeyEvent.ACTION_UP, keyCode, event, event.getDisplayLabel());
|
int eventResult = LCLOnKey(KeyEvent.ACTION_UP, keyCode, event, event.getUnicodeChar());
|
||||||
if ((eventResult & 1) != 0) postInvalidate();
|
if ((eventResult & 1) != 0) postInvalidate();
|
||||||
|
|
||||||
// Now KeyPress
|
|
||||||
//KeyCharacterMap localMap = event.getKeyCharacterMap();
|
|
||||||
|
|
||||||
// Handling of the Back hardware key
|
// Handling of the Back hardware key
|
||||||
super.onKeyUp(keyCode, event);
|
super.onKeyUp(keyCode, event);
|
||||||
if ((eventResult & 2) != 0)
|
if ((eventResult & 2) != 0)
|
||||||
@ -174,7 +171,7 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
public native int LCLOnTouch(float x, float y, int action);
|
public native int LCLOnTouch(float x, float y, int action);
|
||||||
public native int LCLOnCreate(LCLActivity lclactivity);
|
public native int LCLOnCreate(LCLActivity lclactivity);
|
||||||
public native int LCLOnMessageBoxFinished(int Result);
|
public native int LCLOnMessageBoxFinished(int Result);
|
||||||
public native int LCLOnKey(int kind, int keyCode, KeyEvent event, char AChar);
|
public native int LCLOnKey(int kind, int keyCode, KeyEvent event, int AChar);
|
||||||
public native int LCLOnTimer(Runnable timerid);
|
public native int LCLOnTimer(Runnable timerid);
|
||||||
public native int LCLOnConfigurationChanged(int ANewDPI, int ANewWidth);
|
public native int LCLOnConfigurationChanged(int ANewDPI, int ANewWidth);
|
||||||
public native int LCLOnSensorChanged(int ASensorKind, double[] AValues);
|
public native int LCLOnSensorChanged(int ASensorKind, double[] AValues);
|
||||||
|
|||||||
@ -143,6 +143,7 @@ type
|
|||||||
procedure AppProcessMessage;
|
procedure AppProcessMessage;
|
||||||
{$endif}
|
{$endif}
|
||||||
{$ifdef CD_Android}
|
{$ifdef CD_Android}
|
||||||
|
CombiningAccent: Cardinal;
|
||||||
procedure AndroidDebugLn(AStr: string);
|
procedure AndroidDebugLn(AStr: string);
|
||||||
function AndroidKeyCodeToLCLKeyCode(AAndroidKeyCode: Integer): Word;
|
function AndroidKeyCodeToLCLKeyCode(AAndroidKeyCode: Integer): Word;
|
||||||
{$endif}
|
{$endif}
|
||||||
@ -247,7 +248,7 @@ function Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished(
|
|||||||
env:PJNIEnv; this:jobject; AResult: jint): jint; cdecl;
|
env:PJNIEnv; this:jobject; AResult: jint): jint; cdecl;
|
||||||
function Java_com_pascal_lclproject_LCLActivity_LCLOnKey(
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnKey(
|
||||||
env:PJNIEnv; this:jobject; AKind: jint; AKeyCode: jint;
|
env:PJNIEnv; this:jobject; AKind: jint; AKeyCode: jint;
|
||||||
AEvent: jobject; AChar: jchar): jint; cdecl;
|
AEvent: jobject; AChar: jint): jint; cdecl;
|
||||||
function Java_com_pascal_lclproject_LCLActivity_LCLOnTimer(
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnTimer(
|
||||||
env:PJNIEnv; this:jobject; ATimer: jobject): jint; cdecl;
|
env:PJNIEnv; this:jobject; ATimer: jobject): jint; cdecl;
|
||||||
function Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged(
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged(
|
||||||
|
|||||||
@ -30,6 +30,9 @@ const
|
|||||||
ACTION_MULTIPLE = 2;
|
ACTION_MULTIPLE = 2;
|
||||||
// Keys are in KeyCodes.pas
|
// Keys are in KeyCodes.pas
|
||||||
|
|
||||||
|
// from android.view.KeyCharacterMap
|
||||||
|
COMBINING_ACCENT = $80000000;
|
||||||
|
|
||||||
function Java_com_pascal_lclproject_LCLActivity_LCLOnTouch(env:PJNIEnv;this:jobject; x, y: single; action: jint): jint; cdecl;
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnTouch(env:PJNIEnv;this:jobject; x, y: single; action: jint): jint; cdecl;
|
||||||
var
|
var
|
||||||
lCurForm: TCDNonNativeForm;
|
lCurForm: TCDNonNativeForm;
|
||||||
@ -136,19 +139,21 @@ end;
|
|||||||
|
|
||||||
function Java_com_pascal_lclproject_LCLActivity_LCLOnKey(
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnKey(
|
||||||
env:PJNIEnv; this:jobject; AKind: jint; AKeyCode: jint;
|
env:PJNIEnv; this:jobject; AKind: jint; AKeyCode: jint;
|
||||||
AEvent: jobject; AChar: jchar): jint; cdecl;
|
AEvent: jobject; AChar: jint): jint; cdecl;
|
||||||
var
|
var
|
||||||
lCurForm: TCDNonNativeForm;
|
lCurForm: TCDNonNativeForm;
|
||||||
lTarget, lFocusedControl: TWinControl;
|
lTarget, lFocusedControl: TWinControl;
|
||||||
lKey: Word;
|
lKey: Word;
|
||||||
AWideText: widestring;
|
lCombinedAChar: jint;
|
||||||
|
lChar: Cardinal;
|
||||||
AUTF8Text: string;
|
AUTF8Text: string;
|
||||||
AUTF8Char: TUTF8Char;
|
AUTF8Char: TUTF8Char;
|
||||||
lForm: TCDNonNativeForm;
|
lForm: TCDNonNativeForm;
|
||||||
begin
|
begin
|
||||||
|
lChar := Cardinal(AChar);
|
||||||
{$ifdef VerboseCDEvents}
|
{$ifdef VerboseCDEvents}
|
||||||
__android_log_write(ANDROID_LOG_INFO,'lclapp',PChar(
|
__android_log_write(ANDROID_LOG_INFO,'lclapp',PChar(
|
||||||
Format('[LCLOnKey] called AKind=%d AKeyCode=%x AChar=%s', [AKind, AKeyCode, UTF8Encode(WideChar(AChar))])));
|
Format('[LCLOnKey] called AKind=%d AKeyCode=%x AChar=%s', [AKind, AKeyCode, UnicodeToUTF8(lChar)])));
|
||||||
{$endif}
|
{$endif}
|
||||||
eventResult := 0;
|
eventResult := 0;
|
||||||
|
|
||||||
@ -160,13 +165,32 @@ begin
|
|||||||
ACTION_UP:
|
ACTION_UP:
|
||||||
begin
|
begin
|
||||||
CallbackKeyUp(lCurForm, lKey);
|
CallbackKeyUp(lCurForm, lKey);
|
||||||
if AChar <> 0 then
|
if (lChar <> 0) and ((COMBINING_ACCENT and lChar) = 0) then
|
||||||
begin
|
begin
|
||||||
SetLength(AWideText, 1);
|
if CDWidgetset.CombiningAccent <> 0 then
|
||||||
AWideText[1] := WideChar(AChar);
|
begin
|
||||||
AUTF8Text := UTF16ToUTF8(AWideText);
|
(* // Prepare the input
|
||||||
|
lJavaString :=javaEnvRef^^.NewStringUTF(javaEnvRef, Str);
|
||||||
|
javaEnvRef^^.SetObjectField(javaEnvRef, javaActivityObject, JavaField_lcltext, lJavaString);
|
||||||
|
javaEnvRef^^.SetIntField(javaEnvRef, javaActivityObject, javaField_lcltextsize, lFontSize);
|
||||||
|
|
||||||
|
// Call the method
|
||||||
|
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoGetTextBounds);
|
||||||
|
|
||||||
|
// Read the output
|
||||||
|
Size.cx := javaEnvRef^^.GetIntField(javaEnvRef, javaActivityObject, javaField_lclwidth);
|
||||||
|
Size.cy := javaEnvRef^^.GetIntField(javaEnvRef, javaActivityObject, javaField_lclheight);
|
||||||
|
//
|
||||||
|
lCombinedAChar := getDeadChar();*)
|
||||||
|
end;
|
||||||
|
AUTF8Text := UnicodeToUTF8(lChar);
|
||||||
AUTF8Char := AUTF8Text;
|
AUTF8Char := AUTF8Text;
|
||||||
CallbackKeyChar(lCurForm, lKey, AUTF8Char);
|
CallbackKeyChar(lCurForm, lKey, AUTF8Char);
|
||||||
|
CDWidgetset.CombiningAccent := 0;
|
||||||
|
end
|
||||||
|
else if (lChar <> 0) and ((COMBINING_ACCENT and lChar) <> 0) then
|
||||||
|
begin
|
||||||
|
CDWidgetset.CombiningAccent := lChar;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Handle the Back hardware key
|
// Handle the Back hardware key
|
||||||
@ -333,7 +357,7 @@ const NativeMethods: array[0..7] of JNINativeMethod=
|
|||||||
signature:'(I)I';
|
signature:'(I)I';
|
||||||
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished;),
|
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnMessageBoxFinished;),
|
||||||
(name:'LCLOnKey';
|
(name:'LCLOnKey';
|
||||||
signature:'(IILandroid/view/KeyEvent;C)I';
|
signature:'(IILandroid/view/KeyEvent;I)I';
|
||||||
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnKey;),
|
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnKey;),
|
||||||
(name:'LCLOnTimer';
|
(name:'LCLOnTimer';
|
||||||
signature:'(Ljava/lang/Runnable;)I';
|
signature:'(Ljava/lang/Runnable;)I';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user