You've already forked lazarus-ccr
Advances the android sdk bindings gen
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1678 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -39,12 +39,11 @@
|
||||
<PackageName Value="LCL"/>
|
||||
</Item2>
|
||||
</RequiredPackages>
|
||||
<Units Count="9">
|
||||
<Units Count="12">
|
||||
<Unit0>
|
||||
<Filename Value="android_bindings_generator.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="android_bindings_generator"/>
|
||||
<IsVisibleTab Value="True"/>
|
||||
<EditorIndex Value="1"/>
|
||||
<WindowIndex Value="0"/>
|
||||
<TopLine Value="1"/>
|
||||
@ -71,7 +70,7 @@
|
||||
<UnitName Value="androidmenu"/>
|
||||
<EditorIndex Value="4"/>
|
||||
<WindowIndex Value="0"/>
|
||||
<TopLine Value="14"/>
|
||||
<TopLine Value="77"/>
|
||||
<CursorPos X="25" Y="24"/>
|
||||
<UsageCount Value="10"/>
|
||||
<Loaded Value="True"/>
|
||||
@ -91,15 +90,15 @@
|
||||
<UnitName Value="androidview"/>
|
||||
<EditorIndex Value="6"/>
|
||||
<WindowIndex Value="0"/>
|
||||
<TopLine Value="53"/>
|
||||
<CursorPos X="1" Y="1"/>
|
||||
<TopLine Value="109"/>
|
||||
<CursorPos X="59" Y="419"/>
|
||||
<UsageCount Value="10"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit4>
|
||||
<Unit5>
|
||||
<Filename Value="../../../p-tools/turbochessclock4android/androiddialog.pas"/>
|
||||
<UnitName Value="androiddialog"/>
|
||||
<EditorIndex Value="7"/>
|
||||
<EditorIndex Value="8"/>
|
||||
<WindowIndex Value="0"/>
|
||||
<TopLine Value="1"/>
|
||||
<CursorPos X="1" Y="1"/>
|
||||
@ -128,134 +127,161 @@
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="android_sdk_bindings_gen"/>
|
||||
<IsVisibleTab Value="True"/>
|
||||
<EditorIndex Value="2"/>
|
||||
<WindowIndex Value="0"/>
|
||||
<TopLine Value="72"/>
|
||||
<CursorPos X="19" Y="99"/>
|
||||
<TopLine Value="40"/>
|
||||
<CursorPos X="44" Y="66"/>
|
||||
<UsageCount Value="20"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit8>
|
||||
<Unit9>
|
||||
<Filename Value="../../../p-tools/turbochessclock4android/androidapp.pas"/>
|
||||
<UnitName Value="androidapp"/>
|
||||
<EditorIndex Value="7"/>
|
||||
<WindowIndex Value="0"/>
|
||||
<TopLine Value="1"/>
|
||||
<CursorPos X="16" Y="22"/>
|
||||
<UsageCount Value="10"/>
|
||||
<Loaded Value="True"/>
|
||||
</Unit9>
|
||||
<Unit10>
|
||||
<Filename Value="../../../p-tools/turbochessclock4android/androidpipescomm.pas"/>
|
||||
<UnitName Value="androidpipescomm"/>
|
||||
<WindowIndex Value="0"/>
|
||||
<TopLine Value="1"/>
|
||||
<CursorPos X="1" Y="1"/>
|
||||
<UsageCount Value="10"/>
|
||||
</Unit10>
|
||||
<Unit11>
|
||||
<Filename Value="../../../fpcbuild/fpcsrc/rtl/objpas/sysutils/sysstrh.inc"/>
|
||||
<WindowIndex Value="0"/>
|
||||
<TopLine Value="92"/>
|
||||
<CursorPos X="18" Y="116"/>
|
||||
<UsageCount Value="10"/>
|
||||
<DefaultSyntaxHighlighter Value="Delphi"/>
|
||||
</Unit11>
|
||||
</Units>
|
||||
<JumpHistory Count="30" HistoryIndex="29">
|
||||
<Position1>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="13" Column="3" TopLine="9"/>
|
||||
<Caret Line="43" Column="20" TopLine="15"/>
|
||||
</Position1>
|
||||
<Position2>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="62" Column="16" TopLine="47"/>
|
||||
<Caret Line="45" Column="9" TopLine="20"/>
|
||||
</Position2>
|
||||
<Position3>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="14" Column="50" TopLine="1"/>
|
||||
<Caret Line="72" Column="6" TopLine="43"/>
|
||||
</Position3>
|
||||
<Position4>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="18" Column="17" TopLine="1"/>
|
||||
<Caret Line="73" Column="39" TopLine="50"/>
|
||||
</Position4>
|
||||
<Position5>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="67" Column="1" TopLine="54"/>
|
||||
<Caret Line="74" Column="6" TopLine="51"/>
|
||||
</Position5>
|
||||
<Position6>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="55" Column="70" TopLine="34"/>
|
||||
<Filename Value="mainform.pas"/>
|
||||
<Caret Line="38" Column="83" TopLine="1"/>
|
||||
</Position6>
|
||||
<Position7>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="16" Column="39" TopLine="1"/>
|
||||
<Caret Line="28" Column="1" TopLine="1"/>
|
||||
</Position7>
|
||||
<Position8>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="1" Column="30" TopLine="1"/>
|
||||
<Filename Value="mainform.pas"/>
|
||||
<Caret Line="38" Column="13" TopLine="1"/>
|
||||
</Position8>
|
||||
<Position9>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="17" Column="74" TopLine="1"/>
|
||||
<Caret Line="35" Column="78" TopLine="33"/>
|
||||
</Position9>
|
||||
<Position10>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="43" Column="20" TopLine="15"/>
|
||||
<Caret Line="144" Column="17" TopLine="110"/>
|
||||
</Position10>
|
||||
<Position11>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="45" Column="9" TopLine="20"/>
|
||||
<Caret Line="142" Column="34" TopLine="110"/>
|
||||
</Position11>
|
||||
<Position12>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="72" Column="6" TopLine="43"/>
|
||||
<Caret Line="144" Column="33" TopLine="110"/>
|
||||
</Position12>
|
||||
<Position13>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="73" Column="39" TopLine="50"/>
|
||||
<Caret Line="90" Column="143" TopLine="78"/>
|
||||
</Position13>
|
||||
<Position14>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="74" Column="6" TopLine="51"/>
|
||||
<Caret Line="22" Column="24" TopLine="1"/>
|
||||
</Position14>
|
||||
<Position15>
|
||||
<Filename Value="mainform.pas"/>
|
||||
<Caret Line="38" Column="83" TopLine="1"/>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="116" Column="21" TopLine="96"/>
|
||||
</Position15>
|
||||
<Position16>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="28" Column="1" TopLine="1"/>
|
||||
<Caret Line="175" Column="35" TopLine="150"/>
|
||||
</Position16>
|
||||
<Position17>
|
||||
<Filename Value="mainform.pas"/>
|
||||
<Caret Line="38" Column="13" TopLine="1"/>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="21" Column="31" TopLine="40"/>
|
||||
</Position17>
|
||||
<Position18>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="35" Column="78" TopLine="33"/>
|
||||
<Caret Line="98" Column="42" TopLine="75"/>
|
||||
</Position18>
|
||||
<Position19>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="144" Column="17" TopLine="110"/>
|
||||
<Caret Line="84" Column="3" TopLine="77"/>
|
||||
</Position19>
|
||||
<Position20>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="142" Column="34" TopLine="110"/>
|
||||
<Caret Line="89" Column="1" TopLine="77"/>
|
||||
</Position20>
|
||||
<Position21>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="144" Column="33" TopLine="110"/>
|
||||
<Caret Line="114" Column="29" TopLine="91"/>
|
||||
</Position21>
|
||||
<Position22>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="90" Column="143" TopLine="78"/>
|
||||
<Filename Value="../../../p-tools/turbochessclock4android/androidview.pas"/>
|
||||
<Caret Line="421" Column="3" TopLine="395"/>
|
||||
</Position22>
|
||||
<Position23>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="22" Column="24" TopLine="1"/>
|
||||
<Caret Line="157" Column="85" TopLine="124"/>
|
||||
</Position23>
|
||||
<Position24>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="116" Column="21" TopLine="96"/>
|
||||
<Caret Line="127" Column="88" TopLine="104"/>
|
||||
</Position24>
|
||||
<Position25>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="175" Column="35" TopLine="150"/>
|
||||
<Caret Line="151" Column="31" TopLine="129"/>
|
||||
</Position25>
|
||||
<Position26>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="21" Column="31" TopLine="40"/>
|
||||
<Caret Line="24" Column="24" TopLine="1"/>
|
||||
</Position26>
|
||||
<Position27>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="98" Column="42" TopLine="75"/>
|
||||
<Caret Line="25" Column="34" TopLine="1"/>
|
||||
</Position27>
|
||||
<Position28>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="84" Column="3" TopLine="77"/>
|
||||
<Caret Line="123" Column="82" TopLine="97"/>
|
||||
</Position28>
|
||||
<Position29>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="89" Column="1" TopLine="77"/>
|
||||
<Caret Line="18" Column="26" TopLine="1"/>
|
||||
</Position29>
|
||||
<Position30>
|
||||
<Filename Value="android_sdk_bindings_gen.pas"/>
|
||||
<Caret Line="114" Column="29" TopLine="91"/>
|
||||
<Caret Line="124" Column="120" TopLine="101"/>
|
||||
</Position30>
|
||||
</JumpHistory>
|
||||
</ProjectOptions>
|
||||
|
@ -13,13 +13,16 @@ type
|
||||
|
||||
TAndroidSDKBindingsGen = class
|
||||
private
|
||||
FSourceFile, FPasOutputClasses, FPasOutputImpl: TStringList;
|
||||
FSourceFile, FPasOutputClasses, FPasOutputIDs, FPasOutputImpl: TStringList;
|
||||
FClassName: string; // Class name of the class currently being parsed
|
||||
FClassNum, FMethodNum: Integer;
|
||||
procedure ProcessModelFile(ASourceFile, APasOutputFile, AJavaOutputDir: string);
|
||||
procedure ProcessModelLine(ASourceLine: string);
|
||||
function GetNextWord(ALine: string; var AStartPos: Integer): string;
|
||||
function GetPascalTypeName(ABaseName: string): string;
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
procedure GenerateAllBindings(AInputDir, APasOutputDir, AJavaOutputDir: string);
|
||||
end;
|
||||
|
||||
@ -36,9 +39,6 @@ var
|
||||
i: Integer;
|
||||
lPasOutputFile: TStringList;
|
||||
begin
|
||||
FSourceFile := TStringList.Create;
|
||||
FPasOutputClasses := TStringList.Create;
|
||||
FPasOutputImpl := TStringList.Create;
|
||||
lPasOutputFile := TStringList.Create;
|
||||
try
|
||||
FSourceFile.LoadFromFile(ASourceFile);
|
||||
@ -60,18 +60,17 @@ begin
|
||||
lPasOutputFile.AddStrings(FPasOutputClasses);
|
||||
lPasOutputFile.Add(' end;');
|
||||
lPasOutputFile.Add('');
|
||||
lPasOutputFile.Add('');
|
||||
lPasOutputFile.Add('implementation');
|
||||
lPasOutputFile.Add('');
|
||||
lPasOutputFile.Add('const');
|
||||
lPasOutputFile.AddStrings(FPasOutputIDs);
|
||||
lPasOutputFile.Add('');
|
||||
lPasOutputFile.AddStrings(FPasOutputImpl);
|
||||
lPasOutputFile.Add('');
|
||||
lPasOutputFile.Add('end.');
|
||||
|
||||
lPasOutputFile.SaveToFile(APasOutputFile);
|
||||
finally
|
||||
FSourceFile.Free;
|
||||
FPasOutputClasses.Free;
|
||||
FPasOutputImpl.Free;
|
||||
lPasOutputFile.Free;
|
||||
end;
|
||||
end;
|
||||
@ -81,12 +80,16 @@ var
|
||||
lReaderPos: Integer = 1;
|
||||
lCurWord, lParentClassName: string;
|
||||
lMethodReturn, lMethodName, lParamType, lParamName: string;
|
||||
TmpStr: string;
|
||||
DeclarationBase, TmpStr: string;
|
||||
FPasOutputImplCurLine: Integer;
|
||||
begin
|
||||
if ASourceLine = '' then Exit;
|
||||
|
||||
lCurWord := GetNextWord(ASourceLine, lReaderPos);
|
||||
|
||||
// Comments
|
||||
if ASourceLine[1] = '#' then Exit;
|
||||
|
||||
// Starting a new class
|
||||
if ASourceLine[1] = '[' then
|
||||
begin
|
||||
@ -101,20 +104,34 @@ begin
|
||||
lParentClassName := GetPascalTypeName(lParentClassName);
|
||||
FPasOutputClasses.Add(Format(' %s = class(%s)', [FClassName, lParentClassName]));
|
||||
FPasOutputClasses.Add(' public');
|
||||
lCurWord := GetNextWord(ASourceLine, lReaderPos);
|
||||
Inc(FClassNum);
|
||||
FMethodNum := 0;
|
||||
|
||||
Exit;
|
||||
end;
|
||||
|
||||
// Adding methods to a class
|
||||
if lCurWord = 'method' then
|
||||
begin
|
||||
// Method type and name
|
||||
lMethodReturn := GetNextWord(ASourceLine, lReaderPos);
|
||||
lMethodReturn := GetPascalTypeName(lMethodReturn);
|
||||
lMethodName := GetNextWord(ASourceLine, lReaderPos);
|
||||
|
||||
if lMethodReturn = 'void' then TmpStr := ' procedure '
|
||||
else TmpStr := ' function ';
|
||||
if lMethodReturn = 'void' then DeclarationBase := 'procedure '
|
||||
else DeclarationBase := 'function ';
|
||||
|
||||
// Beginning of the implementation part
|
||||
FPasOutputImplCurLine := FPasOutputImpl.Count;
|
||||
FPasOutputImpl.Add('begin');
|
||||
FPasOutputImpl.Add(' vAndroidPipesComm.SendByte(ShortInt(amkUICommand));');
|
||||
FPasOutputImpl.Add(' vAndroidPipesComm.SendInt(amkUI_' + FClassName + '_' + lMethodName + ');');
|
||||
FPasOutputImpl.Add(' vAndroidPipesComm.SendInt(Index); // Self, Java Pointer');
|
||||
FPasOutputIDs.Add(' amkUI_' + FClassName + '_' + lMethodName + ' = 0' + IntToHex(FClassNum*$1000+FMethodNum, 8) + ';');
|
||||
|
||||
// Add all parameters
|
||||
TmpStr := TmpStr + lMethodName + '(';
|
||||
TmpStr := lMethodName + '(';
|
||||
|
||||
repeat
|
||||
lParamType := GetNextWord(ASourceLine, lReaderPos);
|
||||
@ -124,16 +141,33 @@ begin
|
||||
if lParamName = '' then Break;
|
||||
|
||||
TmpStr := TmpStr + lParamName + ': ' + lParamType + '; ';
|
||||
|
||||
FPasOutputImpl.Add(' vAndroidPipesComm.SendInt(Integer(' + lParamName + '));');
|
||||
until lParamName = '';
|
||||
|
||||
// Remove the last ; for the parameters, if necessary
|
||||
if TmpStr[Length(TmpStr)-1] = ';' then TmpStr := System.Copy(TmpStr, 0, Length(TmpStr)-2);
|
||||
|
||||
// Add the return
|
||||
if lMethodReturn = 'void' then TmpStr := TmpStr + ');'
|
||||
else TmpStr := TmpStr + '): ' + lMethodReturn + ';';
|
||||
if lMethodReturn = 'void' then
|
||||
begin
|
||||
TmpStr := TmpStr + ');';
|
||||
FPasOutputImpl.Add(' vAndroidPipesComm.WaitForReturn();');
|
||||
end
|
||||
else
|
||||
begin
|
||||
TmpStr := TmpStr + '): ' + lMethodReturn + ';';
|
||||
FPasOutputImpl.Add(' Result := Boolean(vAndroidPipesComm.WaitForIntReturn());');
|
||||
end;
|
||||
|
||||
FPasOutputClasses.Add(TmpStr);
|
||||
FPasOutputClasses.Add(' ' + DeclarationBase + TmpStr);
|
||||
FPasOutputImpl.Insert(FPasOutputImplCurLine, DeclarationBase + FClassName + '.' + TmpStr);
|
||||
FPasOutputImpl.Add('end;');
|
||||
FPasOutputImpl.Add('');
|
||||
|
||||
Inc(FMethodNum);
|
||||
|
||||
Exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -142,7 +176,7 @@ end;
|
||||
function TAndroidSDKBindingsGen.GetNextWord(ALine: string;
|
||||
var AStartPos: Integer): string;
|
||||
const
|
||||
WordSeparators = [' ','(',')','[',']',','];
|
||||
WordSeparators = [' ','(',')','[',']',',',#9];
|
||||
var
|
||||
lState: Integer = 0;
|
||||
begin
|
||||
@ -179,12 +213,32 @@ begin
|
||||
if ABaseName = '' then Exit('');
|
||||
|
||||
if ABaseName = 'int' then Result := 'Integer'
|
||||
else if ABaseName = 'boolean' then Result := 'Boolean'
|
||||
else if ABaseName = 'void' then Result := ABaseName
|
||||
else if ABaseName = 'CharSequence' then Result := 'string'
|
||||
else if ABaseName = 'TJavaObject' then Result := ABaseName
|
||||
else Result := 'T' + ABaseName;
|
||||
end;
|
||||
|
||||
constructor TAndroidSDKBindingsGen.Create;
|
||||
begin
|
||||
FSourceFile := TStringList.Create;
|
||||
FPasOutputClasses := TStringList.Create;
|
||||
FPasOutputImpl := TStringList.Create;
|
||||
FPasOutputIDs := TStringList.Create;
|
||||
FClassNum := $100;
|
||||
end;
|
||||
|
||||
destructor TAndroidSDKBindingsGen.Destroy;
|
||||
begin
|
||||
FSourceFile.Free;
|
||||
FPasOutputClasses.Free;
|
||||
FPasOutputImpl.Free;
|
||||
FPasOutputIDs.Free;
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TAndroidSDKBindingsGen.GenerateAllBindings(AInputDir, APasOutputDir,
|
||||
AJavaOutputDir: string);
|
||||
begin
|
||||
|
@ -1,6 +1,17 @@
|
||||
[MenuItem] TJavaObject
|
||||
classcallback MenuItem.OnMenuItemClickListener boolean onMenuItemClick (MenuItem item)
|
||||
method MenuItem setOnMenuItemClickListener (MenuItem.OnMenuItemClickListener menuItemClickListener)
|
||||
#[MenuItem] TJavaObject
|
||||
#classcallback MenuItem.OnMenuItemClickListener boolean onMenuItemClick (MenuItem item)
|
||||
#method MenuItem setOnMenuItemClickListener (MenuItem.OnMenuItemClickListener menuItemClickListener)
|
||||
#
|
||||
#[Menu] TJavaObject
|
||||
#method MenuItem add(int groupId, int itemId, int order, CharSequence title)
|
||||
|
||||
[CompoundButton] Button 110
|
||||
method boolean isChecked()
|
||||
method boolean performClick()
|
||||
method void setChecked(boolean checked)
|
||||
#method void setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener listener)
|
||||
method void toggle()
|
||||
|
||||
[CheckBox] CompoundButton 111
|
||||
constructor Create
|
||||
|
||||
[Menu] TJavaObject
|
||||
method MenuItem add(int groupId, int itemId, int order, CharSequence title)
|
||||
|
Reference in New Issue
Block a user