简体   繁体   English

在Blackberry中检测触摸屏?

[英]Detect touch screen in Blackberry?

I am working on a Blackberry application which includes Zoom pinch functionality, but this functionality works in touch screen devices. 我正在使用包含缩放缩放功能的Blackberry应用程序,但是该功能在触摸屏设备上有效。 My app will work on curve type of devices too. 我的应用程序也可以在设备的曲线类型上使用。

Please let me know if "I can detect programmatically if the device is touch screen or not" so I can make my application flexible for both types. 请让我知道“是否可以通过编程方式检测设备是否为触摸屏”,以便使我的应用程序灵活适用于两种类型。

Touch support was added since BlackBerry API 4.7.0. 自BlackBerry API 4.7.0起添加了触摸支持。 Check the documentation of TouchEvent class. 检查TouchEvent类的文档。

So if you are building application for devices running on 4.7.0 or later, you don't need to do anything. 因此,如果要为在4.7.0或更高版本上运行的设备构建应用程序,则无需执行任何操作。 You can code touch event related task and the application will run on both touch and non-touch devices. 您可以编写与触摸事件相关的任务的代码,该应用程序将在触摸和非触摸设备上运行。 For non-touch devices the code related to touch event will not executed. 对于非触摸设备,将不会执行与触摸事件相关的代码。

But if you need to support older devices those are running below 4.7.0 you need use preprocessor directives. 但是,如果需要支持在4.7.0以下运行的旧设备,则需要使用预处理程序指令。

Try following link for using preprocessor directives on you application: 尝试使用以下链接在您的应用程序上使用预处理程序指令:

Coding for Multiple Blackberry Devices - Using Preprocessor Directives in Eclipse 多个Blackberry设备的编码-在Eclipse中使用预处理程序指令

Other related links: 其他相关链接:

Create preprocessor directives for a workspace 为工作区创建预处理程序指令

Specifying preprocessor directives 指定预处理程序指令

Preprocessor directives supported by the RIM compiler RIM编译器支持的预处理器指令

Using preprocessor directives in BlackBerry JDE plugin for eclipse? 在BlackBerry JDE插件中使用预处理器指令进行蚀?

How To - Use the preprocessor in BlackBerry JDE 如何-在BlackBerry JDE中使用预处理器

If you only need to support OS 4.7+ devices, then you don't need to use the preprocessor. 如果您只需要支持OS 4.7+设备,则不需要使用预处理器。 You can programmatically test for the touchscreen with this: 您可以通过以下方式以编程方式测试触摸屏:

boolean isTouch = TouchScreen.isSupported();

What Rupak suggested in his answer may not be enough (just adding touch handling code, which will be ignored for non-touch devices). Rupak在回答中建议的内容可能还不够(仅添加触摸处理代码,对于非触摸设备,它将被忽略)。 In your case, if you want to support a zoom feature, you may need to actively detect a non-touch device (with the code above), and choose to add a new zoom ButtonField , which is not even shown on touch devices that do support the pinch gesture. 在您的情况下,如果要支持缩放功能,则可能需要主动检测非触摸设备(使用上面的代码),然后选择添加新的缩放ButtonField ,即使在具有该功能的触摸设备上也没有显示支持捏手势。 If you don't do this, then either non-touch devices won't be able to zoom, or touch devices will have their screens cluttered with an unnecessary button. 如果您不这样做,则非触摸设备将无法缩放,或者触摸设备的屏幕上会出现不必要的按钮。

But, the TouchScreen API is only for 4.7+. 但是, TouchScreen API仅适用于4.7+。 If you need to run the same code on older OS versions, too, this other method can be used: 如果您还需要在较早的OS版本上运行相同的代码,则可以使用以下另一种方法:

boolean isTouch = (new Canvas(){protected void paint(Graphics graphics){}}).hasPointerEvents();

My apps mostly still do support 4.5+, which can't even compile touch handling code. 我的应用程序大多数仍然支持4.5+,甚至无法编译触摸处理代码。 So, I normally rely on this kind of preprocessor macro to selectively compile different code. 因此,我通常依靠这种预处理器宏来选择性地编译不同的代码。 First, at the top of the file 首先,在文件顶部

//#preprocess

Then, anywhere inside the file: 然后,在文件内的任何位置:

//#ifndef TOUCH_SCREEN
/*
//#endif

// code only for touch devices:
import net.rim.device.api.ui.TouchEvent;

//#ifndef TOUCH_SCREEN
*/
//#endif

And then for builds that I will produce for deployment to touchscreen devices, I add the TOUCH_SCREEN preprocessor flag. 然后,对于要为部署到触摸屏设备而生成的构建,我添加TOUCH_SCREEN预处理器标志。 If you don't want to worry about uploading different app bundles for touch vs. non-touch devices, just programmatically detect touch screens with the Java code ( isTouch ) and use the preprocessor just to remove code that won't compile on pre-4.7 OS versions. 如果您不想为触摸设备和非触摸设备上传不同的应用程序包,只需使用Java代码( isTouch )以编程方式检测触摸屏,并使用预处理器删除在预编译中无法编译的代码4.7操作系统版本。

Note: this somewhat confusing "double negative" preprocessor logic is not a mistake. 注意:这种有点令人困惑的“双重否定”预处理器逻辑不是一个错误。 It's like that to accommodate the slightly different way preprocessors in BlackBerry-enabled IDEs (eg JDE, Eclipse, Netbeans) handle preprocessing. 就像在容纳BlackBerry的IDE(例如JDE,Eclipse,Netbeans)中处理预处理器的方式略有不同一样。 Unfortunately, preprocessing is not a standardized J2ME feature, so it's implementation is a little flaky. 不幸的是,预处理不是标准化的J2ME功能,因此它的实现有点不稳定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM