com.google.zxing.client.result.ResultParser Java Examples

The following examples show how to use com.google.zxing.client.result.ResultParser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResultHandler.java    From barcodescanner-lib-aar with MIT License 6 votes vote down vote up
final String fillInCustomSearchURL(String text) {
  if (customProductSearch == null) {
    return text; // ?
  }
  try {
    text = URLEncoder.encode(text, "UTF-8");
  } catch (UnsupportedEncodingException e) {
    // can't happen; UTF-8 is always supported. Continue, I guess, without encoding      
  }
  String url = customProductSearch;
  if (rawResult != null) {
    // Replace %f but only if it doesn't seem to be a hex escape sequence. This remains
    // problematic but avoids the more surprising problem of breaking escapes
    url = url.replaceFirst("%f(?![0-9a-f])", rawResult.getBarcodeFormat().toString());
    if (url.contains("%t")) {
      ParsedResult parsedResultAgain = ResultParser.parseResult(rawResult);
      url = url.replace("%t", parsedResultAgain.getType().toString());
    }
  }
  // Replace %s last as it might contain itself %f or %t
  return url.replace("%s", text);
}
 
Example #2
Source File: ResultHandler.java    From zxingfragmentlib with Apache License 2.0 6 votes vote down vote up
final String fillInCustomSearchURL(String text) {
  if (customProductSearch == null) {
    return text; // ?
  }
  try {
    text = URLEncoder.encode(text, "UTF-8");
  } catch (UnsupportedEncodingException e) {
    // can't happen; UTF-8 is always supported. Continue, I guess, without encoding      
  }
  String url = customProductSearch;
  if (rawResult != null) {
    // Replace %f but only if it doesn't seem to be a hex escape sequence. This remains
    // problematic but avoids the more surprising problem of breaking escapes
    url = url.replaceFirst("%f(?![0-9a-f])", rawResult.getBarcodeFormat().toString());
    if (url.contains("%t")) {
      ParsedResult parsedResultAgain = ResultParser.parseResult(rawResult);
      url = url.replace("%t", parsedResultAgain.getType().toString());
    }
  }
  // Replace %s last as it might contain itself %f or %t
  return url.replace("%s", text);
}
 
Example #3
Source File: ResultHandler.java    From ZXing-Standalone-library with Apache License 2.0 6 votes vote down vote up
final String fillInCustomSearchURL(String text) {
  if (customProductSearch == null) {
    return text; // ?
  }
  try {
    text = URLEncoder.encode(text, "UTF-8");
  } catch (UnsupportedEncodingException e) {
    // can't happen; UTF-8 is always supported. Continue, I guess, without encoding      
  }
  String url = customProductSearch;
  if (rawResult != null) {
    // Replace %f but only if it doesn't seem to be a hex escape sequence. This remains
    // problematic but avoids the more surprising problem of breaking escapes
    url = url.replaceFirst("%f(?![0-9a-f])", rawResult.getBarcodeFormat().toString());
    if (url.contains("%t")) {
      ParsedResult parsedResultAgain = ResultParser.parseResult(rawResult);
      url = url.replace("%t", parsedResultAgain.getType().toString());
    }
  }
  // Replace %s last as it might contain itself %f or %t
  return url.replace("%s", text);
}
 
Example #4
Source File: ResultHandler.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 6 votes vote down vote up
final String fillInCustomSearchURL(String text) {
  if (customProductSearch == null) {
    return text; // ?
  }
  try {
    text = URLEncoder.encode(text, "UTF-8");
  } catch (UnsupportedEncodingException e) {
    // can't happen; UTF-8 is always supported. Continue, I guess, without encoding      
  }
  String url = customProductSearch;
  if (rawResult != null) {
    // Replace %f but only if it doesn't seem to be a hex escape sequence. This remains
    // problematic but avoids the more surprising problem of breaking escapes
    url = url.replaceFirst("%f(?![0-9a-f])", rawResult.getBarcodeFormat().toString());
    if (url.contains("%t")) {
      ParsedResult parsedResultAgain = ResultParser.parseResult(rawResult);
      url = url.replace("%t", parsedResultAgain.getType().toString());
    }
  }
  // Replace %s last as it might contain itself %f or %t
  return url.replace("%s", text);
}
 
Example #5
Source File: ResultHandler.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
final String fillInCustomSearchURL(String text) {
  if (customProductSearch == null) {
    return text; // ?
  }
  try {
    text = URLEncoder.encode(text, "UTF-8");
  } catch (UnsupportedEncodingException e) {
    // can't happen; UTF-8 is always supported. Continue, I guess, without encoding      
  }
  String url = customProductSearch;
  if (rawResult != null) {
    // Replace %f but only if it doesn't seem to be a hex escape sequence. This remains
    // problematic but avoids the more surprising problem of breaking escapes
    url = url.replaceFirst("%f(?![0-9a-f])", rawResult.getBarcodeFormat().toString());
    if (url.contains("%t")) {
      ParsedResult parsedResultAgain = ResultParser.parseResult(rawResult);
      url = url.replace("%t", parsedResultAgain.getType().toString());
    }
  }
  // Replace %s last as it might contain itself %f or %t
  return url.replace("%s", text);
}
 
Example #6
Source File: ResultHandler.java    From weex with Apache License 2.0 6 votes vote down vote up
final String fillInCustomSearchURL(String text) {
  if (customProductSearch == null) {
    return text; // ?
  }
  try {
    text = URLEncoder.encode(text, "UTF-8");
  } catch (UnsupportedEncodingException e) {
    // can't happen; UTF-8 is always supported. Continue, I guess, without encoding      
  }
  String url = customProductSearch;
  if (rawResult != null) {
    // Replace %f but only if it doesn't seem to be a hex escape sequence. This remains
    // problematic but avoids the more surprising problem of breaking escapes
    url = url.replaceFirst("%f(?![0-9a-f])", rawResult.getBarcodeFormat().toString());
    if (url.contains("%t")) {
      ParsedResult parsedResultAgain = ResultParser.parseResult(rawResult);
      url = url.replace("%t", parsedResultAgain.getType().toString());
    }
  }
  // Replace %s last as it might contain itself %f or %t
  return url.replace("%s", text);
}
 
Example #7
Source File: ResultHandler.java    From reacteu-app with MIT License 5 votes vote down vote up
String fillInCustomSearchURL(String text) {
  if (customProductSearch == null) {
    return text; // ?
  }
  String url = customProductSearch.replace("%s", text);
  if (rawResult != null) {
    url = url.replace("%f", rawResult.getBarcodeFormat().toString());
    if (url.contains("%t")) {
      ParsedResult parsedResultAgain = ResultParser.parseResult(rawResult);
      url = url.replace("%t", parsedResultAgain.getType().toString());
    }
  }
  return url;
}
 
Example #8
Source File: QRCodeEncoder.java    From reacteu-app with MIT License 5 votes vote down vote up
private void encodeFromStreamExtra(Intent intent) throws WriterException {
  format = BarcodeFormat.QR_CODE;
  Bundle bundle = intent.getExtras();
  if (bundle == null) {
    throw new WriterException("No extras");
  }
  Uri uri = (Uri) bundle.getParcelable(Intent.EXTRA_STREAM);
  if (uri == null) {
    throw new WriterException("No EXTRA_STREAM");
  }
  byte[] vcard;
  String vcardString;
  try {
    InputStream stream = activity.getContentResolver().openInputStream(uri);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buffer = new byte[2048];
    int bytesRead;
    while ((bytesRead = stream.read(buffer)) > 0) {
      baos.write(buffer, 0, bytesRead);
    }
    vcard = baos.toByteArray();
    vcardString = new String(vcard, 0, vcard.length, "UTF-8");
  } catch (IOException ioe) {
    throw new WriterException(ioe);
  }
  Log.d(TAG, "Encoding share intent content:");
  Log.d(TAG, vcardString);
  Result result = new Result(vcardString, vcard, null, BarcodeFormat.QR_CODE);
  ParsedResult parsedResult = ResultParser.parseResult(result);
  if (!(parsedResult instanceof AddressBookParsedResult)) {
    throw new WriterException("Result was not an address");
  }
  encodeQRCodeContents((AddressBookParsedResult) parsedResult);
  if (contents == null || contents.length() == 0) {
    throw new WriterException("No content to encode");
  }
}
 
Example #9
Source File: ZxingScanViewActivity.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
@Override
public void onResult(ZxingScanView scanView, Result result, Bitmap barcode,
                     float scaleFactor) {
    ParsedResult parsedResult = ResultParser.parseResult(result);
    final String format = "format:" + result.getBarcodeFormat().toString();
    final String type = "type:" + parsedResult.getType().toString();
    DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
    final String date = "date:" + formatter.format(new Date(result.getTimestamp()));
    String meta = "";
    Map<ResultMetadataType, Object> metadata = result.getResultMetadata();
    if (metadata != null) {
        StringBuilder metadataText = new StringBuilder(20);
        for (Map.Entry<ResultMetadataType, Object> entry : metadata.entrySet()) {
            if (DISPLAYABLE_METADATA_TYPES.contains(entry.getKey())) {
                metadataText.append(entry.getValue()).append('\n');
            }
        }
        if (metadataText.length() > 0) {
            metadataText.setLength(metadataText.length() - 1);
            meta = metadataText.toString();
        }
    }
    CharSequence displayContents = parsedResult.getDisplayResult();
    Toast.makeText(this, format + "\n" + type + "\n" + date + "\n" + meta + "\n" + displayContents,
            Toast.LENGTH_SHORT).show();
    // 重新扫描
    scanView.restartScanDelay(3000);
}
 
Example #10
Source File: QRCodeEncoder.java    From android-apps with MIT License 5 votes vote down vote up
private void encodeContentsFromShareIntentDefault(Intent intent) throws WriterException {
  format = BarcodeFormat.QR_CODE;
  Bundle bundle = intent.getExtras();
  if (bundle == null) {
    throw new WriterException("No extras");
  }
  Uri uri = (Uri) bundle.getParcelable(Intent.EXTRA_STREAM);
  if (uri == null) {
    throw new WriterException("No EXTRA_STREAM");
  }
  byte[] vcard;
  String vcardString;
  try {
    InputStream stream = activity.getContentResolver().openInputStream(uri);
    int length = stream.available();
    if (length <= 0) {
      throw new WriterException("Content stream is empty");
    }
    vcard = new byte[length];
    int bytesRead = stream.read(vcard, 0, length);
    if (bytesRead < length) {
      throw new WriterException("Unable to fully read available bytes from content stream");
    }
    vcardString = new String(vcard, 0, bytesRead, "UTF-8");
  } catch (IOException ioe) {
    throw new WriterException(ioe);
  }
  Log.d(TAG, "Encoding share intent content:");
  Log.d(TAG, vcardString);
  Result result = new Result(vcardString, vcard, null, BarcodeFormat.QR_CODE);
  ParsedResult parsedResult = ResultParser.parseResult(result);
  if (!(parsedResult instanceof AddressBookParsedResult)) {
    throw new WriterException("Result was not an address");
  }
  encodeQRCodeContents((AddressBookParsedResult) parsedResult);
  if (contents == null || contents.length() == 0) {
    throw new WriterException("No content to encode");
  }
}
 
Example #11
Source File: ResultViewModel.java    From privacy-friendly-qr-scanner with GNU General Public License v3.0 5 votes vote down vote up
public void initFromScan(BarcodeResult barcodeResult) {
    currentBarcodeResult = barcodeResult;
    mParsedResult = ResultParser.parseResult(currentBarcodeResult.getResult());
    mCodeImage = currentBarcodeResult.getBitmapWithResultPoints(ContextCompat.getColor(getApplication(), R.color.colorAccent));

    createHistoryItem();
}
 
Example #12
Source File: ResultViewModel.java    From privacy-friendly-qr-scanner with GNU General Public License v3.0 5 votes vote down vote up
/**
 * After this function is called the the following values will not be null:
 * <ul>
 *     <li>currentHistoryItem</li>
 *     <li>mCodeImage</li>
 *     <li>mSavedToHistory</li>
 *     <li>mParsedResult</li>
 * </ul>
 * If the state can not be created the activity will call {@link Activity#finish()}
 * This method will also update the {@link HistoryItem} in the database with a recreation of the QR Code if the image is missing.
 */
public void initFromHistoryItem(HistoryItem historyItem) {
    currentHistoryItem = historyItem;
    mParsedResult = ResultParser.parseResult(currentHistoryItem.getResult());
    mCodeImage = currentHistoryItem.getImage();
    if(mCodeImage == null) {
        mCodeImage = Utils.generateCode(currentHistoryItem.getText(), BarcodeFormat.QR_CODE, null, null);
        currentHistoryItem.setImage(mCodeImage);
        currentHistoryItem.setFormat(BarcodeFormat.QR_CODE);
        updateHistoryItem(currentHistoryItem);
    }
    mSavedToHistory = true;
}
 
Example #13
Source File: ResultHandler.java    From android-apps with MIT License 5 votes vote down vote up
String fillInCustomSearchURL(String text) {
  if (customProductSearch == null) {
    return text; // ?
  }
  String url = customProductSearch.replace("%s", text);
  if (rawResult != null) {
    url = url.replace("%f", rawResult.getBarcodeFormat().toString());
    if (url.contains("%t")) {
      ParsedResult parsedResultAgain = ResultParser.parseResult(rawResult);
      url = url.replace("%t", parsedResultAgain.getType().toString());
    }
  }
  return url;
}
 
Example #14
Source File: QRCodeEncoder.java    From AndroidWebServ with Apache License 2.0 5 votes vote down vote up
private void encodeFromStreamExtra(Intent intent) throws WriterException {
    format = BarcodeFormat.QR_CODE;
    Bundle bundle = intent.getExtras();
    if (bundle == null) {
        throw new WriterException("No extras");
    }
    Uri uri = bundle.getParcelable(Intent.EXTRA_STREAM);
    if (uri == null) {
        throw new WriterException("No EXTRA_STREAM");
    }
    byte[] vcard;
    String vcardString;
    try {
        InputStream stream = activity.getContentResolver().openInputStream(uri);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[2048];
        int bytesRead;
        while ((bytesRead = stream.read(buffer)) > 0) {
            baos.write(buffer, 0, bytesRead);
        }
        vcard = baos.toByteArray();
        vcardString = new String(vcard, 0, vcard.length, "UTF-8");
    } catch (IOException ioe) {
        throw new WriterException(ioe);
    }
    Log.d(TAG, "Encoding share intent content:");
    Log.d(TAG, vcardString);
    Result result = new Result(vcardString, vcard, null, BarcodeFormat.QR_CODE);
    ParsedResult parsedResult = ResultParser.parseResult(result);
    if (!(parsedResult instanceof AddressBookParsedResult)) {
        throw new WriterException("Result was not an address");
    }
    encodeQRCodeContents((AddressBookParsedResult) parsedResult);
    if (contents == null || contents.length() == 0) {
        throw new WriterException("No content to encode");
    }
}
 
Example #15
Source File: ResultHandler.java    From appinventor-extensions with Apache License 2.0 5 votes vote down vote up
String fillInCustomSearchURL(String text) {
  if (customProductSearch == null) {
    return text; // ?
  }
  String url = customProductSearch.replace("%s", text);
  if (rawResult != null) {
    url = url.replace("%f", rawResult.getBarcodeFormat().toString());
    if (url.contains("%t")) {
      ParsedResult parsedResultAgain = ResultParser.parseResult(rawResult);
      url = url.replace("%t", parsedResultAgain.getType().toString());
    }
  }
  return url;
}
 
Example #16
Source File: ResultProcessorFactory.java    From BarcodeEye with Apache License 2.0 5 votes vote down vote up
public static ResultProcessor<? extends ParsedResult> makeResultProcessor(
        Context context, Result result, Uri photoUri) {

    ParsedResult parsedResult = ResultParser.parseResult(result);

    switch (parsedResult.getType()) {
        case PRODUCT:
            return new ProductResultProcessor(context,
                    (ProductParsedResult) parsedResult, result, photoUri);
        case URI:
            return new UriResultProcessor(context,
                    (URIParsedResult) parsedResult, result, photoUri);
        case ISBN:
            return new IsbnResultProcessor(context,
                    (ISBNParsedResult) parsedResult, result, photoUri);
        case SMS:
        case GEO:
        case TEL:
        case CALENDAR:
        case ADDRESSBOOK:
        case EMAIL_ADDRESS:
        case WIFI:
            // currently unsupported so we let them fall through
        default:
            return new TextResultProcessor(context, parsedResult, result, photoUri);
    }
}
 
Example #17
Source File: CaptureActivity.java    From BarcodeScanner with Apache License 2.0 4 votes vote down vote up
/**
 * 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();

	lastResult = rawResult;

	// 把图片画到扫描框
	viewfinderView.drawResultBitmap(barcode);

	beepManager.playBeepSoundAndVibrate();

	Toast.makeText(this,
			"识别结果:" + ResultParser.parseResult(rawResult).toString(),
			Toast.LENGTH_SHORT).show();

}
 
Example #18
Source File: ResultHandlerFactory.java    From barterli_android with Apache License 2.0 4 votes vote down vote up
private static ParsedResult parseResult(Result rawResult) {
    return ResultParser.parseResult(rawResult);
}
 
Example #19
Source File: CaptureActivity.java    From AndroidWebServ with Apache License 2.0 4 votes vote down vote up
/**
 * 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.
 */
@SuppressWarnings("unchecked")
public void handleDecode(Result rawResult, Bitmap barcode, float scaleFactor) {
    inactivityTimer.onActivity();

    ParsedResult result = ResultParser.parseResult(rawResult);

    // Hand back whatever action they requested - this can be changed to Intents.Scan.ACTION when
    // the deprecated intent is retired.
    Intent intent = new Intent(getIntent().getAction());
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
    intent.putExtra(Intents.Scan.RESULT, result.getDisplayResult());
    intent.putExtra(Intents.Scan.RESULT_TYPE, result.getType().ordinal());
    intent.putExtra(Intents.Scan.RESULT_FORMAT, rawResult.getBarcodeFormat().toString());
    byte[] rawBytes = bm2bytes(barcode);
    // byte[] rawBytes = rawResult.getRawBytes();
    if (rawBytes != null && rawBytes.length > 0) {
        intent.putExtra(Intents.Scan.RESULT_BYTES, rawBytes);
    }
    Map<ResultMetadataType, ?> metadata = rawResult.getResultMetadata();
    if (metadata != null) {
        if (metadata.containsKey(ResultMetadataType.UPC_EAN_EXTENSION)) {
            intent.putExtra(Intents.Scan.RESULT_UPC_EAN_EXTENSION,
                    metadata.get(ResultMetadataType.UPC_EAN_EXTENSION).toString());
        }
        Integer orientation = (Integer) metadata.get(ResultMetadataType.ORIENTATION);
        if (orientation != null) {
            intent.putExtra(Intents.Scan.RESULT_ORIENTATION, orientation.intValue());
        }
        String ecLevel = (String) metadata.get(ResultMetadataType.ERROR_CORRECTION_LEVEL);
        if (ecLevel != null) {
            intent.putExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL, ecLevel);
        }
        Iterable<byte[]> byteSegments = (Iterable<byte[]>) metadata
                .get(ResultMetadataType.BYTE_SEGMENTS);
        if (byteSegments != null) {
            int i = 0;
            for (byte[] byteSegment : byteSegments) {
                intent.putExtra(Intents.Scan.RESULT_BYTE_SEGMENTS_PREFIX + i, byteSegment);
                i++;
            }
        }
    }

    Message message = Message.obtain(handler, R.id.return_scan_result, intent);
    handler.sendMessage(message);
}
 
Example #20
Source File: ResultHandlerFactory.java    From android-quick-response-code with Apache License 2.0 4 votes vote down vote up
private static ParsedResult parseResult(Result rawResult) {
    return ResultParser.parseResult(rawResult);
}
 
Example #21
Source File: ResultHandlerFactory.java    From android-apps with MIT License 4 votes vote down vote up
private static ParsedResult parseResult(Result rawResult) {
  return ResultParser.parseResult(rawResult);
}
 
Example #22
Source File: QRCodeEncoder.java    From zxingfragmentlib with Apache License 2.0 4 votes vote down vote up
private void encodeFromStreamExtra(Intent intent) throws WriterException {
  format = BarcodeFormat.QR_CODE;
  Bundle bundle = intent.getExtras();
  if (bundle == null) {
    throw new WriterException("No extras");
  }
  Uri uri = bundle.getParcelable(Intent.EXTRA_STREAM);
  if (uri == null) {
    throw new WriterException("No EXTRA_STREAM");
  }
  byte[] vcard;
  String vcardString;
  InputStream stream = null;
  try {
    stream = activity.getContentResolver().openInputStream(uri);
    if (stream == null) {
      throw new WriterException("Can't open stream for " + uri);
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buffer = new byte[2048];
    int bytesRead;
    while ((bytesRead = stream.read(buffer)) > 0) {
      baos.write(buffer, 0, bytesRead);
    }
    vcard = baos.toByteArray();
    vcardString = new String(vcard, 0, vcard.length, "UTF-8");
  } catch (IOException ioe) {
    throw new WriterException(ioe);
  } finally {
    if (stream != null) {
      try {
        stream.close();
      } catch (IOException e) {
        // continue
      }
    }
  }
  Log.d(TAG, "Encoding share intent content:");
  Log.d(TAG, vcardString);
  Result result = new Result(vcardString, vcard, null, BarcodeFormat.QR_CODE);
  ParsedResult parsedResult = ResultParser.parseResult(result);
  if (!(parsedResult instanceof AddressBookParsedResult)) {
    throw new WriterException("Result was not an address");
  }
  encodeQRCodeContents((AddressBookParsedResult) parsedResult);
  if (contents == null || contents.isEmpty()) {
    throw new WriterException("No content to encode");
  }
}
 
Example #23
Source File: ResultHandlerFactory.java    From zxingfragmentlib with Apache License 2.0 4 votes vote down vote up
private static ParsedResult parseResult(Result rawResult) {
  return ResultParser.parseResult(rawResult);
}
 
Example #24
Source File: QRCodeEncoder.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
private void encodeFromStreamExtra(Intent intent) throws WriterException {
  format = BarcodeFormat.QR_CODE;
  Bundle bundle = intent.getExtras();
  if (bundle == null) {
    throw new WriterException("No extras");
  }
  Uri uri = bundle.getParcelable(Intent.EXTRA_STREAM);
  if (uri == null) {
    throw new WriterException("No EXTRA_STREAM");
  }
  byte[] vcard;
  String vcardString;
  InputStream stream = null;
  try {
    stream = activity.getContentResolver().openInputStream(uri);
    if (stream == null) {
      throw new WriterException("Can't open stream for " + uri);
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buffer = new byte[2048];
    int bytesRead;
    while ((bytesRead = stream.read(buffer)) > 0) {
      baos.write(buffer, 0, bytesRead);
    }
    vcard = baos.toByteArray();
    vcardString = new String(vcard, 0, vcard.length, "UTF-8");
  } catch (IOException ioe) {
    throw new WriterException(ioe);
  } finally {
    if (stream != null) {
      try {
        stream.close();
      } catch (IOException e) {
        // continue
      }
    }
  }
  Log.d(TAG, "Encoding share intent content:");
  Log.d(TAG, vcardString);
  Result result = new Result(vcardString, vcard, null, BarcodeFormat.QR_CODE);
  ParsedResult parsedResult = ResultParser.parseResult(result);
  if (!(parsedResult instanceof AddressBookParsedResult)) {
    throw new WriterException("Result was not an address");
  }
  encodeQRCodeContents((AddressBookParsedResult) parsedResult);
  if (contents == null || contents.isEmpty()) {
    throw new WriterException("No content to encode");
  }
}
 
Example #25
Source File: ResultHandlerFactory.java    From reacteu-app with MIT License 4 votes vote down vote up
private static ParsedResult parseResult(Result rawResult) {
  return ResultParser.parseResult(rawResult);
}
 
Example #26
Source File: ResultHandlerFactory.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
private static ParsedResult parseResult(Result rawResult) {
  return ResultParser.parseResult(rawResult);
}
 
Example #27
Source File: ResultHandlerFactory.java    From letv with Apache License 2.0 4 votes vote down vote up
private static ParsedResult parseResult(Result rawResult) {
    return ResultParser.parseResult(rawResult);
}
 
Example #28
Source File: HistoryItemViewModel.java    From privacy-friendly-qr-scanner with GNU General Public License v3.0 4 votes vote down vote up
public HistoryItemViewModel(Context context, HistoryItem entry) {
    this.context = context;
    this.entry = entry;
    this.parsed = ResultParser.parseResult(entry.getResult());
}
 
Example #29
Source File: ResultHandlerFactory.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
private static ParsedResult parseResult(Result rawResult) {
  return ResultParser.parseResult(rawResult);
}
 
Example #30
Source File: QRCodeEncoder.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
private void encodeFromStreamExtra(Intent intent) throws WriterException {
  format = BarcodeFormat.QR_CODE;
  Bundle bundle = intent.getExtras();
  if (bundle == null) {
    throw new WriterException("No extras");
  }
  Uri uri = bundle.getParcelable(Intent.EXTRA_STREAM);
  if (uri == null) {
    throw new WriterException("No EXTRA_STREAM");
  }
  byte[] vcard;
  String vcardString;
  InputStream stream = null;
  try {
    stream = activity.getContentResolver().openInputStream(uri);
    if (stream == null) {
      throw new WriterException("Can't open stream for " + uri);
    }
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buffer = new byte[2048];
    int bytesRead;
    while ((bytesRead = stream.read(buffer)) > 0) {
      baos.write(buffer, 0, bytesRead);
    }
    vcard = baos.toByteArray();
    vcardString = new String(vcard, 0, vcard.length, "UTF-8");
  } catch (IOException ioe) {
    throw new WriterException(ioe);
  } finally {
    if (stream != null) {
      try {
        stream.close();
      } catch (IOException e) {
        // continue
      }
    }
  }
  Log.d(TAG, "Encoding share intent content:");
  Log.d(TAG, vcardString);
  Result result = new Result(vcardString, vcard, null, BarcodeFormat.QR_CODE);
  ParsedResult parsedResult = ResultParser.parseResult(result);
  if (!(parsedResult instanceof AddressBookParsedResult)) {
    throw new WriterException("Result was not an address");
  }
  encodeQRCodeContents((AddressBookParsedResult) parsedResult);
  if (contents == null || contents.isEmpty()) {
    throw new WriterException("No content to encode");
  }
}