我已经开发了使用uuid
生成条形码和QRCODE的胶子应用程序。使用可以根据商店在条形码和Qrcode之间切换。单击使用时,条形码将仅以纵向屏幕模式显示。因此,当用户单击图像(条形码/ 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中会出错。
答案 0 :(得分:-1)
您可以像这样使用同步
// At class level
private Object mutex;
//initialize this object in constructor like this
mutex = this;
this.img.setOnMousePressed(event -> {
//Rotate Screen
synchronized(mutex){
// your code here
....
}
});
但是,在上述情况下,多个点击事件将以串行方式执行。如果您希望在执行之前忽略多次单击,则可以使用以下代码段
// At class level
private boolean mutex = true;
this.img.setOnMousePressed(event -> {
if(mutex){
mutex = false;
// your code here
....
mutex = true;
}
});