Detecting 'Phablets' like the Note 3 for layout - android

I am trying to differentiate layouts in Android (ICS+) for larger devices like the note 3 but finding it next to impossible to do without reading the device name or attempting to calculate physical size in code.
The (deprecated) size attribute for the note 3 identifies as normal, as does the HTC One Mini.
Same goes for using sw350dp / xxhdpi. Not sure if the HTC Mini is the unusual device here, but I would imagine all the newer high-end mini handsets will be the same. I also don't want to use px values if I can help it as smaller devices can (and probably will) go up to 1080p, and notes prior to 3 use lower.
Is there something I am missing here? If not, is any reliable way to calculate the physical size or am I better off hard-coding device lists to provide optimal layouts?
EDIT
So part of this was due to multiple overriding layout folders causing some funkiness and I now have the Mini using the correct values, however I am still in the same situation with the S4 and Note 3 using the same resources. While this is not as bad, it still isn't optimal.
I expect that the Note 1 and 2 will also drop back to the lower DPI resources meaning their real-estate won't be utilised either.

Do NOT use screen size approach. Some phablet users who have Galaxy Mega 5.8/6.3 device or Nexus 6 may have unintended experience.
Use resource based approach sw600dp and sw720dp as below link.
Tablet or Phone - Android

Related

Android - layout-large not being selected for Samsung Galaxy S8+

In my app, I support multiple screens to a reasonable extent as per the guidelines here and here. However, the S8+ seems to be taking the layout-normal layout instead of layout-large. I remember reading that it could be due to its odd aspect ratio (18.5:9) when its setting for "use fullscreen" or something is enabled. It seems with or without this setting the result is the same (uses normal layout). I suspect there are other phones that will have this issue.
Also, interestingly, I made a generic device definition in Android Studio of that phone, with it's 2960x1440, 6.2" screen to preview the screen and Android automatically reclassified it as a tablet (and forces it to use the large layout in the preview). This leads me to believe that it would do the same at runtime on a device, but it would appear it doesn't.
How can I set my app to have these phones (perhaps those with these...problematic...aspect ratios) use the large layout it was supposed to?
As mentioned in the comment by #CommonsWare, it would be better to use dp size qualifiers, however to shed a little light on why your problem happens:
The old size qualifiers are size "buckets", they represent a range of sizes and aren't very precise. So the S8+ falls into the normal size bucket on the device (probably due to the size the device is reporting), but large on the emulator (which seems suspect to me).
If you look closely at the resource qualifier definitions listed here Providing Resources you will notice the definitions for screen size are a bit vague.. taking a unit dp to be 1/160 inch.. the screen sizes they describe are "approximately":
small: 2" x 2.6"
medium: 2" x 2.9"
large: 3" x 4"
xlarge: 4.5" x 6"
Note that all of these sizes are surprisingly small. In reality the device manufacturer decides the bucket it falls into, which is very likely why your S8+ reports "normal" and the emulator is a tablet.. by the table above, it would be.
Essentially I recommend you use the "smallest width" qualifier. You can find some hints around the values you might want on the same page linked above.

Scale up the app on large devices (generic scale)

I have finished my app and it looks great on phones (regardless of the density). Is there a way (attribute or generic method I can call or some sort of settings) that would just make all the screen elements ( images, buttons and texts) bigger for large screens such as tablets.
I remember one of the tablets (I think TF), had an option to just scale up the whole app to fit the screen. This could be only a feature of that specific company or it could be an attribute set on the app. Perhaps I can achieve the same behavior?
PS: I know some may disagree saying that this may not look good on tablet, not the right way and that specific layouts should be provided for large screens but that's ok. I have considered that and I am ok with my approach. My app target is mainly phones but if it runs on 7 or 10 inch tablet (rarely), I want everything just bigger.
Thank you

7in tablets in Android - screen size qualifiers

I encountered a weird behaviour when starting to test my app on some 7in Android models and I would like to find out if others are finding the same problem and what people recommend as a fix.
Here are the details:
The application has full tablet support, which is triggered with qualifiers for the layouts. xlarge devices get the tablet mode with multiple fragments being displayed on the screen.
For newer Android versions there are also some values that set variable that change the UI on the flow using the sw600dp qualifier as well as the xlarge one.
The problem:
I am now testing on the Kindle Fire and the RIM BlackBerry Playbook and also want to support the upcoming Google Nexus Tablet (or whatever it will be called) and other 7in form factor devices.
Both the playbook as well as the fire have a 7in screen and a 1024x600 screen resolution.
However the playbook seems to trick Android into thinking it is a xlarge device, while the fire does not do that.
Both the tablet as well as the standard UI work fine, but imho the tablet mode is nicer and is fine to be used on the 7in device. However if I push the layout into the large qualifier to also get that tablet mode on the fire I will also get it e.g. on the Note or other quite a bit smaller devices.
With Android 4x I can use the sw600dp and other qualifiers but what about older versions? I assume a 7in device is supposed to behave like a tablet but what about e.g. the Note..
What are best practices for this scenario? Are my observations with the playbook reporting xlarge correct?
However the playbook seems to trick Android into thinking it is a xlarge device, while the fire does not do that.
Device manufacturers are the ones who choose which buckets a device goes in with respect to size and density. This goes double for manufacturers like RIM and Amazon, who do not want the Play Store and therefore do not have to abide by any particular compatibility requirements the Play Store dictates, so they are welcome to thumb their noses at Google's guidance.
What are best practices for this scenario?
I can't tell you "best".
However, if there are specific devices for which you wish to override some layouts to use a specific size, here's what I would try (assuming the layout you would be using for normal cases is known as R.layout.main):
Step #1: Create res/layout/main_funky.xml as a symlink or hardlink to res/layout-xlarge/main.xml (and likewise for -land, etc.).
Step #2: In your Java code, wherever you refer to R.layout.main (e.g., onCreateView() of a Fragment), decide whether to load R.layout.main or R.layout.main_funky depending upon android.os.Build data to detect these oddball devices by model. Since R.layout.main_funky is one of your normal main layouts, all of your code that depends upon widgets should be unaffected by this choice.
Step #3: In your particular case, add MMPD (magic Maven pixie dust) to steps #1 and #2... :-)
Are my observations with the playbook reporting xlarge correct?
I bought a Playbook, determined that RIM's distribution model is... unpleasant, and did the bare minimum to have a book chapter on it. I haven't tried to see if it is -large, -xlarge, or something else.
That being said, the NOOK Tablet IIRC suffers from this (claiming to be -xlarge rather than -large).
I would expect a Google Nexus tablet, if such a thing comes to fruition, to correctly honor size buckets, plus be running a new enough Android version that -sw600dp and kin will work.

Large screens layout not as expected

I developed and application and uploaded all the images in the respective drawable folders (different pixels for different desnities).
Now I am confused when it comes to layout. If I used the layout editor with 4.1 inc (thats considered Med screen I guess?) everything looks great.
Now when I use the editor with 10.1 inch which is the tablet, then I see icons very small and the text is small. I have not run the emulator yet.
So I am wondering:
1- why would the text be small although I didn't specify text size? Shouldnt scalle appropriately? or should I give it a specific size for bigger layouts?
2- Why the icons are small given that I provided the different drawables? I thought it would scale up accordingly.
Please don't give me the supporting multiple screens link in android as an answer, as I already went through it and still no luck with above. I need your personal advice as I think I am missing something here
Thank you so much in advance
Android support for different screens is a little tricky. That's because you can have large, small, medium and xlarge screens, plus high, medium and low density ones. There are a dozen possibilities (xlarge low density, small high density) and not a single resolution is defined. So you must know the principles which the API is designed upon and must define your layout thinking about the role the widget has inside your UI. You also must bear in mind that your layout won't be pixel perfect on 100% of devices, so your aim should be being usable on all possible devices.
In your specific case it seems that either you don't manage to specify the correct resources, or the system doesn't pick up the right ones for you, but I must remark that it doesn't make sense on Android to talk about big, small and scale: you should design your layout with a (good) webdeveloper mindset, who daily deals with tons of different displays, resolutions, physical sizes and even devices.
I also suggest not using the graphical builder if you are new to Android, because you really need to know how Android lays out components, otherwise you will come back to SO very often :)
If you do not specify the text size in your layout file Android will take the default value, which is most likely in DIP (density independent pixel) therefore it will be the same physical size on any devices. That should explain why the text looks so small on your 10 inch tablet.
What I would do in this case is have 3 layouts for each activities and specify the text size for larger devices (given you already like the look on phones) and put them in this folder scheme :
res/layout/layout.xml // phones
res/layout-sw600dp/layout.xml // 7” tablets
res/layout-sw720dp/layout.xml // 10” tablets
Information above was taken in this article. I have this applied in my current personal project and so far it works like a charm.
Secondly, as far as icons go, I'm no drawable expert but if you provided the same file in each folder (like I think you did from what I understand in your question), it will not make it scale. You'll have to create 4 difference icons, one for each possible pixel density.
Information about icon sizes can be found on this page.
Hope this is of some help to you.
My experience with the Android device zoo drew me to the sad conclusion that the built-in screen size/layout facility is useless. Cases in point, straight from support:
a 10 inch tablet with Android 2.2. Screen size xlarge is not supported by Android 2.2
Kindle Fire, which is 7 inch and claims it's xlarge.
I ended up putting all three layouts (med/large/xlarge) into layout, loading one based on run-time density and resolution, and providing an option for user to force a specific layout.
Just sayin'.

How can I distinguish phone from tablet

Using Adobe AIR for Android, I'd like to find a way to distinguish a phone from a tablet. The closest I can find is detecting the dpi. (My phone dpi is 254, my tablet is 149) but is that going to be reliable or is there a better way?
(I've been using stackoverflow for a while but this is my first post - yippee!!)
but is that going to be reliable
Absolutely not. A T-Mobile G1 would be a tablet by that measure.
is there a better way?
Frankly, you should not be caring whether an Android device is a telephone, tablet, television, toaster, telescope, or toilet.
You should be caring about characteristics and capabilities.
For example, if you are thinking about tablets in terms of screen size, use <supports-screens> and the -large and -xlarge resource sets (e.g., res/layout/ for normal stuff and res/layout-large/ for larger screen sizes).
Or, if you are thinking about tablets in terms of whether or not you can place a phone call, use <uses-feature> and hasSystemFeature() on PackageManager.
Whether a device is a tablet or not could mean...
One.... Is it running the Honeycomb tablet version (Android 3.0) ? You can use System.getProperty() to get this information.
or
Two....Is it tablet sized? i.e. is the screen a larger size? But bear in mind some tablets are not that big. Best way to handle these is separate resources for each device size.
I'd say in general it's a bad idea to try to define Android tablets into specific groups, as there are many varieties now and a LOT more are coming. So usually best to build your app so it handles different screen sizes, different OS versions, and different features being available or absent (e.g. GPS, keyboard etc).
cdotspace, don't worry about the real dpi, you only need to get virutal dpi:
int virtual_dpi=webview1.getResources().getDisplayMetrics().densityDpi;
Virutal dpi means dots per virtual inch.
For example, the htc desire hd's real width is 2.21 inches, but its virutal width is still 2 inches, the galaxy tab 10.1's real width is 5.35 inches(portrait orient), but its virtual width is 5 inches.
int portrait_width_pixel=Math.min(this.getResources().getDisplayMetrics().widthPixels, this.getResources().getDisplayMetrics().heightPixels);
int dots_per_virtual_inch=this.getResources().getDisplayMetrics().densityDpi;
float virutal_width_inch=portrait_width_pixel/dots_per_virtual_inch;
if (virutal_width_inch<=2)
{//is phone
}
else
{//is tablet
}

Categories

Resources