mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-19 23:28:16 +02:00
LCL-CustomDrawn-Android: Further improves the improved timer. Starts adding a list to make sure nothing is GCed, uses global reference and adds a new parameter to in the future use only the list ID instead of the raw reference
git-svn-id: trunk@37246 -
This commit is contained in:
parent
0c28a14046
commit
2ae6c90244
@ -315,7 +315,7 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
public native int LCLOnCreate(Activity lclactivity);
|
public native int LCLOnCreate(Activity lclactivity);
|
||||||
public native int LCLOnMessageBoxFinished(int Result, int DialogType);
|
public native int LCLOnMessageBoxFinished(int Result, int DialogType);
|
||||||
public native int LCLOnKey(int kind, int keyCode, KeyEvent event, int 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, int timeridindex);
|
||||||
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);
|
||||||
public native int LCLOnMenuAction(int kind, int itemIndex);
|
public native int LCLOnMenuAction(int kind, int itemIndex);
|
||||||
@ -447,7 +447,8 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
int eventResult = LCLOnTimer(this);
|
int lcltimeridindex = lcltimerids.indexOf(this);
|
||||||
|
int eventResult = LCLOnTimer(this, lcltimeridindex);
|
||||||
ProcessEventResult(eventResult);
|
ProcessEventResult(eventResult);
|
||||||
if (this.Destroyed == false) LocalHandler.postDelayed(this, lcltimerinterval);
|
if (this.Destroyed == false) LocalHandler.postDelayed(this, lcltimerinterval);
|
||||||
}
|
}
|
||||||
@ -461,6 +462,8 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
|
|
||||||
LocalHandler.removeCallbacks(lcltimerid);
|
LocalHandler.removeCallbacks(lcltimerid);
|
||||||
LocalHandler.postDelayed(lcltimerid, lcltimerinterval);
|
LocalHandler.postDelayed(lcltimerid, lcltimerinterval);
|
||||||
|
|
||||||
|
lcltimerids.add(lcltimerid);
|
||||||
};
|
};
|
||||||
|
|
||||||
// input: Runnable lcltimerid
|
// input: Runnable lcltimerid
|
||||||
@ -468,6 +471,7 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
{
|
{
|
||||||
LocalHandler.removeCallbacks(lcltimerid);
|
LocalHandler.removeCallbacks(lcltimerid);
|
||||||
((LCLRunnable) lcltimerid).Destroyed = true;
|
((LCLRunnable) lcltimerid).Destroyed = true;
|
||||||
|
lcltimerids.remove(lcltimerids.indexOf(lcltimerid));
|
||||||
};
|
};
|
||||||
|
|
||||||
public void LCLDoHideVirtualKeyboard()
|
public void LCLDoHideVirtualKeyboard()
|
||||||
@ -679,6 +683,7 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
//
|
//
|
||||||
public int lcltimerinterval;
|
public int lcltimerinterval;
|
||||||
public Runnable lcltimerid;
|
public Runnable lcltimerid;
|
||||||
|
public List lcltimerids = new ArrayList(); // To keep the references alive, avoids a wrong GC
|
||||||
//
|
//
|
||||||
public int lclxdpi;
|
public int lclxdpi;
|
||||||
public int lclydpi;
|
public int lclydpi;
|
||||||
|
@ -351,7 +351,7 @@ 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: jint): 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; ATimerIDIndex: jint): jint; cdecl;
|
||||||
function Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged(
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnConfigurationChanged(
|
||||||
env:PJNIEnv; this:jobject; ANewDPI, ANewWidth: jint): jint; cdecl;
|
env:PJNIEnv; this:jobject; ANewDPI, ANewWidth: jint): jint; cdecl;
|
||||||
function Java_com_pascal_lclproject_LCLActivity_LCLOnSensorChanged(
|
function Java_com_pascal_lclproject_LCLActivity_LCLOnSensorChanged(
|
||||||
|
@ -227,7 +227,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
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; ATimerIDIndex: jint): jint; cdecl;
|
||||||
var
|
var
|
||||||
lTimer: TCDTimer;
|
lTimer: TCDTimer;
|
||||||
begin
|
begin
|
||||||
@ -458,7 +458,7 @@ const NativeMethods: array[0..8] of JNINativeMethod=
|
|||||||
signature:'(IILandroid/view/KeyEvent;I)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)I';
|
||||||
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnTimer;),
|
fnPtr:@Java_com_pascal_lclproject_LCLActivity_LCLOnTimer;),
|
||||||
(name:'LCLOnConfigurationChanged';
|
(name:'LCLOnConfigurationChanged';
|
||||||
signature:'(II)I';
|
signature:'(II)I';
|
||||||
@ -1385,7 +1385,8 @@ begin
|
|||||||
// Read the output
|
// Read the output
|
||||||
lTimerObject := javaEnvRef^^.GetObjectField(javaEnvRef, javaActivityObject, javaField_lcltimerid);
|
lTimerObject := javaEnvRef^^.GetObjectField(javaEnvRef, javaActivityObject, javaField_lcltimerid);
|
||||||
lGlobalTimerObject := javaEnvRef^^.NewGlobalRef(javaEnvRef, lTimerObject);
|
lGlobalTimerObject := javaEnvRef^^.NewGlobalRef(javaEnvRef, lTimerObject);
|
||||||
lTimer.NativeHandle := PtrInt(lGlobalTimerObject);
|
lTimer.NativeHandle := PtrInt(lTimerObject);
|
||||||
|
lTimer.NativeGlobalReference := PtrInt(lGlobalTimerObject);
|
||||||
|
|
||||||
// Add it to our list
|
// Add it to our list
|
||||||
AddTimer(lTimer);
|
AddTimer(lTimer);
|
||||||
@ -1401,19 +1402,20 @@ function TCDWidgetSet.DestroyTimer(TimerHandle: THandle) : boolean;
|
|||||||
var
|
var
|
||||||
lTimer: TCDTimer;
|
lTimer: TCDTimer;
|
||||||
begin
|
begin
|
||||||
DebugLn(Format('[TCDWidgetSet.DestroyTimer] TimerHandle=%x', [PtrInt(TimerHandle)]));
|
|
||||||
Result := False;
|
|
||||||
|
|
||||||
lTimer := TCDTimer(TimerHandle);
|
lTimer := TCDTimer(TimerHandle);
|
||||||
|
|
||||||
|
DebugLn(Format('[TCDWidgetSet.DestroyTimer] TimerHandle=%x lTimer.NativeHandle=%x lTimer.NativeGlobalReference=%x',
|
||||||
|
[PtrInt(TimerHandle), PtrInt(lTimer.NativeHandle), PtrInt(lTimer.NativeGlobalReference)]));
|
||||||
|
Result := False;
|
||||||
|
|
||||||
if lTimer = nil then Exit;
|
if lTimer = nil then Exit;
|
||||||
|
|
||||||
// Prepare the input
|
// Prepare the input
|
||||||
javaEnvRef^^.SetObjectField(javaEnvRef, javaActivityObject, javaField_lcltimerid, jobject(lTimer.NativeHandle));
|
javaEnvRef^^.SetObjectField(javaEnvRef, javaActivityObject, javaField_lcltimerid, jobject(lTimer.NativeGlobalReference));
|
||||||
|
|
||||||
// Call the method
|
// Call the method
|
||||||
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoDestroyTimer);
|
javaEnvRef^^.CallVoidMethod(javaEnvRef, javaActivityObject, javaMethod_LCLDoDestroyTimer);
|
||||||
javaEnvRef^^.DeleteGlobalRef(javaEnvRef, JObject(lTimer.NativeHandle));
|
javaEnvRef^^.DeleteGlobalRef(javaEnvRef, JObject(lTimer.NativeGlobalReference));
|
||||||
|
|
||||||
// Remove from the list
|
// Remove from the list
|
||||||
RemoveTimer(lTimer);
|
RemoveTimer(lTimer);
|
||||||
|
@ -111,6 +111,7 @@ type
|
|||||||
TCDTimer = class
|
TCDTimer = class
|
||||||
public
|
public
|
||||||
NativeHandle: PtrInt; // The X11 timer uses this to store the current time which is summed up to the next interval
|
NativeHandle: PtrInt; // The X11 timer uses this to store the current time which is summed up to the next interval
|
||||||
|
NativeGlobalReference: PtrInt; // Utilized in Android to store the global JNI reference
|
||||||
Interval: integer;
|
Interval: integer;
|
||||||
TimerFunc: TWSTimerProc;
|
TimerFunc: TWSTimerProc;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user