I'll try to be precise as much as possible.
I wrote an app, the full code itself doesn't matter
public void onWindowFocusChanged(boolean hasFocus){
super.onWindowFocusChanged(hasFocus);
if(hasFocus){
globalWidth = mainLayout.getWidth();
refillData();
}
}
it works perfectly on my device (sgs2 DarkyROM hd2.1 android version 4.0.3 also checked it on systems based 2.3 version for sgs2), another sgs2 with PilotX2.1, also it works on ASUS Transformer (android v4.2.1) and many other devices with different screen sizes.
I must say that it has different look depending on what device it run (it builds the main layout dynamically so its really notable if app run correctly or not).
But on some devices it has strange behavior. For example on HTC (htc sense 2.1) running android version 2.3.5 its somehow at line getWidth() returns the half or the actual screen's width. Or sgs2 4.2.1 android version it also returns strange result.
I tried to look up in google and stack overflow to find out are there any specific system differences that should be considered that has such a big influence on app but nothing. I don't use any kind of particular hardware of a device that could be implemented differently by system's developer.
What's the problem that I didn't take in mind? Can be that different kernels make the "problematic" behavior for my app? I thought it could be different ROMs, but I checked at least 6-8 different ROMs and had no problem.
If anyone familiar with that subject or met something similar, I would glad even for a link to webpage. I really frustrated.
Maybe you can correct your measures by using View.makeMeasureSpec
mainLayout.measure(
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
int height = mainLayout.getMeasuredHeight();
int width = mainLayout.getMeasuredWidth();
Related
I've been looking for a way to detect the finger orientation together with a simplification of the touch area in the form of an ellipse, when using a mobile touch device. I choose Android rather than iOS since I found three usefull methods (getTouchMajor(), getTouchMinor(), and getOrientation()) in the Android reference for the MotionEvent class.
But I've tried to implement these three methods in my app, and sadly they does not return the wanted values. The orientation stays at 0, no matter what, while the getTouchMajor and getTouchMinor is exactly the same each time.
So my question is: Am I doing somethign wrong or is these methods just not implemented yet?
(I've tried the functions on several different devices including: Nexus 5, Nexus 7, and HTC One)
As we work together I know you know this answer, but I just wanted to put it up such that fellow users of Stackoverflow can have it as well.
We have found suggestive comments that maybe the touch screen drivers for most devices do not provide this data to the system.
We originally tested: Samsung Galaxy S2, HTC One, Nexus 5 (by LG) and Nexus 7 (by Asus), Samsung Galaxy Tap 3.
As opposed to the others the Samsung Galaxy Tap 3, gave different values for getTouchMajor() and getTouchMinor(), but this relationship was seen getTouchMajor() = getTouchMinor() * 3, and getOrientation() was always 0, as with all the other devices.
About 2 months later we discovered that the Google Nexus 10 can show an ellipse with a direction line, when you activate Input: Pointer Location under developer settings.
The initial conclusion was that most devices do not support, getTouchMajor(), getTouchMinor(). or getOrientation(), Which could be a limitation of the capacitative touch screens.
But seeing the Nexus 10, and the tracking of the ellipse and orientation gives hope for new interaction design.
It indicates to me that some devices do deliver on getTouchMinor and getTouchMajor as well as orientation. (or historical versions of the same functions).
I have not had the chance to code anything for the device myself but it seems plausible.
My app runs with many devices but 2 users have send me simular images as below.
As far as I know the behaviour is only seen on Android 4.2.2 (Samsung S4).
On the full HD screen there seem to be 3 compressed tiles of 160x600 pixels.
I have tried an AVD with full HD screen but that fails to start.
On 4.03 devices I don't see this. I don't use tiles.
Does anybody have a hint what or where this goes wrong ?
This looks like a possible bug in the Android platform on Samsung's S4 devices with that particular Android version. My experience tells me that it's a very real possibility. It could also be that you do something wrong in your app that only causes actual problems on that version (and maybe even only on that device), but there is no indication of that from what you tell. Android 4.2.2 should be backwards compatible with 4.0.3, so in general it should work on the later version too, of course.
I would advice you (or anyone in the same situation) to try it out on other devices with the same Android version if possible. Also, double check that you're not violating anything in the Android API documentation.
Please add more info about what you're doing and how if you need more detailed answers. I guess you've probably found a solution or workaround by now, but still adding my answer here.
I have wrote an application using android 2.2 in eclipse.
My app is working fine on the samsung galaxy mini android 2.2. However, it is not working on samsung galaxy s3 android 4.1.
My app is only taking up half of the screen on the samsung galaxy s3.
Why is my app not working on higher resolution devices?
How can i make the app compatible with other devices running
different versions of android?
Sounds like it's most likely you just have a LinearLayout at the top of your layout XML and it just takes up less space on the S3.
I would advise taking a look at the two links below; if you want a specific starting point, you could adjust your layout to match_parent and use the l/m/h/xhdpi folders to place different size graphics in. Also worth checking whether you are using dp or dip (density independent pixels)
http://developer.android.com/training/multiscreen/index.html
http://android-developers.blogspot.co.uk/2012/11/designing-for-tablets-were-here-to-help.html
The best way to ensure that your app will work on other devices is to get access to other devices and test your application on those devices before you release.
Another way is to make sure that you are targeting the correct SDK you need to target and use the AndroidSupportLibrary when needing to have backwards compatibility.
For us to help with your specific problem we would need more details as to what exactly is going on, but make sure the packages and libraries you are using are compatible with the android versions you are trying to target.
And make good use of the AndroidSupportLibrary.
Did you check the resolution compatibility? This seems more like an Android Manifest issue then an Android version issue.
I have app on the Android Market called Speed Anatomy. It has been working and stable for months. Now before Android 3.2 came out with its pixel-scaling feature, my (canvas based) app appeared un-scaled on some tablets with a large black border. I ended up implementing pixel scaling myself therefore it doesn't use the new 3.2 mechanism. This was fairly easy
public void setSurfaceSize(int width, int height) {
synchronized (mSurfaceHolder) {
matrix.reset();
float cancasScaleFactorY=height/(480.0f*scale);
float cancasScaleFactorX=width/(320.0f*scale);
float cancasScaleFactor=Math.min(cancasScaleFactorY, cancasScaleFactorX);
matrix.postScale(cancasScaleFactor,cancasScaleFactor);
...
public void doDraw(Canvas canvas) {
canvas.setMatrix(matrix);
...
boolean doTouchEvent(MotionEvent event) {
float[] xy=new float[2];
xy[0]=event.getX();
xy[1]=event.getY();
matrixI.set(matrix);
matrixI.invert(matrixI);
//revert touch coordinate to the original unscaled coordinate space.
matrixI.mapPoints(xy);
...
This works with all devices I have tested, including most tablets, the simulators on 3.0, 3.1 etc.
Last week I received an e-mail from a user, saying he had a Sony S with Android 3.2 tablet and the touch coordinates were off by a few centimeters. As I don't have an actual tablet, I went to my local Staples store where they have multiple Android tablets on display. Loaded my app on an eee Transformer with Android 3.2 and a Galaxy tab 10.1 with Android 3.1 and they both ran my app flawlessly.
So I figured the user had made a mistake and used an older version of my app (although he specifically told me he had the latest version of my app from the Android Market).
Yesterday night I was at a concert and there was a booth from Canadian carrier Telus with some Galaxy Tabs 10.1 on display. As I was waiting for some friends and had some time to kill, I loaded my apps on it to do one last test.
To my surprise, the touch detection was all off! Basically it acted like the scaling was done on doDraw(), that is the app was full screen and pixel scaled (except for text which gets rendered at hi-res with my method) but the touch coordinates were not scaled, that is, I had to touch the screen in the top left 320x480 corner or the touches would register outside the screen.
So I have two Galaxy tabs 10.1 with Android 3.1 on it, touches scale properly on one but not the other. I also have a user which claim problems on a Sony S with Android 3.2 and I have it working correctly on a transformer with 3.2. There seems to be a problem with matrix operations on those that don't work correctly. Either it's an intermittent problem or there is some other factor that I haven't thought of. Oh I just thought about the fact that it is probable that the second GT10.1 was a 3g since it was outside on the street while the others were wifi, (I don't know about the user's) but I can't see this affecting matrix transformations, right?
I've never had problems with Android Fragmentation before this, in fact it has been easier than dealing with the different iOS versions.
Any clue what could be causing this and how I fix the problem?
There is a free version of the app if you want to try it. Let me know if it works on your device.
EDIT:I just thought of something else. Is it possible that the Android Market is randomly serving an older version of my app once in a while? I'm not sure but I think this bug may have existed in a version that was briefly up on the Market. It has been fixed and updated more than a month ago however.
After weeks of struggle, I believe I have found the source of the problem in the method:
void android.graphics.Matrix.mapPoints(float[] dst, float[] src)
Since: API Level 1
Apply this matrix to the array of 2D points specified by src, and
write the transformed points into the array of points specified by
dst. The two arrays represent their "points" as pairs of floats [x,
y].
Parameters
dst The array of dst points (x,y pairs)
src The array of src points (x,y pairs)
On some devices, this function cannot take the same array for src and dst. I myself has never been able to reproduce the bug. I debugged this blindly by changing things in my code, making releases and asking some users who had reported the problem if it was fixed.
Changing every instance of:
matrix.mapPoints(xy,xy);
to
float[] tempxy = new float[2];
tempxy[0] = xy[0]; tempxy[1] = xy[1];
matrix.mapPoints(xy,tempxy);
seems to have fixed things.
I found another dev reported the issue here:
http://androidforums.com/developer-101/172225-android-graphics-matrix-mappoints-fail.html
This dev mentions it only happening on older versions of Android whereas to me it seems like a regression happening when users upgrade to Gingerbread. Although it doesn't affect all gingerbread devices as my Galaxy SII X was never affected. I was unable to reproduce it on the Android simulator.
Another hint that Gingerbread is affected is that lately with its rising popularity, users have been reporting the issue more often and the active installation count of my app started to go down. After I implemented the fix, it started going up again.
I hope this helps someone.
Matrix invert_m = new Matrix();
matrixI.invert(invert_m);
invert_m.mapPoints(xy );
You need a new instance of Matrix for return the invert one;
reading about all these different resolutions and hardwares for Android I am a little unsure if the layout I created for an Samsung Galaxy will actually work the same way on all (most) Android devices.
I did not use anything fancy or complicated. However I had to use fixed width in several places to align text and buttons nicely. ALso there is some text with linebreaks that could look differntly if on narrower screens
How can I be sure that my layout will work on other devices? Or is this actually a no issue? Testing in the debugger is sooooo slow, that I actually never got it to work properly.
Thanks very much!
You can set up multiple emulators with different screen sizes, that simulate the possible targets.
In the emulator Ctrl-F11/12 (thanks #ccheneson) allows you to change the orientation, so that you can test that as well.
The emulator may be slow, but to see how the layouts look like it should be fast enough - you may still test the logic on a real device.
Also emulator speed seems to be highly dependent on the screen size.