2012-12-07 41 views
0

我想知道是否有可能識別設備是否有能力觸摸/手勢事件或不在GWT中?識別使用GWT的觸摸/手勢設備

像iPhone這樣的設備在很大程度上支持多點觸控事件。同樣Google桌面版Chrome也支持TouchEvents。而目前,Windows 8已經設計了一個響應TouchEvents的IE。

我正在研究一個應用程序,我想限制某些功能只有觸摸/手勢功能的設備!任何解決方案,請幫忙?

回答

0

我在延遲綁定這樣做有用戶代理檢查。我創建了一個白名單,以便稍後添加更多設備。

下面是代碼,

<!-- 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屬性定義我的班。在這裏,例如,我已經用iPad的設備替換了Flash播放器和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> 
1

我不認爲除UA嗅探之外還有其他方法。

+0

那麼,我們應該定義多少UA? –

+0

任何GWT實現? –

+0

['Windows.Navigator'](http://google-web-toolkit.googlecode.com/svn/javadoc/latest/com/google/gwt/user/client/Window.Navigator.html)? –

1

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

+0

是的,我看到了這一個。但是,當涉及到Windows 8時,這有些問題。在Windows 8中,它只是接受所有的東西...... –

+0

同意。 :)。 GWT還沒有什麼靈丹妙藥。 – SSR

+0

MSDN鏈接很酷...... +1。 –