First Android App: Touch Controlled Cube on Samsung Galaxy S2

A couple of weeks ago I started to tinker with android programming. After reading some articles in android developers guide I developed my first application. It is a simple application that draws a cube in a 2D canvas. The cube can be controlled with touch input. Below you may see the video of the application in action. I have tested the application on a Samsung Galaxy S2.

The Idea

I have created a custom view by extending the View class. In the custom view I overridden the onDraw() method to draw the cube. I also overridden the onTouchEvent() method to capture touch events.

The Code

CubeView.java:

The CubeView class is the custom view responsible for drawing the cube.

10 Comments.

Thank you for the example! I can’t get a working copy because there seems to be a problem with the code in CubeView.java starting at the onDraw method. Is there a way to download the files? I hope you could fix this because I’d love to get a working example of this! Thanks in advance, Mike