procedure TForm1.FormCreate(Sender: TObject); begin TJLooper.JavaClass.prepare; end;
procedure TForm1.Button1Click(Sender: TObject); var t: JToast; cs: JString; chs: JCharSequence; begin cs := StringToJString ('Good job - but I want my external keyboard functioning properly :-)'); chs := cs.subSequence(0, 10); TJToast.JavaClass.makeText(MainActivity.getApplication, chs, TJToast.JavaClass.LENGTH_LONG).Show; end;
{$R *.fmx}
end. ===
But it is not :-(
I think I do not get the correct context, but I have no idea what else to try.
I know it does not really make sense to do this single plattform besides of educational reasons, but I would really like to know how to do it with JNI - does anybody have an idea?
This is my unit. It will be one of the things I demo in my CodeRage 8 talk on Android API stuff. Other things under consideration are launching built-in activities like SMS, email, maps etc., calling .jar-based code, a splash screen that checks FMX requirements, etc.
unit Androidapi.JNI.Toast;
//Java bridge class imported by hand by Brian Long (http://blong.com)
BTW - I could not resist and developed a FMX-Toast (or shall I write FM-Toast) component. It should will work x-plattform on WIN32/WIN64/MACOSX/Android/iOS ...
Hi. Should be working like that. Maybe the duration is set to 0 or perhabs it is a problem with the component. You might need to make it a child of a panel that is in the foreground.
HI..for testing I just dropped a button on a blank form and added the fmx toast component and set code as above...setting a duration to 100 does not change the beaviour on a ioS simulator....after clicking on button1....nothing happens (and the button is not released)
Hi Brian, I checked it - you need to set the stroke thickness to a value > 0. Then it is working. I will change the create of the component so it comes up with reasonable values right away. Sorry for the hassle. Here is a configuration with which it works ... object Toast1: TToast ToastBoxStrokeColor = claNull TextColor = claSlateblue ToastBoxColor = claSlategray ToastBoxStrokeDash = sdSolid TextAlign = taCenter Duration = 1000 OptimalWidth = False ToastBoxAlign = alCenter ToastBoxHeight = 50.000000000000000000 ToastBoxStrokeThickness = 1.000000000000000000 ToastBoxWidth = 100.000000000000000000 Left = 64 Top = 80 end
hummm.setting the strokethickness to 1 made the button return...but i still dont see the message (with duration set to 1000), on iOS simulator (i.e fmx mobile)...are you able to duplicate the same problem on ios simulator, or? thanks for the help
hi, Ok, I have your new update..with the new icon for the component of a toaster :) still not working for just dropping on a iOS mobile form and via a button1click,in the iossimulator on my mac, toast1.Now('testing');
the button does return after 1 second...but no message shows and the button cant be clicked again afterwards... hope this helps...I get the impression I am the first person to test for iOS mobile?
Hi Brian, with XE5 it is working without a problem here in combination with the iOS simulator and a physical iOS device in debug and release mode. Could it be that your toast is positioned in a not visible area of the simulator? Try to use the ToastBoxAlign property and set it to alCenter. You have two possibilities to specify the location of the toastbox either by using the toastboxposition or by using the toastboxalign property. Find attached my testproject,
Am 15. Februar 2014 13:40 schrieb Roland Kossow <****@**>:
Hi Brian. I also tested with Android now. Everything (WIN32,WIN64,MACOSX,Android device, iOS Simpulator and iOS Device) seems to be working with the - once more - updated component under ... https://www.cybertribe.de/info/components/fmx/toast/FMXToast.zip
Please let me know if it does not work for you and perhabs send me your testproject so I can have a look into it.
Best regards
Roland
Am 15. Februar 2014 15:51 schrieb Roland Kossow <****@**>:
> Hi Brian, > with XE5 it is working without a problem here in combination with the iOS > simulator and a physical iOS device in debug and release mode. > Could it be that your toast is positioned in a not visible area of the > simulator? > Try to use the ToastBoxAlign property and set it to alCenter. > You have two possibilities to specify the location of the toastbox either > by using the toastboxposition or by using the toastboxalign property. Find > attached my testproject, > > > Am 15. Februar 2014 13:40 schrieb Roland Kossow <****@**>: > > Hi. >> Which Delphi Version Do you use?
hi...ok, the align was set to alnone...I have set that to alcenter...and set the position to 10 for x and 10 for y the button returns from a click straight away now and you can click as many times as you like now...with your latest update...but I am still not seeing the message box in the simulator..this is with XE5 update 2
Hi Brian, everything is fine, you just have to set the color properties to values different than Null. Then it is working. They should be initialized with values different than Null in the current version of the component.
I tested it now with your testproject - which is about the same as my testproject.
2014-02-15 19:03 GMT+01:00 Roland Kossow <****@**>:
> Hi Brian, > everything is fine, you just have to set the color properties to values > different than Null. > Then it is working. > They should be initialized with values different than Null in the current > version of the component. > > > Best regards > > Roland > >
ah ha...now its working....thanks :) hopefully I have been a good green guinea pig (I had assumed the null colour would have at least defaulted to black) one question: is there a way to make the box transparent , i.e to take on the colour of the background?
Hi Brian, you were an excellent betatester and the component improved already a lot because of our conversation - it now defaults to non-null color values and supports transparency (see below) :-) Thanks for testing. Considering transparency: I added an Opacity property to the newly updated 0.3 Alpha which can be downloaded now under ... https://www.cybertribe.de/info/components/fmx/toast/
excellent,...the transparency works via the opacity, and thinking about it, I can set the background colour to what the background colour is off the app anyway too....one problem though with the opacity setting is that makes the text also opaque....ie harder to read..(e.g using 0.5).but i suppose there is no way to set the rectangle opacity but not the text opacity (which is the text in the rectangle)?
BTW - if you just want the box to disappear set the textboxcolor value to NULL.
2014-02-15 19:42 GMT+01:00 Roland Kossow <****@**>:
> Hi Brian, > yes - I will try to fix that (text opacity) in the next version. Should be > possible ... > But not right now - tomorrow. > > Regards > > Roland > >
that works, setting textbox color to null if you can get the text to not be transparent, but the box to be transparent, then I reckong that would look great
Nope. Not as a readily wrapped object way, anyways...
ReplyDeletei'll not sleep until i get it (or someone else) :D
ReplyDeleteedit:
i give up [ for a while :) ], i have to work tomorrow... :|
I thought it would be working like that ...
ReplyDelete===
unit psJToast;
interface
uses
Androidapi.JNIBridge,
Androidapi.JNI.JavaTypes,
Androidapi.JNI.Os,
Androidapi.JNI.Net,
Androidapi.JNI.Util,
Androidapi.JNI.GraphicsContentViewText;
type
JToast = interface;
JToastClass = interface(JViewClass)
['{0829BB43-F89D-473F-9A59-FB44CA97ED08}']
{ Static methods of toast-class go here }
function makeText(context: JContext; resId, duration: Integer): JToast;
overload; cdecl;
function makeText(context: JContext; text: JCharSequence; duration: Integer)
: JToast; overload; cdecl;
{ Property Methods }
function _GetLENGTH_LONG: Integer;
function _GetLENGTH_SHORT: Integer;
{ Properties }
property LENGTH_LONG: Integer read _GetLENGTH_LONG;
property LENGTH_SHORT: Integer read _GetLENGTH_SHORT;
end;
[JavaSignature('android/widget/Toast')]
JToast = interface(JView)
['{43688786-E77D-40D1-A5DD-7C7AF1BDA20C}']
{ Instance methods of toast-class go here }
procedure cancel; cdecl;
function getDuration: Integer; cdecl;
function getGravity: Integer; cdecl;
function getHorizontalMargin: single; cdecl;
function getVerticalMargin: single; cdecl;
function getView: JView; cdecl;
function getXOffset: Integer; cdecl;
function getYOffset: Integer; cdecl;
procedure setDuration(duration: Integer); cdecl;
procedure setGravity(gravity, xOffset, yOffset: Integer); cdecl;
procedure setMargin(horizontalMargin, verticalMargin: single); cdecl;
procedure setText(resId: Integer); cdecl; overload;
procedure setText(s: JCharSequence); cdecl; overload;
procedure setView(view: JView); cdecl;
procedure show; cdecl;
end;
TJToast = class(TJavaGenericImport)
end;
implementation
end.
===
===
unit JToastTestbedMainForm;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
uses psJToast, Androidapi.JNI.Javatypes,
FMX.Platform.Android, Androidapi.JNI.OS;
procedure TForm1.FormCreate(Sender: TObject);
begin
TJLooper.JavaClass.prepare;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
t: JToast;
cs: JString;
chs: JCharSequence;
begin
cs := StringToJString
('Good job - but I want my external keyboard functioning properly :-)');
chs := cs.subSequence(0, 10);
TJToast.JavaClass.makeText(MainActivity.getApplication, chs,
TJToast.JavaClass.LENGTH_LONG).Show;
end;
{$R *.fmx}
end.
===
But it is not :-(
I think I do not get the correct context, but I have no idea what else to try.
I know it does not really make sense to do this single plattform besides of educational reasons, but I would really like to know how to do it with JNI - does anybody have an idea?
Perhaps the eminent Brian Long can shed some light on the mystery?
ReplyDeleteI'll post a working unit later
ReplyDeleteThis is my unit. It will be one of the things I demo in my CodeRage 8 talk on Android API stuff. Other things under consideration are launching built-in activities like SMS, email, maps etc., calling .jar-based code, a splash screen that checks FMX requirements, etc.
ReplyDeleteunit Androidapi.JNI.Toast;
//Java bridge class imported by hand by Brian Long (http://blong.com)
interface
uses
Androidapi.JNIBridge,
Androidapi.JNI.JavaTypes,
Androidapi.JNI.GraphicsContentViewText;
type
TToastLength = (LongToast, ShortToast);
JToast = interface;
JToastClass = interface(JObjectClass)
['{69E2D233-B9D3-4F3E-B882-474C8E1D50E9}']
{Property methods}
function _GetLENGTH_LONG: Integer; cdecl;
function _GetLENGTH_SHORT: Integer; cdecl;
{Methods}
function init(context: JContext): JToast; cdecl; overload;
function makeText(context: JContext; text: JCharSequence; duration: Integer): JToast; cdecl;
{Properties}
property LENGTH_LONG: Integer read _GetLENGTH_LONG;
property LENGTH_SHORT: Integer read _GetLENGTH_SHORT;
end;
[JavaSignature('android/widget/Toast')]
JToast = interface(JObject)
['{FD81CC32-BFBC-4838-8893-9DD01DE47B00}']
{Methods}
procedure cancel; cdecl;
function getDuration: Integer; cdecl;
function getGravity: Integer; cdecl;
function getHorizontalMargin: Single; cdecl;
function getVerticalMargin: Single; cdecl;
function getView: JView; cdecl;
function getXOffset: Integer; cdecl;
function getYOffset: Integer; cdecl;
procedure setDuration(value: Integer); cdecl;
procedure setGravity(gravity, xOffset, yOffset: Integer); cdecl;
procedure setMargin(horizontalMargin, verticalMargin: Single); cdecl;
procedure setText(s: JCharSequence); cdecl;
procedure setView(view: JView); cdecl;
procedure show; cdecl;
end;
TJToast = class(TJavaGenericImport) end;
procedure Toast(const Msg: string; Duration: TToastLength = ShortToast);
implementation
uses
FMX.Helpers.Android;
procedure Toast(const Msg: string; Duration: TToastLength);
var
ToastLength: Integer;
begin
if Duration = ShortToast then
ToastLength := TJToast.JavaClass.LENGTH_SHORT
else
ToastLength := TJToast.JavaClass.LENGTH_LONG;
CallInUiThread(procedure
begin
TJToast.JavaClass.makeText(SharedActivityContext, StrToJCharSequence(msg),
ToastLength).show
end);
end;
end.
Cool. Thanks a lot for the source - very insightful.
ReplyDelete[Roland spends Brian a virtual beer.]
Fantastic!!thanks
ReplyDeleteBrian Long When you implemented the interface are the GUID's pulled from somewhere or just randomly made up to be a unique ID?
ReplyDeleteYou just press CTL+SHIFT+G .
ReplyDeleteoops - CTRL+SHIFT+G
ReplyDeleteCTL shift g when doing what? Typing out the interface?
ReplyDeletehttp://stackoverflow.com/questions/2992183/are-guids-necessary-to-use-interfaces-in-delphi
ReplyDeleteWhen you want to insert a snipet like ['{DCFB0323-A1D8-4BD5-9268-F47CFF19CEC5}'] in the IDE.
ReplyDeletePress CTRL+SHIFT+G and you get something like ['{DCFB0323-A1D8-4BD6-9268-F47CFF19CAA5}'].
ReplyDeleteI see, I was thinking the GUID's referenced something somewhere else but it's just a unique identifier for the interface or class. Thx.
ReplyDeleteThey are not pulled from somewhere beyond CTRL-SHIFT-G any GUID should do.
ReplyDeleteBTW - I could not resist and developed a FMX-Toast (or shall I write FM-Toast) component.
ReplyDeleteIt should will work x-plattform on WIN32/WIN64/MACOSX/Android/iOS ...
https://docs.google.com/file/d/0B_mUUtJe8v84NEZjTjZCemFDd1U/edit?usp=sharing
Just compile and install.
Your welcome.
Thank you! Worked very well. Even to me, as a completly noob with Java stuff and Android I was able to make my first Toast :)
ReplyDeleteGood to read. You can find updates of the FMX wrapper under https://www.cybertribe.de/info//components/fmx/toast in the future.
ReplyDeletesorry to dig up an old thread...I have this working great on android...but how do you do a similar toast message on iOS? .Thanks!
ReplyDeleteHi Brian,
ReplyDeleteyou can either use my component - it is mimicing a toast based on top of FMX or you do it IOS natively by using UIAlertView see more thorrough explanations here http://stackoverflow.com/questions/3737911/how-to-display-temporary-popup-message-on-iphone-ipad-ios .
hi,ok, I will look into using your fmx toast for iOS...(I was using a java intent for android)
ReplyDeleteOk. Just let me know if it is working for you or if you need support to get it running.
ReplyDeleteHi..do I just need to use
ReplyDeletetoast1.now('text to show');
?
as it does not seem to work on the iOS simulator?
Hi. Should be working like that. Maybe the duration is set to 0 or perhabs it is a problem with the component. You might need to make it a child of a panel that is in the foreground.
ReplyDeleteHI..for testing I just dropped a button on a blank form and added the fmx toast component and set code as above...setting a duration to 100 does not change the beaviour on a ioS simulator....after clicking on button1....nothing happens (and the button is not released)
ReplyDeleteHi Brian,
ReplyDeleteI checked it - you need to set the stroke thickness to a value > 0. Then it is working.
I will change the create of the component so it comes up with reasonable values right away. Sorry for the hassle.
Here is a configuration with which it works ...
object Toast1: TToast
ToastBoxStrokeColor = claNull
TextColor = claSlateblue
ToastBoxColor = claSlategray
ToastBoxStrokeDash = sdSolid
TextAlign = taCenter
Duration = 1000
OptimalWidth = False
ToastBoxAlign = alCenter
ToastBoxHeight = 50.000000000000000000
ToastBoxStrokeThickness = 1.000000000000000000
ToastBoxWidth = 100.000000000000000000
Left = 64
Top = 80
end
BTW the duration is in milliseconds so 100 might be a little short.
ReplyDeleteHi Brian,
ReplyDeletea new ZIP is available at https://www.cybertribe.de/info/components/fmx/toast/FMXToast.zip
This Zip contains some improvements.
hummm.setting the strokethickness to 1 made the button return...but i still dont see the message (with duration set to 1000), on iOS simulator (i.e fmx mobile)...are you able to duplicate the same problem on ios simulator, or?
ReplyDeletethanks for the help
hi, Ok, I have your new update..with the new icon for the component of a toaster :)
ReplyDeletestill not working for just dropping on a iOS mobile form and via a button1click,in the iossimulator on my mac,
toast1.Now('testing');
the button does return after 1 second...but no message shows and the button cant be clicked again afterwards...
hope this helps...I get the impression I am the first person to test for iOS mobile?
ps,no errors though when running in debugger..I will try running on an actual device...
ReplyDeletesame behaviour on my ipad...
ReplyDeleteHi.
ReplyDeleteWhich Delphi Version Do you use?
Hi Brian,
ReplyDeletewith XE5 it is working without a problem here in combination with the iOS
simulator and a physical iOS device in debug and release mode.
Could it be that your toast is positioned in a not visible area of the
simulator?
Try to use the ToastBoxAlign property and set it to alCenter.
You have two possibilities to specify the location of the toastbox either
by using the toastboxposition or by using the toastboxalign property. Find
attached my testproject,
Am 15. Februar 2014 13:40 schrieb Roland Kossow <****@**>:
> Hi.
> Which Delphi Version Do you use?
Hi Brian.
ReplyDeleteI also tested with Android now.
Everything (WIN32,WIN64,MACOSX,Android device, iOS Simpulator and iOS
Device) seems to be working with the - once more - updated component under
...
https://www.cybertribe.de/info/components/fmx/toast/FMXToast.zip
Please let me know if it does not work for you and perhabs send me your
testproject so I can have a look into it.
Best regards
Roland
Am 15. Februar 2014 15:51 schrieb Roland Kossow <****@**>:
> Hi Brian,
> with XE5 it is working without a problem here in combination with the iOS
> simulator and a physical iOS device in debug and release mode.
> Could it be that your toast is positioned in a not visible area of the
> simulator?
> Try to use the ToastBoxAlign property and set it to alCenter.
> You have two possibilities to specify the location of the toastbox either
> by using the toastboxposition or by using the toastboxalign property. Find
> attached my testproject,
>
>
> Am 15. Februar 2014 13:40 schrieb Roland Kossow <****@**>:
>
> Hi.
>> Which Delphi Version Do you use?
hi...ok, the align was set to alnone...I have set that to alcenter...and set the position to 10 for x and 10 for y
ReplyDeletethe button returns from a click straight away now and you can click as many times as you like now...with your latest update...but I am still not seeing the message box in the simulator..this is with XE5 update 2
you can download my test project (very simple)
http://www.weather-display.com/downloadfiles/projecttoast.zip
you say you have a test project attached?
thanks for the help!
Hi Brian,
ReplyDeleteeverything is fine, you just have to set the color properties to values
different than Null.
Then it is working.
They should be initialized with values different than Null in the current
version of the component.
Best regards
Roland
I tested it now with your testproject - which is about the same as my
ReplyDeletetestproject.
2014-02-15 19:03 GMT+01:00 Roland Kossow <****@**>:
> Hi Brian,
> everything is fine, you just have to set the color properties to values
> different than Null.
> Then it is working.
> They should be initialized with values different than Null in the current
> version of the component.
>
>
> Best regards
>
> Roland
>
>
ah ha...now its working....thanks :)
ReplyDeletehopefully I have been a good green guinea pig
(I had assumed the null colour would have at least defaulted to black)
one question: is there a way to make the box transparent , i.e to take on the colour of the background?
Hi Brian,
ReplyDeleteyou were an excellent betatester and the component improved already a lot
because of our conversation - it now defaults to non-null color values and
supports transparency (see below) :-) Thanks for testing.
Considering transparency: I added an Opacity property to the newly updated
0.3 Alpha which can be downloaded now under ...
https://www.cybertribe.de/info/components/fmx/toast/
Happy testing!
Best regards
Roland
excellent,...the transparency works via the opacity, and thinking about it, I can set the background colour to what the background colour is off the app anyway too....one problem though with the opacity setting is that makes the text also opaque....ie harder to read..(e.g using 0.5).but i suppose there is no way to set the rectangle opacity but not the text opacity (which is the text in the rectangle)?
ReplyDeleteHi Brian,
ReplyDeleteyes - I will try to fix that (text opacity) in the next version. Should be
possible ...
But not right now - tomorrow.
Regards
Roland
BTW - if you just want the box to disappear set the textboxcolor value to
ReplyDeleteNULL.
2014-02-15 19:42 GMT+01:00 Roland Kossow <****@**>:
> Hi Brian,
> yes - I will try to fix that (text opacity) in the next version. Should be
> possible ...
> But not right now - tomorrow.
>
> Regards
>
> Roland
>
>
that works, setting textbox color to null
ReplyDeleteif you can get the text to not be transparent, but the box to be transparent, then I reckong that would look great
ps, I am going to use this in my OSX program too....good way to show events/info in the program :)
ReplyDeleteone more setting you might want to make public is the
ReplyDeleteself.FRectangle.AnimateFloat('Opacity', 0, 0.3);
setting that to 0.8 makes the message linger longer on the fade...
:)
Hi.
ReplyDeleteNew version uploaded ...
https://www.cybertribe.de/info/components/fmx/toast/FMXToast.zip
- AppearanceDuration (in milliseconds)
- DisappearanceDuration (in millseconds)
- Text has always an opacity of 1
Major changes could lead to new bugs - happy testing!
Best regards
Roland
works great well done :)
ReplyDeleteGreat - thanks for the feedback.
ReplyDeleteFurther feature requests are welcome.
Regards
Roland