From 2338d7ce64f88f4f5d0b8a22170813102ce48481 Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Fri, 19 Aug 2011 15:26:10 +0000 Subject: [PATCH] androidlcl: Advances to implementing reading text values git-svn-id: trunk@32012 - --- lcl/interfaces/android/android_all.pas | 11 +++++++- lcl/interfaces/android/androidpipescomm.pas | 31 +++++++++++++++++++-- lcl/interfaces/android/androidprivate.pas | 12 ++++++++ lcl/interfaces/android/androidwsfactory.pas | 6 ++-- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/lcl/interfaces/android/android_all.pas b/lcl/interfaces/android/android_all.pas index 063a89b221..cb9ffd640b 100644 --- a/lcl/interfaces/android/android_all.pas +++ b/lcl/interfaces/android/android_all.pas @@ -108,6 +108,7 @@ type procedure callOnClickListener(); public procedure setTextSize(unit_: Integer; size: Single); + function getText(): string; end; TEditText = class(TTextView) @@ -302,6 +303,7 @@ const amkUI_TTextView_OnClickListener_Start = $0010A003; amkUI_TTextView_OnClickListener_Finished = $0010A004; amkUI_TTextView_setTextSize = $0010A005; + amkUI_TTextView_getText = $0010A006; // TEditText amkUI_TEditText_Create = $0010B000; amkUI_TEditText_setText = $0010B001; @@ -536,6 +538,14 @@ begin vAndroidPipesComm.WaitForReturn(); end; +function TTextView.getText(): string; +begin + vAndroidPipesComm.SendByte(ShortInt(amkUICommand)); + vAndroidPipesComm.SendInt(amkUI_TTextView_getText); + vAndroidPipesComm.SendInt(Index); // Self, Java Pointer + Result := vAndroidPipesComm.WaitForStringReturn(); +end; + constructor TEditText.Create(); begin vAndroidPipesComm.SendByte(ShortInt(amkUICommand)); @@ -721,7 +731,6 @@ end; procedure TArrayAdapter_String_.clear(); begin - vAndroidPipesComm.Log(Format('[TArrayAdapter_String_.Clear] Self=%P Index=%X', [@Self, Index])); vAndroidPipesComm.SendByte(ShortInt(amkUICommand)); vAndroidPipesComm.SendInt(amkUI_TArrayAdapter_String__clear); vAndroidPipesComm.SendInt(Index); // Self, Java Pointer diff --git a/lcl/interfaces/android/androidpipescomm.pas b/lcl/interfaces/android/androidpipescomm.pas index aa59c1544e..a87d5241ca 100644 --- a/lcl/interfaces/android/androidpipescomm.pas +++ b/lcl/interfaces/android/androidpipescomm.pas @@ -18,9 +18,10 @@ uses const // Android Message Kind - amkFloatResult = 103; - amkIntResult = 102; - amkResult = 101; + amkStringResult = 14; + amkFloatResult = 13; + amkIntResult = 12; + amkResult = 11; amkActivityCallback = 0; amkLog = 1; amkUICommand = 2; @@ -62,6 +63,7 @@ type function ReadByte: ShortInt; function ReadInt: Integer; function ReadFloat: Single; + function ReadString: string; procedure SendMessage(AKind: ShortInt; ASubtype: DWord); procedure SendByte(AData: ShortInt); procedure SendInt(AData: Integer); @@ -70,6 +72,7 @@ type procedure WaitForReturn(); function WaitForIntReturn(): Integer; function WaitForFloatReturn(): Single; + function WaitForStringReturn(): string; procedure CommError(AStr: string); procedure Log(AStr: string); end; @@ -187,6 +190,18 @@ begin Move(lNum, Result, 4); end; +function TAndroidPipesComm.ReadString: string; +var + lSize, i: Integer; +begin + Result := ''; + lSize := ReadInt(); + for i := 1 to lSize do + begin + Result := Result + Char(ReadByte()); + end; +end; + procedure TAndroidPipesComm.SendMessage(AKind: ShortInt; ASubtype: DWord); begin OutputStream.WriteByte(AKind); @@ -256,6 +271,16 @@ begin Result := ReadFloat(); end; +function TAndroidPipesComm.WaitForStringReturn: string; +var + lByte: ShortInt; +begin + {$ifdef ANDROID_NO_COMM}Exit(0.0);{$ENDIF} + lByte := ReadByte(); + if lByte <> amkStringResult then CommError('[TAndroidPipesComm.WaitForStringReturn] expected amkStringResult but got: ' + IntToStr(lByte)); + Result := ReadString(); +end; + procedure TAndroidPipesComm.CommError(AStr: string); begin dataString1 := AStr; diff --git a/lcl/interfaces/android/androidprivate.pas b/lcl/interfaces/android/androidprivate.pas index a82c74c489..7f59a64c92 100644 --- a/lcl/interfaces/android/androidprivate.pas +++ b/lcl/interfaces/android/androidprivate.pas @@ -60,6 +60,8 @@ type params: TAbsoluteLayout_LayoutParams; constructor Create(const AObject: TCustomEdit; const AParams: TCreateParams); destructor Destroy; override; + function GetText: string; + procedure SetText(AText: string); end; { TAndroidButton } @@ -405,6 +407,16 @@ begin inherited Destroy; end; +function TAndroidEdit.GetText: string; +begin + Result := edittext.GetText(); +end; + +procedure TAndroidEdit.SetText(AText: string); +begin + edittext.SetText(AText); +end; + { TAndroidButton } constructor TAndroidButton.Create(const AObject: TCustomButton; diff --git a/lcl/interfaces/android/androidwsfactory.pas b/lcl/interfaces/android/androidwsfactory.pas index 6e8b0ead6b..576b0e85de 100644 --- a/lcl/interfaces/android/androidwsfactory.pas +++ b/lcl/interfaces/android/androidwsfactory.pas @@ -329,10 +329,8 @@ end; function RegisterCustomMemo: Boolean; alias : 'WSRegisterCustomMemo'; begin - Result := False; -// RegisterWSComponent(TCustomMemo, TGtk2WSCustomMemo, TGtkPrivateScrolling); { GTK1 } -// RegisterWSComponent(TCustomMemo, TGtk2WSCustomMemo); -// Result := True; + RegisterWSComponent(TCustomMemo, TAndroidWSCustomMemo); + Result := True; end; function RegisterButtonControl: Boolean; alias : 'WSRegisterButtonControl';