From fcc353d813317b3b3cd8c59f9cd181f017036e55 Mon Sep 17 00:00:00 2001 From: Axel Uhl Date: Fri, 23 May 2014 17:08:42 +0200 Subject: [PATCH] added form factor detection script and use in Home.gwt.xml --- .../com.google.gwt.eclipse.core.prefs | 2 +- .../com/sap/sailing/gwt/FormFactor.gwt.xml | 51 +++++++++++++++++++ .../com/sap/sailing/gwt/Home.gwt.xml | 15 +++++- 3 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/FormFactor.gwt.xml diff --git a/java/com.sap.sailing.gwt.ui/.settings/com.google.gwt.eclipse.core.prefs b/java/com.sap.sailing.gwt.ui/.settings/com.google.gwt.eclipse.core.prefs index e61c9136447..d22b034e1d2 100755 --- a/java/com.sap.sailing.gwt.ui/.settings/com.google.gwt.eclipse.core.prefs +++ b/java/com.sap.sailing.gwt.ui/.settings/com.google.gwt.eclipse.core.prefs @@ -1,4 +1,4 @@ eclipse.preferences.version=1 entryPointModules= filesCopiedToWebInfLib=gwt-servlet.jar -gwtCompileSettings=PGd3dC1jb21waWxlLXNldHRpbmdzPjxsb2ctbGV2ZWw+SU5GTzwvbG9nLWxldmVsPjxvdXRwdXQtc3R5bGU+T0JGVVNDQVRFRDwvb3V0cHV0LXN0eWxlPjxleHRyYS1hcmdzPjwhW0NEQVRBWy13YXIgLiAtbG9jYWxXb3JrZXJzIDMgLXN0cmljdCAtbG9nTGV2ZWwgVFJBQ0VdXT48L2V4dHJhLWFyZ3M+PHZtLWFyZ3M+PCFbQ0RBVEFbLVhteDIwMjRtIC1EZ3d0LnVzZWFyY2hpdmVzPWZhbHNlXV0+PC92bS1hcmdzPjxlbnRyeS1wb2ludC1tb2R1bGU+Y29tLnNhcC5zYWlsaW5nLmd3dC51aS5EYXRhTWluaW5nPC9lbnRyeS1wb2ludC1tb2R1bGU+PC9nd3QtY29tcGlsZS1zZXR0aW5ncz4\= +gwtCompileSettings=PGd3dC1jb21waWxlLXNldHRpbmdzPjxsb2ctbGV2ZWw+SU5GTzwvbG9nLWxldmVsPjxvdXRwdXQtc3R5bGU+T0JGVVNDQVRFRDwvb3V0cHV0LXN0eWxlPjxleHRyYS1hcmdzPjwhW0NEQVRBWy13YXIgLiAtbG9jYWxXb3JrZXJzIDMgLXN0cmljdCAtbG9nTGV2ZWwgVFJBQ0UgLVhzb3ljRGV0YWlsZWRdXT48L2V4dHJhLWFyZ3M+PHZtLWFyZ3M+PCFbQ0RBVEFbLVhteDIwMjRtIC1EZ3d0LnVzZWFyY2hpdmVzPWZhbHNlXV0+PC92bS1hcmdzPjxlbnRyeS1wb2ludC1tb2R1bGU+Y29tLnNhcC5zYWlsaW5nLmd3dC5Ib21lPC9lbnRyeS1wb2ludC1tb2R1bGU+PC9nd3QtY29tcGlsZS1zZXR0aW5ncz4\= diff --git a/java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/FormFactor.gwt.xml b/java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/FormFactor.gwt.xml new file mode 100644 index 00000000000..d847effe92c --- /dev/null +++ b/java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/FormFactor.gwt.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + = 0) { + var value = args.substring(start); + var begin = value.indexOf("=") + 1; + var end = value.indexOf("&"); + if (end == -1) { + end = value.length; + } + return value.substring(begin, end); + } + + // Detect form factor from user agent. + var ua = navigator.userAgent.toLowerCase(); + if (ua.indexOf("iphone") != -1 || ua.indexOf("ipod") != -1) { + // iphone and ipod. + return "mobile"; + } else if (ua.indexOf("ipad") != -1) { + // ipad. + return "tablet"; + } else if (ua.indexOf("android") != -1 || ua.indexOf("mobile") != -1) { + /* + * Android - determine the form factor of android devices based on the diagonal screen + * size. Anything under six inches is a phone, anything over six inches is a tablet. + */ + var dpi = 160; + var width = $wnd.screen.width / dpi; + var height = $wnd.screen.height / dpi; + var size = Math.sqrt(width*width + height*height); + return (size < 6) ? "mobile" : "tablet"; + } + + // Everything else is a desktop. + return "desktop"; + ]]> + + + diff --git a/java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/Home.gwt.xml b/java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/Home.gwt.xml index e2fbbc64f83..eab03fb9556 100644 --- a/java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/Home.gwt.xml +++ b/java/com.sap.sailing.gwt.ui/src/main/resources/com/sap/sailing/gwt/Home.gwt.xml @@ -9,7 +9,8 @@ - + + @@ -23,8 +24,20 @@ + + + + + + + + + + +