@@ -81,6 +81,7 @@ public class BarcodeScannerView extends FrameLayout implements TextureView.Surfa
8181 private TextView cameraUnavailableView ;
8282 private int displayOrientation ;
8383 private boolean restrictScanningToIndicator = true ;
84+ private float restrictionOvershoot = 1.0f ;
8485 private int bitsPerPixel ;
8586 private boolean indicatorEnabled = true ;
8687 private FrameLayout splashView ;
@@ -725,6 +726,22 @@ public void setIndicatorOffset(int offsetX, int offsetY) {
725726 */
726727 public void setRestrictScanningToIndicator (boolean restrictScanningToIndicator ) {
727728 this .restrictScanningToIndicator = restrictScanningToIndicator ;
729+ updateTransform ();
730+ }
731+
732+ /**
733+ * Sets the multiplicaton value that is used to allow scanning outside of the indicator if
734+ * {@link #setRestrictScanningToIndicator(boolean)} is set
735+ *
736+ * Default is 1.0
737+ */
738+ public void setRestrictionOvershoot (float val ) {
739+ if (val == 0.0f ) {
740+ val = 1.0f ;
741+ }
742+
743+ restrictionOvershoot = val ;
744+ updateTransform ();
728745 }
729746
730747 private void updateTransform () {
@@ -801,6 +818,14 @@ private void updateTransform() {
801818 rect = new Rect (0 , 0 , getWidth (), getHeight ());
802819 }
803820
821+ rect .inset (Math .round (rect .width () * (1.0f - restrictionOvershoot )),
822+ Math .round (rect .height () * (1.0f - restrictionOvershoot )));
823+
824+ rect .left = Math .max (0 , rect .left );
825+ rect .top = Math .max (0 , rect .top );
826+ rect .right = Math .min (getWidth (), rect .right );
827+ rect .bottom = Math .min (getHeight (), rect .bottom );
828+
804829 float left = offsetX + surfaceWidth * ((float ) rect .left / surfaceWidth );
805830 float top = offsetY + surfaceHeight * ((float ) rect .top / surfaceHeight );
806831 float right = offsetX + surfaceWidth * ((float ) rect .right / surfaceWidth );
0 commit comments