Android: Grabbing pixel xy coordinates when image has been scaled or translated via Matrix.

So you have a view, that has an image.  You move around this image, scaling/translate the matrix to give the effect (I was using a view someone else created:, gives a Map View that you create an image of, in a rough way of explaining it).

His code uses a matrix to alter the image to allow you to move around the screen.  This changes your coordinates, as you probably know because you’re looking at this.

So, the fix is easy, and just takes a bit of thinking, but it was still a pain to figure it out, and I couldn’t find any sources online about it, so I’ll put what I figured out below:

 float transX = m[Matrix.MTRANS_X] * -1;
 float transY = m[Matrix.MTRANS_Y] * -1;
 float scaleX = m[Matrix.MSCALE_X];
 float scaleY = m[Matrix.MSCALE_Y];
 lastTouchX = (int) ((event.getX() + transX) / scaleX);
 lastTouchY = (int) ((event.getY() + transY) / scaleY);
 lastTouchX = Math.abs(lastTouchX);
 lastTouchY = Math.abs(lastTouchY);

So, in general, matrix.getValues(m) stores some values you can access from the matrix you’ve been using. In the View I’m using, it has the matrix as a class variable that can be accessed when needed, along with a float matrix, so it worked fine.

Next four lines are just me grabbing some of the values from the matrix, you can look at the android doc here. They’re the constants up top. I multiplied the transX and transY by -1 as it returned a negative value, which I used a positive coordinate system.

Next, we add the translate to the actual MotionEvent’s x/y value. This gives us our total movement with touch, then divide by scale amount. This moves our position in regards to how much we’ve zoomed in and out.

The abs is just a backup, I don’t believe it’s needed, I was testing other things, but just in case, I’ll keep it there.


Putting Android on HP Touchpad

My brother was lucky and bought one of the HP Touchpads when they went real low in price. Recently though, he couldn’t play movies on it, as the codecs didn’t work correctly or the Touchpad didn’t support it (I didn’t see it, just guessing). He asked me to put on Android for him, so this is basically what I did.
1. Downloading all the stuff
2. Some small commands
3. What happened/Extras!


I received a “Unable to find device” on Novacom after putting in the command (Shown in step two), so I had to download this.

I also had the SDK downloaded from HP’s Palm site, so you may want to download this first, then download the previous program to duplicate exactly what I did.  Here is the download.

This is the actual CM9 download.

This is the actual Google Apps.

This is ACME.

This is MOBoot.

This is CWM.

Small Commands

So the “Technical” portion.  Basically, on your machine, go to the furthest Novacom folder, mine was here:

C:\Program Files (x86)\HP webOS\SDK\bin\novacomd\x86>

In this folder, put the download above called ACME.  It won’t be executable by you, but it will know what to do when you enter the command in the cmd (Command prompt, I assume on Linux and Mac you’d use Terminal).  Before this command however, you need to do some work on the Touchpad.  Connect the device as you normally would to the computer.  When connected, on the device, it’ll prompt to enable USB mode.  Say yes.  On the computer, go to the devices folder (Via My Computer) and open up the external device.  Make a directory called “cminstall”.  In here, you want to put the CWM and MOBoot download .zip’s in to this folder.

Now, shut down the device.  But when you go to start it up (Be sure it’s connected to the computer still!), you want to hold the volume up button, (The button closest to the powerbutton).  Once this happens, you want to have your command prompt/terminal still in the previously mentioned path, and input this command:

novacom boot mem:// < ACMEInstaller3

This is the “Magic” portion.  Upon completion, unplug.  If the USB logo stays on, you’ll want to hold all three, the volume up button, the home button (The middle guy below the screen), and then the power button.  Hold until it goes away.  Then go on as normal.

Now, if you start up, you’ll notice that you have WebOS working still.  But you also have a small boot menu.

Now to install the CM9.  You downloaded a .zip file, of which, is named a bit oddly.  Rename the CM9 folder to  (I believe it complained about the naming however, so this may change depending on the versions of things, but it tells you on the HP device what to rename it to).  You want to do the same for the Gapps too, rename it to

Now, run that command above again in the same path, and then it’ll do its thing.  Now you’re done!


I said their were extras.  I was surprised to see that you can still boot in to WebOS.  So you didn’t lose this functionality, which I think my brother will enjoy.  To do this, you want to hold the power button, click Reboot, then select bootloader, then Ok.  It’ll reboot, and prompt you for selection.  To use this menu, use the volume buttons to scroll, then you use the home button to select an option.

Coding Style

1.  Am I weird?

2.  Spacing

3.  Examples

4.  Final Thoughts


I always wonder if I’m just an awkward programmer. I totally understand that everyone has their own style and “mark” with programming, however, I’ve never really met someone who likes as much spacing as I do.  Every default/built-in formatter must be replaced or altered so that it works how I like it.  It’s not that their format is bad or not correct, you could really put everything on one line.  But it’s just not like a book.  Like a book, everything is structured, and such is code.  I’ve always loved books that offer chapters.  Eragon, Harry Potter, Game of Thrones, etc.  All three of these titles use chapters often.  I love it.  I can’t stand reading books that are more or less, compact with tons of information, hence why many academic books, I can’t stand.  I think my coding style relates to this.


By spacing, I mean new lines, tons and tons of new lines.  My methods will knowingly be on this one tab mark.  I will not have else’s hanging near a curly brace, and their will be new lines between different types of packages, and different purposed variables.  And please, please please please, do not have a whole if statement, condition and execution, on one line.  But at the same time, I like long lines.  No 80 character limit, we aren’t in the 90’s anymore.  We have monitors that support three times that many characters now, so please don’t have your method arguments containing multiple lines.  It’s not comfortable to skip down like this, even with the spacing.  To bring back the book idea, one thought, per a line.  If I’m running a condition, that’s a line.  Then I pre-prompt the execution (Curly brace), on another line, then I give the execution, and to end that off, my closing (Another curly brace).

As My Math Professor Says, “I’ll start off with some examples” **Spoken with an English accent**

The simple statement:

 while(true) { System.out.println("Infinite"); } 

No!  Should be something like:


I understand this adds a lot of lines for something not needed.  But read it.  What is easier to comprehend?  If I was to add a comment explaining it, I just add it.  I don’t worry about to reference in the comment, I just put it above or on the side (Depending on size).

Another least favorite of mine:

 if(i==0) i+=10; 

Really?  I mean, I understand usually with a line like this, it’s hard to not understand what’s going on.  But it’s just awkward to me.  I’m sure you can guess what I’d rather see:



Enough of the ramble.  I’ll just leave off with, I like tabs. I don’t like spaces.  Not all editors handle erasing whitespace similarly.  Where-as, I delete a tab, guess what? It deletes that whole block, not that block, including a line or two above it  But alas, I can adapt.  I can also use Astyle (Really love this program) to switch between what a class/company wants, to what I want.  Painlessly simple too.

Hello, World!

I’m starting out with a research position as of now with a professor in order to learn more and pretty much obtain real experience rather than just a normal class room setting.

Basically, the subject matter is going to be computer science, along with mobile security.  Mobile, meaning Android, means my first task is to build a ROM.  The end goal is to actually produce a fully functional ROM that others may install on their own machine.  In this blog, I’ll be posting updates whenever I do work on the project.  As I’m still in school, I can’t dedicate a lot of time to this, however my goal is to upkeep ten hours a week on this project, with most of my work being done on weekends.  I’ll try to update every Monday and possible Wednesday or Thursday (Depending on when I work).  Hopefully all works out, and this becomes something.


I’ll also be posting about food, and what I cook.  Being in college, I won’t be making fancy schmancy meals, but I’ll be making some delicious stuff as time goes on.  I love to cook, and listen to music, and the great thing is, cooking and listening music can be done together! Just like programming and music ;).  Things always work out!

Lastly, I do small mini-projects on my own.  As of now, I’m creating two Android apps (Both of which I’ll post about and problems that occurred during development) and hopefully they’ll get done within the school year (That’s the plan).  The plan is, weekends are a mix day, do both my own projects and research stuff, where-as through the week I do more of the research stuff and app development when I’m free and need a break.  Sort-a my personal 20% project. Last, I hope to start learning Go/golang.