类com.google.zxing.qrcode.decoder.Mode源码实例Demo

下面列出了怎么用com.google.zxing.qrcode.decoder.Mode的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Telegram   文件: Encoder.java

/**
 * Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
 * if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
 */
private static Mode chooseMode(String content, String encoding) {
  if ("Shift_JIS".equals(encoding) && isOnlyDoubleByteKanji(content)) {
    // Choose Kanji mode if all input are double-byte characters
    return Mode.KANJI;
  }
  boolean hasNumeric = false;
  boolean hasAlphanumeric = false;
  for (int i = 0; i < content.length(); ++i) {
    char c = content.charAt(i);
    if (c >= '0' && c <= '9') {
      hasNumeric = true;
    } else if (getAlphanumericCode(c) != -1) {
      hasAlphanumeric = true;
    } else {
      return Mode.BYTE;
    }
  }
  if (hasAlphanumeric) {
    return Mode.ALPHANUMERIC;
  }
  if (hasNumeric) {
    return Mode.NUMERIC;
  }
  return Mode.BYTE;
}
 
源代码2 项目: ScreenCapture   文件: Encoder.java

/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
源代码3 项目: Tesseract-OCR-Scanner   文件: Encoder.java

/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
源代码4 项目: Telegram-FOSS   文件: Encoder.java

/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
源代码5 项目: QrCodeScanner   文件: Encoder.java

/**
 * Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
 * if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
 */
private static Mode chooseMode(String content, String encoding) {
  if ("Shift_JIS".equals(encoding) && isOnlyDoubleByteKanji(content)) {
    // Choose Kanji mode if all input are double-byte characters
    return Mode.KANJI;
  }
  boolean hasNumeric = false;
  boolean hasAlphanumeric = false;
  for (int i = 0; i < content.length(); ++i) {
    char c = content.charAt(i);
    if (c >= '0' && c <= '9') {
      hasNumeric = true;
    } else if (getAlphanumericCode(c) != -1) {
      hasAlphanumeric = true;
    } else {
      return Mode.BYTE;
    }
  }
  if (hasAlphanumeric) {
    return Mode.ALPHANUMERIC;
  }
  if (hasNumeric) {
    return Mode.NUMERIC;
  }
  return Mode.BYTE;
}
 
源代码6 项目: QrCodeScanner   文件: Encoder.java

/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
源代码7 项目: MiBandDecompiled   文件: Encoder.java

private static void a(int i, ErrorCorrectionLevel errorcorrectionlevel, Mode mode, QRCode qrcode)
{
    qrcode.setECLevel(errorcorrectionlevel);
    qrcode.setMode(mode);
    for (int j = 1; j <= 40; j++)
    {
        Version version = Version.getVersionForNumber(j);
        int k = version.getTotalCodewords();
        com.google.zxing.qrcode.decoder.Version.ECBlocks ecblocks = version.getECBlocksForLevel(errorcorrectionlevel);
        int l = ecblocks.getTotalECCodewords();
        int i1 = ecblocks.getNumBlocks();
        int j1 = k - l;
        if (j1 >= a(i, version, mode))
        {
            qrcode.setVersion(j);
            qrcode.setNumTotalBytes(k);
            qrcode.setNumDataBytes(j1);
            qrcode.setNumRSBlocks(i1);
            qrcode.setNumECBytes(l);
            qrcode.setMatrixWidth(version.getDimensionForVersion());
            return;
        }
    }

    throw new WriterException("Cannot find proper rs block info (input data too big?)");
}
 
源代码8 项目: ZXing-Orient   文件: Encoder.java

/**
 * Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
 * if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
 */
private static Mode chooseMode(String content, String encoding) {
  if ("Shift_JIS".equals(encoding)) {
    // Choose Kanji mode if all input are double-byte characters
    return isOnlyDoubleByteKanji(content) ? Mode.KANJI : Mode.BYTE;
  }
  boolean hasNumeric = false;
  boolean hasAlphanumeric = false;
  for (int i = 0; i < content.length(); ++i) {
    char c = content.charAt(i);
    if (c >= '0' && c <= '9') {
      hasNumeric = true;
    } else if (getAlphanumericCode(c) != -1) {
      hasAlphanumeric = true;
    } else {
      return Mode.BYTE;
    }
  }
  if (hasAlphanumeric) {
    return Mode.ALPHANUMERIC;
  }
  if (hasNumeric) {
    return Mode.NUMERIC;
  }
  return Mode.BYTE;
}
 
源代码9 项目: ZXing-Orient   文件: Encoder.java

/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 

/**
 * Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
 * if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
 */
private static Mode chooseMode(String content, String encoding) {
  if ("Shift_JIS".equals(encoding) && isOnlyDoubleByteKanji(content)) {
    // Choose Kanji mode if all input are double-byte characters
    return Mode.KANJI;
  }
  boolean hasNumeric = false;
  boolean hasAlphanumeric = false;
  for (int i = 0; i < content.length(); ++i) {
    char c = content.charAt(i);
    if (c >= '0' && c <= '9') {
      hasNumeric = true;
    } else if (getAlphanumericCode(c) != -1) {
      hasAlphanumeric = true;
    } else {
      return Mode.BYTE;
    }
  }
  if (hasAlphanumeric) {
    return Mode.ALPHANUMERIC;
  }
  if (hasNumeric) {
    return Mode.NUMERIC;
  }
  return Mode.BYTE;
}
 

/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
源代码12 项目: Telegram   文件: Encoder.java

/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
源代码13 项目: RipplePower   文件: Encoder.java

/**
 * Choose the best mode by examining the content. Note that 'encoding' is
 * used as a hint; if it is Shift_JIS, and the input is only double-byte
 * Kanji, then we return {@link Mode#KANJI}.
 */
private static Mode chooseMode(String content, String encoding) {
	if ("Shift_JIS".equals(encoding)) {
		// Choose Kanji mode if all input are double-byte characters
		return isOnlyDoubleByteKanji(content) ? Mode.KANJI : Mode.BYTE;
	}
	boolean hasNumeric = false;
	boolean hasAlphanumeric = false;
	for (int i = 0; i < content.length(); ++i) {
		char c = content.charAt(i);
		if (c >= '0' && c <= '9') {
			hasNumeric = true;
		} else if (getAlphanumericCode(c) != -1) {
			hasAlphanumeric = true;
		} else {
			return Mode.BYTE;
		}
	}
	if (hasAlphanumeric) {
		return Mode.ALPHANUMERIC;
	}
	if (hasNumeric) {
		return Mode.NUMERIC;
	}
	return Mode.BYTE;
}
 
源代码14 项目: barcodescanner-lib-aar   文件: Encoder.java

/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store the result in "bits".
 */
static void appendBytes(String content,
                        Mode mode,
                        BitArray bits,
                        String encoding) throws WriterException {
  switch (mode) {
    case NUMERIC:
      appendNumericBytes(content, bits);
      break;
    case ALPHANUMERIC:
      appendAlphanumericBytes(content, bits);
      break;
    case BYTE:
      append8BitBytes(content, bits, encoding);
      break;
    case KANJI:
      appendKanjiBytes(content, bits);
      break;
    default:
      throw new WriterException("Invalid mode: " + mode);
  }
}
 
源代码15 项目: RipplePower   文件: Encoder.java

/**
 * Append "bytes" in "mode" mode (encoding) into "bits". On success, store
 * the result in "bits".
 */
static void appendBytes(String content, Mode mode, BitArray bits, String encoding) throws WriterException {
	switch (mode) {
	case NUMERIC:
		appendNumericBytes(content, bits);
		break;
	case ALPHANUMERIC:
		appendAlphanumericBytes(content, bits);
		break;
	case BYTE:
		append8BitBytes(content, bits, encoding);
		break;
	case KANJI:
		appendKanjiBytes(content, bits);
		break;
	default:
		throw new WriterException("Invalid mode: " + mode);
	}
}
 
源代码16 项目: ScreenCapture   文件: Encoder.java

/**
 * Decides the smallest version of QR code that will contain all of the provided data.
 *
 * @throws WriterException if the data cannot fit in any version
 */
private static Version recommendVersion(ErrorCorrectionLevel ecLevel,
                                        Mode mode,
                                        BitArray headerBits,
                                        BitArray dataBits) throws WriterException {
  // Hard part: need to know version to know how many bits length takes. But need to know how many
  // bits it takes to know version. First we take a guess at version by assuming version will be
  // the minimum, 1:
  int provisionalBitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, Version.getVersionForNumber(1));
  Version provisionalVersion = chooseVersion(provisionalBitsNeeded, ecLevel);

  // Use that guess to calculate the right version. I am still not sure this works in 100% of cases.
  int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, provisionalVersion);
  return chooseVersion(bitsNeeded, ecLevel);
}
 
源代码17 项目: ScreenCapture   文件: Encoder.java

/**
 * Append length info. On success, store the result in "bits".
 */
static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) throws WriterException {
  int numBits = mode.getCharacterCountBits(version);
  if (numLetters >= (1 << numBits)) {
    throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1));
  }
  bits.appendBits(numLetters, numBits);
}
 
源代码18 项目: Tesseract-OCR-Scanner   文件: Encoder.java

/**
 * Decides the smallest version of QR code that will contain all of the provided data.
 *
 * @throws WriterException if the data cannot fit in any version
 */
private static Version recommendVersion(ErrorCorrectionLevel ecLevel,
                                        Mode mode,
                                        BitArray headerBits,
                                        BitArray dataBits) throws WriterException {
  // Hard part: need to know version to know how many bits length takes. But need to know how many
  // bits it takes to know version. First we take a guess at version by assuming version will be
  // the minimum, 1:
  int provisionalBitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, Version.getVersionForNumber(1));
  Version provisionalVersion = chooseVersion(provisionalBitsNeeded, ecLevel);

  // Use that guess to calculate the right version. I am still not sure this works in 100% of cases.
  int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, provisionalVersion);
  return chooseVersion(bitsNeeded, ecLevel);
}
 
源代码19 项目: QrCodeScanner   文件: Encoder.java

/**
 * Decides the smallest version of QR code that will contain all of the provided data.
 *
 * @throws WriterException if the data cannot fit in any version
 */
private static Version recommendVersion(ErrorCorrectionLevel ecLevel,
                                        Mode mode,
                                        BitArray headerBits,
                                        BitArray dataBits) throws WriterException {
  // Hard part: need to know version to know how many bits length takes. But need to know how many
  // bits it takes to know version. First we take a guess at version by assuming version will be
  // the minimum, 1:
  int provisionalBitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, Version.getVersionForNumber(1));
  Version provisionalVersion = chooseVersion(provisionalBitsNeeded, ecLevel);

  // Use that guess to calculate the right version. I am still not sure this works in 100% of cases.
  int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, provisionalVersion);
  return chooseVersion(bitsNeeded, ecLevel);
}
 
源代码20 项目: RipplePower   文件: Encoder.java

/**
 * Append length info. On success, store the result in "bits".
 */
static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) throws WriterException {
	int numBits = mode.getCharacterCountBits(version);
	if (numLetters >= (1 << numBits)) {
		throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1));
	}
	bits.appendBits(numLetters, numBits);
}
 
源代码21 项目: ZXing-Orient   文件: Encoder.java

/**
 * Append length info. On success, store the result in "bits".
 */
static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) throws WriterException {
  int numBits = mode.getCharacterCountBits(version);
  if (numLetters >= (1 << numBits)) {
    throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1));
  }
  bits.appendBits(numLetters, numBits);
}
 
源代码22 项目: Telegram-FOSS   文件: Encoder.java

/**
 * Decides the smallest version of QR code that will contain all of the provided data.
 *
 * @throws WriterException if the data cannot fit in any version
 */
private static Version recommendVersion(ErrorCorrectionLevel ecLevel,
                                        Mode mode,
                                        BitArray headerBits,
                                        BitArray dataBits) throws WriterException {
  // Hard part: need to know version to know how many bits length takes. But need to know how many
  // bits it takes to know version. First we take a guess at version by assuming version will be
  // the minimum, 1:
  int provisionalBitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, Version.getVersionForNumber(1));
  Version provisionalVersion = chooseVersion(provisionalBitsNeeded, ecLevel);

  // Use that guess to calculate the right version. I am still not sure this works in 100% of cases.
  int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, provisionalVersion);
  return chooseVersion(bitsNeeded, ecLevel);
}
 
源代码23 项目: Telegram   文件: Encoder.java

/**
 * Decides the smallest version of QR code that will contain all of the provided data.
 *
 * @throws WriterException if the data cannot fit in any version
 */
private static Version recommendVersion(ErrorCorrectionLevel ecLevel,
                                        Mode mode,
                                        BitArray headerBits,
                                        BitArray dataBits) throws WriterException {
  // Hard part: need to know version to know how many bits length takes. But need to know how many
  // bits it takes to know version. First we take a guess at version by assuming version will be
  // the minimum, 1:
  int provisionalBitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, Version.getVersionForNumber(1));
  Version provisionalVersion = chooseVersion(provisionalBitsNeeded, ecLevel);

  // Use that guess to calculate the right version. I am still not sure this works in 100% of cases.
  int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, provisionalVersion);
  return chooseVersion(bitsNeeded, ecLevel);
}
 
源代码24 项目: weex   文件: Encoder.java

/**
 * Append length info. On success, store the result in "bits".
 */
static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) throws WriterException {
  int numBits = mode.getCharacterCountBits(version);
  if (numLetters >= (1 << numBits)) {
    throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1));
  }
  bits.appendBits(numLetters, numBits);
}
 
源代码25 项目: barcodescanner-lib-aar   文件: Encoder.java

/**
 * Decides the smallest version of QR code that will contain all of the provided data.
 *
 * @throws WriterException if the data cannot fit in any version
 */
private static Version recommendVersion(ErrorCorrectionLevel ecLevel,
                                        Mode mode,
                                        BitArray headerBits,
                                        BitArray dataBits) throws WriterException {
  // Hard part: need to know version to know how many bits length takes. But need to know how many
  // bits it takes to know version. First we take a guess at version by assuming version will be
  // the minimum, 1:
  int provisionalBitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, Version.getVersionForNumber(1));
  Version provisionalVersion = chooseVersion(provisionalBitsNeeded, ecLevel);

  // Use that guess to calculate the right version. I am still not sure this works in 100% of cases.
  int bitsNeeded = calculateBitsNeeded(mode, headerBits, dataBits, provisionalVersion);
  return chooseVersion(bitsNeeded, ecLevel);
}
 
源代码26 项目: barcodescanner-lib-aar   文件: Encoder.java

/**
 * Append length info. On success, store the result in "bits".
 */
static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) throws WriterException {
  int numBits = mode.getCharacterCountBits(version);
  if (numLetters >= (1 << numBits)) {
    throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1));
  }
  bits.appendBits(numLetters, numBits);
}
 
源代码27 项目: Telegram-FOSS   文件: Encoder.java

/**
 * Append length info. On success, store the result in "bits".
 */
static void appendLengthInfo(int numLetters, Version version, Mode mode, BitArray bits) throws WriterException {
  int numBits = mode.getCharacterCountBits(version);
  if (numLetters >= (1 << numBits)) {
    throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1));
  }
  bits.appendBits(numLetters, numBits);
}
 
源代码28 项目: MiBandDecompiled   文件: Encoder.java

public static Mode chooseMode(String s)
{
    return a(s, ((String) (null)));
}
 
源代码29 项目: ScreenCapture   文件: Encoder.java

private static int calculateBitsNeeded(Mode mode,
                                       BitArray headerBits,
                                       BitArray dataBits,
                                       Version version) {
  return headerBits.getSize() + mode.getCharacterCountBits(version) + dataBits.getSize();
}
 
源代码30 项目: ScreenCapture   文件: Encoder.java

public static Mode chooseMode(String content) {
  return chooseMode(content, null);
}
 
 类所在包
 同包方法