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.



So I’ve started to poke around Google App Engine and Go.  Honestly, I like it.

1. Thoughts

2. Why

3. Little Tutorial


Go, or commonly search, “golang” is a language made by Google.  Dah dah dah, I’m not a guy who knows much about the language, but I’ve read about it, and don’t want to give false information about it, so read it’s Wikipedia page if you’d like.  I decided I wanted to learn Go several months ago.  Problem was, no reason to learn it.  Not that I don’t enjoy learning new things on my own, I just can’t think of project ideas to actually put it to use.  But I found out about Go several months ago, followed it a bit for about a year, then decided I should learn it.

Go, the language, I do enjoy writing in.  I did some of the go-tour (It got boring after number 17 a couple months ago and couldn’t bring myself past fixing Pi in the tour this time around), but decided that I’d just jump in and go for it.  I usually learn this way, unless it’s something that’s massive and complex, in which case I try to find break down tutorials.  But this was actually successful, I’m getting the hang of the syntax and differences from other languages surprisingly quickly.  Again, I’m not doing anything dramatic with Go, but compared to how I feel learning other things, this went very smooth.

Why Go/GAE?

So I’m working on my Android app and I need some multiplayer work done (Nothing major, honestly just submit some info, get some info, pretty basic).  I looked around for some platforms I can get this on (Mostly to test and get it working locally).  I though of Google App Engine and Amazon’s EC2.  Amazon, your interface sucks.  I’m sorry, but honestly, it’s a massive wall of text with what seems (To me, a guy who just wants to make a small app) like a lot of worthless data that I won’t want or need. Google App Engine however, looks appealing, secondly, it’s more structured and organized, and I feel I can actually do something with it.  That’s honestly why I chose what I chose, nothing to do with specs (I’m making a small app that I don’t expect more than a thousand people playing, I don’t need any fancy stuff, just something that works).  Further, GAE supports Go.  I’m slightly certain you could get it to work, maybe with some hassle, but for what I’m planning, I’m sure it’s more than able.  If not, I could just use good ol’ PHP.

Tutorial, how to use POST/GET, and what about the datastore?

Below, I’m omitting package, imports, and the init, simply because the basic tutorial on GAE goes over this pretty well.

type Griddler struct {
	Id         string
	Author     string
	Name       string
	Rank       string
	Difficulty string
	Width      string
	Height     string
	Solution   string

func createHandler(w http.ResponseWriter, r *http.Request) {
	//Creating a Griddler to add to datastore.
	c := appengine.NewContext(r)
	parsed, err := url.Parse(r.URL.String())

	if err != nil {
		fmt.Fprintln(w, "Bad stuff happened in the create handler\t")
	q := parsed.Query()       //Parse the URL.
	griddler := new(Griddler) //Create and set all the data in your griddler.
	griddler.Id = q.Get("id")
	griddler.Author = q.Get("author")
	griddler.Name = q.Get("name")
	griddler.Rank = q.Get("rank")
	griddler.Difficulty = q.Get("diff")
	griddler.Width = q.Get("width")
	griddler.Height = q.Get("height")
	griddler.Solution = q.Get("solution")
	k := datastore.NewKey(c, "Griddler", griddler.Id, 0, nil) //Make a key based on the Id of the Griddler.
	if _, err := datastore.Put(c, k, griddler); err != nil {
		fmt.Fprint(w, "Error during adding item in data store.  Sorry mate.\t", err)
	} else {
		fmt.Fprintf(w, "Added: %s with key %s", griddler, k) //If no error putting in, send back a success message.


So, Honestly this code isn’t too interesting. You parse the url from the request, then you just use the query to set some data. Next you get a key for this Griddler (Please note, all Id’s will be a different hash, so first I’ll want to check if this hash exists).

Beyond this, you Put the griddler in the datastore, and you output the result. Prior, I wrote my own URL parser, which I mean, great and all because I control what the app does, but I’d much rather not doing this.

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.

Distributed File System (CEPH), SSHFS, and More

What all has been happening in the past two to three weeks?

1. Change of plan

2. Learning new things

3. Other projects

Plan Changer

So, previously the main goal was to make a service that would track what all happens on your device, data traffic wise. However, a change has been made, temporarily. While this is still the main goal, I’ll be switching gears towards something else (Look at number two). First though, what’s taken me so long. This extends to point three, but also something to address here. Obviously, I’ll be using other machines to work on everything. Because of this, and it being an university ran system, everything isn’t set up how I normally operate, and I’ve been customizing things to fit how I work. So the past week or two has been me getting used to the changes, not only on the system, but also what I’ll be doing in the future. Rather than jump in to the project, I’m trying to plan out how to go about it and have everything worked out before hand, as this (In my opinion), will make the end shorter.

New Things

The new project is distributed file system, which I’m very interested in, and hopefully can sit-in on our distributed system class here at Wright State. The lab I’m working in contains ~30 machines, each machine with 350 gigs of space, not being used, in its own partition. My professor, Dr. Mateti, has requested that I set up these machines to all collaborate together. He’s recommended the program CEPH, which from what I’ve read thus far, seems to be nice, and simple enough to set up. More about that later.

Also, something I found extremely interesting as I’ve wanted to do this, connect a file system to my local machine that handles files on external servers. I knew it was possible, but never looked in to it, nor have I actually done it. Dr. Mateti has this set up from his home and to multiple machines in the building, and we went over SSHFS. Obviously, SSH is secure shell, and FS is file system. This was the most painless configuration I’ve done for a while.

To set up SSHFS, you first want to make a directory on your local system. Then you run a command similiar to such:

sshfs -o idmap=user remoteUserName@remoteIPOrServer:/your/remote/directory $HOME/YourLocalDirectory

You want to change anything bolded. Once done, go in to the directory, type mount, then enter information requested, and you’re set. Honestly, one of the easiest and most useful things I’ve done for a bit of time.

My Projects

I’m currently working on two personal projects. One of which is a simple app that I do in spare time in my room, probably two or three hours a week. Another is working on Fennec, Firefox’s mobile client. I’ll write more about each of these, but a summary for now.

Fennec, I’m doing general bug fixes. This project is very helpful to me for several reasons. First, I’m learning how to effectively use a large code base. While not wasting anyone’s time but my own, I can go through the files, do what I can to make sense of them, and Log.d every couple of lines and see what’s happening. Secondly, I’m seeing how people who program for a living, program. This is surprisingly not common in academics, even though I believe it should be enforced (This, and revision control, whether it be git or Mercurial, etc.). It’s extremely important, in my opinion, to be able to read and understand others code, be able to implement it effectively, and come up with ways to do this. Lastly, I’m working on something that sees the light of day, using technologies that exist and are used everywhere, collaborating (I’m on their IRC 24/7) with others, helping out a public and open-source project, etc. etc. Their really is no “lastly”.

Pic2Griddler is an app that I’m developing. Yet Another Puzzle App, in other words. This is more for my personal use, as I’ve been in to Griddlers for several months now, but I’m not a fan of paying for an app that I’d get a couple weeks out of, then be done. So my solution, make an app that gives me unlimited amount of time to work on. I’ll be posting more in-depth about this later, you can read the README on the GitHub page on the side bar.