Category Archives: Agile

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);

XML to XML – Translating XML with C#

Working with XML documents is the new way of EDI in today’s business work.  XML to XML provides a way to not only translate data that you want to work with, but also provides a way to store extreme amounts of information in a structured manner.  In this article I will discuss how to use XML in two forms, XML to XML or moving one XML document to another XML document and translating it along the way and XML to Object.  XML to Objects will be used in the XML to XML process but it will also help with keeping your XML uniform as well.

The most important piece in XML to XML is uniform documents

Starting out with a fresh document is very important in being successful in translation.  Here is an example of a simple yet effective XML document:

xml to xml job definition

The first part of XML to XML is to load the document into a XmlDocument file.  We do this through instantiating a XmlDocument and calling the Load method targeting our file.  The XmlDocument will be used to populate our new document and then write out to finish our XML to XML process.

            XmlDocument xmlJobDoc = new System.Xml.XmlDocument();
            XmlDocument xmlLoadDocument = new System.Xml.XmlDocument();
            XmlNode xmlJobNode;
            XmlAttribute xmlAttribute;
            XmlNode xmlRootNode = xmlLoadDocument.CreateElement("Root");
            xmlJobDoc.Load("JobDefinition.xml");
            for (int i = 0; i < 2; i++)
            {
                xmlJobNode = xmlLoadDocument.CreateElement("TruckRun");
                xmlAttribute = xmlLoadDocument.CreateAttribute("JobNumber");
                xmlAttribute.Value = i.ToString();
                xmlJobNode.Attributes.Append(xmlAttribute);

                xmlJobNode.AppendChild(xmlLoadDocument.ImportNode(xmlJobDoc.DocumentElement,true));
                xmlRootNode.AppendChild(xmlJobNode);
            }
            xmlLoadDocument.AppendChild(xmlRootNode);
            xmlLoadDocument.Save("JobFile.xml");

Xml to Xml utilizing Xml ImportNode Command

This will utilize the Xml to Xml specific command called ImportNode. ImportNode is powerful as it allows you to copy one specific section of an Xml document to another Xml document or use the Xml to Xml functionality as if you were copy and pasting. To finish up the Xml to Xml translation, we utilize the Save method on the Xml document and push the information to the specified file.  If you would like to learn more about translating Xml documents from Xml to Xml or other Xml processing capabilities of Microsoft dotNet Framework, check out this MSDN article.

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#.