public static Bitmap getQRCodeBitmap(String address, Activity activity) { final DisplayMetrics displaymetrics = new DisplayMetrics(); activity.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics); final int width = displaymetrics.widthPixels; final Intent intent = new Intent(Intents.Encode.ACTION); intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT); intent.putExtra(Intents.Encode.DATA, address); intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString()); try { Log.i("", "Initializing QR: " + width); final QRCodeEncoder encoder = new QRCodeEncoder(activity, intent, width, false); return encoder.encodeAsBitmap(); } catch (Exception e) { } return null; }
private Bitmap generateQRCode(String uri) { final float REG_RES = 2.0f; Resources resources = getResources(); float scale = resources.getDisplayMetrics().density; Bitmap bitmap = null; int qrCodeDimension = (scale <= REG_RES) ? 440 : 880; QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(uri, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimension); try { bitmap = qrCodeEncoder.encodeAsBitmap(); } catch (WriterException e) { e.printStackTrace(); } return bitmap; }
final void addContact(String[] names, String[] phoneNumbers, String[] emails, String note, String address, String org, String title) { // Only use the first name in the array, if present. Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT, Contacts.CONTENT_URI); intent.setType(Contacts.People.CONTENT_ITEM_TYPE); putExtra(intent, Contacts.Intents.Insert.NAME, names != null ? names[0] : null); int phoneCount = Math.min(phoneNumbers != null ? phoneNumbers.length : 0, Contents.PHONE_KEYS.length); for (int x = 0; x < phoneCount; x++) { putExtra(intent, Contents.PHONE_KEYS[x], phoneNumbers[x]); } int emailCount = Math.min(emails != null ? emails.length : 0, Contents.EMAIL_KEYS.length); for (int x = 0; x < emailCount; x++) { putExtra(intent, Contents.EMAIL_KEYS[x], emails[x]); } putExtra(intent, Contacts.Intents.Insert.NOTES, note); putExtra(intent, Contacts.Intents.Insert.POSTAL, address); putExtra(intent, Contacts.Intents.Insert.COMPANY, org); putExtra(intent, Contacts.Intents.Insert.JOB_TITLE, title); launchIntent(intent); }
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.encode, menu); boolean useVcard = qrCodeEncoder != null && qrCodeEncoder.isUseVCard(); int encodeNameResource = useVcard ? R.string.menu_encode_mecard : R.string.menu_encode_vcard; MenuItem encodeItem = menu.findItem(R.id.menu_encode); encodeItem.setTitle(encodeNameResource); Intent intent = getIntent(); if (intent != null) { String type = intent.getStringExtra(Intents.Encode.TYPE); encodeItem.setVisible(Contents.Type.CONTACT.equals(type)); } return super.onCreateOptionsMenu(menu); }
private void launchSearch(String text) { Intent intent = new Intent(Intents.Encode.ACTION); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT); intent.putExtra(Intents.Encode.DATA, text); intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString()); startActivity(intent); }
private void showTextAsBarcode(String text) { Log.i(TAG, "Showing text as barcode: " + text); if (text == null) { return; // Show error? } Intent intent = new Intent(Intents.Encode.ACTION); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); intent.putExtra(Intents.Encode.TYPE, Contents.Type.TEXT); intent.putExtra(Intents.Encode.DATA, text); intent.putExtra(Intents.Encode.FORMAT, BarcodeFormat.QR_CODE.toString()); startActivity(intent); }
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(fakeR.getId("menu", "encode"), menu); boolean useVcard = qrCodeEncoder != null && qrCodeEncoder.isUseVCard(); int encodeNameResource = useVcard ? fakeR.getId("string", "menu_encode_mecard") : fakeR.getId("string", "menu_encode_vcard"); MenuItem encodeItem = menu.findItem(fakeR.getId("id", "menu_encode")); encodeItem.setTitle(encodeNameResource); Intent intent = getIntent(); if (intent != null) { String type = intent.getStringExtra(Intents.Encode.TYPE); encodeItem.setVisible(Contents.Type.CONTACT.equals(type)); } return super.onCreateOptionsMenu(menu); }