androidlcl: Advances to implementing reading text values

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1818 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat 2011-08-19 15:25:57 +00:00
parent 692a0346c5
commit b194db05d2
5 changed files with 133 additions and 13 deletions

View File

@ -67,6 +67,7 @@ public class AndroidAll
static final int amkUI_TTextView_OnClickListener_Start = 0x0010A003;
static final int amkUI_TTextView_OnClickListener_Finished = 0x0010A004;
static final int amkUI_TTextView_setTextSize = 0x0010A005;
static final int amkUI_TTextView_getText = 0x0010A006;
// EditText
static final int amkUI_TEditText_Create = 0x0010B000;
static final int amkUI_TEditText_setText = 0x0010B001;
@ -145,6 +146,7 @@ public class AndroidAll
float lResult_float;
int lResult_int;
boolean lResult_boolean;
CharSequence lResult_CharSequence;
Display lResult_Display;
switch (Buffer)
@ -396,6 +398,17 @@ public class AndroidAll
param_self_TextView.setTextSize(lint_1, lfloat_2);
MyAndroidPipesComm.SendResult();
break;
// method CharSequence getText()
case amkUI_TTextView_getText:
DebugOut("amkUI_TTextView_getText");
// Self
lInt = MyAndroidPipesComm.GetInt();
param_self_TextView = (TextView) ViewElements.get(lInt);
// params
//
lResult_CharSequence = param_self_TextView.getText();
MyAndroidPipesComm.SendStringResult(lResult_CharSequence);
break;
case amkUI_TEditText_Create:
DebugOut("amkUI_TEditText_Create");
ViewElements.add(new EditText(activity));
@ -598,7 +611,6 @@ public class AndroidAll
DebugOut("amkUI_TArrayAdapter_String__Create");
lint_1 = MyAndroidPipesComm.GetInt();
ViewElements.add(new ArrayAdapter<String>(activity, lint_1));
DebugOut("Result = " + (ViewElements.size() - 1));
MyAndroidPipesComm.SendIntResult(ViewElements.size() - 1);
break;
// method void add(String aobject)
@ -619,7 +631,6 @@ public class AndroidAll
DebugOut("amkUI_TArrayAdapter_String__clear");
// Self
lInt = MyAndroidPipesComm.GetInt();
DebugOut("lInt = " + lInt);
param_self_ArrayAdapter_String_ = (ArrayAdapter<String>) ViewElements.get(lInt);
// params
//
@ -631,7 +642,6 @@ public class AndroidAll
DebugOut("amkUI_TArrayAdapter_String__insert");
// Self
lInt = MyAndroidPipesComm.GetInt();
DebugOut("lInt = " + lInt);
param_self_ArrayAdapter_String_ = (ArrayAdapter<String>) ViewElements.get(lInt);
// params
lInt = MyAndroidPipesComm.GetInt();

View File

@ -23,9 +23,10 @@ public class AndroidPipesComm
int lSubtype = 0;
// Android Message Kind
static byte amkFloatResult = 103;
static byte amkIntResult = 102;
static byte amkResult = 101;
static byte amkStringResult = 14;
static byte amkFloatResult = 13;
static byte amkIntResult = 12;
static byte amkResult = 11;
static byte amkActivityCallback = 0;
static byte amkLog = 1;
static byte amkUICommand = 2;
@ -110,12 +111,7 @@ public class AndroidPipesComm
else if (Buffer == amkLog)
{
DebugOut("amkLog");
int lInt = GetInt(); // Length
char[] lChars = new char[lInt];
for (int i = 0; i < lInt; i++)
{
lChars[i] = (char) GetByte();
}
char[] lChars = GetString();
DebugOut(new String(lChars));
}
else if (Buffer == amkUICommand)
@ -217,6 +213,26 @@ public class AndroidPipesComm
return -1;
}
public char[] GetString()
{
char[] lChars;
try
{
int lInt = reader.readInt(); // Length
lChars = new char[lInt];
for (int i = 0; i < lInt; i++)
{
lChars[i] = (char) reader.readByte();
}
return lChars;
}
catch (IOException e)
{
ErrorOut("[GetString] IOException=" + e.getMessage());
}
return new char[0];
}
// Sending results
public void SendResult()
@ -258,6 +274,24 @@ public class AndroidPipesComm
}
}
public void SendStringResult(CharSequence Result)
{
try
{
writer.writeByte(amkStringResult);
int lInt = Result.length();
writer.writeInt(lInt); // Length
for (int i = 0; i < lInt; i++)
{
writer.writeByte(Result.charAt(i));
}
}
catch (IOException e)
{
ErrorOut("[SendStringResult] IOException=" + e.getMessage());
}
}
// Sending data
// Convenience routine, uses SendIntResult

View File

@ -17,7 +17,7 @@
<MacroValues Count="1">
<Macro1 Name="LCLWidgetType" Value="android"/>
</MacroValues>
<BuildModes Count="3">
<BuildModes Count="4">
<Item1 Name="Android" Default="True"/>
<Item2 Name="Desktop">
<MacroValues Count="1">
@ -75,6 +75,42 @@
</Other>
</CompilerOptions>
</Item3>
<Item4 Name="Android-Debug">
<MacroValues Count="1">
<Macro1 Name="LCLWidgetType" Value="android"/>
</MacroValues>
<CompilerOptions>
<Version Value="10"/>
<Target>
<Filename Value="android/libs/armeabi/libandroidlcltest.so"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<CodeGeneration>
<TargetCPU Value="arm"/>
<TargetOS Value="linux"/>
</CodeGeneration>
<Linking>
<Debugging>
<GenerateDebugInfo Value="True"/>
<GenerateDwarf Value="True"/>
</Debugging>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
<Other>
<CompilerMessages>
<UseMsgFile Value="True"/>
</CompilerMessages>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
</Item4>
</BuildModes>
<PublishOptions>
<Version Value="2"/>

View File

@ -13,6 +13,7 @@ object Form2: TForm2
Top = 35
Width = 87
Caption = 'Button1'
OnClick = Button1Click
TabOrder = 0
end
object CheckBox1: TCheckBox
@ -53,4 +54,12 @@ object Form2: TForm2
TabOrder = 4
Text = 'ComboBox1'
end
object Edit2: TEdit
Left = 147
Height = 25
Top = 144
Width = 80
TabOrder = 5
Text = 'Edit2'
end
end

View File

@ -17,7 +17,9 @@ type
CheckBox1: TCheckBox;
ComboBox1: TComboBox;
Edit1: TEdit;
Edit2: TEdit;
StaticText1: TStaticText;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
@ -29,6 +31,35 @@ var
implementation
{$ifdef LCLAndroid}
uses androidpipescomm;
{$endif}
{ TForm2 }
procedure TForm2.Button1Click(Sender: TObject);
var
lChecked, lEdit1Text: String;
lComboBox: String;
begin
if CheckBox1.Checked then lChecked := 'True'
else lChecked := 'False';
vAndroidPipesComm.Log('3');
lEdit1Text := Edit1.Text;
vAndroidPipesComm.Log('4');
lComboBox := IntToStr(ComboBox1.ItemIndex);
vAndroidPipesComm.Log('5');
Edit2.Text :=
'Edit1.Text='+lEdit1Text+LineEnding+
'Caption='+Caption+LineEnding+
'Checked?='+lChecked+LineEnding+
'ComboBox='+lComboBox;
end;
initialization
{$I mainform.lrs}