GWT-如何编译移动排列

GWT-如何编译移动排列,gwt,mobile,Gwt,Mobile,我知道如何使用延迟绑定为不同的用户代理编译GWT应用程序,但这似乎并没有提供一种在桌面和移动浏览器之间区分IUSH的方法 除了制作基于gwt mobile webkit的新应用程序外,您如何将现有gwt应用程序转换为具有重新设计的移动界面?如果您使用所述的MVP模式,您可以根据用户代理切换视图的实现 您可以拥有ClientFactoryImpl和ClientFactoryMobileImpl。然后使用GWT.create(ClientFactory.class)创建在.GWT.xml文件中定义的

我知道如何使用延迟绑定为不同的用户代理编译GWT应用程序,但这似乎并没有提供一种在桌面和移动浏览器之间区分IUSH的方法


除了制作基于gwt mobile webkit的新应用程序外,您如何将现有gwt应用程序转换为具有重新设计的移动界面?

如果您使用所述的MVP模式,您可以根据用户代理切换视图的实现

您可以拥有ClientFactoryImpl和ClientFactoryMobileImpl。然后使用GWT.create(ClientFactory.class)创建在.GWT.xml文件中定义的实现

下面是.gwt.xml文件的一个示例

<replace-with class="com.bell.cts.e911.ers.web.client.ClientFactoryImpl">
  <when-type-is class="com.bell.cts.e911.ers.web.client.ClientFactory" />
  <when-property-is name="user.agent" value="ie6" />
</replace-with>

<replace-with class="com.bell.cts.e911.ers.web.client.ClientFactoryMobileImpl">
  <when-type-is class="com.bell.cts.e911.ers.web.client.ClientFactory" />
  <when-property-is name="user.agent" value="mobilesafari" />
</replace-with>

您始终可以使用此处描述的技术设置user.agent:


您可以从GWT中看到此示例应用程序: 它检测“FormFactor.gwt.xml”模块中的形状因子,该模块可能如下所示:

<?xml version="1.0" encoding="UTF-8"?>

<!-- Defines the formfactor property and its provider function. -->
<module>

  <!-- Determine if we are in a mobile browser. -->
  <define-property name="formfactor" values="desktop,tablet,mobile"/>

  <property-provider name="formfactor">
  <![CDATA[
      // Look for the formfactor as a url argument.
      var args = location.search;
      var start = args.indexOf("formfactor");
      if (start >= 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";
  ]]>
  </property-provider>

</module>

= 0) {
var值=参数子字符串(开始);
var begin=value.indexOf(“=”)+1;
var end=值。indexOf(“&”);
如果(结束==-1){
end=value.length;
}
返回值。子字符串(开始、结束);
}
//从用户代理检测形状因子。
var ua=navigator.userAgent.toLowerCase();
如果(ua.indexOf(“iphone”)!=-1 | | ua.indexOf(“ipod”)!=-1){
//iphone和ipod。
返回“手机”;
}否则如果(ua.indexOf(“ipad”)!=-1){
//ipad。
返回“平板”;
}否则如果(ua.indexOf(“android”)!=-1 | | ua.indexOf(“移动”)!=-1){
/*
*Android-根据对角线屏幕确定Android设备的形状系数
*尺寸。六英寸以下的都是手机,六英寸以上的都是平板电脑。
*/
var-dpi=160;
变量宽度=$wnd.screen.width/dpi;
变量高度=$wnd.screen.height/dpi;
变量大小=数学sqrt(宽度*宽度+高度*高度);
返回(大小<6)?“手机”:“平板电脑”;
}
//其他一切都是桌面。
返回“桌面”;
]]>