mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-23 04:59:22 +02:00
Android: Minimal implementation of statictext, checkbox, edit and combobox
git-svn-id: trunk@31927 -
This commit is contained in:
parent
dbdec77d4b
commit
c733c92d39
@ -25,6 +25,9 @@ type
|
||||
TScrollView = class;
|
||||
TCompoundButton = class;
|
||||
TCheckBox = class;
|
||||
TAdapterView = class;
|
||||
TAbsSpinner = class;
|
||||
TSpinner = class;
|
||||
|
||||
{ Types }
|
||||
|
||||
@ -143,6 +146,19 @@ type
|
||||
constructor Create();
|
||||
end;
|
||||
|
||||
TAdapterView = class(TViewGroup)
|
||||
public
|
||||
end;
|
||||
|
||||
TAbsSpinner = class(TAdapterView)
|
||||
public
|
||||
end;
|
||||
|
||||
TSpinner = class(TAbsSpinner)
|
||||
public
|
||||
constructor Create();
|
||||
end;
|
||||
|
||||
function HandleMessage(AFirstInt: Integer): Boolean;
|
||||
|
||||
implementation
|
||||
@ -173,6 +189,9 @@ const
|
||||
{ TScrollView }
|
||||
{ TCompoundButton }
|
||||
{ TCheckBox }
|
||||
{ TAdapterView }
|
||||
{ TAbsSpinner }
|
||||
{ TSpinner }
|
||||
|
||||
{ IDs }
|
||||
|
||||
@ -234,6 +253,10 @@ const
|
||||
amkUI_TCompoundButton_toggle = $00110003;
|
||||
// TCheckBox
|
||||
amkUI_TCheckBox_Create = $00111000;
|
||||
// TAdapterView
|
||||
// TAbsSpinner
|
||||
// TSpinner
|
||||
amkUI_TSpinner_Create = $00114000;
|
||||
|
||||
{ Implementation of Classes }
|
||||
|
||||
@ -566,6 +589,12 @@ begin
|
||||
vAndroidPipesComm.SendInt(amkUI_TCheckBox_Create);
|
||||
Index := vAndroidPipesComm.WaitForIntReturn();
|
||||
end;
|
||||
constructor TSpinner.Create();
|
||||
begin
|
||||
vAndroidPipesComm.SendByte(ShortInt(amkUICommand));
|
||||
vAndroidPipesComm.SendInt(amkUI_TSpinner_Create);
|
||||
Index := vAndroidPipesComm.WaitForIntReturn();
|
||||
end;
|
||||
|
||||
{ Message Handling }
|
||||
|
||||
|
@ -8,6 +8,9 @@ unit androidpipescomm;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
// ANDROID_NO_COMM is utilized to test the code flow in the desktop
|
||||
{$ifndef ARM}{$define ANDROID_NO_COMM}{$endif}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
@ -170,11 +173,13 @@ end;
|
||||
|
||||
function TAndroidPipesComm.ReadByte: ShortInt;
|
||||
begin
|
||||
{$ifdef ANDROID_NO_COMM}Exit(0);{$ENDIF}
|
||||
Result := InputStream.ReadByte();
|
||||
end;
|
||||
|
||||
function TAndroidPipesComm.ReadInt: Integer;
|
||||
begin
|
||||
{$ifdef ANDROID_NO_COMM}Exit(0);{$ENDIF}
|
||||
Result := BEToN(InputStream.ReadDWord());
|
||||
end;
|
||||
|
||||
@ -182,6 +187,7 @@ function TAndroidPipesComm.ReadFloat: Single;
|
||||
var
|
||||
lNum: DWord;
|
||||
begin
|
||||
{$ifdef ANDROID_NO_COMM}Exit(0.0);{$ENDIF}
|
||||
lNum := BEToN(InputStream.ReadDWord());
|
||||
Move(lNum, Result, 4);
|
||||
end;
|
||||
@ -230,6 +236,7 @@ procedure TAndroidPipesComm.WaitForReturn();
|
||||
var
|
||||
lByte: ShortInt;
|
||||
begin
|
||||
{$ifdef ANDROID_NO_COMM}Exit;{$ENDIF}
|
||||
lByte := ReadByte();
|
||||
if lByte <> amkResult then CommError('[TAndroidPipesComm.WaitForIntReturn] expected amkResult but got: ' + IntToStr(lByte));
|
||||
end;
|
||||
@ -238,6 +245,7 @@ function TAndroidPipesComm.WaitForIntReturn(): Integer;
|
||||
var
|
||||
lByte: ShortInt;
|
||||
begin
|
||||
{$ifdef ANDROID_NO_COMM}Exit(0);{$ENDIF}
|
||||
lByte := ReadByte();
|
||||
if lByte <> amkIntResult then CommError('[TAndroidPipesComm.WaitForIntReturn] expected amkIntResult but got: ' + IntToStr(lByte));
|
||||
Result := ReadInt();
|
||||
@ -247,6 +255,7 @@ function TAndroidPipesComm.WaitForFloatReturn(): Single;
|
||||
var
|
||||
lByte: ShortInt;
|
||||
begin
|
||||
{$ifdef ANDROID_NO_COMM}Exit(0.0);{$ENDIF}
|
||||
lByte := ReadByte();
|
||||
if lByte <> amkFloatResult then CommError('[TAndroidPipesComm.WaitForFloatReturn] expected amkFloatResult but got: ' + IntToStr(lByte));
|
||||
Result := ReadFloat();
|
||||
|
@ -35,6 +35,7 @@ uses
|
||||
AVL_Tree, LMessages, LCLMessageGlue, stdctrls, Forms;
|
||||
|
||||
type
|
||||
TAndroidComboBoxStrings = class;
|
||||
|
||||
TAndroidView = class
|
||||
public
|
||||
@ -48,6 +49,16 @@ type
|
||||
mainviewgroup: TViewGroup;
|
||||
end;
|
||||
|
||||
{ TAndroidEdit }
|
||||
|
||||
TAndroidEdit = class(TAndroidView)
|
||||
public
|
||||
edittext: android_all.TEditText;
|
||||
params: TAbsoluteLayout_LayoutParams;
|
||||
constructor Create(const AObject: TCustomEdit; const AParams: TCreateParams);
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
{ TAndroidButton }
|
||||
|
||||
TAndroidButton = class(TAndroidView)
|
||||
@ -58,6 +69,39 @@ type
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
{ TAndroidCheckBox }
|
||||
|
||||
TAndroidCheckBox = class(TAndroidView)
|
||||
public
|
||||
checkbox: android_all.TCheckBox;
|
||||
params: TAbsoluteLayout_LayoutParams;
|
||||
constructor Create(const AObject: TCustomCheckBox; const AParams: TCreateParams);
|
||||
destructor Destroy; override;
|
||||
function GetState: TCheckBoxState;
|
||||
procedure SetState(const AState: TCheckBoxState);
|
||||
end;
|
||||
|
||||
{ TAndroidStaticText }
|
||||
|
||||
TAndroidStaticText = class(TAndroidView)
|
||||
public
|
||||
textview: android_all.TTextView;
|
||||
params: TAbsoluteLayout_LayoutParams;
|
||||
constructor Create(const AObject: TCustomStaticText; const AParams: TCreateParams);
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
{ TAndroidComboBox }
|
||||
|
||||
TAndroidComboBox = class(TAndroidView)
|
||||
public
|
||||
spinner: android_all.TSpinner;
|
||||
params: TAbsoluteLayout_LayoutParams;
|
||||
FList: TAndroidComboBoxStrings;
|
||||
constructor Create(const AObject: TCustomComboBox; const AParams: TCreateParams);
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
{ TAndroidWindow }
|
||||
|
||||
TAndroidWindow = class(TAndroidViewGroup)
|
||||
@ -68,12 +112,190 @@ type
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
// Now StringLists
|
||||
|
||||
{ TAndroidComboBoxStrings }
|
||||
|
||||
TAndroidComboBoxStrings = class(TStringList)
|
||||
private
|
||||
FWinControl: TWinControl;
|
||||
FOwner: TAndroidComboBox;
|
||||
protected
|
||||
procedure Put(Index: Integer; const S: string); override;
|
||||
procedure InsertItem(Index: Integer; const S: string); override;
|
||||
procedure InsertItem(Index: Integer; const S: string; O: TObject); override;
|
||||
public
|
||||
constructor Create(AWinControl: TWinControl; AOwner: TAndroidComboBox);
|
||||
procedure Assign(Source: TPersistent); override;
|
||||
procedure Clear; override;
|
||||
procedure Delete(Index: Integer); override;
|
||||
procedure Sort; override;
|
||||
procedure Exchange(AIndex1, AIndex2: Integer); override;
|
||||
public
|
||||
property Owner: TAndroidComboBox read FOwner;
|
||||
end;
|
||||
|
||||
//function CheckHandle(const AWinControl: TWinControl; const AClass: TClass; const DbgText: String): Boolean;
|
||||
//function CheckWidget(const Handle: HWND; const AMethodName: String; AParamName: String = ''): Boolean;
|
||||
//function CheckWidget(const Handle: HWND; const AMethodName: String; AClass: TClass): Boolean;
|
||||
|
||||
implementation
|
||||
|
||||
{ TAndroidComboBoxStrings }
|
||||
|
||||
procedure TAndroidComboBoxStrings.Put(Index: Integer; const S: string);
|
||||
begin
|
||||
inherited Put(Index, S);
|
||||
end;
|
||||
|
||||
procedure TAndroidComboBoxStrings.InsertItem(Index: Integer; const S: string);
|
||||
begin
|
||||
inherited InsertItem(Index, S);
|
||||
end;
|
||||
|
||||
procedure TAndroidComboBoxStrings.InsertItem(Index: Integer; const S: string;
|
||||
O: TObject);
|
||||
begin
|
||||
inherited InsertItem(Index, S, O);
|
||||
end;
|
||||
|
||||
constructor TAndroidComboBoxStrings.Create(AWinControl: TWinControl;
|
||||
AOwner: TAndroidComboBox);
|
||||
begin
|
||||
inherited Create;
|
||||
FWinControl := AWinControl;
|
||||
FOwner := AOwner;
|
||||
end;
|
||||
|
||||
procedure TAndroidComboBoxStrings.Assign(Source: TPersistent);
|
||||
begin
|
||||
inherited Assign(Source);
|
||||
end;
|
||||
|
||||
procedure TAndroidComboBoxStrings.Clear;
|
||||
begin
|
||||
inherited Clear;
|
||||
end;
|
||||
|
||||
procedure TAndroidComboBoxStrings.Delete(Index: Integer);
|
||||
begin
|
||||
inherited Delete(Index);
|
||||
end;
|
||||
|
||||
procedure TAndroidComboBoxStrings.Sort;
|
||||
begin
|
||||
inherited Sort;
|
||||
end;
|
||||
|
||||
procedure TAndroidComboBoxStrings.Exchange(AIndex1, AIndex2: Integer);
|
||||
begin
|
||||
inherited Exchange(AIndex1, AIndex2);
|
||||
end;
|
||||
|
||||
{ TAndroidComboBox }
|
||||
|
||||
constructor TAndroidComboBox.Create(const AObject: TCustomComboBox;
|
||||
const AParams: TCreateParams);
|
||||
var
|
||||
Str: string;
|
||||
begin
|
||||
LCLObject := AObject;
|
||||
ParentGroupView := TAndroidViewGroup(AObject.Parent.Handle).mainviewgroup;
|
||||
|
||||
spinner := android_all.TSpinner.Create;
|
||||
MainView := spinner;
|
||||
params := TAbsoluteLayout_LayoutParams.Create(AObject.Width, AObject.Height, AObject.Left, AObject.Top);
|
||||
ParentGroupView.addView(MainView, TViewGroup_LayoutParams(params));
|
||||
params.Free;
|
||||
end;
|
||||
|
||||
destructor TAndroidComboBox.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
{ TAndroidStaticText }
|
||||
|
||||
constructor TAndroidStaticText.Create(const AObject: TCustomStaticText;
|
||||
const AParams: TCreateParams);
|
||||
var
|
||||
Str: string;
|
||||
begin
|
||||
LCLObject := AObject;
|
||||
ParentGroupView := TAndroidViewGroup(AObject.Parent.Handle).mainviewgroup;
|
||||
|
||||
textview := android_all.TTextView.Create;
|
||||
MainView := textview;
|
||||
Str := AObject.Caption;
|
||||
textview.setText(Str);
|
||||
params := TAbsoluteLayout_LayoutParams.Create(AObject.Width, AObject.Height, AObject.Left, AObject.Top);
|
||||
ParentGroupView.addView(MainView, TViewGroup_LayoutParams(params));
|
||||
params.Free;
|
||||
end;
|
||||
|
||||
destructor TAndroidStaticText.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
{ TAndroidCheckBox }
|
||||
|
||||
constructor TAndroidCheckBox.Create(const AObject: TCustomCheckBox;
|
||||
const AParams: TCreateParams);
|
||||
var
|
||||
Str: string;
|
||||
begin
|
||||
LCLObject := AObject;
|
||||
ParentGroupView := TAndroidViewGroup(AObject.Parent.Handle).mainviewgroup;
|
||||
|
||||
checkbox := android_all.TCheckBox.Create;
|
||||
MainView := checkbox;
|
||||
Str := AObject.Caption;
|
||||
checkbox.setText(Str);
|
||||
params := TAbsoluteLayout_LayoutParams.Create(AObject.Width, AObject.Height, AObject.Left, AObject.Top);
|
||||
ParentGroupView.addView(MainView, TViewGroup_LayoutParams(params));
|
||||
params.Free;
|
||||
end;
|
||||
|
||||
destructor TAndroidCheckBox.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TAndroidCheckBox.GetState: TCheckBoxState;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
procedure TAndroidCheckBox.SetState(const AState: TCheckBoxState);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
{ TAndroidEdit }
|
||||
|
||||
constructor TAndroidEdit.Create(const AObject: TCustomEdit;
|
||||
const AParams: TCreateParams);
|
||||
var
|
||||
Str: string;
|
||||
begin
|
||||
LCLObject := AObject;
|
||||
ParentGroupView := TAndroidViewGroup(AObject.Parent.Handle).mainviewgroup;
|
||||
|
||||
edittext := android_all.TEditText.Create;
|
||||
MainView := edittext;
|
||||
Str := AObject.Caption;
|
||||
edittext.setText(Str);
|
||||
params := TAbsoluteLayout_LayoutParams.Create(AObject.Width, AObject.Height, AObject.Left, AObject.Top);
|
||||
ParentGroupView.addView(MainView, TViewGroup_LayoutParams(params));
|
||||
params.Free;
|
||||
end;
|
||||
|
||||
destructor TAndroidEdit.Destroy;
|
||||
begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
{ TAndroidButton }
|
||||
|
||||
constructor TAndroidButton.Create(const AObject: TCustomButton;
|
||||
@ -85,14 +307,13 @@ begin
|
||||
ParentGroupView := TAndroidViewGroup(AObject.Parent.Handle).mainviewgroup;
|
||||
|
||||
btn := android_all.TButton.Create;
|
||||
MainView := btn;
|
||||
Str := AObject.Caption;
|
||||
btn.setText(Str);
|
||||
{ btn.setOnClickListener(buttonClickCallback);}
|
||||
// btn.setOnClickListener(buttonClickCallback);
|
||||
params := TAbsoluteLayout_LayoutParams.Create(AObject.Width, AObject.Height, AObject.Left, AObject.Top);
|
||||
ParentGroupView.addView(TView(btn), TViewGroup_LayoutParams(params));
|
||||
ParentGroupView.addView(MainView, TViewGroup_LayoutParams(params));
|
||||
params.Free;
|
||||
|
||||
MainView := btn;
|
||||
end;
|
||||
|
||||
destructor TAndroidButton.Destroy;
|
||||
|
@ -309,9 +309,8 @@ end;
|
||||
|
||||
function RegisterCustomComboBox: Boolean; alias : 'WSRegisterCustomComboBox';
|
||||
begin
|
||||
Result := False;
|
||||
// RegisterWSComponent(TCustomComboBox, TGtk2WSCustomComboBox);
|
||||
// Result := True;
|
||||
RegisterWSComponent(TCustomComboBox, TAndroidWSCustomComboBox);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function RegisterCustomListBox: Boolean; alias : 'WSRegisterCustomListBox';
|
||||
@ -324,10 +323,8 @@ end;
|
||||
|
||||
function RegisterCustomEdit: Boolean; alias : 'WSRegisterCustomEdit';
|
||||
begin
|
||||
Result := False;
|
||||
// RegisterWSComponent(TCustomEdit, TGtk2WSCustomEdit, TGtkPrivateEntry); { GTK1 }
|
||||
// RegisterWSComponent(TCustomEdit, TGtk2WSCustomEdit);
|
||||
// Result := True;
|
||||
RegisterWSComponent(TCustomEdit, TAndroidWSCustomEdit);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function RegisterCustomMemo: Boolean; alias : 'WSRegisterCustomMemo';
|
||||
@ -352,9 +349,8 @@ end;
|
||||
|
||||
function RegisterCustomCheckBox: Boolean; alias : 'WSRegisterCustomCheckBox';
|
||||
begin
|
||||
Result := False;
|
||||
// RegisterWSComponent(TCustomCheckBox, TGtk2WSCustomCheckBox);
|
||||
// Result := True;
|
||||
RegisterWSComponent(TCustomCheckBox, TAndroidWSCustomCheckBox);
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function RegisterToggleBox: Boolean; alias : 'WSRegisterToggleBox';
|
||||
@ -373,9 +369,8 @@ end;
|
||||
|
||||
function RegisterCustomStaticText: Boolean; alias : 'WSRegisterCustomStaticText';
|
||||
begin
|
||||
Result := False;
|
||||
// RegisterWSComponent(TCustomStaticText, TGtk2WSCustomStaticText); { GTK1 }
|
||||
// Result := True;
|
||||
RegisterWSComponent(TCustomStaticText, TAndroidWSCustomStaticText); { GTK1 }
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
function RegisterCustomLabel: Boolean; alias : 'WSRegisterCustomLabel';
|
||||
|
@ -109,7 +109,7 @@ end;"/>
|
||||
<License Value="modified LGPL-2
|
||||
"/>
|
||||
<Version Major="1" Release="1"/>
|
||||
<Files Count="336">
|
||||
<Files Count="345">
|
||||
<Item1>
|
||||
<Filename Value="android/androidint.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
@ -1157,6 +1157,7 @@ end;"/>
|
||||
</Item225>
|
||||
<Item226>
|
||||
<Filename Value="win32/alllclintfunits.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="AllLCLIntfUnits"/>
|
||||
</Item226>
|
||||
<Item227>
|
||||
@ -1492,6 +1493,7 @@ end;"/>
|
||||
</Item297>
|
||||
<Item298>
|
||||
<Filename Value="wince/alllclintfunits.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="AllLCLIntfUnits"/>
|
||||
</Item298>
|
||||
<Item299>
|
||||
@ -1676,6 +1678,51 @@ end;"/>
|
||||
<Filename Value="android/alllclintfunits.pas"/>
|
||||
<UnitName Value="alllclintfunits"/>
|
||||
</Item336>
|
||||
<Item337>
|
||||
<Filename Value="android/android_all.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="android_all"/>
|
||||
</Item337>
|
||||
<Item338>
|
||||
<Filename Value="android/androidapp.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="androidapp"/>
|
||||
</Item338>
|
||||
<Item339>
|
||||
<Filename Value="android/androidpipescomm.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="androidpipescomm"/>
|
||||
</Item339>
|
||||
<Item340>
|
||||
<Filename Value="android/androidprivate.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="androidprivate"/>
|
||||
</Item340>
|
||||
<Item341>
|
||||
<Filename Value="android/androidtimer.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="androidtimer"/>
|
||||
</Item341>
|
||||
<Item342>
|
||||
<Filename Value="android/androidwsfactory.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="androidwsfactory"/>
|
||||
</Item342>
|
||||
<Item343>
|
||||
<Filename Value="android/androidwsforms.pp"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="androidwsforms"/>
|
||||
</Item343>
|
||||
<Item344>
|
||||
<Filename Value="android/androidwsstdctrls.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="androidwsstdctrls"/>
|
||||
</Item344>
|
||||
<Item345>
|
||||
<Filename Value="android/javalang.pas"/>
|
||||
<AddToUsesPkgSection Value="False"/>
|
||||
<UnitName Value="javalang"/>
|
||||
</Item345>
|
||||
</Files>
|
||||
<LazDoc Paths="../../docs/xml/lcl"/>
|
||||
<i18n>
|
||||
|
@ -7,7 +7,7 @@ unit LCL;
|
||||
interface
|
||||
|
||||
uses
|
||||
AllLCLIntfUnits, LazarusPackageIntf;
|
||||
alllclintfunits, LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user