From 709f35aca0f445444c8052015e34113e567a3166 Mon Sep 17 00:00:00 2001 From: Denis Anisimov Date: Sun, 7 Sep 2014 16:33:30 +0300 Subject: [PATCH] isIPad() and isIPhone() methods are added to WebBrowser (#14424,#14423). Change-Id: I7b3556d5f9c1dd84beec638d7fbff1c5382070a4 --- .../TestVBrowserDetailsUserAgentParser.java | 14 +++++++++++ server/src/com/vaadin/server/WebBrowser.java | 20 +++++++++++++++ .../com/vaadin/shared/VBrowserDetails.java | 25 +++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/client/tests/src/com/vaadin/client/TestVBrowserDetailsUserAgentParser.java b/client/tests/src/com/vaadin/client/TestVBrowserDetailsUserAgentParser.java index dd892b19ec..6cd0630137 100644 --- a/client/tests/src/com/vaadin/client/TestVBrowserDetailsUserAgentParser.java +++ b/client/tests/src/com/vaadin/client/TestVBrowserDetailsUserAgentParser.java @@ -85,6 +85,7 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase { // assertBrowserMinorVersion(bd, 1); assertEngineVersion(bd, 536f); assertIOS(bd, 6, 1); + assertIPhone(bd); } public void testIPhoneIOS5() { @@ -95,6 +96,7 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase { assertBrowserMinorVersion(bd, 1); assertEngineVersion(bd, 534f); assertIOS(bd, 5, 1); + assertIPhone(bd); } public void testIPhoneIOS4() { @@ -105,6 +107,7 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase { assertBrowserMinorVersion(bd, 0); assertEngineVersion(bd, 532f); assertIOS(bd, 4, 0); + assertIPhone(bd); } public void testIPadIOS4() { @@ -115,6 +118,7 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase { assertBrowserMinorVersion(bd, 0); assertEngineVersion(bd, 533f); assertIOS(bd, 4, 3); + assertIPad(bd); } public void testAndroid21() { @@ -539,6 +543,16 @@ public class TestVBrowserDetailsUserAgentParser extends TestCase { assertOSMinorVersion(browserDetails, minorVersion); } + private void assertIPhone(VBrowserDetails browserDetails) { + assertTrue(browserDetails.isIPhone()); + assertFalse(browserDetails.isIPad()); + } + + private void assertIPad(VBrowserDetails browserDetails) { + assertFalse(browserDetails.isIPhone()); + assertTrue(browserDetails.isIPad()); + } + private void assertWindows(VBrowserDetails browserDetails) { assertWindows(browserDetails, false); } diff --git a/server/src/com/vaadin/server/WebBrowser.java b/server/src/com/vaadin/server/WebBrowser.java index 17ba6756b8..cb5979d612 100644 --- a/server/src/com/vaadin/server/WebBrowser.java +++ b/server/src/com/vaadin/server/WebBrowser.java @@ -290,6 +290,26 @@ public class WebBrowser implements Serializable { return browserDetails.isIOS(); } + /** + * Tests if the browser is run on IPhone. + * + * @return true if run on IPhone false if the user is not using IPhone or if + * no information on the browser is present + */ + public boolean isIPhone() { + return browserDetails.isIPhone(); + } + + /** + * Tests if the browser is run on IPad. + * + * @return true if run on IPad false if the user is not using IPad or if no + * information on the browser is present + */ + public boolean isIPad() { + return browserDetails.isIPad(); + } + /** * Returns the browser-reported TimeZone offset in milliseconds from GMT. * This includes possible daylight saving adjustments, to figure out which diff --git a/shared/src/com/vaadin/shared/VBrowserDetails.java b/shared/src/com/vaadin/shared/VBrowserDetails.java index 5fbf9bbb39..a85d031c49 100644 --- a/shared/src/com/vaadin/shared/VBrowserDetails.java +++ b/shared/src/com/vaadin/shared/VBrowserDetails.java @@ -43,6 +43,8 @@ public class VBrowserDetails implements Serializable { private boolean isIE = false; private boolean isWindowsPhone; + private boolean isIPad; + private boolean isIPhone; private OperatingSystem os = OperatingSystem.UNKNOWN; @@ -176,8 +178,9 @@ public class VBrowserDetails implements Serializable { } else if (userAgent.contains("macintosh") || userAgent.contains("mac osx") || userAgent.contains("mac os x")) { - if (userAgent.contains("ipad") || userAgent.contains("ipod") - || userAgent.contains("iphone")) { + isIPad = userAgent.contains("ipad"); + isIPhone = userAgent.contains("iphone"); + if (isIPad || userAgent.contains("ipod") || isIPhone) { os = OperatingSystem.IOS; parseIOSVersion(userAgent); } else { @@ -473,6 +476,24 @@ public class VBrowserDetails implements Serializable { return os == OperatingSystem.IOS; } + /** + * Tests if the browser is run on iPhone. + * + * @return + */ + public boolean isIPhone() { + return isIPhone; + } + + /** + * Tests if the browser is run on iPad. + * + * @return + */ + public boolean isIPad() { + return isIPad; + } + /** * Returns the major version of the operating system. Currently only * supported for mobile devices (iOS/Android) -- 2.39.5