com.google.zxing.client.android.Contents Java Examples

The following examples show how to use com.google.zxing.client.android.Contents. 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: ShareActivity.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #2
Source File: EncodeActivity.java    From zxingfragmentlib with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #3
Source File: ShareActivity.java    From zxingfragmentlib with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #4
Source File: ShareActivity.java    From zxingfragmentlib with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #5
Source File: ShareActivity.java    From android-apps with MIT License 5 votes vote down vote up
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);
}
 
Example #6
Source File: ShareActivity.java    From android-apps with MIT License 5 votes vote down vote up
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);
}
 
Example #7
Source File: EncodeActivity.java    From reacteu-app with MIT License 5 votes vote down vote up
@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);
}
 
Example #8
Source File: ShareActivity.java    From reacteu-app with MIT License 5 votes vote down vote up
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);
}
 
Example #9
Source File: ShareActivity.java    From reacteu-app with MIT License 5 votes vote down vote up
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);
}
 
Example #10
Source File: EncodeActivity.java    From barcodescanner-lib-aar with MIT License 5 votes vote down vote up
@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);
}
 
Example #11
Source File: EncodeActivity.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #12
Source File: ShareActivity.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #13
Source File: ShareActivity.java    From ZXing-Standalone-library with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #14
Source File: EncodeActivity.java    From weex with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #15
Source File: ShareActivity.java    From weex with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #16
Source File: ShareActivity.java    From weex with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #17
Source File: EncodeActivity.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #18
Source File: ShareActivity.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #19
Source File: ShareActivity.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #20
Source File: EncodeActivity.java    From ZXing-Orient with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #21
Source File: EncodeActivity.java    From ZXing-Standalone-library with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #22
Source File: ShareActivity.java    From ZXing-Standalone-library with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #23
Source File: QRCodeEncoder.java    From weex with Apache License 2.0 4 votes vote down vote up
private void encodeQRCodeContents(Intent intent, String type) {
  switch (type) {
    case Contents.Type.TEXT:
      String textData = intent.getStringExtra(Intents.Encode.DATA);
      if (textData != null && !textData.isEmpty()) {
        contents = textData;
        displayContents = textData;
        title = activity.getString(R.string.contents_text);
      }
      break;

    case Contents.Type.EMAIL:
      String emailData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
      if (emailData != null) {
        contents = "mailto:" + emailData;
        displayContents = emailData;
        title = activity.getString(R.string.contents_email);
      }
      break;

    case Contents.Type.PHONE:
      String phoneData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
      if (phoneData != null) {
        contents = "tel:" + phoneData;
        displayContents = PhoneNumberUtils.formatNumber(phoneData);
        title = activity.getString(R.string.contents_phone);
      }
      break;

    case Contents.Type.SMS:
      String smsData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
      if (smsData != null) {
        contents = "sms:" + smsData;
        displayContents = PhoneNumberUtils.formatNumber(smsData);
        title = activity.getString(R.string.contents_sms);
      }
      break;

    case Contents.Type.CONTACT:
      Bundle contactBundle = intent.getBundleExtra(Intents.Encode.DATA);
      if (contactBundle != null) {

        String name = contactBundle.getString(ContactsContract.Intents.Insert.NAME);
        String organization = contactBundle.getString(ContactsContract.Intents.Insert.COMPANY);
        String address = contactBundle.getString(ContactsContract.Intents.Insert.POSTAL);
        List<String> phones = getAllBundleValues(contactBundle, Contents.PHONE_KEYS);
        List<String> phoneTypes = getAllBundleValues(contactBundle, Contents.PHONE_TYPE_KEYS);
        List<String> emails = getAllBundleValues(contactBundle, Contents.EMAIL_KEYS);
        String url = contactBundle.getString(Contents.URL_KEY);
        List<String> urls = url == null ? null : Collections.singletonList(url);
        String note = contactBundle.getString(Contents.NOTE_KEY);

        ContactEncoder encoder = useVCard ? new VCardContactEncoder() : new MECARDContactEncoder();
        String[] encoded = encoder.encode(Collections.singletonList(name),
                                          organization,
                                          Collections.singletonList(address),
                                          phones,
                                          phoneTypes,
                                          emails,
                                          urls,
                                          note);
        // Make sure we've encoded at least one field.
        if (!encoded[1].isEmpty()) {
          contents = encoded[0];
          displayContents = encoded[1];
          title = activity.getString(R.string.contents_contact);
        }

      }
      break;

    case Contents.Type.LOCATION:
      Bundle locationBundle = intent.getBundleExtra(Intents.Encode.DATA);
      if (locationBundle != null) {
        // These must use Bundle.getFloat(), not getDouble(), it's part of the API.
        float latitude = locationBundle.getFloat("LAT", Float.MAX_VALUE);
        float longitude = locationBundle.getFloat("LONG", Float.MAX_VALUE);
        if (latitude != Float.MAX_VALUE && longitude != Float.MAX_VALUE) {
          contents = "geo:" + latitude + ',' + longitude;
          displayContents = latitude + "," + longitude;
          title = activity.getString(R.string.contents_location);
        }
      }
      break;
  }
}
 
Example #24
Source File: QRCodeEncoder.java    From Study_Android_Demo with Apache License 2.0 4 votes vote down vote up
private void encodeQRCodeContents(Intent intent, String type) {
  switch (type) {
    case Contents.Type.TEXT:
      String textData = intent.getStringExtra(Intents.Encode.DATA);
      if (textData != null && !textData.isEmpty()) {
        contents = textData;
        displayContents = textData;
        title = activity.getString(R.string.contents_text);
      }
      break;

    case Contents.Type.EMAIL:
      String emailData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
      if (emailData != null) {
        contents = "mailto:" + emailData;
        displayContents = emailData;
        title = activity.getString(R.string.contents_email);
      }
      break;

    case Contents.Type.PHONE:
      String phoneData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
      if (phoneData != null) {
        contents = "tel:" + phoneData;
        displayContents = PhoneNumberUtils.formatNumber(phoneData);
        title = activity.getString(R.string.contents_phone);
      }
      break;

    case Contents.Type.SMS:
      String smsData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
      if (smsData != null) {
        contents = "sms:" + smsData;
        displayContents = PhoneNumberUtils.formatNumber(smsData);
        title = activity.getString(R.string.contents_sms);
      }
      break;

    case Contents.Type.CONTACT:
      Bundle contactBundle = intent.getBundleExtra(Intents.Encode.DATA);
      if (contactBundle != null) {

        String name = contactBundle.getString(ContactsContract.Intents.Insert.NAME);
        String organization = contactBundle.getString(ContactsContract.Intents.Insert.COMPANY);
        String address = contactBundle.getString(ContactsContract.Intents.Insert.POSTAL);
        List<String> phones = getAllBundleValues(contactBundle, Contents.PHONE_KEYS);
        List<String> phoneTypes = getAllBundleValues(contactBundle, Contents.PHONE_TYPE_KEYS);
        List<String> emails = getAllBundleValues(contactBundle, Contents.EMAIL_KEYS);
        String url = contactBundle.getString(Contents.URL_KEY);
        List<String> urls = url == null ? null : Collections.singletonList(url);
        String note = contactBundle.getString(Contents.NOTE_KEY);

        ContactEncoder encoder = useVCard ? new VCardContactEncoder() : new MECARDContactEncoder();
        String[] encoded = encoder.encode(Collections.singletonList(name),
                                          organization,
                                          Collections.singletonList(address),
                                          phones,
                                          phoneTypes,
                                          emails,
                                          urls,
                                          note);
        // Make sure we've encoded at least one field.
        if (!encoded[1].isEmpty()) {
          contents = encoded[0];
          displayContents = encoded[1];
          title = activity.getString(R.string.contents_contact);
        }

      }
      break;

    case Contents.Type.LOCATION:
      Bundle locationBundle = intent.getBundleExtra(Intents.Encode.DATA);
      if (locationBundle != null) {
        // These must use Bundle.getFloat(), not getDouble(), it's part of the API.
        float latitude = locationBundle.getFloat("LAT", Float.MAX_VALUE);
        float longitude = locationBundle.getFloat("LONG", Float.MAX_VALUE);
        if (latitude != Float.MAX_VALUE && longitude != Float.MAX_VALUE) {
          contents = "geo:" + latitude + ',' + longitude;
          displayContents = latitude + "," + longitude;
          title = activity.getString(R.string.contents_location);
        }
      }
      break;
  }
}
 
Example #25
Source File: QRCodeEncoder.java    From barcodescanner-lib-aar with MIT License 4 votes vote down vote up
private void encodeQRCodeContents(Intent intent, String type) {
  switch (type) {
    case Contents.Type.TEXT:
      String textData = intent.getStringExtra(Intents.Encode.DATA);
      if (textData != null && !textData.isEmpty()) {
        contents = textData;
        displayContents = textData;
        title = activity.getString(R.string.contents_text);
      }
      break;

    case Contents.Type.EMAIL:
      String emailData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
      if (emailData != null) {
        contents = "mailto:" + emailData;
        displayContents = emailData;
        title = activity.getString(R.string.contents_email);
      }
      break;

    case Contents.Type.PHONE:
      String phoneData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
      if (phoneData != null) {
        contents = "tel:" + phoneData;
        displayContents = PhoneNumberUtils.formatNumber(phoneData);
        title = activity.getString(R.string.contents_phone);
      }
      break;

    case Contents.Type.SMS:
      String smsData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
      if (smsData != null) {
        contents = "sms:" + smsData;
        displayContents = PhoneNumberUtils.formatNumber(smsData);
        title = activity.getString(R.string.contents_sms);
      }
      break;

    case Contents.Type.CONTACT:
      Bundle contactBundle = intent.getBundleExtra(Intents.Encode.DATA);
      if (contactBundle != null) {

        String name = contactBundle.getString(ContactsContract.Intents.Insert.NAME);
        String organization = contactBundle.getString(ContactsContract.Intents.Insert.COMPANY);
        String address = contactBundle.getString(ContactsContract.Intents.Insert.POSTAL);
        List<String> phones = getAllBundleValues(contactBundle, Contents.PHONE_KEYS);
        List<String> phoneTypes = getAllBundleValues(contactBundle, Contents.PHONE_TYPE_KEYS);
        List<String> emails = getAllBundleValues(contactBundle, Contents.EMAIL_KEYS);
        String url = contactBundle.getString(Contents.URL_KEY);
        List<String> urls = url == null ? null : Collections.singletonList(url);
        String note = contactBundle.getString(Contents.NOTE_KEY);

        ContactEncoder encoder = useVCard ? new VCardContactEncoder() : new MECARDContactEncoder();
        String[] encoded = encoder.encode(Collections.singletonList(name),
                                          organization,
                                          Collections.singletonList(address),
                                          phones,
                                          phoneTypes,
                                          emails,
                                          urls,
                                          note);
        // Make sure we've encoded at least one field.
        if (!encoded[1].isEmpty()) {
          contents = encoded[0];
          displayContents = encoded[1];
          title = activity.getString(R.string.contents_contact);
        }

      }
      break;

    case Contents.Type.LOCATION:
      Bundle locationBundle = intent.getBundleExtra(Intents.Encode.DATA);
      if (locationBundle != null) {
        // These must use Bundle.getFloat(), not getDouble(), it's part of the API.
        float latitude = locationBundle.getFloat("LAT", Float.MAX_VALUE);
        float longitude = locationBundle.getFloat("LONG", Float.MAX_VALUE);
        if (latitude != Float.MAX_VALUE && longitude != Float.MAX_VALUE) {
          contents = "geo:" + latitude + ',' + longitude;
          displayContents = latitude + "," + longitude;
          title = activity.getString(R.string.contents_location);
        }
      }
      break;
  }
}
 
Example #26
Source File: QRCodeEncoder.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 4 votes vote down vote up
private void encodeQRCodeContents(Intent intent, String type) {
  switch (type) {
    case Contents.Type.TEXT:
      String textData = intent.getStringExtra(Intents.Encode.DATA);
      if (textData != null && !textData.isEmpty()) {
        contents = textData;
        displayContents = textData;
        title = activity.getString(R.string.contents_text);
      }
      break;

    case Contents.Type.EMAIL:
      String emailData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
      if (emailData != null) {
        contents = "mailto:" + emailData;
        displayContents = emailData;
        title = activity.getString(R.string.contents_email);
      }
      break;

    case Contents.Type.PHONE:
      String phoneData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
      if (phoneData != null) {
        contents = "tel:" + phoneData;
        displayContents = PhoneNumberUtils.formatNumber(phoneData);
        title = activity.getString(R.string.contents_phone);
      }
      break;

    case Contents.Type.SMS:
      String smsData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
      if (smsData != null) {
        contents = "sms:" + smsData;
        displayContents = PhoneNumberUtils.formatNumber(smsData);
        title = activity.getString(R.string.contents_sms);
      }
      break;

    case Contents.Type.CONTACT:
      Bundle contactBundle = intent.getBundleExtra(Intents.Encode.DATA);
      if (contactBundle != null) {

        String name = contactBundle.getString(ContactsContract.Intents.Insert.NAME);
        String organization = contactBundle.getString(ContactsContract.Intents.Insert.COMPANY);
        String address = contactBundle.getString(ContactsContract.Intents.Insert.POSTAL);
        List<String> phones = getAllBundleValues(contactBundle, Contents.PHONE_KEYS);
        List<String> phoneTypes = getAllBundleValues(contactBundle, Contents.PHONE_TYPE_KEYS);
        List<String> emails = getAllBundleValues(contactBundle, Contents.EMAIL_KEYS);
        String url = contactBundle.getString(Contents.URL_KEY);
        List<String> urls = url == null ? null : Collections.singletonList(url);
        String note = contactBundle.getString(Contents.NOTE_KEY);

        ContactEncoder encoder = useVCard ? new VCardContactEncoder() : new MECARDContactEncoder();
        String[] encoded = encoder.encode(Collections.singletonList(name),
                                          organization,
                                          Collections.singletonList(address),
                                          phones,
                                          phoneTypes,
                                          emails,
                                          urls,
                                          note);
        // Make sure we've encoded at least one field.
        if (!encoded[1].isEmpty()) {
          contents = encoded[0];
          displayContents = encoded[1];
          title = activity.getString(R.string.contents_contact);
        }

      }
      break;

    case Contents.Type.LOCATION:
      Bundle locationBundle = intent.getBundleExtra(Intents.Encode.DATA);
      if (locationBundle != null) {
        // These must use Bundle.getFloat(), not getDouble(), it's part of the API.
        float latitude = locationBundle.getFloat("LAT", Float.MAX_VALUE);
        float longitude = locationBundle.getFloat("LONG", Float.MAX_VALUE);
        if (latitude != Float.MAX_VALUE && longitude != Float.MAX_VALUE) {
          contents = "geo:" + latitude + ',' + longitude;
          displayContents = latitude + "," + longitude;
          title = activity.getString(R.string.contents_location);
        }
      }
      break;
  }
}
 
Example #27
Source File: QRCodeEncoder.java    From ZXing-Standalone-library with Apache License 2.0 4 votes vote down vote up
private void encodeQRCodeContents(Intent intent, String type) {
  switch (type) {
    case Contents.Type.TEXT:
      String textData = intent.getStringExtra(Intents.Encode.DATA);
      if (textData != null && !textData.isEmpty()) {
        contents = textData;
        displayContents = textData;
        title = activity.getString(R.string.contents_text);
      }
      break;

    case Contents.Type.EMAIL:
      String emailData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
      if (emailData != null) {
        contents = "mailto:" + emailData;
        displayContents = emailData;
        title = activity.getString(R.string.contents_email);
      }
      break;

    case Contents.Type.PHONE:
      String phoneData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
      if (phoneData != null) {
        contents = "tel:" + phoneData;
        displayContents = PhoneNumberUtils.formatNumber(phoneData);
        title = activity.getString(R.string.contents_phone);
      }
      break;

    case Contents.Type.SMS:
      String smsData = ContactEncoder.trim(intent.getStringExtra(Intents.Encode.DATA));
      if (smsData != null) {
        contents = "sms:" + smsData;
        displayContents = PhoneNumberUtils.formatNumber(smsData);
        title = activity.getString(R.string.contents_sms);
      }
      break;

    case Contents.Type.CONTACT:
      Bundle contactBundle = intent.getBundleExtra(Intents.Encode.DATA);
      if (contactBundle != null) {

        String name = contactBundle.getString(ContactsContract.Intents.Insert.NAME);
        String organization = contactBundle.getString(ContactsContract.Intents.Insert.COMPANY);
        String address = contactBundle.getString(ContactsContract.Intents.Insert.POSTAL);
        List<String> phones = getAllBundleValues(contactBundle, Contents.PHONE_KEYS);
        List<String> phoneTypes = getAllBundleValues(contactBundle, Contents.PHONE_TYPE_KEYS);
        List<String> emails = getAllBundleValues(contactBundle, Contents.EMAIL_KEYS);
        String url = contactBundle.getString(Contents.URL_KEY);
        List<String> urls = url == null ? null : Collections.singletonList(url);
        String note = contactBundle.getString(Contents.NOTE_KEY);

        ContactEncoder encoder = useVCard ? new VCardContactEncoder() : new MECARDContactEncoder();
        String[] encoded = encoder.encode(Collections.singletonList(name),
                                          organization,
                                          Collections.singletonList(address),
                                          phones,
                                          phoneTypes,
                                          emails,
                                          urls,
                                          note);
        // Make sure we've encoded at least one field.
        if (!encoded[1].isEmpty()) {
          contents = encoded[0];
          displayContents = encoded[1];
          title = activity.getString(R.string.contents_contact);
        }

      }
      break;

    case Contents.Type.LOCATION:
      Bundle locationBundle = intent.getBundleExtra(Intents.Encode.DATA);
      if (locationBundle != null) {
        // These must use Bundle.getFloat(), not getDouble(), it's part of the API.
        float latitude = locationBundle.getFloat("LAT", Float.MAX_VALUE);
        float longitude = locationBundle.getFloat("LONG", Float.MAX_VALUE);
        if (latitude != Float.MAX_VALUE && longitude != Float.MAX_VALUE) {
          contents = "geo:" + latitude + ',' + longitude;
          displayContents = latitude + "," + longitude;
          title = activity.getString(R.string.contents_location);
        }
      }
      break;
  }
}