From 956fbe1e44e6219837a12dbc9215c76cf981dedc Mon Sep 17 00:00:00 2001 From: sekelsenmat Date: Fri, 26 Aug 2011 08:58:20 +0000 Subject: [PATCH] android: Updates bindings and adds dialog callbacks git-svn-id: trunk@32060 - --- lcl/interfaces/android/android_all.pas | 41 ++++++++++++----------- lcl/interfaces/android/androidint.pas | 6 ++++ lcl/interfaces/android/androidlclintf.inc | 40 +++++++++++++--------- lcl/interfaces/android/androidobject.inc | 10 ++++++ lcl/interfaces/android/javalang.pas | 4 +-- 5 files changed, 64 insertions(+), 37 deletions(-) diff --git a/lcl/interfaces/android/android_all.pas b/lcl/interfaces/android/android_all.pas index cc17268e1b..7fb8faf5c6 100644 --- a/lcl/interfaces/android/android_all.pas +++ b/lcl/interfaces/android/android_all.pas @@ -52,7 +52,7 @@ type TDisplayMetrics = class(TJavaObject) public - constructor Create(); + constructor Create(); override; function density(): Single; function densityDpi(): Integer; function heightPixels(): Integer; @@ -100,8 +100,8 @@ type TAlertDialog_Builder = class(TJavaObject) public - constructor Create(); - function create(): TAlertDialog; + constructor Create(); override; + function create_(): TAlertDialog; function setMessage(message: string): TAlertDialog_Builder; function setTitle(title: string): TAlertDialog_Builder; function setView(view: TView): TAlertDialog_Builder; @@ -130,13 +130,13 @@ type TLinearLayout = class(TViewGroup) public - constructor Create(); + constructor Create(); override; procedure setOrientation(orientation: Integer); end; TAbsoluteLayout = class(TViewGroup) public - constructor Create(); + constructor Create(); override; end; TAbsoluteLayout_LayoutParams = class(TViewGroup_LayoutParams) @@ -146,7 +146,7 @@ type TTextView = class(TView) public - constructor Create(); + constructor Create(); override; procedure setText(AText: string); public OnClickListener: TView_OnClickListener; @@ -159,12 +159,12 @@ type TEditText = class(TTextView) public - constructor Create(); + constructor Create(); override; end; TButton = class(TTextView) public - constructor Create(); + constructor Create(); override; end; TFrameLayout = class(TViewGroup) @@ -173,7 +173,7 @@ type TTimePicker = class(TFrameLayout) public - constructor Create(); + constructor Create(); override; function getCurrentHour(): Integer; procedure setCurrentHour(currentHour: Integer); function getCurrentMinute(): Integer; @@ -184,7 +184,7 @@ type TScrollView = class(TFrameLayout) public - constructor Create(); + constructor Create(); override; end; TCompoundButton = class(TButton) @@ -197,7 +197,7 @@ type TCheckBox = class(TCompoundButton) public - constructor Create(); + constructor Create(); override; end; TAdapterView = class(TViewGroup) @@ -214,7 +214,7 @@ type TSpinner = class(TAbsSpinner) public - constructor Create(); + constructor Create(); override; end; TFilterable = interface(IJavaInterface) @@ -250,6 +250,9 @@ const { Constants } { TDisplayMetrics } { TDialogInterface } + BUTTON_NEGATIVE = $fffffffe; + BUTTON_NEUTRAL = $fffffffd; + BUTTON_POSITIVE = $ffffffff; { TActivity } { TDisplay } { TWindowManager } @@ -525,7 +528,7 @@ begin vAndroidPipesComm.SendByte(ShortInt(amkUICommand)); vAndroidPipesComm.SendInt(amkUI_TWindowManager_getDefaultDisplay_0); vAndroidPipesComm.SendInt(Index); // Self, Java Pointer - Result := TDisplay(vAndroidPipesComm.WaitForIntReturn()); + Result := TDisplay.Create(vAndroidPipesComm.WaitForIntReturn()); end; procedure TDialog.show(); @@ -597,12 +600,12 @@ begin vAndroidPipesComm.SendInt(amkUI_TAlertDialog_Builder_Create_0); Index := vAndroidPipesComm.WaitForIntReturn(); end; -function TAlertDialog_Builder.create(): TAlertDialog; +function TAlertDialog_Builder.create_(): TAlertDialog; begin vAndroidPipesComm.SendByte(ShortInt(amkUICommand)); vAndroidPipesComm.SendInt(amkUI_TAlertDialog_Builder_create_1); vAndroidPipesComm.SendInt(Index); // Self, Java Pointer - Result := TAlertDialog(vAndroidPipesComm.WaitForIntReturn()); + Result := TAlertDialog.Create(vAndroidPipesComm.WaitForIntReturn()); end; function TAlertDialog_Builder.setMessage(message: string): TAlertDialog_Builder; @@ -614,7 +617,7 @@ begin vAndroidPipesComm.SendInt(amkUI_TAlertDialog_Builder_setMessage_2); vAndroidPipesComm.SendInt(Index); // Self, Java Pointer vAndroidPipesComm.SendInt(lString_1.Index); // text - Result := TAlertDialog_Builder(vAndroidPipesComm.WaitForIntReturn()); + Result := TAlertDialog_Builder.Create(vAndroidPipesComm.WaitForIntReturn()); lString_1.Free; end; @@ -627,7 +630,7 @@ begin vAndroidPipesComm.SendInt(amkUI_TAlertDialog_Builder_setTitle_3); vAndroidPipesComm.SendInt(Index); // Self, Java Pointer vAndroidPipesComm.SendInt(lString_1.Index); // text - Result := TAlertDialog_Builder(vAndroidPipesComm.WaitForIntReturn()); + Result := TAlertDialog_Builder.Create(vAndroidPipesComm.WaitForIntReturn()); lString_1.Free; end; @@ -637,7 +640,7 @@ begin vAndroidPipesComm.SendInt(amkUI_TAlertDialog_Builder_setView_4); vAndroidPipesComm.SendInt(Index); // Self, Java Pointer vAndroidPipesComm.SendInt(Integer(view.Index)); - Result := TAlertDialog_Builder(vAndroidPipesComm.WaitForIntReturn()); + Result := TAlertDialog_Builder.Create(vAndroidPipesComm.WaitForIntReturn()); end; function TAlertDialog_Builder.show(): TAlertDialog; @@ -645,7 +648,7 @@ begin vAndroidPipesComm.SendByte(ShortInt(amkUICommand)); vAndroidPipesComm.SendInt(amkUI_TAlertDialog_Builder_show_5); vAndroidPipesComm.SendInt(Index); // Self, Java Pointer - Result := TAlertDialog(vAndroidPipesComm.WaitForIntReturn()); + Result := TAlertDialog.Create(vAndroidPipesComm.WaitForIntReturn()); end; constructor TViewGroup_LayoutParams.Create(width: Integer; height: Integer); diff --git a/lcl/interfaces/android/androidint.pas b/lcl/interfaces/android/androidint.pas index 76fb9740de..d6d0e825db 100644 --- a/lcl/interfaces/android/androidint.pas +++ b/lcl/interfaces/android/androidint.pas @@ -159,6 +159,12 @@ type property DragImageLock: Boolean read FDragImageLock write FDragImageLock; property OverrideCursor: TObject read FOverrideCursor write SetOverrideCursor;} + public + // Android Callbacks + AndroidDialogResult: Integer; + procedure HandleAlertButtonPositive(); + procedure HandleAlertButtonNegative(); + {$I androidwinapih.inc} {$I androidlclintfh.inc} end; diff --git a/lcl/interfaces/android/androidlclintf.inc b/lcl/interfaces/android/androidlclintf.inc index 88f3c547b2..ece28a84c8 100644 --- a/lcl/interfaces/android/androidlclintf.inc +++ b/lcl/interfaces/android/androidlclintf.inc @@ -863,15 +863,17 @@ end;*) function TAndroidWidgetSet.RequestInput(const InputCaption, InputPrompt : String; MaskInput : Boolean; var Value : String) : Boolean; var alert: TAlertDialog_Builder; + alertdlg: TAlertDialog; input: TEditText; begin { The LCL fills InputDialogFunction, so we cannot uncomment this code or - else we will end up with non-native dialogs, which is not a great idea in Android - + else we will end up with non-native dialogs, which is not a great idea in Android } + {$IFDEF LCL_ANDROID_USE_NON_NATIVE_DIALOGS} if InputDialogFunction<>nil then Result := InputDialogFunction(InputCaption, InputPrompt, MaskInput, Value) else - begin} + begin + {$ENDIF} Result := True; alert := TAlertDialog_Builder.Create; @@ -883,21 +885,27 @@ begin input := TEditText.Create; alert.setView(input); -(* alert.setPositiveButton('Ok', new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - String value = input.getText(); - // Do something with value! - } - }); + // Now add the buttons + alertdlg := alert.create_(); + alertdlg.setButton( + BUTTON_POSITIVE, + 'Ok', + @HandleAlertButtonPositive + ); + alertdlg.setButton( + BUTTON_NEGATIVE, + 'Cancel', + @HandleAlertButtonNegative + ); - alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { - public void onClick(DialogInterface dialog, int whichButton) { - // Canceled. - } - });*) + alertdlg.show(); - alert.show(); -// end; + // Clean-up + alert.Free; + alertdlg.Free; + {$IFDEF LCL_ANDROID_USE_NON_NATIVE_DIALOGS} + end; + {$ENDIF} end; (*procedure TQtWidgetSet.SetEventHandlerFlags(AHandler: PEventHandler; diff --git a/lcl/interfaces/android/androidobject.inc b/lcl/interfaces/android/androidobject.inc index 9d3a46c89c..6630993894 100644 --- a/lcl/interfaces/android/androidobject.inc +++ b/lcl/interfaces/android/androidobject.inc @@ -328,5 +328,15 @@ begin end;} end; +// Android Callbacks +procedure TAndroidWidgetSet.HandleAlertButtonPositive(); +begin + AndroidDialogResult := BUTTON_POSITIVE; +end; + +procedure TAndroidWidgetSet.HandleAlertButtonNegative(); +begin + AndroidDialogResult := BUTTON_NEGATIVE; +end; //------------------------------------------------------------------------ diff --git a/lcl/interfaces/android/javalang.pas b/lcl/interfaces/android/javalang.pas index 6ee9dae793..ffc35087db 100644 --- a/lcl/interfaces/android/javalang.pas +++ b/lcl/interfaces/android/javalang.pas @@ -23,8 +23,8 @@ type TJavaObject = class(IJavaInterface) public FIndex: Integer; - constructor Create(AIndex: Integer); virtual; - constructor Create(); virtual; + constructor Create(AIndex: Integer); virtual; overload; + constructor Create(); virtual; overload; function GetIndex: Integer; procedure SetIndex(AValue: Integer); property Index: Integer read GetIndex write SetIndex;