Tuesday, July 5, 2011

Greek Tragedy

You may be asking yourself: what is going on in Europe with this so-called debt crisis? Why is everyone freaking out about Greece? What's "contagion", and is their an ointment for it? Is there a financial zombie apocalypse happening? I'm going to try and answer all these questions. This is an interesting topic because people make it more complicated than it is. You can actually relate it to things like your household budget very easily.


Let's start simply, with budgets. Countries, like households, have income and expenses. Countries get income through taxes. Taxes tend to be related to a countries gross domestic product (GDP), so the more stuff a country makes, the more its government makes in taxes. If a government spends more than they earn in a given year, it is called a deficit. Do this enough, and that will lead to debt.

Debt isn't a bad thing, as long as it is a reasonable percentage of income. Most of us are comfortable going into debt to buy a house or a car. In Canada, household debt as a percentage of yearly disposable income has steadily increased from 90% in 1990 to about 140% today. The same idea can be applied to countries. For example, Canada's debt to GDP ratio is about 34%, which is reasonable. However, this is only the debt owed to Canadians, called "internal debt". We also have debt we owe to foreigners, which is about 75% of GDP. This is called "external debt".

You may be asking, how can countries have debt? Where does the money come from? Let's go back to our household. Say you buy a house and get a loan from the bank. This is "external" debt, because you borrowed from someone else. But say you want to buy a car but the bank won't lend you money. You could raid your kids college fund, or you borrow from your rich aunt. These could be thought of as "internal" debt.

How do these translate into a countries debt? Well, most countries issue bonds, which are basically I.O.U.s which both citizens and foreigners can buy. You give the government some cash and the government promises to pay you back. The interest rate the government agrees to give you depends on a how risky lending them money is. Stable countries have relatively low interest rates because they don't need to entice people to give them money. Unstable developing countries need to pay more to entice people to give them money because there is a real risk that they could default. The free market determines the interest rate on bonds. For example, the current Greek 2-year bond rate is 28% (i.e., if you lend Greece money for two years, they'll give you 28% a year interest!) Compare this to Canada's 2-year bond rate of about 1.5%.

What does "Greece has a debt crisis" mean? What it means, basically, is Greece spends more than it earns, and it can't make regular payments on the debt it owes to citizens and foreigners. As of 2010, Greece owes 165% of GDP to foreigners (mainly European banks) and 130% of GDP to citizens (mainly entitlement programs like pensions and benefits). Because they are having trouble paying people, no one will lend them any money, and if they will, it is at insane interest rates. This is like not being to pay down a credit card with 10% interest, so you get a credit card with 20% interest to try and make payments -- clearly not a sustainable situation.

(I'm going to take a quick aside here. You may be thinking, "Why do countries have to ask anyone for money? Why don't they just print it?" Some countries do that. The U.S. is doing that right now with their "quantitative easing". The problem is that unless you are a totally self-sustaining country, you have to buy stuff from other countries. If you debase your currency too much, the price for other stuff like oil and grain will just keep getting higher and higher. Eventually, when everyone loses confidence in your currency, hyper-inflation happens. For example, Zimbabwe has a $100 trillion dollar bill.)

Since Greece is a part of the European Union, the fact they are in trouble is affecting everyone. The European Union will help them out, BUT Greece has to get things under control. Foreign banks have put pressure on Greece not to restructure the debt they owe to them (restructure is a fancy term for saying: "I'm broke, so do you want some of what I owe you or none?") Internal debt is much easier to muck around with, so that is what Greece is doing.

Just like we raided our child's college fund to pay for our car, countries can do similar things. Eliminating pensions and benefits are one way. Pensions are a liability, whose cost is born by future generation. To get Greece's spending under control (so Greece can continue to pay back debt to foreigners), the EU is asking them to undertake "austerity measure" (also called "belt tightening" or "belt selling and giving the profits to banks"). If Greece does this, the EU will lend them some more money.

Let's create a detailed example to show what is going on. You buy a house, and are paying a $1000/month mortgage. You want a car, so you take the money out of your kids college fund, and are repaying that back at $500/month. Then your wife loses her job so your monthly income takes a hit. What do you do? You start getting credit cards, at progressively higher interest rates to continue living the life you are accustom, plus paying down your mortgage and replenishing the college fund. But things reach a breaking point. No one will lend you more money. So you go to your rich aunt and say, help, I need money. She looks at your situation and says, "Okay, I'll lend you the money, but you need to balance you budget. You can't spend more than your earn, so you'll have to cut back. No eating out and no new video games. If you do that, I'll lend you the money." You say, "Auntie, don't you know the bank manager? Perhaps he can reduce my mortgage so I can pay less per month?" The bank manager is not pleased to hear this, which your Aunt conveys to you. "Sorry, I think you're going to just have to stop paying into the college fund until you get back on your feet." Given all the pressure, you relent. You cut back (but wife and kids aren't happy), and the college fund payments stop, but the mortgage payments continue on at the same rate, and you get some much needed spending money to make it to next month.

Sounds like a reasonable story, right? Wrong. Greece (and Ireland) should do what Iceland did, and that is say "screw you" to the bank. Iceland had huge foreign debt, but rather than destroy their own country for some foreigners, they shared the pain all around. It isn't perfect. But defaulting is a safety valve in the capitalist system, and is required. The reason is there are always two parties to every transaction: a lender and a lendee. Both have to be kept responsible so neither abuses the system. Lenders have to do their due diligence to make sure they are lending money to people who are able to pay it back. Also, lendees have to be responsible and not take on too much debt. But when things get out of control, all parties involved need to share the pain.

Don't get me wrong, countries like Greece have to stop this insane socialist experiment and balance the books. Democratic governments always have this danger: that they will get caught in a cycle of bribing people with their money. As Thatcher said, "Socialism works until you run out of other people's money to spend."

The final issue is this stupid word "contagion". I hate it. It sounds like financial crises are colds that other people can catch. This is nonsense. The reality is if one person in a community gets laid off, then chances are others are getting laid off too. If a recession hits a community and a bunch of people's houses got foreclosed, you wouldn't say, "We've got to get this foreclosure contagion under control before it spreads to other people." The PIGS nations (Portugal, Ireland, Greece, and Spain) are in trouble because they spend more than they earn. If other nations (I'm looking at you Italy) start having the same problems, its not because they were infected with anything, but because they too spent more than they earned.

Saturday, July 2, 2011

How I Learned to Stop Worrying and Love the Mart

Revelation Chapters 6:12: "And I beheld when he had opened the sixth seal, and, lo, there was a great earthquake; and the two most unholiest of shoes were joinithed togetherith, forming a monstrosity which shall markith the feet of his dark army."

This picture was taken at Walmart, which many consider the evilest of stores. In this blog post, I'm going to try and convince you of something: Walmart isn't really that bad.

I watched a documentary about Walmart (I think it was "The High Cost of Low Price") and it made me not like Walmart. I didn't shop there for years and instead went to Zellers or Superstore. After a few years of pain and suffering, I changed my mind.

Zellers is that absolute worst store in the world for customer service. I have left my basket (full of stuff) and walked out of Zellers more than any other store I've been to. These people just do not want my money.

Question: How many idiot cashiers does it take to determine the price of a can of beans? Answer: It is actually a trick question. It takes three of them, milling about, to figure out they need to call a manager to come over and answer it. When the line-up goes back into the housewares section, it is time to get off your cell phone and open another till.

Many Zellers have self check-outs, which are awesome because 4 tills can be watched by one person, but they never use them. Instead, they have gone to the committee-of-three cashiers model because apparently they only hire people with 1/3rd of a brain. Cashiers are the one place where you want an abundance of staff, because that is where money changes hands.

The other day at Safeway, I tried to buy a chocolate bar and the scanner wasn't recognizing it. The cashier asked a bagboy to go check the price, and I said forget it. The cashier said to me, "Can I offer you the chocolate bar for 50 cents?" Impressive customer service.

Which brings me to Walmart. That store is a joy to go to. The aisles are wide, the staff are friendly, and they get you through those tills fast. There are always dozens of cashiers on.

I'm going to try and read your mind. Right now you are saying:
"But Walmart destroys mom and pop stores."
"Walmart treats its employees bad and bust unions."
"They keep prices too low." What?

Mom and pop stores suck. There, I said it. My wife worked retail for years. Small business owners are crappy to their employees. Here's an actual conversation:
  • "So, there will be a staff meeting on Sunday for 1 hour after the store closes."
  • "You know that you have to pay everyone a minimum of 3 hours, right?"
  • "What?"
  • "That's the law."
  • "I've never heard of that. I'll tell you what, I'll make it 45 minutes, and I'll bring it cookies."
  • "You can bring in anything you want, but you have to pay us for 3 hours."
My wife was never invited to a staff meeting again. You think Walmart can pull that sh!t?

I remember when I worked for Dairy Queen back in GP, the owner used to get some of us guys to go over and mow his lawn and do general yardwork -- during work hours. There is no way that is legal. The mythical mom and pop don't exist -- all business owners are dicks.

The advantage to mom'n'pop stores is that mom and pop will spend money in the community and not ship it back to corporate headquarters, or to foreign shareholders. This is one of the best arguments against Walmart. Unfortunately, it doesn't carry the weight on we look into it.

Let's take the Croc-o-pedic shoes in the photo above. Let's say they cost $10 at Walmart, which can be broken down into:
  • $5 - wholesale cost of shoes, which goes to some Chinese manufacturer
  • $2 - wages to employees
  • $2 - overhead like rent and power
  • $1 - profit to head office and/or shareholders
The problem with mom'n'pop stores is they buy the same stuff from China, but they don't have the clout to get them to lower their prices. So you get the same foam-a-geddon shoe, but its more expensive, say $15.
  • $7 - again, wholesale to China
  • $4 - wages (assuming mom'n'pop are better to their employees)
  • $4 - overhead (because they have a smaller store that is not in some industrial park, so the relative cost is higher)
So in this example, buying your mac-goofy-shoes at Walmart causes $6 to leave the community, while buying them at mom'n'pops pulls $7 out of the community. This is just ignoring the fact you spent more of your hard earned money on the shoes. The only time that mom'n'pop stores have an advantage is when they are selling locally made products. In that case, I fully support local businesses. But if you are buying Chinese-made shiny crap, then buying from mom'n'pops is just throwing your money away.

Note: I have nothing against Chinese products. They are awesome. But America really screwed up. You know the expression, "A capitalist will sell you the rope to hang him"? In the pursuit of short-term profits, they outsourced all their knowledge. So now, there is really nothing China can't make. I for one, will welcome our Chinese overlords.

On a final note, the reason these fitness shoes alegedly work is they make it more difficult to keep your balance and walk, so you have to work harder and therefore burn calories and tone your muscles. I see elderly people wearing these and I think, What the hell are you doing, this is going to make you more likely to fall. I guess you'll lose a bunch of weight when you are in the hospital with a broken hip.

Tune in next time when we open the Seventh Seal of the Apocalypse!

Sunday, June 5, 2011

Creating my first Android app, Part 4

This is the last post in a four part series. Go here to read Part 1, Part 2, and Part 3.


This is the final blog about creating apps. First, I'm going to clean up some functionality from the last blog. Second, I'm going to show you how to email a note.

If you "packaged" the app and downloaded to your phone, you would notice it worked, but notes would not be saved between instances of the program. Actually, the notes are saved, but the list of notes aren't.

Here's the solution. We need to store the list of note titles in the database every time we save a note, and then load them every time we try and load a note. It involves modifying two blocks. First, modify the [ButtonNoteSave.Click] block:

  1. Click [My Blocks], click [DatabaseNotes], click+drag [call DatabaseNotes.StoreValue] just below the [call add items to list] block.
  2. Click [Built-In], click [Text], click+drag [text text] to the "tag" slot. Click on the second "text" on the [text text] block, which allows you to edit it. Rename it "TagNoteTitles". This will be the tag where we will store the list of Note Titles. Confusing enough for you?
  3. Click [My Blocks], click [My Definitions], click+drag [global ListNoteTitles] to the "valueToStore" slot.
Now when you save a note, the current list of note titles will be saved into the database. That way, if we close the app and start it again, that list of titles is stored. As I said before, there is no easy way to extract what exactly is in the database, so we need to keep track of it.

Second, we need to load the list. This can be done in several different places, but for simplicity, lets do it before we load a note. We need to modify the [ListNoteLoad.BeforePicking] block.
  1. Click [My Blocks], click [My Definitions], click+drag [set global ListNoteTitles to] just above the [set ListNoteLoad.Elements to] block.
  2. Click [My Blocks], click [DatabaseNotes], click+drag [call DatabaseNotes.GetValue] to the "to" slot.
  3. Click the block we created above named [text TagNoteTitles]. We want to copy it, so press CTRL+C, and press CTRL+V. This should create a duplicate of this text block which we can drag over to the "tag" slot on the [call DatabaseNotes.GetValue] block.
So before we load a note, the list named "ListNoteTitles" is pulled from the database.

Emailing a note

On to being able to email yourself (or some other person) a note. The biggest problem I had with other note apps was the notes were trapped on the phone. To get them off, you had to cut and paste the note into an email.

The basic idea is the note title is the email subject, the note message is the email body, and the email address in the TextBoxEmail is where the email is to be sent. The app will call a component called Activity Starter (which we named AppEmail). Activity Starter can be used to start the camera, open the browser, open a map, etc.

The steps are below:
  1. Click [My Blocks], click [ButtonEmail], click+drag [when ButtonEmail.Click] to the editor.
  2. Click [My Blocks], click [AppEmail], click+drag [set AppEmail.Action] to the notch.
  3. Click [Built-In], click [Text], click+drag [text text] to the "to" slot. Edit the text to say "android.intent.action.VIEW".
I'll be honest; I'm not sure what this does exactly. But I read it on another blog and it works. Did I shatter any ideas you had that I wasn't a hack? Good. Now we have to pass all the interesting information to the Activity Starter. This involves a huge string of text with the email address, subject, and body.
  1. Click [My Blocks], click [AppEmail], click+drag [set AppEmail.DataUri] to the notch below [AppEmail.Action].
  2. Click [Built-In], click [Text], click+drag [call make text] to the "to" slot.
  3. Click [Built-In], click [Text], click+drag [join] to the "text" slot. The [call make text] block will create a new open slot named "text". Click and drag two more [join] blocks to the [call make text] block so there are three total.
  4. Click [Built-In], click [Text], click+drag [text text] to the [join] blocks. It needs to go to the first slot. Do this three times for all three [join] blocks. Edit them to say "mailto:", "?subject=", and "&body=".
  5. Click [My Blocks], click [TextBoxEmail], click+drag [TextBoxEmail.Text] to the top right [join] block. The other two need to be filled in with [TextBoxTitle.Text] and [TextBoxMessage.Text]. I think you are getting the hang of this by now.
  6. Click [My Blocks], click [AppEmail], click+drag [call AppEmail.StartActivity] to the notch below [set AppEmail.DataUri].
When the [Email Note] button is pressed in the app, your email program will come up ready to send the note. All you have to press is [Send]. (Your phone may ask you to specify which mail program to use, if you have more than one.)

So there you go! You have a useful app for recording, playing, storing, and emailing notes. You can go on to add a bunch of extras, like bitmaps for the buttons, icons for the app, etc. to make your app look really pretty (see the picture above for my finished app -- note the gaudy yellow/red/blue color scheme). If you have any questions, please feel free to post comments on my blog. They are moderated (only because I was getting a bunch of Chinese spam) but I usually respond within a day or so. And by "so", I mean weeks or months later. Or never. These are all acceptable definitions of "so'.

I may, at sometime in the future, decide to bore everyone again, and post some of the games I've made. Or maybe not.


Wednesday, June 1, 2011

What catchy title for a post uses the word thermodynamics?

Understanding thermodynamics can help you in the world (seriously). There are four laws of thermodynamics, but one and two are most interesting. They are paraphrased below:

Law 1 - Energy cannot be created or destroyed, it can only change form.
Law 2 - When changing form, some energy is always lost as waste heat.

Put another way: "Not only can you not win, you can't break even."

Practical application #1
I read a story about a plan to put wind turbines near a highway to try and recapture the wind created by the fast passing cars. Sounds like a great idea, right? Use Law 1 above and tell me what is wrong with it.

Where does the energy come from? When the highway is empty, the wind turbine won't turn, so the cars must be providing the energy. And that is exactly what they found when they tested it. The fuel efficiency of each car was found to be reduced slightly. The energy created by the cars was being changed from mechanical energy (motion of the car) into wind energy (motion of the air molecules) into mechanical energy (motion of the turbine) into electrical energy.

The worst part is, as Law 2 states, every time you change form, you waste some energy. So you are basically burning gasoline to create electricity, but in the most inefficient way possible. It is sort of a Rube Goldberg contraption of idiocy.

So you may be asking yourself, "Where exactly is the practical application of thermodynamics you promised?" And here it is. You can yell at the monitor when you read these types of dumb ideas and your partner and/or dog and/or fish and/or D&D action figure can nod their head at how smart you are. Or maybe shake their head at how crazy you are. I'm not sure.

Practical Application #2
If the 1st practical application wasn't enough, here is a second one, which actually involves money and prison!

I had a co-worker pitch an idea for an invention to me. He said that his brother-in-law had a patent for a machine that could generate energy very cheaply. It was made from an outer hub with seven magnets, which was attached to an inner ring with .... (he paused and looked around, like he was about to blow my mind and didn't want any other minds around us to blow -- no collateral mind blowing) six magnets. "Because the magnets are spaced like that, the hub magnets are always pushing the ring magnets around, like a merry-go-round that never stops."

I'm sure you've all heard of perpetual motion machines. Now contrary to popular belief, the US Patent office will not reject the filing of a patent just because it is for a perpetual motion machine. However, it does stipulate that a working model must be provided before the patent will be granted. Needless to say, that has never happened.

Here's the thing. It is possible to build a "perpetual" motion machine with magnets. The reason is magnets do have energy in them, so as the machine moves it will slowly weaken the magnets. This obeys Law 1. However, taking the final step and trying to generate electricity from it can be a tricky step. Law 2 says that every time you try and change the form of energy, you piss some of that energy away. So the very act of hooking up a generator to your spinning 13 magnet science project will cause it to either spin slower or maybe weaken the magnets faster. In any case, you are just using the magnets like batteries and they will eventually die out, requiring you to get more magnets.

You may have been waiting for the money and prison part. Here it is. My co-worker told me about this incredible invention and asked me if I wanted to invest in it. His brother-in-law was selling stakes in the company, which could be "worth millions". I explained how perpetual motion machines were impossible without an energy source. My co-worker looked at me, and then tried to explain the 6 magnet / 7 magnet configuration again. He even produced a sketch on some graph paper which "proved" it. Did I mention this co-worker had a degree in Engineering? I politely looked at his sketch and explained that you couldn't violate the first or second law of thermodynamics, which this idea clearly did. I warned him that he should not invest, and should explain thermodynamics to his brother-in-law next time they meet. "Well, I won't be seeing him for a while. He's in prison on fraud charges." I got up and slowly backed out of his office, which was a surprisingly awkward way to leave an office.

Moral of the story: There is no thermodynamic law against being a moron.

PS. I swear to dog this story is true.

Sunday, May 29, 2011

Creating my first Android app, Part 3

Go here to read Part 1 and Part 2. (Note: I have slightly edited the previous posts, changing the name of one textbox to TextBoxMessage instead of TextBoxNote.)

Blogger is being a jerk, so I had to d/l Google Chrome to compose this. What's that? You don't care? You just came here to eat my brains and gain my app knowledge? Okay, on with the meager meal.

We will be doing something very complicated today: storing notes in a database which can then be retrieved using the ListPicker component. We will be building the functionality behind the [Save Note] button and the [Load Note] "button". The latter is an air quote "button" because it is actually a listpicker element that looks like a button.

One of the components we put into our app was a TinyDB (which we named DatabaseNotes). This database works by storing stuff under a tag. For example, you could store your age ("39" in my case) under the tag "age". The nice part about TinyDB is that it stores stuff even after you turn your app off.

We will store our notes, which consist of a title and a message, to the database using the title as the tag. That way, we can search the database for the title and reload our note.

Let's start with the [Save Note] button. When we press it, we need to save the note in the database (using the title as the tag). But we need to think further ahead. How are we going to get the note back out? There is no easy way to pull out all the tags from the database, so we need to keep a list of all the tags we put in. The way to do this is with a list.

A list is an 1-dimensional array. If that description made things more unclear, then a list is a list of things. So a list can be a list of numbers or a list of names or a list of titles. We will create a list of note titles and store it in the database, so we can pull it out, choose a title of a note, and then load the note.

I think I've talked too much. Let's do some programming. I'm assuming you've opened up your app in App Inventor and opened up the Blocks Editor. First, define our list of note titles:

  1. Click [Built-In]. This is where all the build-in blocks are.
  2. Click [Definitions].
  3. Click [def variable as] and drag it to the editor.
  4. Click on the "variable" and type "ListNoteTitles".
  5. Click on [Built-In], click on [Lists], click on [call make a list], and drag it to [def ListNoteTitles as] and plug it in. This will define a list called "ListNoteTitles" which we can later store our list of note titles in.
Next, the [Save Note] button.
  1. Click [My Blocks], click [ButtonNoteSave], click [when ButtonNoteSave.Click] and drag it to the editor. This will allow us to define what happens when the [Save Note] button is pressed.
  2. Click [My Blocks], click [DatabaseNotes], click [call DatabaseNotes.StoreValue] and drag it to the editor. There is a notch at the top of it. Fit this into the spike on the [when ButtonNoteSave.Click] block.
  3. Click [My Blocks], click [TextBoxTitle], click [TextBoxTitle.Text], and drag it and plug it into the "tag" slot.
  4. Click [My Blocks], click [TextBoxMessage], click [TextBoxMessage.Text], and drag it and plug it into the "valueToStore" slot.
This will save the note to the database, but we also need to save the note title to the list of titles, and then save that list of titles to the database.
  1. Click [Built-In], click [Lists], click [call add items to list], drag it, and put it below the [call DatabaseNotes.StoreValue].
  2. Click [My Blocks], click [My Definitions], click+drag [global ListNoteTitles] to the "list" slot.
  3. Click [My Blocks], click [TextBoxTitle], click+drag [TextBoxTitle.Text]to the "item" slot.
Unfortunately, there is really no way to test this to see if it is working. We need to build the [Load Note] button first. There are two parts: before picking from the list and after. Before we pick from the list, we need to define what the list is.
  1. Click [My Blocks], click [ListNoteLoad], click+drag [when ListNoteLoad.BeforePicking] to the editor.
  2. Click [My Blocks], click [ListNoteLoad], click+drag [set ListNoteLoad.Element to] and attach it to the notch in [when ListNoteLoad.BeforePicking].
  3. Click [My Blocks], click [My Definitions], click+drag [global ListNoteTitles] to the "to" slot.
This populates the list with all our note titles. After we choose which note we want to load, we need to copy the note from the database to the text boxes.
  1. Click [My Blocks], click [ListNoteLoad], click+drag [when ListNoteLoad.AfterPicking] to the editor.
  2. Click [My Blocks], click [TextBoxTitle], click+drag [set TextBoxTitle.Text to] and attach it to the notch in [when ListNoteLoad.AfterPicking].
  3. Click [My Blocks], click [ListNoteLoad], click+drag [ListNoteLoad.Selection] to the "to" slot.
  4. Click [My Blocks], click [TextBoxMessage], click+drag [set TextBoxMessage.Text to] and attach it below [set TextBoxTitle.Text to].
  5. Click [My Blocks], click [DatabaseNotes], click+drag [call DatabaseNotes.GetValue] to the "to" slot.
  6. I'm going to show you a short cut. Click on the [ListNoteLoad.Selection] block, press CTRL+C, and press CTRL+V. This created a duplicate! Click and drag the duplicate to the "tag" slot below.
Test out the app on your phone. Press the [Record] button on your phone and say "test". Press the [Copy to Title] and [Copy to Message]. The text "test" should show up in both text boxes. Now press the [Save Note] button. Nothing should happen: SUCCESS! Next press the [Load Note] button. The screen should go black and you should see the word "test". Click on it and you should go back to your app and everything will look the same. Again, SUCCESS! Okay, to really test if things are working, repeat all those steps except say "best". Now when you press [Load Note], you'll see "test" and "best". Pressing "best" will load that into both text boxes.

My eyes are going blurry looking at all this code. I'll show you how to email a note to someone next time.

Go here for Part 4.




Monday, May 23, 2011

Creating my first Android app, Part 2

Go here to read Part 1.

Now that all the components have been created in App Inventor, it is time to open the Blocks Editor and make the App actually work. Remember, the first part of App Inventor is like the clock-face, creating the look of the app. The second part is the Blocks Editor which creates the clock-mechanism, or how the app functions.

Before you do that, you can clean up the look of the apps by using Screen Arrangements to group buttons together. I grouped mine together like this:
[Record] [Play]
[Copy To Title] [Copy To Message]
[New Note] [Save Note] [Load Note]
[Email Note] [Play Note]

Now, click the [Open the Blocks Editor] button. This will download and run a Java program. You can connect to your phone by clicking the [Connect to Device...] button and selecting your phone. This will allow you to demo your app in real time and make sure it is working.

The blocks editor is like a sand box where you can create blocks of code which do different things. If you are familiar with coding with programs like Pascal or Visual Basic, this is going to look weird. There is no where to type out the code! Not very powerful but very user friendly.

Let's start with a simple one. What happens when we push the [Record] button in our app? We want to open up the SpeechRecognizer app, record some text, and then put that text into a text box. Here are the steps:
  1. Click on [My Blocks]. This is where all the components you defined in App Inventor are. Now it should be clear why I named everything the way I did: because all your blocks are in alphabetical order. So all the buttons are grouped together, all the text boxes are grouped together, etc.
  2. Click on [ButtonRecord]. For component [ButtonRecord] there is a bunch of stuff you can do to interact with it. These different things are called "blocks". They are colored green, purple, dark blue, and grey. Green blocks allow you to do stuff when the component is interacted with (e.g., press a button). Purple blocks call other programs. Dark blue blocks set the properties of components (and have a puzzle piece shape on the right). Grey blocks are variables which represent the current properties of components (and have a puzzle piece on the left).
  3. Click on [when ButtonRecord.Click]. This is one of the green blocks. When the [Record] button is pressed in our app, this block tells the app what to do. Click the block and drag it to the editor.
  4. Click on [AppSpeechRecognizer]. Click on the purple block named [call AppSpeechRecognizer.GetText] and drag it to the editor. Notice there is a notch at the top of it. That should fit into the spike on the [when ButtonRecord.Click] block. They should click together. Now when the [Record] button is pressed, the Android built in app which translates speech-to-text should run. Try it now on your phone.
What happened? It should have worked. Except where did the text go? We have to do a few more things before the text goes somewhere. Go back to the block editor:
  1. Click on [My Blocks]. Click on [AppSpeechRecognizer]. Click on [when AppSpeechRecognizer.AfterGettingText] and drag it to the editor. Notice that there is something called "result" on the right which has a value of "result". The text that the voice-to-text created is stored in a variable called "result".
  2. Click on [TextBoxVoice]. Click on [set TextBoxVoice.Text to] and drag it to the editor. Attach it to [when AppSpeechRecognizer.AfterGettingText].
  3. Click on [My Definitions]. The value "result" is here. This is where stuff that isn't specifically associated with any one component is stored, like global variables. Drag [value result] and plug it into [set TextBoxVoice.Text to]. Try the [Record] button on your phone again.
Now what you say should appear in the Voice Textbox.

For the end of Part 2, create the functionality of the [Play], [Copy to Title], and [Copy to Message] buttons. Below is what the blocks editor should look like.

Go here for Part 3.



Sunday, May 22, 2011

Creating my first Android app, Part 1


I have an android phone (Samsung Galaxy S - model SGH-I896). I love all the app's that can be downloaded, for practically anything purpose you can think of. Google recently came out with an app creator called App Inventor. I created an app for my phone which I find really useful. I was thinking about uploading it to the Android Market, but that would cost me $25. Instead, I'll write some blog post that will be very very boring to any normal person, but maybe some budding programers will enjoy it.

First, you must install App Inventor. This requires a google email address. (These first few steps are going to be pretty sketchy, because since I have now installed everything, I can't remember what to do.) App Inventor is a two-part program. First, it is a web-based app creator which allows you up create the look of your app (images, buttons, text boxes, etc.) Second, it calls a Java program which downloads and runs. This program allows you to program the logic behind your app. Think of them as the clock face and the clock mechanics.

The most difficult part to creating your app is actually downloading and installing all the appropriate drivers for your phone. This took me several days to do. I had to update my phone to the latest android version (2.2). After much google searching, I found all the drivers for my phone (both 32- and 64-bit) and saved them to a directory called c:\drivers\. Everything finally worked.

So you've installed App Inventor and have all the drivers for you phone. Now it's time to start creating an app. (Don't forget to set your phone to development mode in Settings->Applications->Development.)

If you've never programmed before, you may want to stop reading right now. Sorry I didn't put this earlier. Wow, you are tenacious. Next step is to do all the tutorials. These will help you understand how App Inventor works.

The app I created is called VoiceBox. The reason I created it is I haven't found a notepad app I like. Android has voice-to-text and text-to-voice features which I thought would be great for an app. Imagine creating a grocery list by talking, and then play it back to yourself. What? Why would you want to play back a grocery list when it is just as easy to look down and read the list? This is a great question. I'll save it as a note in VoiceBox and play it to myself later.

You will need these components:
  • Eight (8) Buttons named ButtonRecord, ButtonCopyToTitle, ButtonCopyToMessage, ButtonPlay, ButtonNoteNew, ButtonNoteSave, ButtonEmail, ButtonPlayNote.
  • One (1) ListPicker named ListNoteLoad.
  • Four (4) TextBox named TextboxVoice, TextboxTitle, TextboxMessage, TextboxEmail
  • One (1) TinyDB named DatabaseNotes.
  • One (1) ActivityStarter named AppEmail.
  • One (1) SpeechRecognizer named AppSpeechRecognizer.
  • One (1) TextToSpeech named AppTextToSpeech.
Drag all these components to the viewer and name them as above. Your app inventor should look like the screen shot below. I've realized these series is going to take several blog posts, so I'm going to leave it here. Stay tuned for more "exciting" slash "incredibly boring" posts in this series!

Go here for Part 2.