/** * This will take the information returned from the barcode scan, check if it is one of the * exhibits, and if it is will navigate to that page. * * @param context The application's environment. * @param contents A string containing the barcode scan information. */ static void processBarcodeContents(WireActivity context, String contents) { String potentialKey = null; String prefix = context.loadString(R.string.qr_prefix); if (contents.length() > prefix.length() && contents.substring(0, prefix.length()).equals(prefix)) { potentialKey = contents.substring(prefix.length()).replaceAll("_", " "); } if (potentialKey != null) { ExhibitList exhibitList = ContentManager.getExhibitList(); if (true == exhibitList.containsKey(potentialKey)) { ExhibitActivity.start(context, potentialKey); } } else { Toast.makeText( context.getApplicationContext(), context.loadString(R.string.qr_unknown), Toast.LENGTH_SHORT) .show(); Log.w(Common.class.getName(), "Unrecognized QR code " + contents); } } /* CommonUnitTest */
/** * Checks if you have an application to scan a QR code and launch it if you have one. * * @param context The activity to serve as the parent of the new activity */ public static void startScan(WireActivity context) { boolean scanAvailable = Common.isIntentAvailable(context, context.loadString(R.string.intent_action_scan)); boolean scan2Available = Common.isIntentAvailable(context, context.loadString(R.string.intent_action_scan_2)); if (scanAvailable) { Intent intent = new Intent(context.loadString(R.string.intent_action_scan)); intent.putExtra( context.loadString(R.string.intent_extra_scan_mode), context.loadString(R.string.intent_qr_mode)); context.startActivityForResult(intent, context.loadInt(R.integer.CODE_SCAN_ACTIVITY_REQUEST)); } else if (scan2Available) { Intent intent = new Intent(context.loadString(R.string.intent_action_scan_2)); context.startActivityForResult( intent, context.loadInt(R.integer.CODE_SCAN_2_ACTIVITY_REQUEST)); } else { context.showDialog(WireActivity.SCAN_DIALOG); } } /* CommonUnitTest */