Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-10492] MobileWeb: Need a way to determine if the browser is on tablet or handset

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionWon't Fix
Resolution Date2017-06-26T22:23:51.000+0000
Affected Version/sRelease 3.0.0
Fix Version/sn/a
ComponentsMobileWeb
Labelsapi
ReporterRussell McMahon
AssigneeChris Barber
Created2012-08-18T21:08:35.000+0000
Updated2018-04-04T23:20:33.000+0000

Description

Comments

  1. Bryan Hughes 2012-08-20

    Subtle distinction worth noting: we can determine if the device is handset or is not a handset. This means that tablets and desktop browsers will be lumped together.
  2. Tony Lukasavage 2012-08-28

    Bryan, that sounds absolutely fine for alloy's purposes. Out of curiosity, hat type of measurement will you be performing to determine the form factor?
  3. Bryan Hughes 2012-08-28

    We are looking at the screen width. Because of historical reasons, handheld devices always have a reported width (when viewed in portrait) of 320, and every tablet device we tested has a width greater than about 450 IIRC. Landscape has a width slightly smaller due to window chrome, so we basically do:
       var isHandheld = Math.min(screen.width, screen.height) < 375;
       
  4. Tony Lukasavage 2012-08-28

    Are the height and width measurements affected by screen density in mobileweb? Density made things especially tricky when finding a solution for this on Android.
  5. Bryan Hughes 2012-08-28

    Height and width measurements are not affected by density on handheld devices, but are on tablets and desktops.
  6. Tony Lukasavage 2012-09-11

    Currently in Alloy I do. iOS gets a certain value based on Ti.Platform.osname being either 'iphone' or 'ipad'. Android gets a certain value based on a custom module, which will be replaced by Ti.Platform.Android.physicalSizeCategory. Mobileweb is currently checked by simply measuring the height and width of the device. The current calculation looks like this:
       isTablet = !(Math.min(
       			Ti.Platform.displayCaps.platformHeight,
       			Ti.Platform.displayCaps.platformWidth
       		) < 700);
       
    This isn't exactly as consistent as iOS and Android so the nature of this ticket was to see if the Mobileweb crew could devise a more reliable method to determine the device size. If a better solution cannot be achieved, we will continue to use the above method. Also, if the above method looks inaccurate, please provide feedback.
  7. Bryan Hughes 2012-09-11

    @Tony Try setting your min a lot lower. I found that 400 was a better value. Every last phone that I tested reported a width of exactly 320 in portrait, and a height that was a little less in landscape. That should give you better results. The method you are using is the only one available, and is how we would have implemented it in Mobile Web. Nit pick: I would call it isPhone and remove the negation because your detection code really detects if it is a phone, or something else that isn't a phone (which includes tablets, desktops, and everything else).
  8. Tony Lukasavage 2012-09-11

    @Bryan thanks for the help there. I'll adjust the measurements. The snippet above doesn't quite give the whole context of how these values are used, but I can assure you your concerns with the negation are handled appropriately. As for the naming, we will probably keep it as is for now, but in future versions of Alloy, a more precise "size" identification will probably be in order.
  9. Bryan Hughes 2012-09-11

    @Tony Perhaps I wasn't clear...I have no problem with the negation, just the name. Using the name isTablet is disingenuous because that does not accurately represent what the device is. I would say it's better to use !isPhone in conditionals than isTablet. Same logic, just a better name :).
  10. Lee Morris 2017-06-26

    Resolving as "Won't Fix" as MobileWeb has been deprecated.
  11. Eric Merriman 2018-04-04

    Closing as will not fix.

JSON Source