This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Merge pull request #977 from elinw/androidtablet

Android Tablet Detection
  • Loading branch information...
2 parents 5f90f5c + 38d0e46 commit 263e67d5673210923c5e7a1bc0d0a0b76561c756 @eddieajau eddieajau committed Apr 8, 2012
@@ -51,6 +51,7 @@ class JApplicationWebClient
const CHROME = 19;
const SAFARI = 20;
const OPERA = 21;
+ const ANDROIDTABLET = 22;
/**
* @var integer The detected platform on which the web client runs.
@@ -267,7 +268,7 @@ protected function detectBrowser($userAgent)
if (preg_match_all($pattern, $userAgent, $matches))
{
// Do we have both a Version and browser match?
- if (count($matches['browser']) > 1)
+ if (count($matches['browser']) == 2)
{
// See whether Version or browser came first, and use the number accordingly.
if (strripos($userAgent, 'Version') < strripos($userAgent, $patternBrowser))
@@ -279,6 +280,14 @@ protected function detectBrowser($userAgent)
$this->browserVersion = $matches['version'][1];
}
}
+ elseif (count($matches['browser']) > 2)
+ {
+ $key = array_search('Version', $matches['browser']);
+ if ($key)
+ {
+ $this->browserVersion = $matches['version'][$key];
+ }
+ }
// We only have a Version or a browser so use what we have.
else
{
@@ -443,6 +452,18 @@ protected function detectPlatform($userAgent)
{
$this->mobile = true;
$this->platform = self::ANDROID;
+ /**
+ * Attempt to distinguish between Android phones and tablets
+ * There is no totally foolproof method but certain rules almost always hold
+ * Android 3.x is only used for tablets
+ * Some devices and browsers encourage users to change their UA string to include Tablet.
+ * Google encourages manufacturers to exclude the string Mobile from tablet device UA strings.
+ * In some modes Kindle Android devices include the string Mobile but they include the string Silk.
+ */
+ if (stripos($userAgent, 'Android 3') !== false || stripos($userAgent, 'Tablet') !== false || stripos($userAgent, 'Mobile') === false || stripos($userAgent, 'Silk') !== false )
+ {
+ $this->platform = self::ANDROIDTABLET;
+ }
}
elseif (stripos($userAgent, 'Linux') !== false)
{
@@ -50,8 +50,12 @@ public static function getUserAgentData()
array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::WEBKIT, JApplicationWebClient::CHROME, '15.0.864.0', 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.864.0 Safari/535.2'),
array(JApplicationWebClient::BLACKBERRY, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '6.0.0.546', 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9700; pt) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.546 Mobile Safari/534.8+'),
array(JApplicationWebClient::BLACKBERRY, true, JApplicationWebClient::WEBKIT, '', '', 'BlackBerry9700/5.0.0.862 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/120'),
- array(JApplicationWebClient::ANDROID, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '999.9', 'Mozilla/5.0 (Linux; U; Android 2.3; en-us) AppleWebKit/999+ (KHTML, like Gecko) Safari/999.9'),
+ array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '999.9', 'Mozilla/5.0 (Linux; U; Android 2.3; en-us) AppleWebKit/999+ (KHTML, like Gecko) Safari/999.9'),
array(JApplicationWebClient::ANDROID, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4', 'Mozilla/5.0 (Linux; U; Android 2.2.1; en-ca; LG-P505R Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'),
+ array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4', 'Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13'),
+ array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4', 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Silk/1.1.0-84) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 Silk-Accelerated=false'),
+ array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::GECKO, JApplicationWebClient::FIREFOX, '12', ' Mozilla/5.0 (Android; Tablet; rv:12.0) Gecko/12.0 Firefox/12.0'),
+ array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::PRESTO, JApplicationWebClient::OPERA, '11.5', 'Opera/9.80 (Android 3.2.1; Linux; Opera Tablet/ADR-1111101157; U; en) Presto/2.9.201 Version/11.50'),
array(JApplicationWebClient::IPAD, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.4', 'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10gin_lib.cc'),
array(JApplicationWebClient::IPHONE, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.5', 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B5097d Safari/6531.22.7'),
array(JApplicationWebClient::IPAD, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.4', 'Mozilla/5.0(iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10gin_lib.cc'),

0 comments on commit 263e67d

Please sign in to comment.