デバイスがGWTでタッチ/ジェスチャイベントに対応しているかどうかを識別できるかどうかを知りたいですか?
iPhoneのようなデバイスは、マルチタッチイベントを大幅にサポートしています。同様に、デスクトップのGoogleChromeもをサポートしていますTouchEvents
。そして現在、Windows8はに応答するIEで設計されていTouchEvents
ます。
特定の機能をタッチ/ジェスチャー対応デバイスのみに制限したいアプリケーションに取り組んでいます!解決策はありますか?
GWT は現在、そのようなユーティリティを提供していません。
また、gwt が直接のユーティリティ api を提供するまでは、これらの既存の javascript 手法に jsni を上書きすることは理にかなっています。 device-using-javascript .
Windows 8 の場合、参照する msdn ドキュメントはhttp://blogs.msdn.com/b/ie/archive/2011/09/20/touch-input-for-ie10-and-metro-style-apps.aspxです。
これは、 Deferred Binding の User Agent Check で行いました。後でデバイスを追加できるように、ホワイト リストを作成しました。
これがコードです。
<!-- 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 Player を 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>