Building Android interfaces using Corona
I've tinkering with this for a while but I never seem to have enough time in the day to make sustain progress. Rather than keep this to myself I thought I would post up what I've got and let others get involved with ideas, questions, coding and general advise of what they think.
If you have an android device you can download this application (see screenshot below) and try it. It'll talk to my house livebox iServer so you'll see what I see on my joggler.
Don't worry about pressing any of the butons nothing is wired up behind them so I'll just see xAP traffic and state changes on my joggler, nothing will turn on/off.
On your android brower download - http://www.dbzoo.com/public/xap-ui-demo.apk
The code is very rough and ready, and those that have been playing around with plugboard for a while will be happy to know this is all coded in LUA too.... Much of the Framework from the livebox to do with callbacks, Frames and the like I've kept the same for simplicity of making a transition of your knowledge.
I won't comment too much on how things work. The curious will soon discover this for themselves and can ask questions for things you do not.
Anyway HAPPY EASTER !
Brett
PS: To play you need the cool development environment from: https://www.coronalabs.com/
Modified for my Dynamic DNS service
working well so far
This runs well onm my HTC OneX. However, the app doesn't appear on the list of 'running' applications. This makes it a bit awkward to navigate back to the app or to shut it down/restart it.
Added a 'Quit' button with the following code.
local widget = require "widget"
local function onButtonRelease( event )
local btn = event.target
native.requestExit()
end
local button = widget.newButton{
label = "Quit",
font = "HelveticaNeue-Bold",
fontSize = 18,
yOffset = -2,
labelColor = { default={ 65 }, over={ 0 } },
emboss = true,
onRelease = onButtonRelease
}
button.x = display.contentCenterX
button.y = display.contentCenterY
Hi Derek,
I can see the app running on my Handset (HTC Desire HD) both in the running applications and 3rd party task manager
will add your button code and give it a go
heres the background code - local background = display.newImage( "background.png", true)
I have noticed a few app crashes which appear to be socket releated, im still logging these with logcat to see if i can find a workaround.
Andrew
I have a few different variants of the xAP app on my OneX. Most of the confusion that I've had with the piece seems to be caused by launching a 2nd app whilst another one is still running.
I still can't see the xAP apps in the list of 'running apps'. The only way I can get back to the app is to hit the icon that launched it in the first place (I'm assuming that this just takes me back to the already running instance rather than starting a new one).
I can however, use 'Settings/apps/all - Force Stop' to kill off the app.
Of course, we are using the 'demo' version of the Corona environment. The production one seems to be rather newer. Some of the issues might be down to bugs that have been fixed.
I've not tried to hookup the USB 'debug log' thing yet. Might give that a spin.
Hi Brett & Derek,
Brett, - this is the message on screen when the app crashes ""This application encountered a Lua error (see logs)" - this appears to be a very generic error and from what i have read and normally relates to a typo or character case error on a path i.e for an image.png
I was able crash your demo app almost everytime and could only run it up once i had cleared the App data / cache (built in android feature) or restarted my phone
the error logs at the time (I didnt save a copy) mentioned a lua txsocket error which is why i mentioned socket errors above - next time it crashes i will be sure to save a log
I also added the following error handling into the main.lua - is this correct?
local function myUnhandledErrorListener( event )
local iHandledTheError = true
if iHandledTheError then
print( "Handling the unhandled error", event.errorMessage )
else
print( "Not handling the unhandled error", event.errorMessage )
end
return iHandledTheError
end
Derek, you can use ADB Logcat via usb "$ adb logcat -s corona or an app, i am using this https://play.google.com/store/apps/details?id=org.jtb.alogcat&hl=en
you can also filter "Corona" events for ease of viewing.
Cheers guys,
Yet more flexibility! I am trying to use a cheap tablet mounted in a frame (see pic) as my central controller, to keep swmbo happy. This runs xapflash but I find it takes an age to refresh from standby meaning it isn't yet as useful as I had hoped. Am definitely interested in giving this a go when I get a few hours!
Keep up the good work folks!
Garry
Attachment | Size |
---|---|
image.jpg | 16.53 KB |
Brett,
Thanks that could indeed explain the socket error - it has worked flawlessly the past 2 days with not a single crash which is strange as i haven't actually made any changes as yet.
I will append your stop code to the end of the main.lua and will give it a test going foward, where do i need to add the UDPServer class code?
Andrew
Something else to play with :)
Hi Brett,
Thanks for the updated code, the Grid method is a huge improvement :)
Can i ask which resolution this is currently based on?
A few comments and suggestions that could enchance this apps awesomeness even further :)
Grid to adjust to landscape rotation
Detect phone resolution and scale accordingly
Multiple grid pages
Connection Status
Cosm graph feeds
Brett,
Thanks for the Resolution info, i took a look at Config.lua
My Desire HD screen res is 800 x 480 (800 / 480 = 1.66) therefore the second scaling method applies
I was puzzled how four 80 pixel images could fill my 480 pixel screen, the config now explains that :)
A small issue i did have was to the move the "Quit button" down from -54 to -40 to fit on my screen - other than that everything seems to fit nicely
just on a side note - the Temp / Lightbulb images are currently 100x100 despire your code stating 80 x 80, not a major issue, just pointing it out.
Regarding the crashes - i am now running the new code with your fixes and it does appear to still crash but only on two occasions
1 - If the App has been running in the background and i attempt to go back into it, i may receive the lua error mentioned before (closing the app via a task manager and obviously using the quit button before exiting the app seems to get around this - is the app possibly attempting to reconnect but already connected to the iserver?)
2 - I have noticed that the app does occasionally crash my livebox - i've yet debug this but no xap flash access is avaliable this is also noticed using the xapflash app on my jogglers
Somthing else noticed - If i have been outside of the app for a while but it is still running and it lets me back in without displaying a lua error i see a quick flash of updates to the endpoints as if its playing catchup - again not an issue but something to mention
One final thing, i cant seem to get the lobat and moved indicators working using the following, prehaps you havn't implemented this yet despite your screenshots.
{ -- ROW 5
{c=toggle, text="R2-PWR", xapSource="dbzoo.livebox.jeenode:bedroom2.lobat", readOnly=true},
{c=toggle, text="R2-PIR", xapSource="dbzoo.livebox.jeenode:bedroom2.moved", readOnly=true},
thanks
Andrew
I can see this really catching on Brett
SWMBO likes it, so it must be good
Love the custom icons Mark, a real nice layout with the Red, Green and Blue too.
Got an email earlier announcing the "Free" starter sdk...
i guess this gets rid of the nag screen :)
Yup. Running the latest from Brett & the nag is gone. Also decent handling of errors when no Wifi or 3G connection can be established.
Been watching this thread for a while as most of you know i am not a coder.
but downloaded the demo and it is excellent.
Just wish it could pull screen layout from iServer like my 3 jogglers do.
Oh well can only hope someone crack's it.
Been playing on a 7" android tab i got for free for buying some toner cartridges for my work printer.
Dean
Hi Dean,
Im pretty sure thats on Bretts list of things to do.
Regarding the coding aspect you really dont have to do much to get this running
1, change the domain for your own i.e home.dbzoo.com to your own dynamic service
2, set your endpoints up using Bretts as a guide
these are all done in the main.lua file provided by Brett
you then fire up the simulator and build for Android - this will generate an APK (Android installer package) which you can copy / email over to your device and install.
Andrew
downloading now.
you do realize you just caused a flood of potentially stupid questions from me :)
havent coded since zeap (Z80 assembly protocol)
That means your a seasoned pro! maybe a bit rusty but the principles are the same :)
sent app via email and my android device says no installed app can open?
huh
stupid android
no installed app can open?
Mark on here was having trouble installing the app, that was displayed as app not installed
your issue sounds different.
I had an issue with using yahoo mail. Gmail worked - just click on the attachment & select 'install'.
I ended up just hooking the phone up to the computer and copying the file across.
I must admit it only worked on my works phone (once I added an SD card) and not on my own phone.
Derek, sounds great regarding the comms fixes will Brett be releasing this?
Hi Brett
This is great stuff, wish I'd got this before embarking down the Java road. (Pretty heavyweight) I'm not too savvy with Lua, is there an easy way to send an alias message with slight mod to the code?
John
Any guidance as to how to get a button (read only) to trigger this event?
On my Java app I send an alias eg "bedroom boost 2" which the HAH interprets.
thanks
John
Well i now have a nearly all working android app.
not as flash as some but i am getting there.
Sorry Brett,
Completely missed that :)
up and running now
Hi Mark....
The icon/graphics are really nice.... any chance you could post a zip of the components and the main.lua so I can have a go at building my own....thanks in advance...
Elliot
Hi Elliot
Did you get my email?
I've been out of the loop for a while and have so much to catch up on.
New house so chnace to start from scratch on the home automation, I have so much to do :)
Wow, this is simply awesome!!!
Thanks Brett, been waiting for this as you know :)
Happy Easter to you too