检测触摸屏黑莓? [英] Detect touch screen in Blackberry?

查看:166
本文介绍了检测触摸屏黑莓?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个BlackBerry应用程序,其中包括捏缩放功能,但这个功能在触摸屏设备的工作原理。我的应用程序将工作在曲线类型的设备太。

I am working on a Blackberry application which includes Zoom pinch functionality, but this functionality works in touch screen devices. 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.

推荐答案

如果您只需要支持OS 4.7+设备,那么你就需要使用preprocessor。您可以通过编程测试与此触摸屏:

If you only need to support OS 4.7+ devices, then you don't need to use the preprocessor. You can programmatically test for the touchscreen with this:

boolean isTouch = TouchScreen.isSupported();

什么Rupak在他的回答暗示可能没有足够的(只是添加触摸操控code,这将对于非触摸设备被忽略)。在你的情况,如果你想支持缩放功能,您可能需要主动检测非触摸设备(与code以上),并选择添加新的缩放 ButtonField字段,这是不是即使在那些支持缩放手势触摸设备中。如果你不这样做,那么无论非触摸设备将不能够放大,或触摸设备将有自己的屏幕堆满了不必要的按钮。

What Rupak suggested in his answer may not be enough (just adding touch handling code, which will be ignored for non-touch devices). 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. 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.

不过,在触摸屏 API仅供4.7+。如果你需要运行在旧操作系统版本的同一code,也可以采用这种方法,其他:

But, the TouchScreen API is only for 4.7+. If you need to run the same code on older OS versions, too, this other method can be used:

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

我的应用大多还是做支持4.5+,甚至不能编译:触摸操控code。所以,我通常依靠这种preprocessor宏观选择性编译不同code。首先,在该文件的顶部

My apps mostly still do support 4.5+, which can't even compile touch handling code. 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

和则建立,我将生产部署到触摸屏设备,我添加了TOUCH_SCREEN preprocessor标志。如果你不想操心触摸与非触摸设备上载不同的应用程序包,只是程序检测与Java code触摸屏( isTouch )并使用preprocessor刚刚的删除的code,不会在pre-4.7的操作系统版本编译。

And then for builds that I will produce for deployment to touchscreen devices, I add the TOUCH_SCREEN preprocessor flag. 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.

注意:这个有些混乱的双重否定preprocessor逻辑的不是一个错误这就像以适应稍微不同的方式preprocessors黑莓启用集成开发环境(如JDE,Eclipse的,Netbeans的)把手preprocessing。不幸的是,preprocessing不是一个规范的J2ME的功能,所以它的实施是一个有点片状。

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 (e.g. JDE, Eclipse, Netbeans) handle preprocessing. Unfortunately, preprocessing is not a standardized J2ME feature, so it's implementation is a little flaky.

这篇关于检测触摸屏黑莓?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆