Category Archives: Droid

Droid related project banter and java development targeting the android platform.

Drawing with the Canvas object in Android

When writing an Android game one of the first things I had to start looking at is the methods provided for drawing. Being that I had no real purpose for developing a 3D game, I decided to go 2D. There are many things that a bitmap can do for you in regards to saving you development time, but the game platform that I am pursuing next did much better with mathematical drawing.

This brought me to searching out the object that I would use to display colorful shapes that I chose at specific window positions. The first object I have come across to do this is the Canvas. A Canvas can be accessed by overriding the OnDraw method of the Android View object. A View is an object that you place in your layout to indicate UI functionality. While there are many methods in the Canvas that work well for drawing, I focused in on two of them which were drawLine and drawRectangle.

In my example I went through a few iterations to figure out screen width and what I should do with it, but ultimately I started focusing in on using a percentage of the screen with as opposed to using hard coded numbers, as it scales better on landscape mode if you go back and forth between portrait. Ultimately I came up with a method that looks like this to draw a block on my game:

GamePieceBlock block = m_BoardBlocks.get(i);
block.getXPosition();
blockLeftSide = leftSide + (width / m_PiecesWide) * block.getXPosition();
blockRightSide = blockLeftSide + (width / m_PiecesWide);
Paint pnt = new Paint();
pnt.setColor(block.getColor());

blockBottomSide = bottomSide - (height / m_PiecesTall) * block.getYPosition();
blockTopSide = blockBottomSide - (height / m_PiecesTall);

m_Canvas.drawRect(blockLeftSide, blockTopSide, blockRightSide, blockBottomSide, pnt);

This method draws a solid block of color at the position that I calculated.  To get the m_Canvas instance I set it in my onDraw method and then call down to my game methods to draw the object on the canvas.  The other method that I use is the drawLine method which looks like this:

m_Canvas.drawLine(rightSide, bottomSide, rightSide, topSide, boardPaint);
m_Canvas.drawLine(rightSide + 1, bottomSide, rightSide + 1, topSide, boardPaint);

Ubuntu: The competition or the future?

For the longest time I have been turned off by Linux.  Like with any big change to the way things in my life work, I met it with a little resistance and some of the issues fueled some of my opinions.  Recently I had a seminar where we were required to install Ubuntu and compare the latest version of it to Windows.  The following seminars were to examine system processes, the advantages and disadvantages of using Ubuntu and in a nut shell re-evaluate everything comparing it to what we like about Windows.  At week 5 of this class, I can say I am using both equally now and I am starting to push more towards using Ubuntu. I am very interested in future releases and being a developer I am considering looking at some code with it to help the worldwide development team out.

Here are some big turning points for me:

  1. Free software galore!  – Ubuntu comes installed with Libre Office.  This is probably the best comparison I have seen to Microsoft Office thus far and I am enjoying using it to write my thesis papers.  A big selling point on this was having the ability to save and open existing Microsoft Office files up to version 2010.
  2. Automatic Updating Restored – Windows has always been very functional with their update system, and diving into automatic updates.  Previous releases of Linux that I have used required that you download a zip file for almost everything you do, unzip it into a folder, make and build it and then take the updated pieces and overwrite your existing kernel.  Very much dislike.  Hallelujah for seamless code updates.
  3. Updated Navigation – I have always hated XWindows and almost every attempt at making some kind of Windows clone, but there is a nice refeshing UI target for Ubuntu and Unity, MAC!  Almost every time I have ever heard of great UI, Macintosh comes up and if you compare the starting screens of  Ubuntu and MacOS you will see a lot of similarities.
  4. Speed – Ubuntu boots very well and has almost no lag time compared to my failing deadlocking page faulting version of Windows.  I sit on this machine all day and I find that I personally am running out of memory after about 10 minutes of use.  Linux on the other hand has always been designed to run on lower end systems so it seems almost natural that it is quick.
  5. Support for Windows Apps – This one is another biggie for me, all of the games and programs that I like to use for Windows which have no Linux clones are holding me back.  I recently installed Wine on Ubuntu and found it to be extremely easy to use and it was almost transparent enough where I did not have to do anything extra to install and use a Windows application.

Careful everyone, I might trade in my Windows PC for Mac hardware running Ubuntu.  Of course my first goal is to find a way to port Visual Studio so I can still write .NET and hopefully get more into C and less into C#.

Grabbing Click Events In Droid App

Hello everyone,

Over the past few weeks I have stepped into the deep end of a market that I felt was up and coming. I decided to write a droid application fresh as a java guy, because I got my new Droid 3. First off, if you have a droid you know why I did this and if you don’t have it, go try one, they are awesome! To start, I had to get thrown into a world of XML oriented UI design which I realized how much I loved from XAML. I ran through a few droid tutorials on the developer site for droid and got myself setup with Eclipse and the droid addins.

My first application, I created a simple timer that had a progress button and updated a progress bar. The idea here was to recreate a classic Progress Quest application that you may or may not know. The nice thing that I found about this whole process was how open the community was and how easy it was to pick up a lot of the concepts. Here is some sample code below that I came up with for getting a hold onto a button click event and some multi threading in Java.

public class DroidQuestActivity extends Activity implements OnClickListener {
    private ToggleButton mApplicationToggleButton;
     /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setupFormVariables();
    }
    public void setupFormVariables() {
       mApplicationToggleButton = (ToggleButton)findViewById(R.id.ToggleAppButton);
       mApplicationToggleButton.setOnClickListener(this);    }
    }        
    public void onClick(View v) {
       // Do some click events from the button   
   }
}