What causes variations in x/y (Left/Top) positions between devices? - basic4android

I've noticed that hard coded Top/left positions (gathered via code) from the avd do not correspond to the same points on my android device.
Basically I have a map image as a panel with another panel containing a position indicator (like x marks the spot) works fine in the avd, but there is a significant offset on the phone I'm using to test. Concerned such hard coding will cause issues on other phones too. Any suggestions?

You should use 'dip' units (device independent pixel). For example:
Button1.Left = 30dip
By using 'dip' units the actual value is scaled based on the device scale.

Related

Calculate the distance between the iPhone and a door, knowing their physical widths

I have this scenario:
I know the physical (not only in pixel) size of the screen of the iPhone.
Also I know the width of a door.
Now, if I have the iPhone camera on (with UIImagePicker or whatever), and I am in the position where the width of the door fits perfectly in the width of the camera, and the iPhone stands perfectly vertical, is it possible to know the distance between the iPhone and the door?
It would depend on the camera specs which vary between devices. For this reason I would try to sample some data with a ruler - for instance take a 3' wide plank, align the edges perfectly and measure distance. Do this with varying widths on different devices and you'll have a formula per device (basic algebra)

How to handle resolution change 320x480 => 640x960 related to gameplay

I have decided to have 2 set of images for my iPod game. One with 320x480 and the other for the retina one. I can switch happily between them but this forces me to add extra code to handle the change in resolution.
My game is played in screen space on a grid, so, if I have 32 pixel tiles, I will have to use 32 offsets in low res and 64 in retina (because of doubling resolution). For a simple game this can be no problem, but what about other more complex games? How do you handle this without hardcoding things depending on the target resolution.
Of course an easy way to bypass this is just releasing a 320x480 version an let the hardware upscale, but this is not what I want because of blurry images. I'm a bit lost here.
If you have to, you can do the conversion from points to pixels (and vice versa), easily by either multiplying or dividing the pixel/point position with the contentScaleFactor of your view. However, normally this is done automatically by you if you just keep it to using points instead of pixels.
This is automatic. You only need to add image files suffixed '#2x' for the retina resolution.
Regarding pixels, from your program you work in points which are translated to pixels by the system. Screen dimensions are 320x480 points for iphone retina and non-retina.

Manipulating Gyroscope / Accelerometer Values obtained from iPhone 4

I'm developing a project for my university, to manipulate gyroscope/accelerometer values obtained from the iPhone 4. But i'm stuck with a mathmatical issue and I hope you guys can help me out.
I'll give you an example of what's about:
Your iPhone is face up and you move it UP, on Y axis.
Your iPhone is face right and you move it UP, on X axis this time (since you rotated the iphone 90 degrees).
On the second time, the computer interprets that i've moved the iphone to the RIGHT, but it's wrong. I've moved it up, but my axis were rotated since the iphone was face right.
What do I need?
I need a way to VIRTUALY position back the iphone face up (where the 3 axis are correct) and give each axis his correct movement value.
If the iphone is turned 90 degrees, then I can easily switch X-Z axis and its correct. But I want to make it work for any angle of rotation.
I would be really thankfull if anyone can help me with some sort of pseudo-algorithm or mathmatical description of what to do.
NOTE: I only need a way to compensate all three axis acording with the iPhone rotation.
Update:
I don't actually need the precise values, since I'm making a graph coparition between all the records I get from the gyroscope. I'll make it clearer.
-> You draw a LETTER just by moving the iphone in the air and my application will recognize the letter you just drew. The method I use for recognition is based on TFT algorithm, and recording to a database with sample values originated from letters I've previously drawed.
My point is: Don't really matter the values I get, or what they represent. All I need is that all graphs be equal even if the iPhone is on different position. Quite hard to explain, but if you draw the letter 'P' with the iphone turned UP, the graph originated will be different if you draw the 'P' with the iPhone turned RIGHT.
So I need to compensate the axis to their original orientation, that way I'll get always similar graphs.
This post was before iOS5 was released. FYI to anyone coming here, DeviceMotion relative to world - multiplyByInverseOfAttitude shows how to transform device-relative acceleration values to earth-relative for iOS5 and above.
So, what you want is to convert from iPhone's coordinate system (or object/tangent system) to world coordinate system (or vice versa, as you see it, doesn't matter). You know the iPhone coordinate system as you have gyroscope data. So what you want is to create the object->world transformation matrix and multiple each of the velocity vectors (from accelerometer) by it.
Take a look here for a good explanation of tangent space and how to create tangent space -> world transformation matrix. If you aren't familiar with 3D/linear math it might be a bit tricky, but worth the trouble.

Is there a way to see which pixels are what coordinates with crosshairs on iPhone simulator?

Is there a tool that will do this? I want to be running the simulator and then be able to put the mouse over some point and have it tell me what the (x,y) coordinates are. Surely there's a simple tool that does this.
I just use the built-in screenshot snapper from OS X. Just Command+Shift+4 and when you drag it shows the dimensions of the snap you'd take. Press escape to drop it. Works great.
In the Developer Tools -> Applications -> Graphics Tools there is a program called Pixie. It will do what you want. In Preferences you can set it up so that an option-drag will count pixels. You can also set it to just show the pixel coordinates and do the math yourself.
I've used the Iconfactory's xScope for this before. If you create rulers that are the size of the display in the Simulator, you can get a readout of the X and Y coordinates of the mouse pointer as you move across the Simulator screen. Getting the rulers precisely aligned with the edge of the Simulator screen can be a little tricky for applications with dark backgrounds, though.

iPhone4 UI Element Size in Pixels?

Does anyone know where the various screen dimensions are for the iPhone4? I have checked the MobileHIG but alls I could find where references back to the old iPhone3G. Should I just assume that all previous values are doubled (i.e. StatusBar = 40 pixels), or is there a more accurate illustration (like the one below hidden somewhere else?
Cheers Gary
Points are the new pixels.
You keep working with the values you're used to, just like if you were still developing for 3G / 3Gs. The unit of these values is now called points instead of pixels, to avoid confusion. On the older iPhone models, a 2x2 point square equals 2x2 pixels on the screen. But on iPhone 4 the same square equals 4x4 pixels. UI elements are rendered at the appropriate resolution automatically, images and other content you provide will be scaled, unless you provide high resolution versions of those ressources.
You might want to read this document for further information.
You shouldn't really assume anything about the screen dimensions. If you need the dimensions, read them vie the API.
There is no promise that dimensions or even proportions will stay the same forever. (The iPhone, iPad and new iPhone all have different resolution size and proportions.)
That said, the dimensions on the iPhone 4 should be exactly twice the dimensions of earlies iPhone models.