Android: Fully Loaded Easter Eggs

Easter eggs are little hidden things thrown into movies, TV shows, video games, and similar works. George Lucas did this in Star Wars, working a reference to 1138, part of the title of his first movie, into each of the films. Pixar is well known for this as well. For example, every Pixar movie has included the pizza delivery truck from the original Toy Story.

One of the little joys I get in writing is the ability to add Easter eggs into my books. As much as possible, if I need to reference a number it will be 42. Each book has contained at least one reference to Firefly or Serenity*. The only problem has been that most of my books have been project-based, which has made it difficult at times to have fun with some of the examples. My latest book, Android: Fully Loaded, gave me a unique opportunity to have a lot more fun in the examples and it is thus full of Easter egss. So full, in fact, that I thought I might take a moment and go through and explain them.

The first fun bit in the book is in Figure 4.4 on page 46. I needed to show a number being entered into the phone’s dialer, but obviously I could not use a number that might violate someone’s privacy. I considered using a 555 number like they do in movies, but I’m not generally a fan of those, so instead I used a real number: the White House.

Pages 102 and 103 have the first Serenity references that made it into the book. (I actually had one earlier on, but the screen shot got cut in the editing process.) Figures 8.1 and 8.2 show importing the movie’s soundtrack into iTunes.

In Figure 8.6 on Page 107, I’m listening to “I Want To Know What Love Is” by Foreigner, the first song my wife and I danced to at our wedding. Another reference to the song is in Figure 8.8 on Page 108. In Figure 8.7, I’m setting my ringtone to the “Bad Horse Chorus” from Dr. Horrible’s Sing-Along Blog, another favorite of mine. I did actually use “Bad Horse Chorus” as my ringtone for a long time, until switching, while writing the book, to my current ringtone, the theme from the children’s show “Wonder Pets”. I use it now because the lyrics are very appropriate (“The phone! The phone is ringing!”) and because it makes my kids laugh every time my phone rings. The custom ringtone for when my wife calls is, as you might have guessed, “I Want To Know What Love Is”.

Page 113 shows Figure 8.13, in which I’m adding a podcast to Google Listen. The podcast in question is the one from AndroidCentral.com, a site run by my cousin and the book’s tech editor, Phil Nickinson.

Figure 9.1 on page 117 shows the headquarters of Wiley Publishing in Indianapolis, IN. I was fortunate enough to be able to visit them late in the production of the book, and thought a shot of their building nicely appropriate for the book. The building is shown again in Figure 9.2 on the next page, and it’s longitude and latitude are in Figure 9.7 on page 124. Figure 9.1 also shows a couple of pictures of my son playing soccer, and Firefly/Serenity reference #2: look closely on the books shown in the picture to the right and you’ll see my collection of Serenity ornaments. You can find a bunch of pictures of the kids in Figure 9.8 on page 124, as well as closer-up pictures of them in Figures 9.9, 9.10, 9.11 and 9.12. My daughter, by the way, wasn’t too pleased that she was, in her words, “all fuzzy” in that last shot; as my next book is going to be about photographs, I’ll be able to make it up to her.

She appears again in Figures 10.1, 10.2 and 10.5 on pages 131 and 133, this time in the first frame of a video I shot of her while reading. The movie in Figure 10.13 on page 138 is Casablanca, my wife’s favorite. Figure 10.14 is probably the most obvious geek reference in the book.

Chapter 12 let me get a bit meta in the book. In Figure 12.4 on page 158, I’m looking at a draft of the book’s first chapter. Figure 12.6 on the next page shows some text from that very chapter, which I did actually write on the phone (you can see the text on the previous page.) The PowerPoint presentation in Figure 12.5 is from an ActionScript class I teach at the Art Institute of California, Sacramento. For the eBook to show in Figure 12.8 on page 161, I actually struggled a bit. I have an electronic copy of my Flash Catalyst Bible that I had planned to use, but in the end I went with the opening page of my all-time favorite, Mary Shelley’s Frankenstein. Figure 12. 10 shows a page from Sun Tzu’s Art of War, a book I really will get around to reading some day.

Figure 14.6 on page 186 combines two pop-culture references. My shopping list includes Duff Beer, which will be recognized by any fan of the Simpsons. The other two items are Firefly/Serenity references: Fruit Oaty Bars feature prominently in the movie, while strawberries play an important role in the first episode of the series. On the next page, notice the amount of the bill I’m supposedly paying.

Figure 14.12 on page 191 was a late addition to the book, but one I was glad to work in: it shows the final score of the final game of the 2010 baseball regular season in which the San Francisco Giants beat the San Diego Padres, clinching the Western Division title. The shot shows that their next game would be played against the Atlanta Braves, the beginning of the play-offs. Of course, the Giants would go on to win not only the playoffs, but the World Series. Figure 14.13 is shows, of course, several of my other books.

* I had the hardest time coming up with a way to work a Firefly/Serenity reference into the Flash Catalyst Bible. Finally, late in the process, I found a place to do it, but unfortunately the screenshot that contains the reference got cropped. It’s still there and visible if you download the practice files, but does not actually appear in the text.

Open Letter to Adobe: Please fix the debug version of Flash Player

Dear Adobe,

I am a Flash developer. I do a lot of work in Flash Professional, Flash Catalyst, and the Flex framework via Flash Builder. Working in Flex, of course, makes having the debug version of Flash Player on my systems a simple job requirement. However, I am also a web user – like most geeks (and these days, really like most people in general) I do spend a fair amount of time just surfing the web. Recently, those two activities have come into conflict, though, because surfing the web with the debug version of Flash Player – especially on Firefox – has become annoying at best, and downright infuriating at worst. I know I am not alone here, either, and I have seen others comment on Twitter about their frustrations of trying to be a web user while having the Flash Player debugger installed. I am not one who is generally inclined to just complain about things without at least trying to do something about it, so I have outlined below three things that I believe can be done to fix this problem.

First, why is the debugger installed with Flash Builder, but not Flash Professional? Ultimately, the problem I and others have is that too many Flash designers publish movies with errors in them. To a point, you can almost argue that it is not entirely their fault, since the “normal” version of Flash Player is designed to fail silently, so many of these designers may be entirely unaware that their movie is generating errors. In fact, just today I reported a Flash error to a very large, quite prominent blog, and got a quick response back that they could see no errors when they loaded their page. And of course not: they have the normal version of Flash player. I forwarded them a screenshot of their page with the error displayed, but obviously it would have been better if they had known about it in the first place. So my first suggestion is this: get the debugger out to folks using Flash Pro. Push an update to Flash Pro that installs the debugger, and moving forward, make sure that whenever someone installs Flash Pro, they also end up installing the debugger (just as now happens when one installs Flash Builder). That way, all of those folks out there that are building Flash content in Flash Pro will be able to see and fix their errors before they publish.

Second, please provide a way for those of us running the debugger to turn it off. I absolutely need it in order to build my apps, and I absolutely do not need it in order to just surf the web. I’ll be the first to admit that I do not know exactly how plug-ins work, so this might be more difficult than it sounds. However, I would really love to be able to tell Flash Player that, for this browser session, I don’t need debugging, thank you very much. Even more ideally: allow me to disable debugging by default, and only turn it on when I actually need it. That way, for that majority of the time when I’m using my browser as, you know, a browser, I could actually use it and not spend so much time wondering why so many people publish Flash content with errors (although, see above). When I needed to get some work done, though, I could enable debugging and thus make it so that I did not become one of those folks.

Third, and this is really the most important piece: please fix the debugger for Firefox. It is simply broken. When I hit a page that contains Flash errors in IE, I get the error dialog box, click Dismiss, repeat for each other error, and then continue surfing. On Firefox, however, I get the error dialog, and then the browser locks up. I cannot click the Dismiss button; instead, I just get the little spinning circle. Thankfully, I have learned that I do not need to kill Firefox entirely: I can instead press Ctrl-Shift-Esc and simply kill the plugin-container.exe process. Of course, if I want to then view Flash content, I have to restart the browser. What is even more fun is when the error dialog box pops up but then immediately loses focus and drops down behind the browser window so that it cannot be seen, leading me to think that the browser itself has in fact crashed. Again, none of these problems are present on other browsers, so clearly there is just something wrong with the Firefox plug-in. By the way: I am seeing these issues on Firefox 3.6.13 on 64-bit Windows 7 Home Premium, running the debug version of Flash Player 10.1.

Thank you.

Sincerely,

Rob

(Note to my users: constructive feedback is welcomed in the comments. Generic “I hate Flash” or “Flash sux” comments will be deleted.)

Dynamically Resize Text to Fit a Text Field

In putting together the app I’m building for the Blackberry Playbook, I hit upon an interesting problem. I need to have a text field across the top of the app, but the text will be inserted dynamically based on some user settings. I can’t necessarily predict what the text will be, but I know that given several choices it might be quite long. I can’t have the field expand forever, since of course I have a limited amount of real estate. Thus, I needed to figure out a way to get the text to resize down if it doesn’t fit. While I’m quite familiar with the methods to resize a text field to fit text, I had never seen a way to do the opposite and resize the text to fit the field. A Google search didn’t turn up anything either, so I turned to Twitter. Thankfully, I got a response fairly quickly from Arul Kumaran, who is officially now one of my heroes.

Before I start in on this solution, let me say outright that this doesn’t strike me as the most elegant solution. If someone knows of a better way to do this, by all means please let me know in the comments. In the meantime, taking Arul’s suggestion I was able to get this working.

First off, we need to import the three classes we’ll need:

import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

The TextField class will be used, obviously, for the field itself. The TextFieldAutoSize class handles resizing the text field, which, paradoxically, we still need to do. Finally, the TextFormat class is needed anytime you want to format text in ActionScript. Because font size is a format, we need that one too.

OK, next we need to create the text field, populate it with sample text for testing purposes, set its initial size (via a variable I can use for the test later), and add it to the stage. I want to make sure that my initial text is long enough to not fit in the field.

var txtTest:TextField = new TextField();
var desiredWidth:Number = 200;
txtTest.width = desiredWidth;
txtTest.text = "If this works, it'll be really really really really cool.";
addChild(txtTest);

Next, we need to resize the field. This is where I start to think that we aren’t going to win any awards for this code, but hey it works. The concept provided by Aral is to have the field resize, and then detect the new width. If it’s greater than what we started with, we size the text down, then repeat until the text no longer forces the field to resize. Resizing the field requires that we use one of the static properties of the TextFieldAutoSize class:

txtTest.autoSize = TextFieldAutoSize.LEFT;

(The other options are CENTER and RIGHT. For the app, I’ll like use CENTER, but any will work for this app.)

OK, next up is creating the instance of the TextFormat class to set the size. I’m going to go ahead and set a nice big initial size while I’m at it, as well as apply the format to the field:

var txtTestFormat:TextFormat = new TextFormat();
txtTestFormat.size = 20;
txtTest.setTextFormat(txtTestFormat);

The final setup bit we need is a way to dynamically reset the size. I had to do some head-scratching here, because I had always assumed that the size property of the TextFormat class took a number. That’s certainly what it looks like, but it turns out that it actually takes an object. Not sure exactly why, but whatever – we need to create a generic object to hold our size so that we can manipulate it:

var newSize:Object = new Object();
newSize.size = txtTestFormat.size;

OK, now for the magic bit. I’m going to create a function that will test the size of the text field. If it’s greater than the initial size, then I’m going to reduce the size of the text, set that size to the TextFormat object, and apply it to the text field. Then, I’m going to have the function call itself to repeat the testing and resizing until the text no longer causes the field to resize:

function resizeText():void
{
 if(txtTest.width > desiredWidth)
 {
   newSize.size--;
   txtTestFormat.size = newSize.size;
   txtTest.setTextFormat(txtTestFormat);
   resizeText();
 }
}

Here’s all of the code together:

import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import flash.text.TextFormat;

var txtTest:TextField = new TextField();
txtTest.width = 200;

txtTest.text = "If this works";
addChild(txtTest);
txtTest.autoSize = TextFieldAutoSize.LEFT;

var txtTestFormat:TextFormat = new TextFormat();
txtTestFormat.size = 20;
txtTest.setTextFormat(txtTestFormat);
var newSize:Object = new Object();
newSize.size = txtTestFormat.size;
resizeText();
function resizeText():void
{
 if(txtTest.width > 200)
 {
  newSize.size--;
  txtTestFormat.size = newSize.size;
  txtTest.setTextFormat(txtTestFormat);
  resizeText();
 }
}

So there you have it. Again, I really think there must be a better, more elegant way to handle this, but for the time being it works. Thanks again to Aral for setting me off in the right direction with this.

Skyline

The problem with Skyline is not that it is so truly, utterly bad, but rather that it could so easily have been very, very good. The directors, brothers Colin and Greg Strause (who bill themselves as “The Strouse Brothers”, as if we care) had in their hands a pretty good premise, but rather tragically decided to ignore it and go with what turns out to be a lame retread of about 100 previous alien invasion movies.

Things start out well: nighttime over LA, and suddenly blue fireball-like-things descend from the sky. Cut to an apartment, where a couple (Eric Balfour and Scottie Thompson) are awoken by the strange blue light and earthquake-like rumbling. Balfour’s character (it’s not one of those movies where you ever bother to pay attention and learn the character’s names) goes out into the living room, obviously the scene of a major party the night before, where another girl is screaming something about some guy being gone. Balfour stares into the blue light and begins to change … then we cut to the movie’s title. OK. I’m thinking, “so far, so good – they’re getting right to the action, so we don’t have to sit through 30 minutes of boring character development … oh, wait.”

Yup – strike 1: right after the title disappears, we get Balfour and Thompson on an airplane and are told it is now 15 hours earlier. Dammit. Character development hell, here we come. So they arrive in LA, blah blah blah hours later we see the beginning of the invasion again. And guess what? They actually show it again. Yup, that’s right – except for a brief scene of Thompson in her underwear from the opening, we actually get to watch the entire sequence over again about 30 minutes into the film. Why? No clue, but definitely strike 2.

So here’s where they cool premise briefly flashes by. The movie is, at its heart, a simple retelling of “Independence Day”: evil aliens are here and they are kicking our butts. But what makes this one different, and oh how I wish the directors, writers, or heck anyone involved could have seen this, is that we don’t have the normal global scope in this movie. There are no grandiose scenes of battles around the world until the very end; no scenes of the President rallying the troops. Instead, what we have is a four people (really five, but we never get more than four at once) stuck in a high-rise apartment while the world goes to hell around them. All they can do is hide, or peer through a telescope as the residents of LA are sucked into the alien ships or as the military finally engages (for some reason, it actually takes an entire day for the Air Force to respond) the aliens in a can’t-win battle, or argue about what they should do to try to survive. There are some brief moments where it almost looks like we’re going to get the movie we could so easily have gotten, but every time those moments are sacrificed for explosions and lame action sequences.

Strike 3, by the way, involves one of the worst endings of a movie in modern cinema. SPOILER ALERT: Please don’t read the next paragraph if you care to not know what happens.

Balfour and Thompson are, predictably, the sole survivors, and eventually make their way to the roof of the building, where they fight off a few baddies before finally succumbing. There’s actually a fairly touching moment when they realize that all is lost and bravely decide to face their fates together (again teasing us with the film-that-could-have-been). As they get sucked into the alien ship, we see that we have totally lost: no more American forces remain in the sky, and a fleet of ships off the coast is sinking in flames. Briefly, we finally get that global scope as we see that New York, London, Hong Kong and (weirdly) Las Vegas have suffered similar fates. Cut to credits at this moment, and you end up with an OK movie that manages to pull itself together at the last moment. We don’t know why the aliens came or what they want, but hey we’re all dead now so what does it matter? But you can probably guess that that is not what happens. Rather, we’re forced to endure a long end sequence aboard the alien ship. The movie still ends with all hope for humanity lost, but unfortunately it took all hope for the film with it.

Ultimately, the Strause Brothers ought to be arrested for Grand Theft Premise. Barring that, you can at least save yourself the trauma of sitting through their horrific film.

Skyline gets one and a half very disappointed stars out of five.

Scott Pilgrim vs. the World

When I first saw the previews for Scott Pilgrim vs. the World, I wasn’t impressed: it looked like an over-produced mess. Then, it came out to fairly positive reviews, which made me begin to rethink seeing it. What finally pushed me to see it, though, were the absolutely raving reviews of it I was hearing from a bunch of people I know who generally have similar tastes in movies. In this case, the “similar” is what applies, because I did not like the movie at all.

The basic idea of the movie is that a geeky young man (Michael Cera, playing essentially the same character he did in Juno) falls for an enigmatic woman (Mary Elizabeth Winstead). In order to date her, though, he must first defeat her seven evil exes.

One thing I cannot criticize at all in the film is its creativity. The movie is in essence one long video game – when Scott defeats the exes (oops … hope I didn’t just give something away there) they disintegrate into coins and a score slowly floats up; each ex he defeats gives him more points. It’s visually very interesting as well, with graphics onscreen that make it look somewhere between a comic book (it is based on a graphic novel) and a video game.

And yet, the video game motif was in the end what I really disliked about the film. Through most of it, I felt as though I was watching someone else play a video game. Now, I’ll admit that I have done that in the past – you’re walking through an arcade and see someone who is really good at a game playing it, so you stop to watch. The key, though, is that most likely you stop to watch for a few minutes – not for close to 2 hours. By the end, I was just getting bored. You pretty much know what the outcome of a movie like this is going to be. Boy wants girl, girl wants boy – does this really seem like the kind of film that is going to go with the non-obvious ending? Of course not.

I can certainly understand why some people would love this movie. I’m just not one of them.