First ANDROID app with quite a few features and questions

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

First ANDROID app with quite a few features and questions

Post by BarrySumpter » Thu May 05, 2011 4:06 am

I've attached my first app.

My first research was to prove RunRev LiveCode works on all platforms.
I've confirmed the 3 Apple OSX platforms and WinXP and Android and web.

Then I wanted to see what controls are available and which would work for Android.
So I just plastered my Mainstack with all the controls in the livecode native tool bar.
With so many controls it takes a bit too long to test on the Android imulator
and takes about 10 seconds of black screen to start.

I noticed there was a display width and height cliped limit on both Android imulator and on my actual phone.
That's why I created my first app to show the mouseMove x,y positions.
on windows i just have to more the mouse around.
But on Android imulator I have to Left mouse click and hold and move around to get the mouseMove even to fire.
and my actual phone I have to finger press and hold and move around to get the mouseMove even to fire.

Even though my app shows MouseOver: x,y
- it means that pointer in now over the following points of x, y
- it does NOT mean the even MouseOver
I got the code from RunRev Revolution forums and just copied it in.

I was very dissapointed that LC 4.6.1 didn't have a treeview control.
And that I'll have to pay for one if needed.

I then had a look around to see if I could find an app to miminc for a study target.
Not being satisfied that there is a standard I decided on one myself.

I found a scratched metal graphic that I wanted to use as a background.
But couldn't figure out how to assign it to the stack background.
More on this later. You'll see why.

I couldn't find any graphics that were inlcuded in the OmegaBundle for gel buttons

So I contacted Scott from tm | tools to see if he could help me find a way to build gel buttons.
If you've seen his work you'll know exactly why I contacted him.
( I actually swore out lound when I first viewed his works. )
I sent Scott the get button tutorial from Xara in hopes of assisting.
Scott not only sent me instruction but a sample.
As well as follow up emails. Very happy with the tools and with the support.

His follow up email lead into researching UNGrouping the three images
to pull them apart so I could see how it was layered.
Then grouping them back again.
Regretably TM | Tools doesn't reflect the graphic that has the focus.

I played around with tm | tools enough
to get the jist and made slight changes
that I thought were an improvement
and learned how to changed the color.

Another followup email with Scott discussed how to
NOT rely on the LC graphics engine to render the three layers of the button.
But to create a single graphic from the group of the three button images.
By seleecting the the button group then open the Message Box and paste the following command line:
import snapshot from the selectedObject
after pressing enter - an image control is create with a pic/snap of the grouped button images.
Very freakin cool!

Now I can use that image as the staring point of another button that has a Label on top to show text.
Then group that image with a label with the text: "Exit" or "Open" or "Cancel"
And import that snapshot as an image as well.

Then change the label to some other text and snapshot again.
In a few minutes I have all kinds of buttons.

----
As I mentioned before too many controls takes android too long to start my app.
(If I have three images per gel button that would add up to a lot of controls especially for Android)
So be sure to remove any extranous controls not needed.
Here it would be the three grouped images.

-----
Now back to the scratched image background.

I was just playing around with livecode inspector for the card.
Just to see what trouble I could find.
I got to the colors and Pattens and the properties listed the Foreground and Background selection.
I click on the Patterns button and found that I could assign a pattern as an image to the card background from the image library.

Further experimenting shows that I could change its library from Standard Icons to "This Stack"
And I realized I could see the red from my button and selected it to see what would happen.
And the background of the card turned into tiled images of my button image.

So being the tinkering genious I am I created a new image control and select my scratched metal background graphic as its content.
Then selected it and took a snapshot like the button image.

Then set the cards background patter of my scrarched metal in the "This Stack" Image Library.
Freakin heck! It worked!

-----

Also, I mentioned on this forum that I couldn't get my licensed Android app to test in the emulator.
After a full reboot its all working now.

When exiting the Android SDK and AVD Manager,
make sure the Virtual devices is selected then exit.
Otherwise if the Install packages is selected on exit
the next time you execut the AVD manager it will run thru the installed packages again.
Wasting your time. - NOPE - this does NOT work after all.

----
Running my app on windows, you'll notice my app is quite small.
But running on Android Inulator and my physical phone the background covers the whole screen.
Surprising but acceptable since thats really what I wanted anyway.

----

Questions:

While editing a card - I close it using the top right windows X close button
How do I open this card again?
That card will appear again if I close out of LiveCode with the save x button
just before the save message appears. And I just cancel the exit/save and I'm back to my project.
Is there a more logical menu item to open this card again instead having to exit?


My app on Android imulator and physical phone shows variations of max width, height as 479, 761.
Would that be 480 x 760?
Is that standard for all Androids?

Otherwise, How do I retrieve the width and heigth of whatever android phone my app is running on?


In my code copied here you'll see the double ampersand &&:
put "MouseOver: " && x && "," && y into FIELD Field1
What's the difference between the & and the &&?

Is there a way to have the text displayed as Etched text to match the scratched metal background?

I'm still wasting a lot of time with the Apply button.
Then I realize I haven't clicked the Apply button and have to start the process again.
Anyone know of a way to force the Apply?

Also, when I am editing code with the Edit (pointer) tool selected.
The mouseMove events are still firing when I drag the pointer over the card background.
Is there anyway to turn this off while in edit tool mode?

In my MouseMove even you'll see:
Pass MouseMove
What does this do?

back later
Attachments
GelButtonSample.zip
(1.19 KiB) Downloaded 306 times
Scratched Metal Background 3.zip
(149.18 KiB) Downloaded 288 times
Last edited by BarrySumpter on Sat May 07, 2011 10:16 pm, edited 1 time in total.
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

Regulae
Posts: 136
Joined: Tue Oct 20, 2009 6:05 am

Re: First app with quite a few features and questions

Post by Regulae » Thu May 05, 2011 9:13 am

Hi there,

I may not have understood correctly, but if you only want the mouseMoves registered when you are "browsing" (the tool on the top left of the toolbar, which lets you click buttons, type in text fields, etc.) rather than "editing" (the tool top right of the toolbar, which lets you select controls, moving and resizing them), you could use this:

Code: Select all

On MouseMove x,y
   if the tool = "Browse tool" then
      ##Answer "moving" && x,y
      put "MouseOver: " && x && "," && y into FIELD Field1
      ## put "MouseOver me" && x,y & "." into field Label2
      Pass MouseMove
   end if
end MouseMove
... so it only responds if the browse tool is in use.

"pass mouseMove" allows the mouseMove messages to continue through the message path, beyond the current handler. As your mouseMove handler is in the card script, "passing" the mouseMove means that the messages continue on their way through the message path, which (from the card script) is background/stack/main stack/library stacks/backscripts/LiveCode engine. In your example "Scratched Metal Background 3", not all of these are in use- there are no groups whose backgroundBehavior is set to true (thus being "backgrounds" in the LiveCode sense of the term, i.e. possibly containing scripts, as distinct from a visual background in the sense of the scratched metal pattern which you have nicely achieved in your stack), there is only one stack ("Scratched Metal Background 3") so this is the mainstack, and the example doesn't load any library stacks or backscripts. So the next script in this case is the stack script. If you put the following in the stack script:

Code: Select all

On MouseMove x,y
   if the tool = "Browse tool" then
      ##Answer "moving" && x,y
      put "MouseOver: " && x && "," && y
      ## put "MouseOver me" && x,y & "." into field Label2
      Pass MouseMove
   end if
end MouseMove
... the mouse coordinates will be shown in the message box. If you don't "pass mouseMove" in the card script, the message box will not update, as the stack script no longer gets the mouseMove messages.

"&" joins two strings, e.g. "Hello"&"there!" evaluates to "Hellothere!". Extra "&'s" adds spaces, e.g. "Hello"&&"there!" evaluates to "Hello there!". You can achieve the same effect by adding actual spaces within the quotes, e.g. "Hello "&"there!". You can see the effect by replacing the && with just & in your card script. Of course, my example was rather trivial- you could simply write "Hello there!" in the first place. A more realistic example might be, in a button script:

Code: Select all

on mouseUp
   put "The mouseLoc is: "&(the mouseLoc)
end mouseUp
... and the message box shows the actual coordinates when the mouse was clicked on the button. "&" is essential in joining things like this together.

You might like to check the User Guide (available through the Help menu) and do a search for "Shortcuts"- there's a section at the end that lists quite a few- they may well make life a little easier. There are shortcuts for applying script changes, and apply/close script editor. My notebook computer has a compact keyboard layout which affects what works for me, so I recommend you check which shortcuts work with your particular setup.

If you've closed a stack using the top right "X" in Windows (I'm using XP as well), the stack remains in memory though its window is closed, and it will normally be shown again when you shut down LiveCode, with the "Do you want to save this?" shown. I think this is what you're describing. You can reopen the stack more easily using, under File, "Open recent file" ... this gives you a list of the stacks you've most recently been working with. Perhaps this is what you're looking for.

I've only addressed questions I might be able to help with (and I've tackled them somewhat out of order), and I'm sure others will chip in on things I don't know about, or have misunderstood. I'm not deploying on Android myself at the moment, so I'm not much use on those questions. It's interesting to hear of your tests on the platform, what works and what doesn't, especially when mouseMoves are sent. I'm not sure I fully understood exactly what was happening with mouseMove:
Even though my app shows MouseOver: x,y
- it means that pointer in now over the following points of x, y
- it does NOT mean the even MouseOver
I got the code from RunRev Revolution forums and just copied it in.
I might mention that the copied code:

Code: Select all

put "MouseOver: " && x && "," && y into FIELD Field1
... might be improved by enclosing the name of the field "Field1" in quotes, so it's clear it is the name of the field, as opposed to a variable. It's very easy to get confused otherwise. Anyway, I hope some of this is of use.

Regards,
Michael

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: First ANDROID app with quite a few features and questions

Post by BarrySumpter » Thu May 05, 2011 10:03 am

What an absolutly brilliant reply.

Thanks so much for taking the time to post.
Sincerely much appreciated.

I've been a coder for 35 years.
Thanks for including the code with your reply.
So much nicer.

I've change that put code to:

put "Pointer Position x, y: " && x && "," && y into FIELD fldPointerPosition
The text "MouseOver" looks like an event name and was confusing on multiple levels.
As would have .into FIELD "fld Pointer Position".
I'm going to stay away from spaces in my control names.

I also changed fldPointerPosition to a Label control instead of a text entry field control.
(I kept getting the keyboard popping up on android to enter data into the text entry field. LOL)

The 480 x 760 is correct for my HD2 and for the Android Froyo 2.2.
Other Android phones would be differnet I'm sure.

if the tool = "Browse tool" then ...
Nice, very nice. Thanks for that solution.
That was driving me crazy when I had an error in my script that kept firing when I moved the mouse pointer.

&& = concatination and space - should have caught that myself - another nice little thing to remember

File, "Open recent file" ...
Yeah that was really throwing me off.
I couldn't really tell what was happening there and my confidence wained.
It was as if the card was no longer part of the stack.
And if I would save the stack and reopen the same stack the card wouldn't be there.
And if I had two different project stacks I could be pointing to the same card. (???)
That concept is still a bit blurry but I'll get it along the way.

background/stack/main stack/library stacks/backscripts/LiveCode engine
nice confirmation. I'll need to research those more.

Thanks again for the response.
You've given me a good kick in the inspiration.
So instead of going to sleep trouble, I'll be dreaming of what I can find next.
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

SparkOut
Posts: 2946
Joined: Sun Sep 23, 2007 4:58 pm

Re: First ANDROID app with quite a few features and questions

Post by SparkOut » Thu May 05, 2011 10:24 am

Regarding the window area and resolution questions, I dug these references out of the Android Release Notes
Windowing and Stacks
The Android engine uses a very simple model for window management: only one stack can be displayed at a time.
The stack that is displayed is the most recent one that has been targeted with the go command.
The currently active stack will be the target for all mouse and keyboard input, as well as be in receipt of a resizeStack message should the orientation or layout of the screen change.
The modal command can also still be used, and will cause the calling handler to block until the modal'ed stack is closed as with the normal engine. Note, however, that performing a further go stack from a modal'ed stack will cause the new stack to layer above the modal stack – this will likely cause many headaches, so it is probably best to avoid this case!
At this time menus and other related popups will not work correctly, as these are implemented in the engine (essentially) as a specialized form of go stack they will cause the current stack to be overlaid completely, with various undesirable side-effects.
Note: The 'go in window' form of the 'go stack' command will not work correctly in the Android engine and must not be used. Since there is only one stack/window displayed at once on this platform, a generic 'go stack' should be used instead.
Resolution handling
The engine makes no attempt to scale or adjust layout of stacks based on the resolution or density of the display the application is running on.
A single pixel on the desktop maps to a single screen pixel on Android, giving you full access to all the pixels on a device's display regardless of what dpi it might have.
When a stack is displayed, it will receive a resizeStack message resizing to the full area of the screen (minus status bar).
You can use the screenRect and the working screenRect propertiesproperties to find out the current full size of the screen, and the area not including the status bar.
HTH

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: First ANDROID app with quite a few features and questions

Post by BarrySumpter » Thu May 05, 2011 2:10 pm

Thanks for posting that info.

Getting late....

I think I'm getting confused and research tomorrow regarding LiveCode definition of
window
card
stack
sub-stack
go in window
go in stack


nice to know the resolution is solidly fixed on the android.

I'll be playing with these tomorrow:
resizeStack event
screenRect and the working screenRect properties


ALSO: how do you quit an Android stack AND remove it completely from memory?
I can
Close the defaultStack
as in my example
but if I try to execute the same stack again
the android screen just goes blank,
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: First ANDROID app - better faster easier gel button generatr

Post by BarrySumpter » Sat May 07, 2011 5:01 am

Was trying to find a super easy way to create my gel buttons again.
I wanted to make a mouse over color and a pressed color for the buttons.

I had to keep changing a number of layer colors using the previous procedures.

Instead I chased down XARA again and someone has sorted out a super simple button creator.

I've attached here in case others are interested in the technique.

hth
easy gel button 3.zip
(83.21 KiB) Downloaded 279 times
ZaraSphereGenerator.gif
ZaraGelButtonGenerator.gif
Last edited by BarrySumpter on Fri Jun 24, 2011 11:07 am, edited 2 times in total.
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: First ANDROID app with quite a few features and questions

Post by BarrySumpter » Sat May 07, 2011 10:20 pm

BarrySumpter wrote: ...
ALSO: how do you quit an Android stack AND remove it completely from memory?
I can
Close the defaultStack
as in my example
but if I try to execute the same stack again
the android screen just goes blank
...
There is also a Quit command.
executing the quit commant while editing closes LiveCode completely.

But, I might be getting confused with the "Hold HOME Button to show RECENT apps"
I thought this function would show apps still in memory.
But really only shows recent apps.
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

cu3e
Posts: 46
Joined: Mon May 23, 2011 10:03 am

Re: First ANDROID app with quite a few features and questions

Post by cu3e » Mon May 23, 2011 9:21 pm

Hello Barry, did you found a fix for the resolution problem? I think I have the same problem.

http://forums.runrev.com/phpBB2/viewtop ... =53&t=7696

BarrySumpter
Posts: 1201
Joined: Sun Apr 24, 2011 2:17 am

Re: First ANDROID app with quite a few features and questions

Post by BarrySumpter » Tue May 24, 2011 1:39 am

I've hard coded my screen size to 480 x 760 form my HD2.
I did test on my actual device and decided on a button size.
But this could change at any time. Depending on the need of the specific app.

At this stage it would be nice to sort something out but for me not required.

As posted above:
Resolution handling
The engine makes no attempt to scale or adjust layout of stacks based on the resolution or density of the display the application is running on.
A single pixel on the desktop maps to a single screen pixel on Android, giving you full access to all the pixels on a device's display regardless of what dpi it might have.
When a stack is displayed, it will receive a resizeStack message resizing to the full area of the screen (minus status bar).
You can use the screenRect and the working screenRect propertiesproperties to find out the current full size of the screen, and the area not including the status bar.

So using the
Stack
On resizeStack
-- adjust my controls based on screenRect
End resizeStack

I think elenor posted an example of how to resize text on resizeStack
Have a look at the code. Maybe there is a formula we can take advantage of.

=====
After another look it looks like the square background you have behind your button is a graphic.
You need to leave the grapic there but tick Visible OFF
and have lock size and position ticked ON.
then edit the card background pattern (I think like we did in Webinar 2)
(sorry in the middle of installing a new windows so I don't have immediate access to my development environment nor all the proper words)
and select "this stack" and select that graphic.

Then use the resizeStack as mentioned above.

hth
All my best,
Barry G. Sumpter

Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.

Post Reply