@SuppressWarnings("ConstantConditions")
    public void onPreviewFrame(byte[] data, Camera incomingCamera) {
      try {
        if (System.currentTimeMillis() > lastSnapshotTime) {
          lastSnapshotTime = System.currentTimeMillis() + SNAPSHOT_DELAY;

          Camera.Parameters cameraParameters = incomingCamera.getParameters();
          Camera.Size previewSize = cameraParameters.getPreviewSize();
          Image barcode = new Image(previewSize.width, previewSize.height, GREY_COLOR_SPACE);
          barcode.setData(data);

          if (scanner.scanImage(barcode) != 0) {
            SymbolSet scannerResults = scanner.getResults();

            if (vibrator != null) vibrator.vibrate(VIBRATE_TIME);

            for (Symbol symbol : scannerResults)
              if (scannerListener == null)
                Toast.makeText(getActivity(), symbol.getData(), Toast.LENGTH_LONG).show();
              else scannerListener.onDataReceive(symbol.getData(), symbol.getType());
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
 public void run() {
   try {
     if (cameraView != null && cameraView.getCamera() != null && isHaveAutoFocus())
       cameraView.getCamera().autoFocus(autoFocusCallback);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 @Override
 public void onResume() {
   super.onResume();
   try {
     configureCamera();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
 @Override
 public void onPause() {
   super.onPause();
   try {
     cameraView.stopCamera();
     stopAutofocus();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
    @Override
    public void run() {
      try {
        boolean isConfigured = cameraView.configureCamera(getResources().getConfiguration());

        if (!isConfigured) {
          configurationHandler.postDelayed(this, CONFIGURE_DELAY);
          cameraView.stopCamera();
        } else {
          configurationHandler.removeCallbacks(this);
          cameraView.startCamera();
          startAutofocus();
        }

      } catch (Exception e) {
        e.printStackTrace();
      }
    }