Java Code Examples for com.google.zxing.client.result.ParsedResult

The following examples show how to use com.google.zxing.client.result.ParsedResult. These examples are extracted from open source projects. 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
public AddressBookResultHandler(Activity activity, ParsedResult result) {
  super(activity, result);
  AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
  String[] addresses = addressResult.getAddresses();
  boolean hasAddress = addresses != null && addresses.length > 0 && addresses[0] != null && !addresses[0].isEmpty();
  String[] phoneNumbers = addressResult.getPhoneNumbers();
  boolean hasPhoneNumber = phoneNumbers != null && phoneNumbers.length > 0;
  String[] emails = addressResult.getEmails();
  boolean hasEmailAddress = emails != null && emails.length > 0;

  fields = new boolean[MAX_BUTTON_COUNT];
  fields[0] = true; // Add contact is always available
  fields[1] = hasAddress;
  fields[2] = hasPhoneNumber;
  fields[3] = hasEmailAddress;

  buttonCount = 0;
  for (int x = 0; x < MAX_BUTTON_COUNT; x++) {
    if (fields[x]) {
      buttonCount++;
    }
  }
}
 
Example 2
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 Project: weex   Source File: AddressBookResultHandler.java    License: Apache License 2.0 6 votes vote down vote up
public AddressBookResultHandler(Activity activity, ParsedResult result) {
  super(activity, result);
  AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
  String[] addresses = addressResult.getAddresses();
  boolean hasAddress = addresses != null && addresses.length > 0 && addresses[0] != null && !addresses[0].isEmpty();
  String[] phoneNumbers = addressResult.getPhoneNumbers();
  boolean hasPhoneNumber = phoneNumbers != null && phoneNumbers.length > 0;
  String[] emails = addressResult.getEmails();
  boolean hasEmailAddress = emails != null && emails.length > 0;

  fields = new boolean[MAX_BUTTON_COUNT];
  fields[0] = true; // Add contact is always available
  fields[1] = hasAddress;
  fields[2] = hasPhoneNumber;
  fields[3] = hasEmailAddress;

  buttonCount = 0;
  for (int x = 0; x < MAX_BUTTON_COUNT; x++) {
    if (fields[x]) {
      buttonCount++;
    }
  }
}
 
Example 4
public AddressBookResultHandler(Activity activity, ParsedResult result) {
    super(activity, result);
    AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
    String[] addresses = addressResult.getAddresses();
    boolean hasAddress = addresses != null && addresses.length > 0 && addresses[0].length() > 0;
    String[] phoneNumbers = addressResult.getPhoneNumbers();
    boolean hasPhoneNumber = phoneNumbers != null && phoneNumbers.length > 0;
    String[] emails = addressResult.getEmails();
    boolean hasEmailAddress = emails != null && emails.length > 0;

    fields = new boolean[4];
    fields[0] = true; // Add contact is always available
    fields[1] = hasAddress;
    fields[2] = hasPhoneNumber;
    fields[3] = hasEmailAddress;
}
 
Example 5
@Override
public CharSequence getDisplayContents() {
    CalendarParsedResult calResult = (CalendarParsedResult) getResult();
    StringBuilder result = new StringBuilder(100);
    ParsedResult.maybeAppend(calResult.getSummary(), result);
    Date start = calResult.getStart();
    String startString = start.toGMTString();
    appendTime(startString, result, false, false);

    Date end = calResult.getEnd();
    String endString = end.toGMTString();
    if (endString != null) {
        boolean sameStartEnd = startString.equals(endString);
        appendTime(endString, result, true, sameStartEnd);
    }

    ParsedResult.maybeAppend(calResult.getLocation(), result);
    ParsedResult.maybeAppend(calResult.getAttendees(), result);
    ParsedResult.maybeAppend(calResult.getDescription(), result);
    return result.toString();
}
 
Example 6
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == ScanCodeActivity.RESULT_OK && requestCode == CHOOSE_PICTURE) {
        //获取uri拿bitmap要做压缩处理,防止oom
        ShowDialog.showDialog(this, "识别中...", true, null);
        Uri originalUri = null;
        File file = null;
        if (null != data) {
            originalUri = data.getData();
            file = FilesUtils.getFileFromMediaUri(ScanCodeActivity.this, originalUri);
        }
        Bitmap photoBmp = null;
        try {
            photoBmp = FilesUtils.getBitmapFormUri(ScanCodeActivity.this, Uri.fromFile(file));
        } catch (IOException e) {
            e.printStackTrace();
        }
        int degree = FilesUtils.getBitmapDegree(file.getAbsolutePath());
        //把图片旋转为正的方向
        Bitmap newbitmap = FilesUtils.rotateBitmapByDegree(photoBmp, degree);
        QRDecode.decodeQR(newbitmap, new OnScannerCompletionListener() {
            @Override
            public void onScannerCompletion(Result result, ParsedResult parsedResult, Bitmap bitmap) {
                ShowDialog.dissmiss();
                if (parsedResult != null) {
                    pareCode(parsedResult.toString());

                } else {
                    toast(getString(R.string.scanner_error_toast));
                }
            }
        });
    }
}
 
Example 7
Source Project: android-apps   Source File: ResultHandlerFactory.java    License: MIT License 5 votes vote down vote up
public static ResultHandler makeResultHandler(CaptureActivity activity, Result rawResult) {
  ParsedResult result = parseResult(rawResult);
  switch (result.getType()) {
    case ADDRESSBOOK:
      return new AddressBookResultHandler(activity, result);
    case EMAIL_ADDRESS:
      return new EmailAddressResultHandler(activity, result);
    case PRODUCT:
      return new ProductResultHandler(activity, result, rawResult);
    case URI:
      return new URIResultHandler(activity, result);
    case WIFI:
      return new WifiResultHandler(activity, result);
    case GEO:
      return new GeoResultHandler(activity, result);
    case TEL:
      return new TelResultHandler(activity, result);
    case SMS:
      return new SMSResultHandler(activity, result);
    case CALENDAR:
      return new CalendarResultHandler(activity, result);
    case ISBN:
      return new ISBNResultHandler(activity, result, rawResult);
    default:
      return new TextResultHandler(activity, result, rawResult);
  }
}
 
Example 8
public static void maybeInvokeRetrieval(TextView textView,
                                        ParsedResult result,
                                        HistoryManager historyManager,
                                        Context context) {
  try {
    if (result instanceof URIParsedResult) {
      SupplementalInfoRetriever uriRetriever =
          new URIResultInfoRetriever(textView, (URIParsedResult) result, historyManager, context);
      uriRetriever.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
      SupplementalInfoRetriever titleRetriever =
          new TitleRetriever(textView, (URIParsedResult) result, historyManager);
      titleRetriever.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else if (result instanceof ProductParsedResult) {
      ProductParsedResult productParsedResult = (ProductParsedResult) result;
      String productID = productParsedResult.getProductID();
      SupplementalInfoRetriever productRetriever =
          new ProductResultInfoRetriever(textView, productID, historyManager, context);
      productRetriever.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else if (result instanceof ISBNParsedResult) {
      String isbn = ((ISBNParsedResult) result).getISBN();
      SupplementalInfoRetriever productInfoRetriever =
          new ProductResultInfoRetriever(textView, isbn, historyManager, context);
      productInfoRetriever.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
      SupplementalInfoRetriever bookInfoRetriever =
          new BookResultInfoRetriever(textView, isbn, historyManager, context);
      bookInfoRetriever.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
  } catch (RejectedExecutionException ree) {
    // do nothing
  }
}
 
Example 9
Source Project: appinventor-extensions   Source File: ResultHandler.java    License: 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 10
Source Project: android-apps   Source File: WifiResultHandler.java    License: MIT License 5 votes vote down vote up
@Override
public CharSequence getDisplayContents() {
  WifiParsedResult wifiResult = (WifiParsedResult) getResult();
  StringBuilder contents = new StringBuilder(50);
  String wifiLabel = parent.getString(R.string.wifi_ssid_label);
  ParsedResult.maybeAppend(wifiLabel + '\n' + wifiResult.getSsid(), contents);
  String typeLabel = parent.getString(R.string.wifi_type_label);
  ParsedResult.maybeAppend(typeLabel + '\n' + wifiResult.getNetworkEncryption(), contents);
  return contents.toString();
}
 
Example 11
Source Project: reacteu-app   Source File: TextResultHandler.java    License: MIT License 5 votes vote down vote up
public TextResultHandler(Activity activity, ParsedResult result, Result rawResult) {
   super(activity, result, rawResult);
buttons = new int[]{
	fakeR.getId("string", "button_web_search"),
	fakeR.getId("string", "button_share_by_email"),
	fakeR.getId("string", "button_share_by_sms"),
	fakeR.getId("string", "button_custom_product_search"),
};
 }
 
Example 12
public static ResultHandler makeResultHandler(CaptureActivity activity, Result rawResult) {
  ParsedResult result = parseResult(rawResult);
  switch (result.getType()) {
    case ADDRESSBOOK:
      return new AddressBookResultHandler(activity, result);
    case EMAIL_ADDRESS:
      return new EmailAddressResultHandler(activity, result);
    case PRODUCT:
      return new ProductResultHandler(activity, result, rawResult);
    case URI:
      return new URIResultHandler(activity, result);
    case WIFI:
      return new WifiResultHandler(activity, result);
    case GEO:
      return new GeoResultHandler(activity, result);
    case TEL:
      return new TelResultHandler(activity, result);
    case SMS:
      return new SMSResultHandler(activity, result);
    case CALENDAR:
      return new CalendarResultHandler(activity, result);
    case ISBN:
      return new ISBNResultHandler(activity, result, rawResult);
    default:
      return new TextResultHandler(activity, result, rawResult);
  }
}
 
Example 13
Source Project: zxingfragmentlib   Source File: ProductResultHandler.java    License: Apache License 2.0 5 votes vote down vote up
private static String getProductIDFromResult(ParsedResult rawResult) {
  if (rawResult instanceof ProductParsedResult) {
    return ((ProductParsedResult) rawResult).getNormalizedProductID();
  }
  if (rawResult instanceof ExpandedProductParsedResult) {
    return ((ExpandedProductParsedResult) rawResult).getRawText();
  }
  throw new IllegalArgumentException(rawResult.getClass().toString());
}
 
Example 14
Source Project: ProjectX   Source File: ZxingScanViewActivity.java    License: 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 15
Source Project: reacteu-app   Source File: CalendarResultHandler.java    License: MIT License 5 votes vote down vote up
public CalendarResultHandler(Activity activity, ParsedResult result) {
   super(activity, result);

buttons = new int[]{
	fakeR.getId("string", "button_add_calendar")
};
 }
 
Example 16
Source Project: reacteu-app   Source File: AddressBookResultHandler.java    License: MIT License 5 votes vote down vote up
public AddressBookResultHandler(Activity activity, ParsedResult result) {
   super(activity, result);
BUTTON_TEXTS = new int[]{
     fakeR.getId("string", "button_add_contact"),
     fakeR.getId("string", "button_show_map"),
     fakeR.getId("string", "button_dial"),
     fakeR.getId("string", "button_email"),
   };
   AddressBookParsedResult addressResult = (AddressBookParsedResult) result;
   String[] addresses = addressResult.getAddresses();
   boolean hasAddress = addresses != null && addresses.length > 0 && addresses[0].length() > 0;
   String[] phoneNumbers = addressResult.getPhoneNumbers();
   boolean hasPhoneNumber = phoneNumbers != null && phoneNumbers.length > 0;
   String[] emails = addressResult.getEmails();
   boolean hasEmailAddress = emails != null && emails.length > 0;

   fields = new boolean[MAX_BUTTON_COUNT];
   fields[0] = true; // Add contact is always available
   fields[1] = hasAddress;
   fields[2] = hasPhoneNumber;
   fields[3] = hasEmailAddress;

   buttonCount = 0;
   for (int x = 0; x < MAX_BUTTON_COUNT; x++) {
     if (fields[x]) {
       buttonCount++;
     }
   }
 }
 
Example 17
Source Project: reacteu-app   Source File: SMSResultHandler.java    License: MIT License 5 votes vote down vote up
public SMSResultHandler(Activity activity, ParsedResult result) {
   super(activity, result);
buttons = new int[]{
	fakeR.getId("string", "button_sms"),
	fakeR.getId("string", "button_mms")
};
 }
 
Example 18
public static ResultHandler makeResultHandler(CaptureActivity activity, Result rawResult) {
  ParsedResult result = parseResult(rawResult);
  switch (result.getType()) {
    case ADDRESSBOOK:
      return new AddressBookResultHandler(activity, result);
    case EMAIL_ADDRESS:
      return new EmailAddressResultHandler(activity, result);
    case PRODUCT:
      return new ProductResultHandler(activity, result, rawResult);
    case URI:
      return new URIResultHandler(activity, result);
    case WIFI:
      return new WifiResultHandler(activity, result);
    case GEO:
      return new GeoResultHandler(activity, result);
    case TEL:
      return new TelResultHandler(activity, result);
    case SMS:
      return new SMSResultHandler(activity, result);
    case CALENDAR:
      return new CalendarResultHandler(activity, result);
    case ISBN:
      return new ISBNResultHandler(activity, result, rawResult);
    default:
      return new TextResultHandler(activity, result, rawResult);
  }
}
 
Example 19
Source Project: barcodescanner-lib-aar   Source File: SMSResultHandler.java    License: MIT License 5 votes vote down vote up
@Override
public CharSequence getDisplayContents() {
  SMSParsedResult smsResult = (SMSParsedResult) getResult();
  String[] rawNumbers = smsResult.getNumbers();
  String[] formattedNumbers = new String[rawNumbers.length];
  for (int i = 0; i < rawNumbers.length; i++) {
    formattedNumbers[i] = PhoneNumberUtils.formatNumber(rawNumbers[i]);
  }
  StringBuilder contents = new StringBuilder(50);
  ParsedResult.maybeAppend(formattedNumbers, contents);
  ParsedResult.maybeAppend(smsResult.getSubject(), contents);
  ParsedResult.maybeAppend(smsResult.getBody(), contents);
  return contents.toString();
}
 
Example 20
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);

    View v = inflater.inflate(R.layout.fragment_result_sms, container, false);
    result = (SMSParsedResult) parsedResult;

    TextView to = (TextView) v.findViewById(R.id.fragment_result_sms_to);
    TextView toLabel = (TextView) v.findViewById(R.id.fragment_result_sms_to_label);
    TextView via = (TextView) v.findViewById(R.id.fragment_result_sms_via);
    TextView viaLabel = (TextView) v.findViewById(R.id.fragment_result_sms_via_label);
    TextView subject = (TextView) v.findViewById(R.id.fragment_result_sms_subject);
    TextView subjectLabel = (TextView) v.findViewById(R.id.fragment_result_sms_subject_label);
    TextView body = (TextView) v.findViewById(R.id.fragment_result_sms_body);

    if(result != null) {
        StringBuilder numberSb = new StringBuilder();
        ParsedResult.maybeAppend(result.getNumbers(), numberSb);

        StringBuilder viaSb = new StringBuilder();
        ParsedResult.maybeAppend(result.getVias(), viaSb);

        to.setText(numberSb.toString());
        via.setText(viaSb.toString());
        subject.setText(result.getSubject());
        body.setText(result.getBody());

        to.setVisibility(TextUtils.isEmpty(numberSb.toString()) ? View.GONE : View.VISIBLE);
        toLabel.setVisibility(TextUtils.isEmpty(numberSb.toString()) ? View.GONE : View.VISIBLE);
        via.setVisibility(TextUtils.isEmpty(viaSb.toString()) ? View.GONE : View.VISIBLE);
        viaLabel.setVisibility(TextUtils.isEmpty(viaSb.toString()) ? View.GONE : View.VISIBLE);
        subject.setVisibility(TextUtils.isEmpty(result.getSubject()) ? View.GONE : View.VISIBLE);
        subjectLabel.setVisibility(TextUtils.isEmpty(result.getSubject()) ? View.GONE : View.VISIBLE);
        body.setVisibility(TextUtils.isEmpty(result.getBody()) ? View.GONE : View.VISIBLE);
    }

    return v;
}
 
Example 21
public static void maybeInvokeRetrieval(TextView textView,
                                        ParsedResult result,
                                        HistoryManager historyManager,
                                        Context context) {
  try {
    if (result instanceof URIParsedResult) {
      SupplementalInfoRetriever uriRetriever =
          new URIResultInfoRetriever(textView, (URIParsedResult) result, historyManager, context);
      uriRetriever.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
      SupplementalInfoRetriever titleRetriever =
          new TitleRetriever(textView, (URIParsedResult) result, historyManager);
      titleRetriever.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else if (result instanceof ProductParsedResult) {
      ProductParsedResult productParsedResult = (ProductParsedResult) result;
      String productID = productParsedResult.getProductID();
      SupplementalInfoRetriever productRetriever =
          new ProductResultInfoRetriever(textView, productID, historyManager, context);
      productRetriever.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else if (result instanceof ISBNParsedResult) {
      String isbn = ((ISBNParsedResult) result).getISBN();
      SupplementalInfoRetriever productInfoRetriever =
          new ProductResultInfoRetriever(textView, isbn, historyManager, context);
      productInfoRetriever.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
      SupplementalInfoRetriever bookInfoRetriever =
          new BookResultInfoRetriever(textView, isbn, historyManager, context);
      bookInfoRetriever.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    }
  } catch (RejectedExecutionException ree) {
    // do nothing
  }
}
 
Example 22
Source Project: android-apps   Source File: QRCodeEncoder.java    License: 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 23
@Override
public CharSequence getDisplayContents() {
    EmailAddressParsedResult result = (EmailAddressParsedResult) getResult();
    StringBuilder contents = new StringBuilder(100);
    ParsedResult.maybeAppend(result.getTos(), contents);
    contents.trimToSize();
    return contents.toString();
}
 
Example 24
Source Project: barterli_android   Source File: ResultHandlerFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static ResultHandler makeResultHandler(Activity activity, Result rawResult) {
    ParsedResult result = parseResult(rawResult);
    switch (result.getType()) {
    case ADDRESSBOOK:
        return new AddressBookResultHandler(activity, result);
    case EMAIL_ADDRESS:
        return new EmailAddressResultHandler(activity, result);
    case PRODUCT:
        return new ProductResultHandler(activity, result, rawResult);
    case URI:
        return new URIResultHandler(activity, result);
    case WIFI:
        return new WifiResultHandler(activity, result);
    case TEXT:
        return new TextResultHandler(activity, result, rawResult);
    case GEO:
        return new GeoResultHandler(activity, result);
    case TEL:
        return new TelResultHandler(activity, result);
    case SMS:
        return new SMSResultHandler(activity, result);
    case CALENDAR:
        return new CalendarResultHandler(activity, result);
    case ISBN:
        return new ISBNResultHandler(activity, result, rawResult);
    }
    return new TextResultHandler(activity, result, rawResult);
}
 
Example 25
@Override
public CharSequence getDisplayContents() {
    ProductParsedResult result = (ProductParsedResult) getResult();
    StringBuilder contents = new StringBuilder(100);
    ParsedResult.maybeAppend(result.getNormalizedProductID(), contents);
    contents.trimToSize();
    return contents.toString();
}
 
Example 26
Source Project: weex   Source File: ProductResultHandler.java    License: Apache License 2.0 5 votes vote down vote up
private static String getProductIDFromResult(ParsedResult rawResult) {
  if (rawResult instanceof ProductParsedResult) {
    return ((ProductParsedResult) rawResult).getNormalizedProductID();
  }
  if (rawResult instanceof ExpandedProductParsedResult) {
    return ((ExpandedProductParsedResult) rawResult).getRawText();
  }
  throw new IllegalArgumentException(rawResult.getClass().toString());
}
 
Example 27
Source Project: weex   Source File: ResultHandlerFactory.java    License: Apache License 2.0 5 votes vote down vote up
public static ResultHandler makeResultHandler(CaptureActivity activity, Result rawResult) {
  ParsedResult result = parseResult(rawResult);
  switch (result.getType()) {
    case ADDRESSBOOK:
      return new AddressBookResultHandler(activity, result);
    case EMAIL_ADDRESS:
      return new EmailAddressResultHandler(activity, result);
    case PRODUCT:
      return new ProductResultHandler(activity, result, rawResult);
    case URI:
      return new URIResultHandler(activity, result);
    case WIFI:
      return new WifiResultHandler(activity, result);
    case GEO:
      return new GeoResultHandler(activity, result);
    case TEL:
      return new TelResultHandler(activity, result);
    case SMS:
      return new SMSResultHandler(activity, result);
    case CALENDAR:
      return new CalendarResultHandler(activity, result);
    case ISBN:
      return new ISBNResultHandler(activity, result, rawResult);
    default:
      return new TextResultHandler(activity, result, rawResult);
  }
}
 
Example 28
Source Project: barcodescanner-lib-aar   Source File: ProductResultHandler.java    License: MIT License 5 votes vote down vote up
private static String getProductIDFromResult(ParsedResult rawResult) {
  if (rawResult instanceof ProductParsedResult) {
    return ((ProductParsedResult) rawResult).getNormalizedProductID();
  }
  if (rawResult instanceof ExpandedProductParsedResult) {
    return ((ExpandedProductParsedResult) rawResult).getRawText();
  }
  throw new IllegalArgumentException(rawResult.getClass().toString());
}
 
Example 29
Source Project: reacteu-app   Source File: ResultHandler.java    License: MIT License 5 votes vote down vote up
ResultHandler(Activity activity, ParsedResult result, Result rawResult) {
   this.result = result;
   this.activity = activity;
   this.rawResult = rawResult;
   this.customProductSearch = parseCustomSearchURL();

fakeR = new FakeR(activity);

// Make sure the Shopper button is hidden by default. Without this, scanning a product followed
   // by a QR Code would leave the button on screen among the QR Code actions.
   View shopperButton = activity.findViewById(fakeR.getId("id", "shopper_button"));
   shopperButton.setVisibility(View.GONE);
 }
 
Example 30
@Override
public CharSequence getDisplayContents() {
    ISBNParsedResult result = (ISBNParsedResult) getResult();
    StringBuilder contents = new StringBuilder(100);
    ParsedResult.maybeAppend(result.getISBN(), contents);
    contents.trimToSize();
    return contents.toString();
}