【问题标题】:Identify Touch/Gesture Capable Devices using GWT使用 GWT 识别具有触摸/手势功能的设备
【发布时间】:2012-11-25 08:13:33
【问题描述】:

我想知道是否可以在 GWT 中识别设备是否能够触摸/手势事件

iPhone 等设备在很大程度上支持多点触控事件。同样,桌面版 Google Chrome 也支持TouchEvents。而目前,Windows 8已经设计了一个响应TouchEvents的IE。

我正在开发一个应用程序,我想将某些功能限制为仅支持触摸/手势的设备!有什么解决办法,请帮忙?

【问题讨论】:

    标签: gwt mobile touch device jsni


    【解决方案1】:

    我认为除了 UA 嗅探之外没有其他方法。

    【讨论】:

    【解决方案2】:

    GWT 目前不提供此类实用程序。

    此外,在 gwt 为我们提供直接实用程序 api 之前,在现有的 javascript 技术(如 stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript )上编写 jsni 是有意义的。

    对于 Windows 8,要参考的 msdn 文档是 http://blogs.msdn.com/b/ie/archive/2011/09/20/touch-input-for-ie10-and-metro-style-apps.aspx

    【讨论】:

    • 是的,我看到了这个。但这在 Windows 8 中存在问题。在 Windows 8 中,它只是将所有内容都视为触摸......
    • 其经典的 Microsoft 方法 :( 。我们被困在自定义代码以专门用于 IE10。
    【解决方案3】:

    我使用 延迟绑定中的用户代理检查来做到这一点。我创建了一个白名单,以便以后可以添加更多设备。

    这是代码,

    <!-- Definitions for mobile -->
    <define-property name="mobile.user.agent" values="android, ios, not_mobile" />
    <property-provider name="mobile.user.agent"><![CDATA[
    {
       var ua = window.navigator.userAgent.toLowerCase();
       if (ua.indexOf("android") != -1) { return "android"; }
       if (ua.indexOf("iphone") != -1) { return "ios"; }
       if (ua.indexOf("ipad") != -1) { return "ios"; }
         return 'not_mobile';
       }
    ]]></property-provider>
    
    <!-- Constrain the value for non-webkit browsers -->
    <set-property name="mobile.user.agent" value="not_mobile" >
      <none> <!-- Actually means NOR, in this case "not safari" -->
        <when-property-is name="user.agent" value="safari" />
      </none>
    </set-property>
    

    然后我使用模块文件中的 replace-with 属性定义了我的类。例如,我已将 Flash 播放器替换为适用于 iPad 等设备的 HTML5 视频。

    <replace-with class="com.example.HTML5Player">
            <when-type-is class="com.example.FlashPlayer" />
            <any>
               <when-property-is name="mobile.user.agent" value="android" />
               <when-property-is name="mobile.user.agent" value="ios" />
            </any>
    </replace-with>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-19
      • 1970-01-01
      • 2018-12-31
      • 2017-04-23
      • 1970-01-01
      • 1970-01-01
      • 2013-05-28
      相关资源
      最近更新 更多