@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQ_CAPTURE) { if (resultCode == RESULT_OK) { String result = data.getStringExtra(Intents.Scan.RESULT); ParsedResultType type = ParsedResultType.values()[data.getIntExtra( Intents.Scan.RESULT_TYPE, ParsedResultType.TEXT.ordinal())]; boolean isShow = false; try { if (type == ParsedResultType.URI) { toBrowserActivity(result); } else { isShow = true; } } catch (ActivityNotFoundException e) { isShow = true; } finally { lastResult = result; if (isShow) showDialog(DLG_SCAN_RESULT); } } } else { super.onActivityResult(requestCode, resultCode, data); } }
public static ResultHandler makeResultHandler(SweepActivity activity, Result rawResult) { ParsedResult result = parseResult(rawResult); if (result.getType() == ParsedResultType.URI) { return new URIResultHandler(activity, result); } return new TextResultHandler(activity, result, rawResult); }
public static ResultHandler makeResultHandler(Activity activity, Result rawResult) { ParsedResult result = parseResult(rawResult); ParsedResultType type = result.getType(); if (type.equals(ParsedResultType.ADDRESSBOOK)) { return new AddressBookResultHandler(activity, result); } else if (type.equals(ParsedResultType.EMAIL_ADDRESS)) { return new EmailAddressResultHandler(activity, result); } else if (type.equals(ParsedResultType.PRODUCT)) { return new ProductResultHandler(activity, result, rawResult); } else if (type.equals(ParsedResultType.URI)) { return new URIResultHandler(activity, result); } else if (type.equals(ParsedResultType.WIFI)) { return new WifiResultHandler(activity, result); } else if (type.equals(ParsedResultType.TEXT)) { return new TextResultHandler(activity, result, rawResult); } else if (type.equals(ParsedResultType.GEO)) { return new GeoResultHandler(activity, result); } else if (type.equals(ParsedResultType.TEL)) { return new TelResultHandler(activity, result); } else if (type.equals(ParsedResultType.SMS)) { return new SMSResultHandler(activity, result); } else if (type.equals(ParsedResultType.CALENDAR)) { return new CalendarResultHandler(activity, result); } else if (type.equals(ParsedResultType.ISBN)) { return new ISBNResultHandler(activity, result, rawResult); } else { // The TextResultHandler is the fallthrough for unsupported formats. return new TextResultHandler(activity, result, rawResult); } }
public ParsedResultType getType() { return mType; }
private void updateCode(final String codeHash, final String codeContents, final BarcodeFormat barcodeFormat, final ParsedResultType barcodeType) { // delay so we let the UI queries load first new Handler().postDelayed(new Runnable() { @Override public void run() { CloudCallbackHandler<List<CloudEntity>> handler = new CloudCallbackHandler<List<CloudEntity>>() { @Override public void onComplete(List<CloudEntity> results) { if (results.size() <= 0) { // no record for this code exists - create a CloudEntity with the new code CloudEntity newCode = new CloudEntity(QRCloudUtils.DATABASE_KIND_CODES); newCode.put(QRCloudUtils.DATABASE_PROP_HASH, codeHash); newCode.put(QRCloudUtils.DATABASE_PROP_CONTENTS, codeContents); newCode.put(QRCloudUtils.DATABASE_PROP_FORMAT, barcodeFormat.name()); newCode.put(QRCloudUtils.DATABASE_PROP_TYPE, barcodeType.name()); newCode.put(QRCloudUtils.DATABASE_PROP_SCANS, 1); // this is the initial scan newCode.put(QRCloudUtils.DATABASE_PROP_SOURCE, ContentProviderAuthority.DB_SOURCE); // execute the insertion; nothing we can do on error, so ignore the result getCloudBackend().insert(newCode, null); } else { CloudEntity existingEntity = results.get(0); if (existingEntity != null) { Object currentScanCount = existingEntity.get(QRCloudUtils.DATABASE_PROP_SCANS); if (currentScanCount != null) { // update to increase the scan count; nothing to do on error, so no result handler existingEntity.put(QRCloudUtils.DATABASE_PROP_SCANS, Integer.valueOf(currentScanCount.toString()) + 1); getCloudBackend().update(existingEntity, null); } } } } @Override public void onError(IOException exception) { // nothing else we can do } }; // now search for an existing record of this code CloudQuery cloudQuery = new CloudQuery(QRCloudUtils.DATABASE_KIND_CODES); cloudQuery.setFilter(F.eq(QRCloudUtils.DATABASE_PROP_HASH, codeHash)); cloudQuery.setLimit(1); cloudQuery.setScope(Scope.PAST); getCloudBackend().list(cloudQuery, handler); } }, NON_URGENT_QUERY_DELAY); }
NDEFSmartPosterParsedResult(int action, String uri, String title) { super(ParsedResultType.NDEF_SMART_POSTER); this.action = action; this.uri = uri; this.title = title; }
/** * A convenience method to get the parsed type. Should not be overridden. * * @return The parsed type, e.g. URI or ISBN */ public final ParsedResultType getType() { return result.getType(); }