【发布时间】:2019-05-28 14:52:26
【问题描述】:
我已经开发了使用uuid 生成条形码和二维码的胶子应用程序。使用可以根据商店在条形码和二维码之间切换。当使用点击 QRCODE(图像)时,条码将仅在纵向屏幕模式下显示。所以当用户点击图片(条形码/二维码)时,屏幕会自动旋转。
this.img.setOnMousePressed(event -> {
//Rotate Screen
Services.get( CMOrientationService.class ).ifPresent( o -> {
Orientation orientation = Services.get( OrientationService.class )
.flatMap(OrientationService::getOrientation)
.orElse(Orientation.HORIZONTAL);
Services.get(LogService.class).ifPresent(service -> service.log("orientation="+orientation.toString()));
if (orientation == Orientation.VERTICAL) {
Services.get(LogService.class).ifPresent(service -> service.log("Currently="+orientation.toString()));
//Change to Barcode
//GenerateBarQRCode(orientation == Orientation.VERTICAL);
o.coerceOrientation( Orientation.HORIZONTAL );
} else {
Services.get(LogService.class).ifPresent(service -> service.log("Currently="+orientation.toString()));
//Change to QRCode
//GenerateBarQRCode(orientation == Orientation.VERTICAL);
o.coerceOrientation( Orientation.VERTICAL );
}
GenerateBarQRCode(orientation == Orientation.VERTICAL);
} );
});
当用户尝试快速点击图片(双击、三次点击)时会出现问题。
您可以查看this video 以获得更多了解(请看视频中的 6 秒)。
注意。它仅在 Android 中出错。
【问题讨论】:
-
这可能是同步问题,你可以尝试同步 onMousePressed 事件中的代码,这样它就可以处理多个触摸。您还可以使用在处理时未设置并在处理完成时设置的原子标志,即在 GenerateBarQRCode 方法之后,在未设置标志时不应执行代码。使用它不需要的触摸将被消耗而不是执行。
-
你能给我一些代码吗?
-
不确定这是否可行,但您可以检查 the
clickCountproperty of theMouseEvent并仅在为 1 时触发更改。如果这不起作用,请考虑存储最后一次更改方向的时间由此事件处理程序触发,并确保仅在自上次方向更改后经过一定时间时才执行逻辑。 -
@fabian 当我在桌面上使用 clickCount 时,它运行良好。但是在Android中clickCount总是1,所以如果我们双击,这个事件会触发两次。
-
@fabian:是的,如果我们延迟到 1000 毫秒,它会起作用。但它会影响性能,当应用程序延迟时会显示黑屏。所以这个解决方案有效,但我认为使用它不是一个好主意。
标签: javafx gluon gluon-mobile