예제 #1
0
 public void showDialogCall(DataItem dataItem) {
   final String[] stringsCall = new String[dataItem.getListPhone().size()];
   for (int index = 0; index < dataItem.getListPhone().size(); index++) {
     stringsCall[index] = dataItem.getListPhone().get(index).getPhoneName();
   }
   AlertDialog.Builder builderCall = new AlertDialog.Builder(context);
   builderCall
       .setTitle("Call to:")
       .setItems(
           stringsCall,
           new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int which) {
               Intent smsIntent =
                   new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + stringsCall[which]));
               context.startActivity(smsIntent);
             }
           });
   builderCall.create().show();
 }
예제 #2
0
  public int addContact(DataItem dataItem) {
    if (dataItem.getContact_position() != -1) {
      deleteContact(dataItem.getContact_position());
    }
    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
    int rawContactInsertIndex = ops.size();
    ops.add(
        ContentProviderOperation.newInsert(ContactsContract.RawContacts.CONTENT_URI)
            .withValue(ContactsContract.RawContacts.ACCOUNT_TYPE, null)
            .withValue(ContactsContract.RawContacts.ACCOUNT_NAME, null)
            .build());

    // ------------------------------------------------------ Names
    if (dataItem.getNameCard() != null) {
      ops.add(
          ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
              .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
              .withValue(
                  ContactsContract.Data.MIMETYPE,
                  ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
              .withValue(
                  ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME,
                  dataItem.getNameCard())
              .build());
    }
    // ------------------------------------------------------ Photo
    if (dataItem.getImage() != null) {
      Bitmap bitmap = BitmapFactory.decodeFile(dataItem.getImage());
      if (bitmap != null) {
        bitmap = Bitmap.createScaledBitmap(bitmap, 1024, 768, true);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
        byte imageInByte[] = stream.toByteArray();
        ops.add(
            ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
                .withValue(
                    ContactsContract.Data.MIMETYPE,
                    ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE)
                .withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, imageInByte)
                .build());
      }
    }
    // ------------------------------------------------------ Company
    if (dataItem.getNameCompany() != null) {
      ops.add(
          ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
              .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
              .withValue(
                  ContactsContract.Data.MIMETYPE,
                  ContactsContract.CommonDataKinds.Organization.CONTENT_ITEM_TYPE)
              .withValue(
                  ContactsContract.CommonDataKinds.Organization.COMPANY, dataItem.getNameCompany())
              .build());
    }
    // ------------------------------------------------------ Phone
    for (int index = 0; index < dataItem.getListPhone().size(); index++) {
      PhoneItem phoneItem = dataItem.getListPhone().get(index);
      if (phoneItem.getType() == 0) {
        ops.add(
            ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
                .withValue(
                    ContactsContract.Data.MIMETYPE,
                    ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
                .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phoneItem.getPhoneName())
                .withValue(
                    ContactsContract.CommonDataKinds.Phone.TYPE,
                    ContactsContract.CommonDataKinds.Phone.TYPE_WORK)
                .build());
      } else if (phoneItem.getType() == 1) {
        ops.add(
            ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
                .withValue(
                    ContactsContract.Data.MIMETYPE,
                    ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
                .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phoneItem.getPhoneName())
                .withValue(
                    ContactsContract.CommonDataKinds.Phone.TYPE,
                    ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE)
                .build());
      } else {
        ops.add(
            ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
                .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
                .withValue(
                    ContactsContract.Data.MIMETYPE,
                    ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
                .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phoneItem.getPhoneName())
                .withValue(
                    ContactsContract.CommonDataKinds.Phone.TYPE,
                    ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK)
                .build());
      }
    }
    // ------------------------------------------------------ Email
    for (int index = 0; index < dataItem.getListEmail().size(); index++) {
      EmailItem emailItem = dataItem.getListEmail().get(index);
      ops.add(
          ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
              .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
              .withValue(
                  ContactsContract.Data.MIMETYPE,
                  ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
              .withValue(ContactsContract.CommonDataKinds.Email.DATA, emailItem.getEmailName())
              .withValue(
                  ContactsContract.CommonDataKinds.Email.TYPE,
                  ContactsContract.CommonDataKinds.Email.TYPE_WORK)
              .build());
    }
    // ------------------------------------------------------ Web
    for (int index = 0; index < dataItem.getListWeb().size(); index++) {
      WebItem webItem = dataItem.getListWeb().get(index);
      ops.add(
          ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
              .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
              .withValue(
                  ContactsContract.Data.MIMETYPE,
                  ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE)
              .withValue(ContactsContract.CommonDataKinds.Website.DATA, webItem.getWebName())
              .withValue(
                  ContactsContract.CommonDataKinds.Website.TYPE,
                  ContactsContract.CommonDataKinds.Website.TYPE_WORK)
              .build());
    }

    // ------------------------------------------------------ Address
    for (int index = 0; index < dataItem.getListAddress().size(); index++) {
      AddressItem addressItem = dataItem.getListAddress().get(index);
      ops.add(
          ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
              .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, rawContactInsertIndex)
              .withValue(
                  ContactsContract.Data.MIMETYPE,
                  ContactsContract.CommonDataKinds.StructuredPostal.CONTENT_ITEM_TYPE)
              .withValue(
                  ContactsContract.CommonDataKinds.StructuredPostal.STREET,
                  addressItem.getAddressName())
              .withValue(
                  ContactsContract.CommonDataKinds.StructuredPostal.TYPE,
                  ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME)
              .build());
    }
    // Asking the Contact provider to create a new contact
    try {
      context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
      int contactId = getContactId();
      return contactId;
    } catch (Exception e) {
      // e.printStackTrace();
      // Toast.makeText(context, "Exception: " + e.getMessage(),
      // Toast.LENGTH_SHORT).show();
      return -1;
    }
  }
예제 #3
0
 public void showDialogSms(ArrayList<DataItem> listData) {
   final ArrayList<StringItem> listString = new ArrayList<StringItem>();
   for (int index = 0; index < listData.size(); index++) {
     DataItem dataItem = listData.get(index);
     if (null == dataItem.getNameCard()) {
       StringItem stringItem = new StringItem("Unknows");
       listString.add(stringItem);
     } else {
       StringItem stringItem = new StringItem(dataItem.getNameCard());
       listString.add(stringItem);
     }
     for (int index2 = 0; index2 < dataItem.getListPhone().size(); index2++) {
       StringItem stringItem = new StringItem(dataItem.getListPhone().get(index2).getPhoneName());
       stringItem.setType(1);
       listString.add(stringItem);
     }
   }
   AlertDialog.Builder builder = new AlertDialog.Builder(context);
   // Get the layout inflater
   LayoutInflater inflater = ((Activity) context).getLayoutInflater();
   View view = inflater.inflate(R.layout.dialogfeatures_custom, null);
   CustomArrayAdapter adapter = new CustomArrayAdapter(context, listString);
   ListView listView = (ListView) view.findViewById(R.id.listViewFeatures);
   listView.setAdapter(adapter);
   builder
       .setTitle("Send sms")
       .setView(view)
       // Add action buttons
       .setPositiveButton(
           "OK",
           new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface dialog, int id) {
               StringBuilder smsBuider = new StringBuilder();
               smsBuider.append("smsto:");
               for (int index3 = 0; index3 < listString.size(); index3++) {
                 StringItem item = listString.get(index3);
                 if (item.getType() == 1 && item.iCheck == 1) {
                   smsBuider.append(item.getTitle() + ";");
                 }
               }
               if (smsBuider.length() > 6) {
                 smsBuider.deleteCharAt(smsBuider.length() - 1);
                 Intent smsIntent =
                     new Intent(Intent.ACTION_SENDTO, Uri.parse(smsBuider.toString()));
                 context.startActivity(smsIntent);
               }
             }
           })
       .setNegativeButton(
           "CANCEL",
           new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int id) {}
           });
   AlertDialog alert = builder.create();
   alert.show();
   Button nbutton = alert.getButton(DialogInterface.BUTTON_NEGATIVE);
   nbutton.setTextColor(Color.rgb(59, 185, 255));
   Button pbutton = alert.getButton(DialogInterface.BUTTON_POSITIVE);
   pbutton.setTextColor(Color.rgb(59, 185, 255));
 }