If you have an info level event that you want to notify the user about in Delphi XE5 Firemonkey but you don’t need the user to click an Okay button about it the Android Toast messages might be what you’re looking for. You can launch a Toast to display something like ‘Low Battery’ or ‘Low Memory’ to the user. You are notifying the user of the event without disturbing their usage of your app. As you can see in the screenshot the Toast message pops up in a rectangle on the screen. Usually it fades in and then fades about again. Toast is a native Android feature but there is some code I found which will also give you a similar message system in your IOS apps. These two units are from Delphi developer Paul Thornton. Here is some code from the Android.JNI.Toast.pas unit:
{$IFDEF ANDROID}
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;
{$ENDIF}
You can also access the Toast API using the DPF for Android suite of Delphi Firemonkey components.
Check out the source for the Toast API and the Toast like cross platform messages on Google Code.
works great, thanks for sharing 🙂
You can find a crossplattform toast like component here …
https://www.cybertribe.de/info/components/fmx/toast/
Best regards
Roland
To be precise – Paul Thornton created the repository …
https://code.google.com/p/fmx-extensions/source/browse/trunk/?r=5#trunk%2FLib%2FAPI … but the native toast code is from Brian Long ( http://blog.blong.com/ ) and the unit FMX.AndroidLike.Toast.pas is coded by me.
See for a new version of the toast like component with an improved interface and a fancy component icon 😉
https://www.cybertribe.de/info/components/fmx/toast/
I cannot get the toast component to work. Keeps asking for FMX.AndroidLike.Toast.dcu. I have put the path into the Libary path.
The strange thing is it works when I select Win32 as the target but when I select Android it give above error.
Can someone help. Thanks
Could it be that you did not add the path for the case of Android Build Target or that you did not recompile?
Not sure how/where to do this?
Sorry my message did not come out how I wanted it.
Not sure how/where to add the path for the case of Android Build Target
Tools/Options/Delphi Options/Library Path & Searchpath.
Above the options you can see a combobox labeled something like “Selected Platform” – be sure to select Android there before adding the paths.
(Descriptions may vary since I do not have my IDE in English at the moment.)
Thanks. I did not see that you had to set the path for each platform.
One suggestion. Can I suggest a property “WordWrap” which is linked to the “OptimalWidth”. At the
moment it wraps the text which does not always look so good.
Yes – good idea – I put it on the ToDo list.
Tools/Options/Delphi Options/Library Path & Searchpath.
Above the options you can see a combobox labeled something like “Selected Platform” – be sure to select Android there before adding the paths.
(Descriptions may vary since I do not have my IDE in English at the moment.)
Roland,
I am using your Toast unit, thanks to implement it. Why dont you create a repository for it also?
There are 2 issues on the component right now:
– I am using it as a large band in the middle of the window, It works fine, however after the timer event is fired and it gets “closed” actually the rectangle remains there, and consumes all the mouse clicks. I thought I was suffering another FMX bug then I realized was the Toast area. I believe using small rectangles you did not noticed that.
– The other problem is that for unknown reason in one of my projects I removed the component and replaced it again, and since there is a tabcontrol with animation to switch pages the toast rectangle is anchored in one of the pages and I see it passing by when the page is animated for change. I dont understand why, since I have another exact copy of this project where I did not remove the component and the Toast message is on the form level.
If you could fix that bug when closing the rectangle I would appreciate much. Just put a TEdit and open a Toast over it and you can see the problem after closing. You cannot select the TEdit anymore.
Thanks !
Hi. I will check this and post here when a new version is there.
Godfreys suggestion to have a wordwrap property has been imlemented …
https://www.cybertribe.de/druid/index.php?q=de/node/85
… for download of FMXToast.zip
Hi. I downloaded the new install but could not find a Wordwrap property.
It is definitely in the source of the unit FMX.AndroidLike.Toast.pas in the download (check if this is the case in the unit which you use for development).
You should recompile the component package and should be able to see the wordwrap property in the objectinspector.
For easier communication you might contact me via the website …
https://www.cybertribe.de/druid/index.php?q=de/node/11 …
and provide your email on this way to me.
Got my files mixed up. Working now. Thanks for a great component
You are welcome :-)))
Thanks for awesome product management 🙂