From cdc7a41075fd3e4b8a0f396a6d2b9be7af470368 Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Mon, 22 Aug 2011 08:49:24 +0000 Subject: [PATCH] android-sdk: Adds the possibility of having global objects git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1822 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../android_bindings_generator.lpi | 100 +++++++++--------- .../android-sdk/android_sdk_bindings_gen.pas | 65 ++++++++++-- .../android-sdk/sdk_level_7/android_all.txt | 14 ++- 3 files changed, 118 insertions(+), 61 deletions(-) diff --git a/bindings/android-sdk/android_bindings_generator.lpi b/bindings/android-sdk/android_bindings_generator.lpi index 59aae8dde..662cd7815 100644 --- a/bindings/android-sdk/android_bindings_generator.lpi +++ b/bindings/android-sdk/android_bindings_generator.lpi @@ -119,8 +119,8 @@ - - + + @@ -200,8 +200,8 @@ - - + + @@ -246,8 +246,8 @@ - - + + @@ -273,123 +273,123 @@ - + - + - + - - + + - - + + - - + + - - + + - + - - + + - + - + - + - + - + - - + + - - + + - + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + - + - + - - + + - + diff --git a/bindings/android-sdk/android_sdk_bindings_gen.pas b/bindings/android-sdk/android_sdk_bindings_gen.pas index d490ff92a..a27112b25 100644 --- a/bindings/android-sdk/android_sdk_bindings_gen.pas +++ b/bindings/android-sdk/android_sdk_bindings_gen.pas @@ -15,10 +15,13 @@ type private FSourceFile: TStringList; FPasOutputTypes, FPasOutputClassesForward, FPasOutputClasses, - FPasOutputConsts, FPasOutputIDs, FPasOutputImpl, FPasOutputMessages: TStringList; + FPasOutputConsts, FPasOutputIDs, FPasOutputImpl, FPasOutputMessages, + FPasGlobalVars, FPasInitialization: TStringList; FJavaOutputIDs, FJavaOutputMethods: TStringList; FClassName, FClassNamePas: string; // Class name of the class currently being parsed FClassNum, FMethodNum: Integer; + FIsGlobalObject: Boolean; + FGlobalObject: string; procedure GeneratePascalFile(ASourceFile: string; ADest: TStringList); procedure GenerateJavaFile(ASourceFile: string; ADest: TStringList); procedure ProcessModelFile(ASourceFile, APasOutputFile, AJavaOutputFile: string); @@ -85,6 +88,9 @@ begin ADest.Add(''); ADest.Add('function HandleMessage(AFirstInt: Integer): Boolean;'); ADest.Add(''); + ADest.Add('var'); + ADest.AddStrings(FPasGlobalVars); + ADest.Add(''); ADest.Add('implementation'); ADest.Add(''); ADest.Add('const'); @@ -108,6 +114,10 @@ begin ADest.Add(' end;'); ADest.Add('end;'); ADest.Add(''); + ADest.Add('initialization'); + ADest.Add(''); + ADest.AddStrings(FPasInitialization); + ADest.Add(''); ADest.Add('end.'); end; @@ -172,7 +182,7 @@ begin ADest.Add(' AbsSpinner param_self_AbsSpinner;'); ADest.Add(' ArrayAdapter param_self_ArrayAdapter_String_;'); ADest.Add(' // Params'); - ADest.Add(' ViewGroup.LayoutParams lViewGroup_LayoutParams_1, lViewGroup_LayoutParams_2;'); + ADest.Add(' ViewGroup.LayoutParams lViewGroup_LayoutParams_1, lViewGroup_LayoutParams_2, lViewGroup_LayoutParams_3;'); ADest.Add(' SpinnerAdapter lSpinnerAdapter_1;'); ADest.Add(' DisplayMetrics lDisplayMetrics_1;'); ADest.Add(' CharSequence lCharSequence_1;'); @@ -250,6 +260,15 @@ begin // Starting a new class if ASourceLine[1] = '[' then begin + FIsGlobalObject := False; + ProcessModelClass(ASourceLine, False); + Exit; + end; + + // Starting a new global object class + if ASourceLine[1] = '%' then + begin + FIsGlobalObject := True; ProcessModelClass(ASourceLine, False); Exit; end; @@ -257,6 +276,7 @@ begin // Starting a new interface if ASourceLine[1] = '{' then begin + FIsGlobalObject := False; ProcessModelClass(ASourceLine, True); Exit; end; @@ -313,6 +333,15 @@ begin FClassNamePas := GetPascalTypeName(lCurWord); FClassName := lCurWord; + + // Read the global object, if it is one + if FIsGlobalObject then + begin + FGlobalObject := GetNextWord(ASourceLine, lReaderPos); + FPasGlobalVars.Add(Format(' %s: %s;', [FGlobalObject, FClassNamePas])); + FPasInitialization.Add(Format(' %s := %s.Create;', [FGlobalObject, FClassNamePas])); + end; + lTmpParent := GetNextWord(ASourceLine, lReaderPos); lParentClassName := GetPascalTypeName(lTmpParent); @@ -365,6 +394,8 @@ var HasStringParam: Boolean = False; StringParamCount: Integer = 0; i: Integer; + // + lPascalMethodModifiers: string = ''; begin if ASourceLine = '' then Exit; @@ -385,15 +416,21 @@ begin FPasOutputImpl.Add('begin'); FPasOutputImpl.Add(' vAndroidPipesComm.SendByte(ShortInt(amkUICommand));'); FPasOutputImpl.Add(' vAndroidPipesComm.SendInt(' + lIDString + ');'); - FPasOutputImpl.Add(' vAndroidPipesComm.SendInt(Index); // Self, Java Pointer'); + if not FIsGlobalObject then + FPasOutputImpl.Add(' vAndroidPipesComm.SendInt(Index); // Self, Java Pointer'); lJavaParamSelf := 'param_self_' + JavaRemoveGeneric(FClassName); FJavaOutputMethods.Add(' // ' + ASourceLine); FJavaOutputMethods.Add(' case ' + lIDString + ':'); FJavaOutputMethods.Add(' DebugOut("' + lIDString + '");'); - FJavaOutputMethods.Add(' // Self'); - FJavaOutputMethods.Add(' lInt = MyAndroidPipesComm.GetInt();'); - FJavaOutputMethods.Add(' ' + lJavaParamSelf + ' = (' + FClassName + ') ViewElements.get(lInt);'); + if not FIsGlobalObject then + begin + FJavaOutputMethods.Add(' // Self'); + FJavaOutputMethods.Add(' lInt = MyAndroidPipesComm.GetInt();'); + FJavaOutputMethods.Add(' ' + lJavaParamSelf + ' = (' + FClassName + ') ViewElements.get(lInt);'); + end + else + lJavaParamSelf := FGlobalObject; FJavaOutputMethods.Add(' // params'); // Lists of constants for the IDs @@ -407,6 +444,11 @@ begin // Method modifiers if (lParamType = 'virtual') or (lParamType = 'override') then Continue; + if (lParamType = 'overload') then + begin + lPascalMethodModifiers := ' overload;'; + Continue; + end; lParamTypePas := GetPascalTypeName(lParamType); lParamName := GetNextWord(ASourceLine, lReaderPos); @@ -465,7 +507,7 @@ begin end; // Insert the start - FPasOutputClasses.Add(' ' + DeclarationBase + TmpStr); + FPasOutputClasses.Add(' ' + DeclarationBase + TmpStr + lPascalMethodModifiers); FPasOutputImpl.Insert(FPasOutputImplCurLine, DeclarationBase + FClassNamePas + '.' + TmpStr); if HasStringParam then begin @@ -751,7 +793,7 @@ end; function TAndroidSDKBindingsGen.GetNextWord(ALine: string; var AStartPos: Integer): string; const - WordSeparators = [' ','(',')','[',']','{','}',',',';',':',#9{TAB}]; + WordSeparators = [' ','(',')','[',']','{','}','%',',',';',':',#9{TAB}]; var lState: Integer = 0; begin @@ -844,9 +886,10 @@ begin else Result := Format('(%s) ViewElements.get(lInt)', [AType]); end; +// We add the method num too for overloaded routines function TAndroidSDKBindingsGen.GetIDString(AMethodName: string): string; begin - Result := 'amkUI_' + FClassNamePas + '_' + AMethodName;; + Result := Format('amkUI_%s_%s_%d', [FClassNamePas, AMethodName, FMethodNum]); Result := ConvertJavaSpecialCharsToUnderline(Result); end; @@ -890,6 +933,8 @@ begin FPasOutputIDs := TStringList.Create; FPasOutputConsts := TStringList.Create; FPasOutputMessages := TStringList.Create; + FPasGlobalVars := TStringList.Create; + FPasInitialization := TStringList.Create; FJavaOutputIDs := TStringList.Create; FJavaOutputMethods := TStringList.Create; @@ -908,6 +953,8 @@ begin FPasOutputIDs.Free; FPasOutputConsts.Free; FPasOutputMessages.Free; + FPasGlobalVars.Free; + FPasInitialization.Free; FJavaOutputIDs.Free; FJavaOutputMethods.Free; diff --git a/bindings/android-sdk/sdk_level_7/android_all.txt b/bindings/android-sdk/sdk_level_7/android_all.txt index f1a27229b..7c46127a5 100644 --- a/bindings/android-sdk/sdk_level_7/android_all.txt +++ b/bindings/android-sdk/sdk_level_7/android_all.txt @@ -3,6 +3,9 @@ # [ClassName] Parent Interface1 Interface2 # declarations of fields, contructors, methods, consts, etc # +# For Classes which are only used through a global object: +# %ClassName%ObjectName% Parent Interface1 Interface2 +# # For Interfaces: # {InterfaceName} Parent1 Parent2 Parent3 # @@ -30,6 +33,10 @@ field float ydpi # # android.app.* # +%Activity%activity% TJavaObject +method void setTitle(CharSequence title) +method CharSequence getTitle() + [Display] TJavaObject method void getMetrics(DisplayMetrics outMetrics) @@ -53,8 +60,11 @@ const INVISIBLE = 4; const GONE = 8; [ViewGroup] View -method void addView(View child, ViewGroup.LayoutParams params); -# method void addView(View child); +method void addView(View child, int aindex, ViewGroup.LayoutParams params); overload; +method void addView(View child, ViewGroup.LayoutParams params); overload; +method void addView(View child, int aindex); overload; +method void addView(View child); overload; +method void addView(View child, int width, int height); overload; [LinearLayout] ViewGroup constructor Create(Activity);