My first Android App

This is a step-by-step guide that you can copy to get a working app.

Getting started:

You will need:

  • A computer with internet
  • An android phone.
  • A way to connect it to your computer (USB cable or I hear there is another app you can use to have your phone talk to your computer).

Get Set Up

1.  Download and install the Android Software development kit

It will take a while.  While waiting:

2.  In your phone, find and turn on the ‘debug mode’ setting.  Different versions of android have it in different places.  The latest version of android (4.2+ I believe) requires you to tap 7 times at the bottom of the settings screen!  The point is to get your phone to allow downloads from your usb cable without warnings or needing anything signed.

3.  Connect your phone to your computer.  If you get a warning saying ‘drivers not installed’ then you will need to look up the model number of your phone and find the driver online and install it.  For example, my phone was a Kyocera Rise Model c5155 so I just googled that and it took me to the page.

The code

4. You can find your own code online somewhere or you can just create an empty file called index.html and put an image it using word or whatever.  If you want to use my code, go and do File->Save Web Page and save it as index.html.

5. Zip it up.  This means selecting the files we made/saved and right-clicking them and “add to zip file”.  If you don’t have winzip, go download it.  You can also use winRar (free).

6.  Submit your zip file to PhoneGap (click here for link).  You will need to make an account.  Submit your zip file and wait a bit and it will show you it building.  When the Android build is done (It also will build windows phones, iOS, blackberry versions of your app), click on the .apk button for the app and it will download to your computer.  In my case the file was called crApp-debug.apk.  Now you need to get it on your phone.

Getting it on your phone

7.  Run the Android Debug Bridge.  In your Android SDK you downloaded and installed (You do remember where you installed it, right?), find the platform tools folder.  Somewhere In there is a small executable file called adb.exe and a couple .dll files.  You will probably have to look a bit to find it.  We need to run that adb executable with the command “INSTALL” and the name and full path of your app.

Command line way:

Copy the .exe and .dll files over to where you downloaded the .apk file.  Now in the windows command prompt (Windows->run->’cmd’) navigate to the directory you copied the files.  (or add the directory to your PATH environmental variable)  In my case it was my downloads directory c:/users/J/Downloads.  So I type ‘cd C:/users/J/Downloads‘.    Now type:  “adb install -r crApp-debug.apk” where crApp-debug is the name of your file.  The -r stands for ‘overwrite’.

Windows shortcut way:

Make a shortcut to adb.exe (right-click->send to desktop) and edit the command line properties (right-click->properties->target).  In my case it looked like this:  “E:\Program Files (x86)\Google\ADT\sdk\platform-tools\adb.exe” install -r e:\users\j\downloads\crApp-debug.apk

8.  Done!  After running the ADB.exe it should be on your phone.  Scroll through your icons till you find it.  Click on it.  Whatever files you submitted to the site will now execute.  In my case I have a crappy bird app where I have to tap the screen to guide my block through a bunch of other blocks.


Getting started building apps for an absolute beginner.

Codename One turned out to be a bust.  It’s been two days since I submitted my simple ‘hello world’ app to them and its status still says ‘building’.

So I’ve been looking around at other alternatives.  There’s nothing free – nothing, that is, except PhoneGap.  Everyone talks about phonegap on all these app-building sites, and they always say ‘poor performance’ so I dismissed it out-of-hand.

But what is phonegap?  I thought it was a developing environment, but really its a service that turns web-based code into something that can run on Iphones or Android phones.  Any phone, really.  It is a compiler.

There’s a fundamental problem with any app-building endeavor: you need a computer.  You cannot code or (easily) test your code on your phone.   It’s too hard to get the app onto your phone.  Especially Iphones.  Apple has made it so a Mac is required to compile any app for Iphone.  Why?  Because they are greedy.  They have made it so you have to use a certain program, and only that program, to compile Iphone apps.  And this requires you to buy a developer license for $99 – even for a simple hello world app.

Google phones are sightly more developer-friendly, but it still a pain to get an app on the phone, and you still need a computer ie. something with a keyboard.  This creates a new problem:  Finding a way to make and test an app on your computer.  Computers are different operating systems.  Even a Apple Mac computer uses a different operating system (OS X) than its Iphone (iOS).  So to make any app on your computer, you have to basically have some kind of phone emulator.  And this is not an easy thing to ask for.  Hence, anyone who made one also wants you to pay.

Codename one promised to be free, and it is, until you need to get it to the phone.  You have to compile it.  And only they can compile projects created with Codename one.  Gotcha!  They have a free service where you submit it online, but its limited to 100 uses, and as I have just reported, it takes too long for a simple compile.

So there must be a new solution, something to run and test code on a computer, and a way to compile it and get it to your phone.

But wait – why should someone have to use a completely new developing environment to run code, when such a thing exists already, on almost any computer?  What am I talking about?  Web browsers can run javascript, which requires no compiler!  Just a text editor and a web browser is needed to start writing and testing code.

Phonegap realized this and made a way to turn javascript code into phone code.  I didn’t need to learn a new environment – I could just use javascript.  So that’s what I did.  I made a simple app using javascript and submitted it to phonegap’s build site.  I had to register, but it was free and took less than a minute to get my app compiled.  Really.  Yes, you heard that right, its already done.  One day.  That’s how long it took me to write a game and get it compiled for my phone.

There’s a nice javascript wrapper made especially for games, called Phaser.  It took less than an hour to copy the examples into my own app.  Here is my app.  You may play it.  Since it is javascript it runs on any browser.  Aren’t I awesome?!  Ok, well, I cheated a little by copying the code from here, but it was a great way to learn and I think even people who have never coded could understand it.  It almost reads like english.

I zipped up the code and uploaded it on the phonegap site, and voila, it automatically compiled it for every phone operating system it could (meaning everything except Apples IPhone).  WOOHOO!

Problem is, I don’t have a phone to run it on!  I will try to get ahold of a cheap android phone and see if it works.

As for performance issues, from what I understand, it makes an app that runs through the webbrowser.  Basically an emulation.  But I see no problem with that.  All the mobile apps ive seen are low-intensity.  I’m not making a first-person shooter.  I’m trying to make a chess app.  What do I need optimized speed for?  yes, I want it to be fast, but I can easily rewrite my code if need be.  And there are now services out there that take your javascript code and turn it into native, optimized code for iphone or whatever.  This one is called CocoonJS and looks very exciting.


Codename one: My first five minutes.

So I’m trying to make an app for my Iphone.  Why?  Why not.

I researched all the various methods, and decided, based on reviews and comparisons from other sites, to go with Codename One.  Great looking site, active forums, it seems like the real deal.  I’m going to have to deal with crashes or buggy features or something that just plain doesn’t work.  It even has a tutorial for beginners.  So here’s my first five minutes.  May others find it informative.

You have to use a supported code editor.   It doesn’t come with its own, so you have to download netbeans or eclipse as well.  I already had netbeans, so I just had to download codeone and install it as a netbeans plugin.  It worked, until I tried to create a new project.   Nothing.  It say its successful, but nothing happens.
Solution: reinstall netbeans.  My existing plugins caused codename one to not work.

Now I have a new project, annnddd… now what?  Codename one creates a bunch of files, and they show in a list at the side, but what are you supposed to do?  Turns out you are supposed to find the file named “theme.res” and double click on that.

This brings up the GUI editor in a separate process.  This looked all right.  A big ‘add a new GUI element’ seems to create a form, which you can see on the left of your screen, and a separate panel lets you drag and drop components (buttons, checkboxes) onto it.  There is a default form called main.  Good.  I add a button that does nothing, go back to the main screen, and tried to run the program.  A simulator pops up but my changes did not appear.  Ok….. I try again.  This time click save.  There we go.  My new button appears as expected.  So far so good.

Now how to get at the code for the button?  I’m looking, I’m clicking, I’m looking – finally I find it at the bottom of the file  But oh great, there is a warning at the top of the file saying “Do not modify”.  So what do I do now?  I click around, searching, searching – I find a properties tab headed ‘events’.  I click on “Action Event”, a ‘choose file’ dialogue pops up, I assume its asking for the file with the code, I click the, aaaaannnddd… Error.  Not a valid application. Crap.  I’m stuck.  Time to read the documentation.
The in-application help files are useless, but that’s normal.  I try online.  “Hey look, a hello world tutorial!”  Right there on the codebase one site.  How thoughtful.  So I’m reading, I’m reading, events, events, looking for events, and I read:
Binding Events To The Source Is Trivial And You Can Invoke The Codename One API To Do Anything
But they don’t tell you how to do it!  The closest thing I can find is Picture Now we can edit the generated GUI and makes changes to the screens within the GUI builder. We can bind an action event to the button and go to the code to show a dialog.

More lies.

“Screw it” I say, I’m going to edit the codenamebase file, the one that told me not to edit it.  I stick in a basic dialogue“Hello”, “Hi There”, “OK”, null);, save, click run, aaaannnddd…. YES!  It works!  A dialogue pops up when I click the button in the simulator.

And thats my first five, or maybe fifteen, minutes with codename one.

I shall continue to use codename one.

Inverting the Pyramid, Kick the Balls, The Beckham Experiment, Why Everything you think you know about soccer is wrong

Inverting the Pyramid:  A classic history of soccer.

The title subtitle says it is a history of soccer tactics, but a better title would be ‘a history of the great teams of soccer’.

I’ve heard this called a ‘must read’ for anyone who studies soccer, but after reading it, I cannot agree.  It’s a history book.  This means a lot of names, dates, and places.  The first few chapters were interesting as it talks about pre-1900 soccer, how there were no set rules, how everyone played forward, how the Scottish dominated.  But after that the format of the book is as follows:

  • Pick a good team from each decade.
  • Go back thirty years in that teams history.
  • Catalog all their coaches, managers, wins, losses, major trades, tournaments.  Describe their style in vague words like ‘flowing’ or ‘physical’.  Put in lots of quotes from others about how great the team was.
  • Repeat.

    It is informative, and as far as history books go rather easy to read, but its still a history book.  It attempts to make a story out of each team and their changes, but the fact is coaches change, are hired and fired, all the time.  I’m not sure why the author talks so much about coaches and players that, by all accounts, failed to win.
    There was the occasional paragraph about why the tactics that team used worked, and maybe even a diagram, but I could have used far less names and dates far more whys and hows.

The Beckham Experiment.

This is a book chronicling David Beckham’s move to the LA Galaxy from 2005 to 2008.  Sadly, the book isn’t about David Beckham.  It’s about the engineers of David Beckham’s move, and relegates Beckham to a sort of dunce, or stooge, ignorant and naive to the damage he and his friends are inflicting upon his team.

There is a lot of Alexi Lalas.  Which I like, because I like Alexi as a player and a commentator.  The book could easily be called ‘What Alexi thinks about everything’ but I doubt that would sell many copies.  There is also a lot of talk about finances, and how expensive players are, and how the MLS is struggling to stay afloat.  I liked those bits.  But the rest of the book reads like a magazine article that someone tried to turn into a book.  5% punchlines and 95% tedious background facts.

Kick the balls

This is an autobiography of an alcoholic Scottish bartender coaching a bunch of 10-year-olds in America.  It accurately depicts little kid’s dialogue.  It also thoroughly depicts how much of a loser this Scottish guy is.  It’s more about him ripping on how awful he is and how awful he treats the kids, and less about soccer.  Every other chapter is an irrelevant, if humorous, letter to a TV evangelist he watches when he cannot sleep (He cannot sleep a lot).  He also talks to his Ben & Jerry ice cream.  The only interesting parts were about his Scottish childhood, and how barbaric kids are.

What I want to know is:  How did he get this published??  What was his selling pitch?  “Its about a Scottish loser abusing kids”?  It is well written, but who would publish a perverted, kid-centered, foul mouthed horror story interspersed with making fun of religion?  In a way I am inspired.  If a book this bad can get published, than anything I can write should have a chance too.

Why everything you think you know about soccer is wrong

The eye-catching title hints at the chicanery inside.  This is a book about statistics, written by some guy with a PhD who has never played soccer.  Each chapter he takes a ‘well-known’ soccer adage, like ‘you are more likely to be scored upon immediately after you score’, and refutes it with statistics.  There’s charts and graphs and quotes from people you don’t know.  Its specious and banal and I hope no one will be fooled by anything.  Like the old saying goes, “There’s 3 types of lies: white lies, damning lies, and statistics.”  And I think The Author knows it.  In the introduction he even says some of his conclusions are ‘simple parlor tricks’.

Let me elaborate.  Lets take the example I already used, “You are more likely to be scored upon immediately after you score.”  According to all his computer-generated match analysis, this is not true.  ‘All second goals are, statistically, evenly distributed across all minutes of the game’, he claims.  So why do people say this?  His answer is because everyone just attaches a greater emotional weight to equalizing goals.  ‘We are just imagining it’, basically.  But that’s not true.

I have personally seen how immediately after a team scores, the next five minutes of play are different than the previous five minutes.  The celebrating team either visibly relaxes or gets more excited.  The other team seems to give up or produce a surge of effort.  I’m not imagining that.  I don’t know if these surges lead to more goals, but that is the theoretical basis for ‘goals tend to come in pairs’.  I understand that the statistics do not show that, but until you adequately explain the discrepancy, I’m going to believe my own eyes over your statistics.  For all I know, he hand-picked the games to prove his own hypothesis.

Some statistics of his are interesting.  I liked the one about “Leading 1-0” only gives you a 50% chance to win.  It makes no sense.  Leading the game doesn’t help you??  Bullshit.  But the idea is interesting, and worded a different way, kinda makes sense.  Reworded it says ‘After you score, the other team is more likely to score than you are’.  That makes sense.  Teams tend to get more defensive when they lead.  The losing side tries harder to score.  This explains why draws are so common in soccer and 1-1 is the most common score.  I don’t think its 50 percent of the time – I think the author is cherry picking his numbers – but it is interesting food for thought.

Only one conclusion of his did I really have a problem with.  “More corners do not lead to more goals”, and he mocks teams that get excited about corners.  Statistically speaking, he is right.  Teams with more corner kicks do not have more goals.  But then he goes on to say that corner kicks are better played short, and should not be used as an attempt on goal.  I have heard this argument from other coaches and I strongly disagree, and am upset that someone who claims to be an authority on soccer would use perfectly good statistics to support this inaccurate claim to the detriment of teams, the people watching games looking for a little action, and soccer in general.

A corner kick, almost by definition, is because the defending team is doing a good job of preventing goals.  A defender blocked a shot and the ball went out of bounds.  If you put it in those terms, more corner kicks mean the defenders are doing a better job than the attackers.  Corner kicks should then be correlated with less goals.  And this would be true if the team did not take the corner kick.  But they do.  They take the corner kick, it results in more shots on goals, and therefore more goals.  Any loss of goals from being blocked is gained back because they had a corner and went for a shot on goal!

Saying ‘The same amount of corners leads to the same amount of goals’, does not say anything about their relationship.  Correlation is not causation.  Flip it around: More goals lead to more corner kicks!  Maybe.  Maybe not.  But it uses the same statistic and the same logic.  This could be a statement about possessing the ball in the opponents half.  It’s all about how you word the question

Lets use another statistic to prove my point.  What are the chances that a possession leads to a shot on goal?  Think about it.  How many shots on goal does a typical professional team have?  Around 10.  Yet how many possessions do they have?  Hundreds.  The ball changes sides at least three hundred times during a game.  This is a game of turnovers.  1 in 9 shots go in, that’s a well established fact.  The odds of any one possession leading to a goal is less than 1%.  99% of all possessions result in losing the ball.

Now lets look at corner kicks.  What are the odds of a corner kick leading to a goal.  Statistics show it is 1 in 40.  2.5%  Already that is better than 1%.  But John, you say, there’s not a lot of difference between 1% and 2%.  You might have rounding error or something.

Ok, fine, lets go into a little more detail.  What are the odds that a corner kick leads to a shot on goal?  1 in 5.  20%.  That is better than the average possession, and it makes sense intuitively.  If you drop the ball in front of the goal, any shot is more likely to be on target.  You’re super close to the goal – there’s no way to miss.  The only way to be stopped is by the other team blocking it.  More evidence that a corner kick is better than possession.

And the last little statistic I want to throw out is that, out of all goals scored, 1 in 10 come from corner kicks.  What other strategy or set play can you say leads to such a high percentage, other than penalty kicks?  Can you say ‘dribble the ball down the sideline, and there’s a 10% chance it will eventually lead to a goal?’  ‘Cross the ball, it will result in one of our 10 goals?’  No.  You cannot make any such firm declaration.  But ‘1 in 10 of our goals will come from corner kicks?’  That’s a pretty strong statement, and a rather exciting one.  I know its not the same as saying ‘1 in 10 corner kicks will lead to goals’, but it nevertheless creates a definitive moment to anticipate, something easy to recognize, something easy to plan for and execute, with defined and above-average results.  Fans should definitely cheer.

What someone really needs to do is compile statistics between corner kicks played long and corner kicks played short (And to define long and short – playing a 1-yard short pass to someone who crosses it long is the same as doing a long corner kick).  From my observations, it is much more profitable to do a long corner kick where the ball is dropped in the goal box, than a short pass outside the penalty box.



Bastion and Games for iPhone

Video games for the IOS.  The IOS is Iphone’s operating system, in case you didn’t know.  I”ve been downloading a lot of games for it, trying them out.
First off, there is an INSANE amount of games.  I venture to say there are more games for phones than there are games made for All console systems combined.  I don’t know about PC games.  I’d guess PC games and phone games exist in similar quantities.  The reason for so many games is money.  Puzzles and Dragons makes 3 million dollars A DAY.  Yes, you read that right.  A DAY.

So everyone is jumping on the app train.  I myself have downloaded Xamarin and will be making an app soon.  A chess app.  I downloaded every single chess app on the apple app store, and none of them do suicide chess.  So I’ll make it myself.  (BTW the best chess app i’ve found so far is smallfish).  Unfortunately you have to pay $100 to put an app on the app store so who knows if I’ll ever get it published.

Anyways.  Games.

If you like art mixed in with your games and a rocking soundtrack, get Bastion.  I cannot believe I used to waste time playing crappy facebook games when things like Bastion exist and I can play lying down in bed.  Here’s how the game starts:
I was hooked in the first 20 seconds and am downloading the soundtrack as I speak.

I’m also playing Mystic Knight, an old school RPG that so far is good, and Rune Raiders, made by the same guys that do Clash of Clans.  Its a turn based strategy game.  I like it but I’ve just hit level 15 and its impossible to beat the boss.  Every round he nukes every single member of your party no matter where on the screen they are.  I can’t figure it out.  So I think the balance is out of wack.

I also think I will delete Puzzles and Dragons.  I just got my 60 day consecutive log in bonus and used all my magic stones on the new ‘Evangelion Egg Machine’ and got nothing but crappy Rei and Kauru.  The game has also gotten too hard.  The gap between the expert dungeons and the master dungeons, which is supposed to be one step removed in difficultly, is light-years apart.  I get annihilated the first round.  I survive two rounds, max.  It doesn’t matter which dungeon.  It’s just too hard.  I have all my starting characters leveled to max.  It seems the only way to progress is get some super-overpowered God characters, which costs real money or a lot of luck.  So bye bye Puzzles and Dragons.

There is also GBA4iOS, an emulator which allows you to play any game boy advanced game on your iPhone.  There is also one for Nintendo DS, but my iPhone 4s lags too much to be usable.  Maybe ipHone 5 has a better processor.

Ruzzle is also very fun.  You find words hidden in a grid, and compete 1 v 1 against facebook friends or anyone with the app.  My ID is Dax006.  Someone play against me!

One Dot Enemies – bugs appear on a blank screen and you click on them to kill them.  Thats it.  no levels.  It goes on indefinately.  The only challenge is the bugs are 1 pixel big (Very very small) so you do a lot of peering into the screen.  Boring after about 10 seconds.

Consciousness and the Brain

Consciousness and the Brain – Deciphering how the brain codes our thoughts.

Loved this book.  The entire book is a result of a simple fact: A message or picture flashed less than 30ms before the eyes is not perceived by the consciousness, yet will influence a persons decisions.  Aka a subliminal message.  Normally these psychology books are full of wanna-be scientists.  I fully expected this book to ramble on and on about how ‘OMG seeing a picture creates brain waves!’ and nothing more.  But it delves into some really state-of-the art technology like microscopic electrodes where people can measure the electrical potential of INDIVIDUAL neurons, and by putting these probes into peoples brains, they can cause people to think about or even see certain objects.  They found a ‘Bill Clinton’ neuron, that only activates when shown a picture of OR SEES THE WORDS ‘Bill Clinton’.  Matrix-like virtual reality is a real possibility.

Then the book got even better by getting all theoretical – and better yet, the authors invent experiments to validate their theories.  Some attempts failed, but I was fascinated just reading about them.  They worked with people in comas, and did a lot of mapping of the brain.  They talked about computer neural-networks and even Lucretius’ “swerve atom” (Which is weird because I just read this 3000 year old book last month).

I was a little disappointed they didn’t talk about Google’s recent billion-node neural network experiment.  A lot of their theories were already put to the test in their experiment and shown to be valid.  If you haven’t heard about Google’s little experiment, Google harnessed the processing power of computers they store their data on (some 16,000 cores) and created a open-ended neural network simulation and found that certain features created stronger responses than others, like faces.  Although this was still something like 1/600,000th of the brains processing power, I see no idea why this concept could not be extended to infinity to explain how our brain works.  Memory, visual recognition, even consciousness could be explained (if you create a neural network that links to itself as its inputs).

The other small disappointment was not referencing Eric Kandel’s work.  With so much talk about neurons the book could have benefited from a discussion of how neurons work and remember things.