ElkArte Community

Elk Development => Bug Reports => Exterminated Bugs => Topic started by: Antechinus on February 12, 2013, 06:44:50 pm

Title: Android tablets are teh sex!
Post by: Antechinus on February 12, 2013, 06:44:50 pm
So they wont want silly little mobile themes forced on them, will they? :D


Code: [Select]
		// blackberry, playbook, iphone, nokia, android and ipods set a mobile flag
if ($this->_browsers['is_iphone'] || $this->_browsers['is_blackberry'] || $this->_browsers['is_android'] || $this->_browsers['is_nokia'])
$this->_is_mobile = true;


Android sets a mobile tag in the user agent for phones, and doesn't set it for tablets. Examples here: http://www.gtrifonov.com/2011/04/15/google-android-user-agent-strings-2/

So, it would be better to split Android detection so that we have a $context thingy for teh phonez and another for teh tablets. Second one could be rolled into the iPad biz to make a is_tablet dooverlacky. This would be a better solution than the current code.
Title: Re: Android tablets are teh sex!
Post by: Antechinus on February 14, 2013, 05:40:41 pm
In case anyone gives a rat's this is what I'm using.

Code: [Select]
		'is_iphone' => (strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone') !== false || strpos($_SERVER['HTTP_USER_AGENT'], 'iPod') !== false) && strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') === false,
'is_ipad' => strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') !== false,
'is_android_phone' => strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') !== false,
'is_android_tablet' => strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false && strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') === false,

And this for tablets:
Code: [Select]
	$context['browser']['is_tablet'] = $context['browser']['is_ipad'] || $context['browser']['is_android_tablet'];

Can add others of course, if anyone ever actually buys a W8 tablet. :D
Title: Re: Android tablets are teh sex!
Post by: Spuds on February 14, 2013, 10:36:53 pm
Logged the issue for tracking ... thanks for the heads up  :)
Title: Re: Android tablets are teh sex!
Post by: Antechinus on February 19, 2013, 04:10:01 pm
         'is_android' => strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false,
         'is_nokia' => strpos($_SERVER['HTTP_USER_AGENT'], 'SymbianOS') !== false,
         'is_ipad' => strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') !== false,
      );

      // blackberry, playbook, iphone, nokia, android and ipods set a mobile flag
      if ($this->_browsers['is_iphone'] || $this->_browsers['is_blackberry'] || $this->_browsers['is_android'] || $this->_browsers['is_nokia'])
         $this->_is_mobile = true;

      // iPad and droid tablets get a tablet flag
      if ($this->_browsers['is_ipad'] || ($this->_browsers['is_android'] && strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') === false))
         $this->_is_tablet = true;
Title: Re: Android tablets are teh sex!
Post by: Antechinus on February 19, 2013, 04:16:15 pm
Just had to post the above without comment, coz I haz found another bug! :D

(Namely: put stuff in code tag, stretch out post box, oops cannot get cursor outside code tag to post extra comment).

Anyway: the detection code above is going to start by flagging droid tablets as droid phones, then set another flag as tablet. What's the advantage in doing it that way? If someone writes code that depends on the right choice between the two, you might get a conflict, yes?

'is_android' => strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false, <<Oh looky, it's a phone!

if ($this->_browsers['is_ipad'] || ($this->_browsers['is_android'] && strpos($_SERVER['HTTP_USER_AGENT'], 'Mobile') === false))
         $this->_is_tablet = true;  <<Oh bugger, which is it then?

That's why I wrote my code to split the two before it got that far. I think it's safer that way.
Title: Re: Android tablets are teh sex!
Post by: Spuds on February 19, 2013, 05:05:32 pm
$this->_is_tablet as well as $this->_is_mobile are private variables to the class (meaning you don't access them, they are internal flags). 

For final output it simply gives precedence to $this->_is_tablet over $this->_is_mobile ... meaning if tablet was detected that's output and that's all, otherwise mobile otherwise browser x

I did it that way to avoid repetitively doing (essentially) the same strpos checks again
Title: Re: Android tablets are teh sex!
Post by: Antechinus on February 19, 2013, 05:31:46 pm
Wotcha mean can't access them? Surely they can be used in templates n stuff?
Title: Re: Android tablets are teh sex!
Post by: Spuds on February 19, 2013, 05:58:15 pm
Meaning those particular items you listed don't get used outside that function

Now it just sets $context['browser_body_id'] as tablet or mobile or ie or chrome or firefox etc

Guess we could add in isBrowser('tablet') and isBrowser('mobile') for completeness
Title: Re: Android tablets are teh sex!
Post by: Antechinus on February 19, 2013, 06:03:06 pm
Aha. Yeah I'd be inclined to go for something more comprehensive. Mobile/tablet stuff is still a tad wonky as far as standards support goes. Around a third of Android usrs are still on 2.x.x for instance, which is not as solid as the later versions. iShiz has significant problems with some areas of basic standards too (fixed positioning springs to mind). I think it'd be worthwhile giving maximum targeting ability for anything related to 'droid and iShiz, at least for the next couple of years.
Title: Re: Android tablets are teh sex!
Post by: emanuele on November 01, 2013, 10:12:21 am
/me lost track of what is needed here