Monday, January 31, 2011

Google App Inventor and my first real program

First, a little background.  In Jr. High I was able to program in HTML.  Nothing too fancy, but in 1998 it was good enough to create a website that had a few thousand hits a month (on Geocities at that).  In High School I had a class in C++ and Flash.  In college I had classes in VB and Java.  Outside of HTML, I sucked at each and every one of them.  I learned enough to pass the classes, but I never was able to grasp the languages.

A few weeks ago I heading to bed when I remembered I had to remind my roommate of something.  He happened to be driving home at the time so I didn't want to send the message right away.  Plus, he needed the message while he was at work, two hours away.  I checked online to see if there was an app that could send a predefined message after a set time, but it doesn't exist as far as I could find.  So I had two choices: Send a message that may distract him and cause him to wreck, or stay up until 1:00am just to send a message.  I chose option three, I didn't send the message and he didn't remember.

This wasn't the first time I found a need for a message delaying program, so when I discovered that Google was providing a way to program for the Android that supposedly anyone could use, I jumped on it.  That was Friday, It's now Monday and I've finished my program.



The first thing I noticed was the basic user interface.


Simple enough, pick your object on the left, place it in the WYSIWYG screen in the middle, and set the settings on the right.  So I started by setting up the user interface.  Buttons, text boxes, selections.  Then I tried to edit the coding behind it, I got some weird error.  It was asking for some path.  Took me half an hour to figure out what was wrong.  Turns out, if I read the instructions, I would have found out I needed to install a client side and the drivers for the phone.

Once that was done, I was able to open the "Blocks Editor."  From there I quickly found that the objects I had placed on the WYSIWYG screen showed up on the left and other functions.  I could put them on the empty canvas and then put the functions together like a puzzle.


Took a little bit of time to get it all straight.  I had to keep in mind that in computer talk 1 second is 1000 milliseconds.  So an hour is 3,600,000 milliseconds.  Keeping that in mind, I set the program to take every minute set and multiply it by 60,000 and every hour set by 3,600,000.  That way the timer I set would run for the hours and minutes I set.  Lots and lots of numbers and math to figure out.  Too bad it didn't work.

I got it to send the message after the correct delay, but the countdown timer didn't work.  The first problem was that it didn't count down every second, more like every 1.01 seconds.  Not much, but that ends up to be about 2 seconds off per minute.  Then I found that when I just set it for one minute it would give random countdown times.  It would start at 60 and count down, but when I stopped it and started it again, it would start again at 35 or some other random number.  I worked on it for hours, couldn't figure it out.  I even looked it up online and found this huge section of code just for that.  I didn't believe it could be that much code just to do a countdown.

I had things to do Saturday and Sunday so I didn't work on it.  Monday I finally figured out what was wrong.  The timer function isn't truly a timer, it's a clock.  The clock keeps track of the date, time, and timer functions.  When I called it to see where it was in the count down, it would return the current second in the system time, not the true countdown time.

The only other countdown timer code I could find was the giant one I found earlier.  After I finally dug into it and tried to understand it, I found it wasn't just functional, it was better then what I was trying.  I don't fully understand what it does at the beginning, but it works.

After a lot of fiddling, it works.  You just type in the message, pick your contact or you can type in the number manually, and you set the hours/minutes/seconds and hit send.  It's the most complex program I've ever made and the first I think is worthy of giving to others.  And here it is.  Both the app (the .apk) and the source code (the .zip).  I don't know how to set the final settings to put it on the app store so you have to check the box for non-signed apps.  As for the source code, just import the .zip into the Google Apps Inventor interface.

For testing, you can ether use your Android phone directly, or you can use the built in emulator.  It's slow, but it should be good enough to test the code.  Nothing to install there, probably runs off of Google's servers and is why it's slow.


In the end I'd have to say that the Google App Inventor is not for everyone.  To truly understand what is going on where, you do need some basic coding understanding.  For example, telling it to see if something is not like something else and doing something in that case; you have to create in if statement and tell it "not something equals something else".  Not vary intuitive, but that's the nature of computers.


So, while it's not for everyone, prepare for an influx of Google apps.  Hopefully a reasonable amount will be good.  Definitely worth a look.

No comments:

Post a Comment