android: Adds the bindings side of the timer support

git-svn-id: trunk@31735 -
This commit is contained in:
sekelsenmat 2011-07-18 14:10:36 +00:00
parent 07bb9fee4c
commit 0225972c3c
3 changed files with 75 additions and 3 deletions

1
.gitattributes vendored
View File

@ -5206,6 +5206,7 @@ lcl/interfaces/android/androidint.pas svneol=native#text/pascal
lcl/interfaces/android/androidobject.inc svneol=native#text/pascal
lcl/interfaces/android/androidpipescomm.pas svneol=native#text/pascal
lcl/interfaces/android/androidprivate.pas svneol=native#text/pascal
lcl/interfaces/android/androidtimer.pas svneol=native#text/pascal
lcl/interfaces/android/androidwsfactory.pas svneol=native#text/pascal
lcl/interfaces/android/interfaces.pp svneol=native#text/plain
lcl/interfaces/android/javalang.pas svneol=native#text/pascal

View File

@ -75,7 +75,7 @@ var
implementation
uses android_all, androidapp, javalang;
uses android_all, androidapp, androidtimer, javalang;
var
Str: string;
@ -159,8 +159,8 @@ begin
amkTimer: // A Timer Callback
begin
lPascalPointer := ReadInt();
{ TAndroidTimer(lPascalPointer).callOnTimerListener();
vAndroidPipesComm.SendMessage(amkTimer, amkTimer_Callback_Finished);}
TAndroidTimer(lPascalPointer).callOnTimerListener();
vAndroidPipesComm.SendMessage(amkTimer, amkTimer_Callback_Finished);
end;
end;
// dataString1 := 'Pascal log: ' + IntToStr(lByte) + LineEnding;

View File

@ -0,0 +1,71 @@
{
Android4Pascal - Android API Bindings for Pascal
Author: Felipe Monteiro de Carvalho - 2011
License: modified LGPL (the same as the Free Pascal RTL, Lazarus LCL)
}
unit androidtimer;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, javalang;
type
{ TAndroidTimer }
TAndroidTimer = class(TJavaObject)
OnTimer: TNotifyEvent;
constructor Create;
procedure postDelayed(ADelay: Integer);
procedure removeCallbacks();
procedure callOnTimerListener();
end;
const
amkTimer_New_Runnable = $0000;
amkTimer_postDelayed = $0001;
amkTimer_removeCallbacks = $0002;
amkTimer_Callback_Finished = $0EEE0000;
implementation
uses androidpipescomm;
{ TAndroidTimer }
constructor TAndroidTimer.Create;
begin
vAndroidPipesComm.SendByte(ShortInt(amkTimer));
vAndroidPipesComm.SendInt(amkTimer_New_Runnable);
vAndroidPipesComm.SendInt(PtrInt(Self)); // Self, Pascal pointer
Index := vAndroidPipesComm.WaitForIntReturn();
end;
procedure TAndroidTimer.postDelayed(ADelay: Integer);
begin
vAndroidPipesComm.SendByte(ShortInt(amkTimer));
vAndroidPipesComm.SendInt(amkTimer_postDelayed);
vAndroidPipesComm.SendInt(Index); // Self
vAndroidPipesComm.SendInt(ADelay);
vAndroidPipesComm.WaitForReturn();
end;
procedure TAndroidTimer.removeCallbacks();
begin
vAndroidPipesComm.SendByte(ShortInt(amkTimer));
vAndroidPipesComm.SendInt(amkTimer_removeCallbacks);
vAndroidPipesComm.SendInt(Index); // Self
vAndroidPipesComm.WaitForReturn();
end;
procedure TAndroidTimer.callOnTimerListener();
begin
if Assigned(OnTimer) then OnTimer(Self);
end;
end.