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

The following examples show how to use com.google.zxing.client.result.ParsedResult. 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: CalendarResultHandler.java    From android-quick-response-code with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: AddressBookResultHandler.java    From android-quick-response-code with 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].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 #3
Source File: AddressBookResultHandler.java    From ZXing-Standalone-library with 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
Source File: AddressBookResultHandler.java    From weex with 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 #5
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 #6
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 #7
Source File: ResultHandlerFactory.java    From analyzer-of-android-for-Apache-Weex with 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 #8
Source File: SMSResultHandler.java    From reacteu-app with 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 #9
Source File: AddressBookResultHandler.java    From reacteu-app with 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 #10
Source File: CalendarResultHandler.java    From reacteu-app with 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 #11
Source File: ScanCodeActivity.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 #12
Source File: WifiResultHandler.java    From android-apps with 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 #13
Source File: SupplementalInfoRetriever.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
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 #14
Source File: TextResultHandler.java    From reacteu-app with 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 #15
Source File: ResultHandlerFactory.java    From ZXing-Standalone-library with 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 #16
Source File: ProductResultHandler.java    From zxingfragmentlib with 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 #17
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 #18
Source File: SupplementalInfoRetriever.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
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 #19
Source File: SMSResultHandler.java    From barcodescanner-lib-aar with 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
Source File: SMSResultFragment.java    From privacy-friendly-qr-scanner with GNU General Public License v3.0 5 votes vote down vote up
@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
Source File: ResultHandlerFactory.java    From android-apps with 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 #22
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 #23
Source File: EmailAddressResultHandler.java    From android-quick-response-code with Apache License 2.0 5 votes vote down vote up
@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 File: ResultHandlerFactory.java    From barterli_android with 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
Source File: ProductResultHandler.java    From android-quick-response-code with Apache License 2.0 5 votes vote down vote up
@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 File: ProductResultHandler.java    From weex with 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 File: ResultHandlerFactory.java    From weex with 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 File: ProductResultHandler.java    From barcodescanner-lib-aar with 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 File: ResultHandler.java    From reacteu-app with 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
Source File: ISBNResultHandler.java    From android-quick-response-code with Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence getDisplayContents() {
    ISBNParsedResult result = (ISBNParsedResult) getResult();
    StringBuilder contents = new StringBuilder(100);
    ParsedResult.maybeAppend(result.getISBN(), contents);
    contents.trimToSize();
    return contents.toString();
}