Android Question How to achieve this effect?

DaOne

Member
Licensed User
Longtime User
I am looking to display climate control data on my car installed nexus 7via blueooth. I have the data already coming in but I want to display it better. This effect would be perfect for this. The requirement is graphics /text I can change before it shows and update while its showing. It will time out when data is not changed. It also needs to be global as in it will show no matter what app your in. Is there a way to do this in B4A?

Here is the app effect I am trying to duplicate...

https://play.google.com/store/apps/details?id=com.nlucas.wp7notificationslite
 

DaOne

Member
Licensed User
Longtime User
When you say not free do you mean it requires the paid version of b4a? If so I am paid up for 2 years. Toast would probably get the job done if there was a way to update the message in real time when it receives new data such as set temperature that's on a rotary dial. Is there a way to make that happen?
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
I mean Standout library is not free from bugs...lol, just kidding (had to do that)
No it is apparently a paid library, which you have to pay separately from B4A. At this stage I dont recommend it unless you want to replicate that effect exacto.
To update the messages in real-time you will need to have a service running in the background that fetches the information. As long as you can fetch it you should be able to display it.
 
Upvote 0

DaOne

Member
Licensed User
Longtime User
Basically what I have working now is a bluetooth serial connection that watches for a new string followed by a end on line and displays this as a toast message. The problem with doing this with a toast message is that it creates a new message. I need it to update the original one. Say the temp is set to 70 degree and I raise the temp to 80 deg. That will result in 10 toast messages that must wait for each other to display. Is there a better way?
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
To be honest, displaying messages when your app isnt active without disrupting another activity is quite hard in android.
The usual method for this is to use notifications, since it is non-invasive.

Another way would be to display a partially transparent activity, but that will block the activity behind it.

What you want is an always-on-screen notification, that doesnt interfere with any other app?

Have a look at the tooleap notification and see if that looks ok to you?
 
Upvote 0

DaOne

Member
Licensed User
Longtime User
What I am looking for I guess is a fixed overlay strip across the top or bottom of the screen that displays the climate info such as temp, fan speed, mode, etc. When the data stops updating I want it to disappear. Trying for an oem look. I plan to use bit mapped images to show the fan speed/ mode etc and text for the two temperatures. Data is just plain text identifiers.
 
Upvote 0

DaOne

Member
Licensed User
Longtime User
The look and feel isnt a huge priority. Getting something reliable and functional is key. I actually like the toast message style as well however I need to update the information within the toast message if and of the incoming serial data is changed. Is there an elegant way of doing this? I was thinking maybe like setting a toast for a fraction of a second and repeat it 10 times if data dos not change. If the data changes stop the display of the old data and insert the new followed by the same routine. I hope that makes sense? Is this even possible with toast to do such a thing?
 
Upvote 0

DaOne

Member
Licensed User
Longtime User
Steve05, I used your module. I tried putting a Toast.Cancel before displaying the new toast so if I get an update it will just cancel the old one. I end up with an error of "java.lang.NoSuchMethodException: cancel[]" Any ideas on how to fix? It compiles fine.
 
Upvote 0

DaOne

Member
Licensed User
Longtime User
No. Is there a way to test if its showing a toast? Is there a better method then say using a timer to know if a toast is still showing or does it even matter if its still showing as long as it was called first? I am thinking of using a set flag and a timer to fix this. Is there a better way?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If you are running in a loop and want to call cancel as the first thing, you can replace the code in the module with:

B4X:
'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    Dim T As Object
    Dim R As Reflector
    Dim IsInitialized As Boolean

End Sub
Sub Show(sText As String,sDur As Boolean)
  
    Dim C As Object
    Dim Duration As Int
  
    C = R.GetContext
  
    Duration = 0
    If sDur = True Then Duration = 1
  
    T = R.RunStaticMethod("android.widget.Toast","makeText",Array As Object(C,sText,Duration),Array As String("android.content.Context","java.lang.CharSequence","java.lang.int"))
  
    R.Target=T
    R.RunMethod("show")
    IsInitialized = True
End Sub
Sub Cancel
    R.Target=T
    R.RunMethod("cancel")
    IsInitialized = False
End Sub

And call the cancel method as:

B4X:
If Toast.IsInitialized Then Toast.Cancel

It wont then fail if you haven't already displayed a toast.
 
Upvote 0

DaOne

Member
Licensed User
Longtime User
Thanks stevel05 that should work great! Kinda the other direction I was looking at. Next question. Hopefully not a stupid one (I am still new at this). The toast messages do not show unless I am in the app. If new data comes in I have to switch back to the app to get the toast to display. Something tells me I need to look into making this a service?? Maybe is something simple I am overlooking? Thanks for all the help guys!
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Yes that would work in a service, but while making it a service you'd be better off using notifications. That way they will stay until removed and won't get missed.
 
Upvote 0

DaOne

Member
Licensed User
Longtime User
Well the only time they need to show is when an adjustment is made. They don't really need to be dismissed. I will also be creating a screen that will show all the information (main app). Could you help me turn this into a service so these toast messages will be shown no matter what app I am in?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Have a look at this , it'll tell you all you need to know. Creating a service isn't much different from creating a class. You can't directly touch any UI objects, though. You have to write a sub in the activity and call that using CallSub (after checking the activity isn't paused) or callsubdelayed.

If you get any problems, post a question, someone will be around to help.
 
Upvote 0

DaOne

Member
Licensed User
Longtime User
Is the only way to get a toast message to show is to create a service? I figured that was kinda the point of toast messages is to be momentary system wide messages? The bluetooth part of my app is running in the background just fine as its filling the buffer with the data. The problem is it requires me to switch back to my app before it will show the toast message. As soon as i do i get the toast message(s).
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…