Java 类com.google.zxing.Result 实例源码

项目:weex-3d-map    文件:WifiResultParser.java   
@Override
public WifiParsedResult parse(Result result) {
  String rawText = getMassagedText(result);
  if (!rawText.startsWith("WIFI:")) {
    return null;
  }
  String ssid = matchSinglePrefixedField("S:", rawText, ';', false);
  if (ssid == null || ssid.isEmpty()) {
    return null;
  }
  String pass = matchSinglePrefixedField("P:", rawText, ';', false);
  String type = matchSinglePrefixedField("T:", rawText, ';', false);
  if (type == null) {
    type = "nopass";
  }
  boolean hidden = Boolean.parseBoolean(matchSinglePrefixedField("H:", rawText, ';', false));
  return new WifiParsedResult(type, ssid, pass, hidden);
}
项目:IJPay    文件:ZxingKit.java   
/**
 * @param srcImgFilePath
 *            要解码的图片地址
 * @return {Result}
 */
@SuppressWarnings("finally")
public static Result decode(String srcImgFilePath) {
    Result result = null;
    BufferedImage image;
    try {
        File srcFile = new File(srcImgFilePath);
        image = ImageIO.read(srcFile);
        if (null != image) {
            LuminanceSource source = new BufferedImageLuminanceSource(image);
            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

            Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
            hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
            result = new MultiFormatReader().decode(bitmap, hints);
        } else {
            throw new IllegalArgumentException ("Could not decode image.");
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        return result;
    }
}
项目:atlant-android    文件:CameraPresenterImpl.java   
@Override
public void handleResult(Result result) {
  if (typeResult == CameraActivity.TAG_FROM_SEND || typeResult == CameraActivity.TAG_FROM_HOME) {
    if (WalletUtils.isValidAddress(result.getText())) {
      view.onSuccessfulScanQR(result.getText());
    } else {
      view.onFailScanQR();
      mScannerView.resumeCameraPreview(this);
    }
  }
  if (typeResult == CameraActivity.TAG_FROM_IMPORT) {
    if (WalletUtils.isValidPrivateKey(result.getText())) {
      view.onSuccessfulScanQR(result.getText());
    } else {
      view.onFailScanQR();
      mScannerView.resumeCameraPreview(this);
    }
  }
}
项目:Tesseract-OCR-Scanner    文件:RSS14Reader.java   
@Override
public Result decodeRow(int rowNumber,
                        BitArray row,
                        Map<DecodeHintType,?> hints) throws NotFoundException {
  Pair leftPair = decodePair(row, false, rowNumber, hints);
  addOrTally(possibleLeftPairs, leftPair);
  row.reverse();
  Pair rightPair = decodePair(row, true, rowNumber, hints);
  addOrTally(possibleRightPairs, rightPair);
  row.reverse();
  for (Pair left : possibleLeftPairs) {
    if (left.getCount() > 1) {
      for (Pair right : possibleRightPairs) {
        if (right.getCount() > 1 && checkChecksum(left, right)) {
          return constructResult(left, right);
        }
      }
    }
  }
  throw NotFoundException.getNotFoundInstance();
}
项目:awe-awesomesky    文件:CodeUtil.java   
public static String decode(File file) throws Exception {
    BufferedImage image;
    image = ImageIO.read(file);
    if (image == null) {
        return null;
    }
    CodeImage source = new CodeImage(
            image);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    Result result;
    Hashtable hints = new Hashtable();
    hints.put(DecodeHintType.CHARACTER_SET, CHARSET);
    result = new MultiFormatReader().decode(bitmap, hints);
    String resultStr = result.getText();
    return resultStr;
}
项目:QrCode    文件:RSSExpandedReader.java   
@Override
public Result decodeRow(int rowNumber,
                        BitArray row,
                        Map<DecodeHintType,?> hints) throws NotFoundException, FormatException {
  // Rows can start with even pattern in case in prev rows there where odd number of patters.
  // So lets try twice
  this.pairs.clear();
  this.startFromEven = false;
  try {
    return constructResult(decodeRow2pairs(rowNumber, row));
  } catch (NotFoundException e) {
    // OK
  }

  this.pairs.clear();
  this.startFromEven = true;
  return constructResult(decodeRow2pairs(rowNumber, row));
}
项目:ForeverLibrary    文件:ScanToolActivity.java   
/**
 * 初始化扫描
 */
private void initScan() {
    scanManager = new ScanManager(this, sfvContent, rlAll, rlCapture, imgLine,
            Constant.REQUEST_SCAN_MODE_ALL_MODE, new ScanListener() {
        @Override
        public void scanResult(Result rawResult, Bundle bundle) {
            String scanData = rawResult.getText().trim();
            ShowTextActivity.Companion.start(getActivity(), scanData);
        }

        @Override
        public void scanError(Exception e) {
            showToast("扫描失败,请重试!");
        }
    });
}
项目:Tesseract-OCR-Scanner    文件:ScannerActivity.java   
private void handleResult(Result result) {
    if (TextUtils.isEmpty(result.getText())) {
        mDecodeManager.showCouldNotReadQrCodeFromScanner(this, new DecodeManager.OnRefreshCameraListener() {
            @Override
            public void refresh() {
                restartPreview();
            }
        });
    } else {
        Vibrator vibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.vibrate(200L);
        if (switch1.isChecked()) {
            qrSucceed(result.getText());
        } else {
            phoneSucceed(result.getText(), result.getBitmap());
        }
    }
}
项目:MyFire    文件:BitmapDecoder.java   
/**
 * 获取解码结果
 * 
 * @param bitmap
 * @return
 */
public Result getRawResult(Bitmap bitmap) {
    if (bitmap == null) {
        return null;
    }

    try {
        return multiFormatReader.decodeWithState(new BinaryBitmap(
                new HybridBinarizer(new BitmapLuminanceSource(bitmap))));
    }
    catch (NotFoundException e) {
        e.printStackTrace();
    }

    return null;
}
项目:iBase4J-Common    文件:QrcodeUtil.java   
public static String decodeQr(String filePath) {
    String retStr = "";
    if ("".equalsIgnoreCase(filePath) && filePath.length() == 0) {
        return "图片路径为空!";
    }
    try {
        BufferedImage bufferedImage = ImageIO.read(new FileInputStream(filePath));
        LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
        Binarizer binarizer = new HybridBinarizer(source);
        BinaryBitmap bitmap = new BinaryBitmap(binarizer);
        HashMap<DecodeHintType, Object> hintTypeObjectHashMap = new HashMap<>();
        hintTypeObjectHashMap.put(DecodeHintType.CHARACTER_SET, "UTF-8");
        Result result = new MultiFormatReader().decode(bitmap, hintTypeObjectHashMap);
        retStr = result.getText();
    } catch (Exception e) {
        logger.error("", e);
    }
    return retStr;
}
项目:QrCode    文件:RSS14Reader.java   
@Override
public Result decodeRow(int rowNumber,
                        BitArray row,
                        Map<DecodeHintType,?> hints) throws NotFoundException {
  Pair leftPair = decodePair(row, false, rowNumber, hints);
  addOrTally(possibleLeftPairs, leftPair);
  row.reverse();
  Pair rightPair = decodePair(row, true, rowNumber, hints);
  addOrTally(possibleRightPairs, rightPair);
  row.reverse();
  for (Pair left : possibleLeftPairs) {
    if (left.getCount() > 1) {
      for (Pair right : possibleRightPairs) {
        if (right.getCount() > 1) {
          if (checkChecksum(left, right)) {
            return constructResult(left, right);
          }
        }
      }
    }
  }
  throw NotFoundException.getNotFoundInstance();
}
项目:Tesseract-OCR-Scanner    文件:UPCEANExtension2Support.java   
Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange) throws NotFoundException {

    StringBuilder result = decodeRowStringBuffer;
    result.setLength(0);
    int end = decodeMiddle(row, extensionStartRange, result);

    String resultString = result.toString();
    Map<ResultMetadataType,Object> extensionData = parseExtensionString(resultString);

    Result extensionResult =
        new Result(resultString,
                   null,
                   new ResultPoint[] {
                       new ResultPoint((extensionStartRange[0] + extensionStartRange[1]) / 2.0f, rowNumber),
                       new ResultPoint(end, rowNumber),
                   },
                   BarcodeFormat.UPC_EAN_EXTENSION);
    if (extensionData != null) {
      extensionResult.putAllMetadata(extensionData);
    }
    return extensionResult;
  }
项目:Hitalk    文件:QRCodeDecoder.java   
/**
 * 同步解析bitmap二维码。该方法是耗时操作,请在子线程中调用。
 *
 * @param bitmap 要解析的二维码图片
 * @return 返回二维码图片里的内容 或 null
 */
public static String syncDecodeQRCode(Bitmap bitmap) {
    try {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        int[] pixels = new int[width * height];
        bitmap.getPixels(pixels, 0, width, 0, 0, width, height);
        RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
        Result result = new MultiFormatReader().decode(new BinaryBitmap(new HybridBinarizer(source)), HINTS);
        return result.getText();
    } catch (Exception e) {
        return null;
    }
}
项目:boohee_v5.6    文件:UPCEANExtension2Support.java   
Result decodeRow(int rowNumber, BitArray row, int[] extensionStartRange) throws
        NotFoundException {
    StringBuilder result = this.decodeRowStringBuffer;
    result.setLength(0);
    int end = decodeMiddle(row, extensionStartRange, result);
    String resultString = result.toString();
    Map<ResultMetadataType, Object> extensionData = parseExtensionString(resultString);
    Result extensionResult = new Result(resultString, null, new ResultPoint[]{new ResultPoint
            (((float) (extensionStartRange[0] + extensionStartRange[1])) / 2.0f, (float)
                    rowNumber), new ResultPoint((float) end, (float) rowNumber)},
            BarcodeFormat.UPC_EAN_EXTENSION);
    if (extensionData != null) {
        extensionResult.putAllMetadata(extensionData);
    }
    return extensionResult;
}
项目:RLibrary    文件:UIScanView.java   
private void decodeOrStoreSavedBitmap(Bitmap bitmap, Result result) {
    if (handler == null) {
        savedResultToShow = result;
    } else {
        if (result != null) {
            savedResultToShow = result;
        }
        if (savedResultToShow != null) {
            Message message = Message.obtain(handler,
                    IDecodeCallback.decode_succeeded,
                    savedResultToShow);
            handler.sendMessage(message);
        }
        savedResultToShow = null;
    }
}
项目:Zxing    文件:CaptureActivity.java   
protected Result scanningImage(Uri path) {
    if (path == null || path.equals("")) {
        return null;
    }
    // DecodeHintType 和EncodeHintType
    Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
    hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); // 设置二维码内容的编码
    try {
        Bitmap scanBitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(uri));

        RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap);
        BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
        QRCodeReader reader = new QRCodeReader();
        return reader.decode(bitmap1, hints);

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
项目:boohee_v5.6    文件:ProductResultParser.java   
public ProductParsedResult parse(Result result) {
    BarcodeFormat format = result.getBarcodeFormat();
    if (format != BarcodeFormat.UPC_A && format != BarcodeFormat.UPC_E && format !=
            BarcodeFormat.EAN_8 && format != BarcodeFormat.EAN_13) {
        return null;
    }
    String rawText = ResultParser.getMassagedText(result);
    if (!ResultParser.isStringOfDigits(rawText, rawText.length())) {
        return null;
    }
    String normalizedProductID;
    if (format == BarcodeFormat.UPC_E && rawText.length() == 8) {
        normalizedProductID = UPCEReader.convertUPCEtoUPCA(rawText);
    } else {
        normalizedProductID = rawText;
    }
    return new ProductParsedResult(rawText, normalizedProductID);
}
项目:Lunary-Ethereum-Wallet    文件:QRScanActivity.java   
@Override
public void handleResult(Result result) {
    if (result == null) return;
    String address = result.getText();
    try {
        AddressEncoder scanned = AddressEncoder.decode(address);
        Intent data = new Intent();
        data.putExtra("ADDRESS", scanned.getAddress().toLowerCase());

        if (scanned.getAddress().length() > 42 && !scanned.getAddress().startsWith("0x") && scanned.getAmount() == null)
            type = PRIVATE_KEY;

        if (scanned.getAmount() != null) {
            data.putExtra("AMOUNT", scanned.getAmount());
            type = REQUEST_PAYMENT;
        }

        data.putExtra("TYPE", type);
        setResult(RESULT_OK, data);
        finish();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:Fetax-AI    文件:CodeUtil.java   
/**
* 解析条形码
*/
  public static String decodes(String imgPath) {
      BufferedImage image = null;
      Result result = null;
      try {
          image = ImageIO.read(new File(imgPath));
          if (image == null) {
              System.out.println("the decode image may be not exit.");
          }
          LuminanceSource source = new BufferedImageLuminanceSource(image);
          BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

          result = new MultiFormatReader().decode(bitmap, null);
          return result.getText();
      } catch (Exception e) {
          e.printStackTrace();
      }
      return null;
  }
项目:OSchina_resources_android    文件:CaptureActivityHandler.java   
@Override
public void handleMessage(Message message) {
    switch (message.what) {
        case R.id.restart_preview:
            restartPreviewAndDecode();
            break;
        case R.id.decode_succeeded:
            state = State.SUCCESS;
            Bundle bundle = message.getData();

            activity.handleDecode((Result) message.obj, bundle);
            break;
        case R.id.decode_failed:
            // We're decoding as fast as possible, so when one decode fails,
            // start another.
            state = State.PREVIEW;
            cameraManager.requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
            break;
        case R.id.return_scan_result:
            activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
            activity.finish();
            break;
    }
}
项目:weex-3d-map    文件:CaptureActivity.java   
private void decodeOrStoreSavedBitmap(Bitmap bitmap, Result result) {
    // Bitmap isn't used yet -- will be used soon
    if (handler == null) {
        savedResultToShow = result;
    } else {
        if (result != null) {
            savedResultToShow = result;
        }
        if (savedResultToShow != null) {
            Message message = Message.obtain(handler,
                    R.id.decode_succeeded, savedResultToShow);
            handler.sendMessage(message);
        }
        savedResultToShow = null;
    }
}
项目:weex-3d-map    文件:HistoryManager.java   
public List<HistoryItem> buildHistoryItems() {
  SQLiteOpenHelper helper = new DBHelper(activity);
  List<HistoryItem> items = new ArrayList<>();
  SQLiteDatabase db = null;
  Cursor cursor = null;
  try {
    db = helper.getReadableDatabase();
    cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
    while (cursor.moveToNext()) {
      String text = cursor.getString(0);
      String display = cursor.getString(1);
      String format = cursor.getString(2);
      long timestamp = cursor.getLong(3);
      String details = cursor.getString(4);
      Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp);
      items.add(new HistoryItem(result, display, details));
    }
  } finally {
    close(cursor, db);
  }
  return items;
}
项目:weex-3d-map    文件:HistoryManager.java   
public HistoryItem buildHistoryItem(int number) {
  SQLiteOpenHelper helper = new DBHelper(activity);
  SQLiteDatabase db = null;
  Cursor cursor = null;
  try {
    db = helper.getReadableDatabase();
    cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC");
    cursor.move(number + 1);
    String text = cursor.getString(0);
    String display = cursor.getString(1);
    String format = cursor.getString(2);
    long timestamp = cursor.getLong(3);
    String details = cursor.getString(4);
    Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp);
    return new HistoryItem(result, display, details);
  } finally {
    close(cursor, db);
  }
}
项目:QrCode    文件:MultiFormatOneDReader.java   
@Override
public Result decodeRow(int rowNumber,
                        BitArray row,
                        Map<DecodeHintType,?> hints) throws NotFoundException {
  for (OneDReader reader : readers) {
    try {
      return reader.decodeRow(rowNumber, row, hints);
    } catch (ReaderException re) {
      // continue
    }
  }

  throw NotFoundException.getNotFoundInstance();
}
项目:tvConnect_android    文件:ScanFromWebPageManager.java   
public String buildReplyURL(Result rawResult, ResultHandler resultHandler) {
  String result = returnUrlTemplate;
  result = replace(CODE_PLACEHOLDER,
                   returnRaw ? rawResult.getText() : resultHandler.getDisplayContents(), result);
  result = replace(RAW_CODE_PLACEHOLDER, rawResult.getText(), result);
  result = replace(FORMAT_PLACEHOLDER, rawResult.getBarcodeFormat().toString(), result);
  result = replace(TYPE_PLACEHOLDER, resultHandler.getType().toString(), result);
  result = replace(META_PLACEHOLDER, String.valueOf(rawResult.getResultMetadata()), result);
  return result;
}
项目:boohee_v5.6    文件:ISBNResultParser.java   
public ISBNParsedResult parse(Result result) {
    if (result.getBarcodeFormat() != BarcodeFormat.EAN_13) {
        return null;
    }
    String rawText = ResultParser.getMassagedText(result);
    if (rawText.length() != 13) {
        return null;
    }
    if (rawText.startsWith("978") || rawText.startsWith("979")) {
        return new ISBNParsedResult(rawText);
    }
    return null;
}
项目:QrCode    文件:UPCAReader.java   
private static Result maybeReturnResult(Result result) throws FormatException {
  String text = result.getText();
  if (text.charAt(0) == '0') {
    return new Result(text.substring(1), null, result.getResultPoints(), BarcodeFormat.UPC_A);
  } else {
    throw FormatException.getFormatInstance();
  }
}
项目:ZXingDemo    文件:CaptureActivityHandler.java   
@Override
public void handleMessage(Message message) {
    if (message.what == R.id.auto_focus) {
        //Log.d(TAG, "Got auto-focus message");
        // When one auto focus pass finishes, start another. This is the closest thing to
        // continuous AF. It does seem to hunt a bit, but I'm not sure what else to do.
        if (state == State.PREVIEW) {
            CameraManager.get().requestAutoFocus(this, R.id.auto_focus);
        }
    }else if (message.what == R.id.restart_preview) {
        Log.d(TAG, "Got restart preview message");
        restartPreviewAndDecode();
    }else if (message.what == R.id.decode_succeeded) {
        Log.d(TAG, "Got decode succeeded message");
        state = State.SUCCESS;
        Bundle bundle = message.getData();

        /***********************************************************************/
        Bitmap barcode = bundle == null ? null :
            (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);//���ñ����߳�

        activity.handleDecode((Result) message.obj, barcode);//���ؽ��
        /***********************************************************************/
    }else if (message.what == R.id.decode_failed) {
        // We're decoding as fast as possible, so when one decode fails, start another.
        state = State.PREVIEW;
        CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
    }else if (message.what == R.id.return_scan_result) {
        Log.d(TAG, "Got return scan result message");
        activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
        activity.finish();
    }else if (message.what == R.id.launch_product_query) {
        Log.d(TAG, "Got product query message");
        String url = (String) message.obj;
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        activity.startActivity(intent);
    }
}
项目:postixdroid    文件:MainActivity.java   
@Override
public void handleResult(Result rawResult) {
    if (config.getCamera()) {
        qrView.resumeCameraPreview(this);
    }
    String s = rawResult.getText();
    if (s.equals(lastScanCode) && System.currentTimeMillis() - lastScanTime < 5000) {
        return;
    }
    lastScanTime = System.currentTimeMillis();
    lastScanCode = s;

    handleScan(s);
}
项目:QrCode    文件:QRCodeMultiReader.java   
@Override
public int compare(Result a, Result b) {
  int aNumber = (int) a.getResultMetadata().get(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE);
  int bNumber = (int) b.getResultMetadata().get(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE);
  if (aNumber < bNumber) {
    return -1;
  }
  if (aNumber > bNumber) {
    return 1;
  }
  return 0;
}
项目:Mobike    文件:QrUtils.java   
/**
 * Decode the data within the viewfinder rectangle, and time how long it took. For efficiency, reuse the same reader
 * objects from one decode to the next.
 */
public static Result decodeImage(byte[] data, int width, int height) {
    // 处理
    Result result = null;
    try {
        Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
        hints.put(DecodeHintType.CHARACTER_SET, "utf-8");
        hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
        hints.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.QR_CODE);
        PlanarYUVLuminanceSource source =
            new PlanarYUVLuminanceSource(data, width, height, 0, 0, width, height, false);
        /**
         * HybridBinarizer算法使用了更高级的算法,但使用GlobalHistogramBinarizer识别效率确实比HybridBinarizer要高一些。
         * 
         * GlobalHistogram算法:(http://kuangjianwei.blog.163.com/blog/static/190088953201361015055110/)
         * 
         * 二值化的关键就是定义出黑白的界限,我们的图像已经转化为了灰度图像,每个点都是由一个灰度值来表示,就需要定义出一个灰度值,大于这个值就为白(0),低于这个值就为黑(1)。
         * 在GlobalHistogramBinarizer中,是从图像中均匀取5行(覆盖整个图像高度),每行取中间五分之四作为样本;以灰度值为X轴,每个灰度值的像素个数为Y轴建立一个直方图,
         * 从直方图中取点数最多的一个灰度值,然后再去给其他的灰度值进行分数计算,按照点数乘以与最多点数灰度值的距离的平方来进行打分,选分数最高的一个灰度值。接下来在这两个灰度值中间选取一个区分界限,
         * 取的原则是尽量靠近中间并且要点数越少越好。界限有了以后就容易了,与整幅图像的每个点进行比较,如果灰度值比界限小的就是黑,在新的矩阵中将该点置1,其余的就是白,为0。
         */
        BinaryBitmap bitmap1 = new BinaryBitmap(new GlobalHistogramBinarizer(source));
        // BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
        QRCodeReader reader2 = new QRCodeReader();
        result = reader2.decode(bitmap1, hints);
    } catch (ReaderException e) {
    }
    return result;
}
项目:QrCode    文件:UPCAReader.java   
@Override
public Result decodeRow(int rowNumber,
                        BitArray row,
                        int[] startGuardRange,
                        Map<DecodeHintType,?> hints)
    throws NotFoundException, FormatException, ChecksumException {
  return maybeReturnResult(ean13Reader.decodeRow(rowNumber, row, startGuardRange, hints));
}
项目:CodeScaner    文件:CaptureActivity.java   
/**
     * A valid barcode has been found, so give an indication of success and show the results.
     *
     * @param rawResult   The contents of the barcode.
     * @param scaleFactor amount by which thumbnail was scaled
     * @param barcode     A greyscale bitmap of the camera data which was decoded.
     */
    public void handleDecode(Result rawResult, Bitmap barcode, float scaleFactor) {
        inactivityTimer.onActivity();

        boolean fromLiveScan = barcode != null;
        if (fromLiveScan) {
            beepManager.playBeepSoundAndVibrate();
        }

        String resultString = rawResult.getText();
        //FIXME
        if (TextUtils.isEmpty(resultString)) {
            Toast.makeText(CaptureActivity.this, "扫描二维码失败了", Toast.LENGTH_SHORT).show();
        } else {
            Intent resultIntent = new Intent();
            Bundle bundle = new Bundle();
            bundle.putByteArray(KEY_RESULT, resultString.getBytes());
            // 不能使用Intent传递大于40kb的bitmap,可以使用一个单例对象存储这个bitmap
//            bundle.putParcelable("bitmap", barcode);
            resultIntent.putExtras(bundle);
            this.setResult(RESULT_OK, resultIntent);
        }
        if (DEBUG) {
            long time = System.currentTimeMillis() - mScanStartTime;
            Toast.makeText(this, ("Time: " + time / 1000.0f), Toast.LENGTH_SHORT).show();
            drawResultPoints(barcode, scaleFactor, rawResult);
            viewfinderView.drawResultBitmap(barcode);
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    CaptureActivity.this.finish();
                }
            }, 3000);
        } else {
            CaptureActivity.this.finish();
        }
    }
项目:Tesseract-OCR-Scanner    文件:RSS14Reader.java   
private static Result constructResult(Pair leftPair, Pair rightPair) {
  long symbolValue = 4537077L * leftPair.getValue() + rightPair.getValue();
  String text = String.valueOf(symbolValue);

  StringBuilder buffer = new StringBuilder(14);
  for (int i = 13 - text.length(); i > 0; i--) {
    buffer.append('0');
  }
  buffer.append(text);

  int checkDigit = 0;
  for (int i = 0; i < 13; i++) {
    int digit = buffer.charAt(i) - '0';
    checkDigit += (i & 0x01) == 0 ? 3 * digit : digit;
  }
  checkDigit = 10 - (checkDigit % 10);
  if (checkDigit == 10) {
    checkDigit = 0;
  }
  buffer.append(checkDigit);

  ResultPoint[] leftPoints = leftPair.getFinderPattern().getResultPoints();
  ResultPoint[] rightPoints = rightPair.getFinderPattern().getResultPoints();
  return new Result(
      buffer.toString(),
      null,
      new ResultPoint[] { leftPoints[0], leftPoints[1], rightPoints[0], rightPoints[1], },
      BarcodeFormat.RSS_14);
}
项目:MyFire    文件:CaptureActivity.java   
/**
 * A valid barcode has been found, so give an indication of success and show
 * the results.
 * 
 * @param rawResult
 *            The contents of the barcode.
 * 
 * @param bundle
 *            The extras
 */
public void handleDecode(Result rawResult, Bundle bundle) {
    inactivityTimer.onActivity();
    beepManager.playBeepSoundAndVibrate();

    bundle.putInt("width", mCropRect.width());
    bundle.putInt("height", mCropRect.height());
    bundle.putString("result", rawResult.getText());

    startActivity(new Intent(CaptureActivity.this, ResultActivity.class).putExtras(bundle));
}
项目:code-scanner    文件:Decoder.java   
@Override
public void run() {
    for (; ; ) {
        try {
            mStateListener.onStateChanged(Decoder.State.IDLE);
            Result result = null;
            try {
                DecodeTask task = mDecodeQueue.take();
                mStateListener.onStateChanged(Decoder.State.DECODING);
                result = task.decode(mReader);
            } catch (ReaderException ignored) {
            } finally {
                if (result != null) {
                    mProcessingResult = true;
                    mDecodeQueue.clear();
                    if (mStateListener.onStateChanged(Decoder.State.DECODED)) {
                        DecodeCallback callback = mCallback;
                        if (callback != null) {
                            callback.onDecoded(result);
                        }
                    }
                    mProcessingResult = false;
                }
            }
        } catch (InterruptedException e) {
            break;
        }
    }
}
项目:code-scanner    文件:DecodeTask.java   
@NonNull
@SuppressWarnings("SuspiciousNameCombination")
public Result decode(@NonNull MultiFormatReader reader) throws ReaderException {
    int imageWidth = mImageSize.getX();
    int imageHeight = mImageSize.getY();
    byte[] image;
    int width;
    int height;
    if (mOrientation == 0) {
        image = mImage;
        width = imageWidth;
        height = imageHeight;
    } else {
        image = Utils.rotateNV21(mImage, imageWidth, imageHeight, mOrientation);
        if (mOrientation == 90 || mOrientation == 270) {
            width = imageHeight;
            height = imageWidth;
        } else {
            width = imageWidth;
            height = imageHeight;
        }
    }
    Rect frameRect = Utils.getImageFrameRect(mSquareFrame, width, height, mPreviewSize, mViewSize);
    return reader.decodeWithState(new BinaryBitmap(new HybridBinarizer(
            new PlanarYUVLuminanceSource(image, width, height, frameRect.getLeft(), frameRect.getTop(),
                    frameRect.getWidth(), frameRect.getHeight(), mReverseHorizontal))));
}
项目:APIJSON-Android-RxJava    文件:CaptureActivity.java   
/**
 * Handler scan result
 * @param result
 * @param barcode
 */
public void handleDecode(Result result, Bitmap barcode) {
    inactivityTimer.onActivity();
    playBeepSoundAndVibrate();
    String resultString = result.getText();
    //FIXME
    if (resultString.equals("")) {
        Toast.makeText(CaptureActivity.this, "Scan failed!", Toast.LENGTH_SHORT).show();
    }

    setResult(RESULT_OK, new Intent().putExtra(RESULT_QRCODE_STRING, resultString));
    finish();
}
项目:boohee_v5.6    文件:PDF417Reader.java   
public Result decode(BinaryBitmap image, Map<DecodeHintType, ?> hints) throws
        NotFoundException, FormatException, ChecksumException {
    Result[] result = decode(image, hints, false);
    if (result != null && result.length != 0 && result[0] != null) {
        return result[0];
    }
    throw NotFoundException.getNotFoundInstance();
}
项目:GCSApp    文件:CaptureActivityHandler.java   
@Override
public void handleMessage(Message message) {
    switch (message.what) {
        case R.id.auto_focus:
            //Log.d(TAG, "Got auto-focus message");
            // When one auto focus pass finishes, start another. This is the closest thing to
            // continuous AF. It does seem to hunt a bit, but I'm not sure what else to do.
            if (state == State.PREVIEW) {
                CameraManager.get().requestAutoFocus(this, R.id.auto_focus);
            }
            break;
        case R.id.restart_preview:
            restartPreviewAndDecode();
            break;
        case R.id.decode_succeeded:
            state = State.SUCCESS;
            Bundle bundle = message.getData();
            Bitmap barcode = bundle == null ? null :
                    (Bitmap) bundle.getParcelable(DecodeThread.BARCODE_BITMAP);
            activity.handleDecode((Result) message.obj, barcode);
            break;
        case R.id.decode_failed:
            // We're decoding as fast as possible, so when one decode fails, start another.
            state = State.PREVIEW;
            CameraManager.get().requestPreviewFrame(decodeThread.getHandler(), R.id.decode);
            break;
        case R.id.return_scan_result:
            activity.setResult(Activity.RESULT_OK, (Intent) message.obj);
            activity.finish();
            break;
        case R.id.launch_product_query:
            String url = (String) message.obj;
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            activity.startActivity(intent);
            break;
    }
}