Category: Uncategorized

New Android App

Published an android port of the open source Simple Tetris Clone. You can find it on the Android Market. The plan is to implement many more features, however I’ll probably publish the current feature state as open source soon.

Hello again.

Hi. There used to be a blog here last year. I’m in the process of retrieving the old posts and re-posting them.

Update: Posts recovered! Thank you google reader for keeping them safe for me!

Check out this Java 5 code:

  public static <T> List<T> extractSomeStuff(Collection collection) {
    List<T> extractedStuff = new ArrayList<T>(collection.size());
    for (Object element : collection) {
      extractedStuff.add((T) element);
    }
    return extractedStuff;
  }

  public static void someMethodThatIsRunning() {
    List integers = new ArrayList();
    integers.add(1); integers.add(2); integers.add(500);

    List longs = extractSomeStuff(integers);

    long notAnInteger = longs.get(0);
  }

Will there be a ClassCastException thrown? Yes.
Do you know what line it will be on?

Possibly not where you expect. Java Generics are designed to be able to easily compile down to older Java versions. In essence, I could write a program in Java 5 and make it target a Java 1.4 JVM so I can run on older machines that haven’t upgraded their JVM. The way this works is by a process called type erasure which happens at compile time. Any uses of Generics are checked to make sure the types are in agreement, and after they are validated, all type information is erased.

At any point where you actually need to the typed object, it will be replaced with a cast at runtime, so for List, when T get(int index) is called, the result gets cast to T.

The result is that the ClassCastException happens at long notAnInteger = longs.get(0); and not atextractedStuff.add((T) element); because that type information is erased.

The moral of the story is don’t cast objects with Generic types unless you really know what you’re doing. 90% of the time, you’re probably presenting a user with a method contract that you won’t be able to fulfill, and the user will only find out several lines later in their code when they realize that their collection is filled with objects they didn’t expect.

Photo Gallery Live Wallpaper

QR Code to App in MarketQR Code to App in Market

My first live wallpaper. (Note: This is a live wallpaper which requires android 2.1. currently only the nexus one has it officially, but other phones should have it soon.)

After choosing the live wallpaper, use the settings menu to choose what folder to pull images from and how often you want the image to change.

If people are still having force close issues, please let me know and if possible post a log using the log collector app in the marketplace.

Open sourced as of v0.6! http://code.google.com/p/photogallerylivewallpaper/

Current features:

  • Adjustable timer
  • User specified SD Card folder
  • Shifting when switching home pages (screen scrolling)
  • Fade transition
  • Double tap to change image

Future features:

  • more transitions
  • ???

Let me know what features you want!

Changelog:

  • v0.7 – Accepted a bunch of changes by Dániel Kalmár.
    • turned stretching into scaling (keeps aspect ratio, can up&down scale)
    • fixed possible bug with the image shifting randomly
    • better way to figure out if image needs rotating
    • the scaled & rotated image is only generated once and cached
    • added white background to preferences screen
    • all the features should work well together in any permutation
  • v0.6 – fixed a force closed bug with John Bibbs’ help (hopefully). Implemented double tapping to change the image.
  • v0.5 – implemented a fade transition! ability to turn on and off stretching for users that don’t want it. subsample images that cause out of memory exceptions in attempt to still use them.
  • v0.4 – put in the option to choose screen scrolling for those that don’t want it. able to choose the directory via the OI File Manager.
  • v0.3 – added screen scrolling. if the picture is smaller than the virtual width, it will be scaled horizontally.
  • v0.2 – added settings for timer and folder choice. lots of bullet proofing. if it still force closes, please let me know the circumstances, like what is in the folder you chose, or what you were doing to make it happen, as well as your phone and if you are using any special firmware. added an icon made byhttp://tango.freedesktop.org/Tango_Icon_Library
  • v0.1 – first release, set timer to 5s, set folder to /<sdcard>/wallpaperphotos

http://lukehutch.wordpress.com/2010/01/05/the-cheap-way-to-pay-for-a-nexus-one-think-tco/

In summary,

Total Cost of Ownership of buying the full priced Nexus 1 : $2173 (can switch anytime, can cut features out of the plan to make it cheaper)
TCO on buying the subsidized Nexus 1:  $2292 (must stay on plan and contract for 2 years or face ETF)

edit: That article also brought to light that if you’ve been in a T-Mobile contract for at least a year, you can switch to the non-contract plan which is $20 cheaper by paying a $35 migration fee. Over the course of a year, that’s saving $20*12 – $35 = $205. I’m doing this tonight.

more details in this article:

http://androidandme.com/2009/10/carriers/t-mobile-news/new-rate-plans-for-t-mobile-start-today/
and
http://news.cnet.com/8301-17938_105-10382707-1.html

Mario Hat Instruction Manual

Photos of hat will be up later this afternoon, maybe.

Mario Hat Instruction ManualMario Hat Instruction Manual

Web Reference

To all web developers, Google is on it’s way to compiling the ultimate web reference. The project, called doctype, is a wiki containing references and links to existing references on DOM and CSS matters as well as tips and tricks and HOW TOs covering various topics such as browser compatibility or detecting when the user resizes the browser window. One of the main contributors is the dude who runs quirksmode.

Update (9/3/2011):
Two years and a couple of websites later, I’ve realized my favorite resource for DOM / CSS / JS is the Mozilla Developer Network (MDN) documentation. They’ve got great tutorials and really well written and easy to browse documentation on all the latest and greatest HTML5 stuff.

New Blog

This is a new blog. It’ll probably be very nerdy. As in, I want to talk about code.