mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 08:19:27 +02:00
customdrawn-android: Starts implementing touch events
git-svn-id: trunk@33829 -
This commit is contained in:
parent
f50e6546ff
commit
2617db3cbc
@ -460,7 +460,7 @@ type va_list=pointer;
|
|||||||
GetObjectRefType:function(Env:PJNIEnv;AObject:JObject):jobjectRefType;{$ifdef mswindows}stdcall;{$else}cdecl;{$endif}
|
GetObjectRefType:function(Env:PJNIEnv;AObject:JObject):jobjectRefType;{$ifdef mswindows}stdcall;{$else}cdecl;{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
JNIInvokeInterface={$ifdef packedrecords}packed{$endif} record
|
JNIInvokeInterface=packed record
|
||||||
reserved0:pointer;
|
reserved0:pointer;
|
||||||
reserved1:pointer;
|
reserved1:pointer;
|
||||||
reserved2:pointer;
|
reserved2:pointer;
|
||||||
@ -472,7 +472,7 @@ type va_list=pointer;
|
|||||||
AttachCurrentThreadAsDaemon:function(PVM:PJavaVM;PEnv:PPJNIEnv;Args:pointer):JInt;{$ifdef mswindows}stdcall;{$else}cdecl;{$endif}
|
AttachCurrentThreadAsDaemon:function(PVM:PJavaVM;PEnv:PPJNIEnv;Args:pointer):JInt;{$ifdef mswindows}stdcall;{$else}cdecl;{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
JavaVMAttachArgs={$ifdef packedrecords}packed{$endif} record
|
JavaVMAttachArgs=packed record
|
||||||
version:jint; // must be >= JNI_VERSION_1_2
|
version:jint; // must be >= JNI_VERSION_1_2
|
||||||
name:pchar; // NULL or name of thread as modified UTF-8 str
|
name:pchar; // NULL or name of thread as modified UTF-8 str
|
||||||
group:jobject; // global ref of a ThreadGroup object, or NULL
|
group:jobject; // global ref of a ThreadGroup object, or NULL
|
||||||
|
@ -196,12 +196,18 @@ function WindowProc(Window: HWnd; Msg: UInt; WParam: Windows.WParam;
|
|||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
{$ifdef CD_Android}
|
{$ifdef CD_Android}
|
||||||
function Java_com_pascal_lclproject_LCLActivity_stringFromJNI(env:PJNIEnv;this:jobject):jstring; cdecl;
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnTouch(env:PJNIEnv;this:jobject; x, y: single; action: jint): jint; cdecl;
|
||||||
function Java_com_pascal_lclproject_LCLActivity_intFromJNI(env:PJNIEnv;this:jobject): jint; cdecl;
|
|
||||||
function Java_com_pascal_lclproject_LCLActivity_LCLDrawToBitmap(
|
function Java_com_pascal_lclproject_LCLActivity_LCLDrawToBitmap(
|
||||||
env:PJNIEnv;this:jobject; width, height: jint; abitmap: jobject): jint; cdecl;
|
env:PJNIEnv;this:jobject; width, height: jint; abitmap: jobject): jint; cdecl;
|
||||||
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
|
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
|
||||||
procedure JNI_OnUnload(vm:PJavaVM;reserved:pointer); cdecl;
|
procedure JNI_OnUnload(vm:PJavaVM;reserved:pointer); cdecl;
|
||||||
|
|
||||||
|
var
|
||||||
|
curVM: PJavaVM=nil;
|
||||||
|
curEnv: PJNIEnv=nil;
|
||||||
|
curJavaClass: JClass = nil;
|
||||||
|
curJavaObject: jobject = nil;
|
||||||
|
nativeCodeLoaded:JfieldID=nil;
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
@ -17,23 +17,45 @@
|
|||||||
* *
|
* *
|
||||||
*****************************************************************************
|
*****************************************************************************
|
||||||
}
|
}
|
||||||
var
|
|
||||||
curClass:JClass=nil;
|
|
||||||
nativeCodeLoaded:JfieldID=nil;
|
|
||||||
|
|
||||||
function Java_com_pascal_lclproject_LCLActivity_stringFromJNI(env:PJNIEnv;this:jobject):jstring; cdecl;
|
{function Java_com_pascal_lclproject_LCLActivity_stringFromJNI(env:PJNIEnv;this:jobject):jstring; cdecl;
|
||||||
var x:single;
|
var x:single;
|
||||||
begin
|
begin
|
||||||
{ __android_log_write(ANDROID_LOG_INFO,'nativetest','Java_com_bero_nativetest_Main_stringFromJNI entered');
|
__android_log_write(ANDROID_LOG_INFO,'nativetest','Java_com_bero_nativetest_Main_stringFromJNI entered');
|
||||||
curEnv^.SetLongField(curEnv,curClass,nativeCodeLoaded,1);
|
curEnv^.SetLongField(curEnv,curClass,nativeCodeLoaded,1);
|
||||||
x:=8;
|
x:=8;
|
||||||
result:=env^.NewStringUTF(env,pchar('Hello from native free pascal code by BeRo to the java world on the android platform ! '+floattostr(x*0.5)));
|
result:=env^.NewStringUTF(env,pchar('Hello from native free pascal code by BeRo to the java world on the android platform ! '+floattostr(x*0.5)));
|
||||||
__android_log_write(ANDROID_LOG_INFO,'nativetest','Java_com_bero_nativetest_Main_stringFromJNI exited');}
|
__android_log_write(ANDROID_LOG_INFO,'nativetest','Java_com_bero_nativetest_Main_stringFromJNI exited');
|
||||||
end;
|
end;}
|
||||||
|
|
||||||
function Java_com_pascal_lclproject_LCLActivity_intFromJNI(env:PJNIEnv;this:jobject): jint; cdecl;
|
const
|
||||||
|
ACTION_DOWN = 0;
|
||||||
|
ACTION_UP = 1;
|
||||||
|
|
||||||
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnTouch(env:PJNIEnv;this:jobject; x, y: single; action: jint): jint; cdecl;
|
||||||
|
var
|
||||||
|
lCurForm: TCDNonNativeForm;
|
||||||
|
lTarget: TWinControl;
|
||||||
begin
|
begin
|
||||||
Result := 8;
|
Result := 0;
|
||||||
|
|
||||||
|
__android_log_write(ANDROID_LOG_INFO,'nativetest','LCLOnTouch called');
|
||||||
|
{ curJavaClass := env^^.GetObjectClass(env, this);
|
||||||
|
__android_log_write(ANDROID_LOG_INFO,'nativetest','LCLOnTouch after GetObjectClass');}
|
||||||
|
curJavaObject := this;
|
||||||
|
curEnv := env;
|
||||||
|
|
||||||
|
lCurForm := GetCurrentForm();
|
||||||
|
lTarget := FindControlWhichReceivedEvent(lCurForm.LCLForm, lCurForm.Children, Round(X), Round(Y));
|
||||||
|
|
||||||
|
case action of
|
||||||
|
ACTION_DOWN: LCLSendMouseDownMsg(lTarget, Round(X), Round(Y), mbLeft, []);
|
||||||
|
ACTION_UP:
|
||||||
|
begin
|
||||||
|
LCLSendMouseUpMsg(lTarget, Round(X), Round(Y), mbLeft, []);
|
||||||
|
LCLSendClickedMsg(lTarget);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function Java_com_pascal_lclproject_LCLActivity_LCLDrawToBitmap(
|
function Java_com_pascal_lclproject_LCLActivity_LCLDrawToBitmap(
|
||||||
@ -52,14 +74,6 @@ begin
|
|||||||
Result := 0;
|
Result := 0;
|
||||||
AndroidBitmap_lockPixels(env, abitmap, @pixels);
|
AndroidBitmap_lockPixels(env, abitmap, @pixels);
|
||||||
|
|
||||||
// debug info to check if we are painting
|
|
||||||
pixels[30*width+30] := $FFFFFFFF;
|
|
||||||
pixels[30*width+31] := $FFFFFFFF;
|
|
||||||
pixels[30*width+32] := $FFFFFFFF;
|
|
||||||
pixels[30*width+33] := $FFFFFFFF;
|
|
||||||
pixels[30*width+34] := $FFFFFFFF;
|
|
||||||
pixels[30*width+35] := $FFFFFFFF;
|
|
||||||
|
|
||||||
lCurForm := GetCurrentForm();
|
lCurForm := GetCurrentForm();
|
||||||
if lCurForm <> nil then
|
if lCurForm <> nil then
|
||||||
begin
|
begin
|
||||||
@ -94,33 +108,27 @@ begin
|
|||||||
AndroidBitmap_unlockPixels(env, abitmap);
|
AndroidBitmap_unlockPixels(env, abitmap);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
const NativeMethods: array[0..2] of JNINativeMethod=
|
const NativeMethods: array[0..1] of JNINativeMethod=
|
||||||
((name:'stringFromJNI';
|
((name:'LCLDrawToBitmap';
|
||||||
signature:'()Ljava/lang/String;';
|
|
||||||
fnPtr:@Java_com_pascal_lclproject_LCLActivity_stringFromJNI;),
|
|
||||||
(name:'intFromJNI';
|
|
||||||
signature:'()I';
|
|
||||||
fnPtr:@Java_com_pascal_lclproject_LCLActivity_intFromJNI;),
|
|
||||||
(name:'LCLDrawToBitmap';
|
|
||||||
signature:'(IILandroid/graphics/Bitmap;)I';
|
signature:'(IILandroid/graphics/Bitmap;)I';
|
||||||
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLDrawToBitmap;)
|
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLDrawToBitmap;),
|
||||||
|
(name:'LCLOnTouch';
|
||||||
|
signature:'(FFI)I';
|
||||||
|
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnTouch;)
|
||||||
);
|
);
|
||||||
|
|
||||||
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
|
function JNI_OnLoad(vm:PJavaVM;reserved:pointer):jint; cdecl;
|
||||||
var
|
|
||||||
curVM:PJavaVM=nil;
|
|
||||||
curEnv:PJNIEnv=nil;
|
|
||||||
begin
|
begin
|
||||||
curVM:=vm;
|
curVM:=vm;
|
||||||
__android_log_write(ANDROID_LOG_INFO,'nativetest','JNI_OnLoad called');
|
{ __android_log_write(ANDROID_LOG_INFO,'nativetest','JNI_OnLoad called');
|
||||||
__android_log_write(ANDROID_LOG_INFO,'nativetest',PChar(Format('CurVM=%x', [PtrInt(CurVM)])));
|
__android_log_write(ANDROID_LOG_INFO,'nativetest',PChar(Format('CurVM=%x', [PtrInt(CurVM)])));
|
||||||
__android_log_write(ANDROID_LOG_INFO,'nativetest',PChar(Format('CurVM^=%x', [PtrInt(CurVM^)])));
|
__android_log_write(ANDROID_LOG_INFO,'nativetest',PChar(Format('CurVM^=%x', [PtrInt(CurVM^)])));
|
||||||
__android_log_write(ANDROID_LOG_INFO,'nativetest',PChar(Format('CurVM^^.reserved0=%x', [PtrInt(CurVM^^.reserved0)])));
|
__android_log_write(ANDROID_LOG_INFO,'nativetest',PChar(Format('CurVM^^.reserved0=%x', [PtrInt(CurVM^^.reserved0)])));
|
||||||
__android_log_write(ANDROID_LOG_INFO,'nativetest',PChar(Format('CurVM^^.GetEnv=%x', [PtrInt(Pointer(@CurVM^^.GetEnv))])));
|
__android_log_write(ANDROID_LOG_INFO,'nativetest',PChar(Format('CurVM^^.GetEnv=%x', [PtrInt(Pointer(@CurVM^^.GetEnv))])));
|
||||||
{ if curVM^^.GetEnv(curVM,@curEnv,JNI_VERSION_1_4)<>JNI_OK then begin //<<<--- THIS CRASHES
|
if vm^^.GetEnv(curVM,@curEnv,JNI_VERSION_1_4)<>JNI_OK then begin //<<<--- THIS CRASHES
|
||||||
__android_log_write(ANDROID_LOG_INFO{FATAL},'nativetest','curVM^.GetEnv failed');
|
__android_log_write(ANDROID_LOG_INFO{FATAL},'nativetest','curVM^.GetEnv failed');
|
||||||
// result:=JNI_ERR;
|
result:=JNI_ERR;
|
||||||
// exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
__android_log_write(ANDROID_LOG_INFO,'nativetest','Reading curClass');
|
__android_log_write(ANDROID_LOG_INFO,'nativetest','Reading curClass');
|
||||||
|
@ -117,7 +117,15 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
class procedure TCDWSCustomForm.SetText(const AWinControl: TWinControl; const AText: String);
|
class procedure TCDWSCustomForm.SetText(const AWinControl: TWinControl; const AText: String);
|
||||||
|
//var
|
||||||
|
// javamethod: jmethodID;
|
||||||
begin
|
begin
|
||||||
|
{ javamethod := CurEnv->GetMethodID(clazz, "callFromCPP", "()V");
|
||||||
|
if (javamethod == 0) {
|
||||||
|
LOGI("GetMethodID error");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
env->CallVoidMethod(obj, javamethod); }
|
||||||
end;
|
end;
|
||||||
|
|
||||||
class function TCDWSCustomForm.GetClientBounds(const AWincontrol: TWinControl; var ARect: TRect): Boolean;
|
class function TCDWSCustomForm.GetClientBounds(const AWincontrol: TWinControl; var ARect: TRect): Boolean;
|
||||||
|
Loading…
Reference in New Issue
Block a user