MTK平台下,相同联系人不能进行保存

diff --git a/src/com/android/contacts/editor/CompactContactEditorFragment.java b/src/com/android/contacts/editor/CompactContactEditorFragment.java
index e0507a0..c01e396 100644
--- a/src/com/android/contacts/editor/CompactContactEditorFragment.java
+++ b/src/com/android/contacts/editor/CompactContactEditorFragment.java
@@ -34,18 +34,24 @@ import com.mediatek.contacts.util.Log;
 import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
+import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.net.Uri;
 import android.os.Bundle;
 import android.os.Handler;
+import android.provider.ContactsContract;
+import android.text.TextUtils;
 import android.view.inputmethod.InputMethodManager;
 import android.view.LayoutInflater;
 import android.view.MenuItem;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.LinearLayout;
+import android.widget.Toast;
 
 import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.regex.Pattern;
 
 /**
  * Contact editor with only the most important fields displayed initially.
@@ -56,7 +62,6 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
 
     private static final String KEY_PHOTO_URI = "photo_uri";
     private static final String KEY_PHOTO_RAW_CONTACT_ID = "photo_raw_contact_id";
-
     /// M: save Fragment MainView and a Handler
     private View mMainView;
     private Handler mHandler ;
@@ -156,6 +161,10 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
     private Uri mPhotoUri;
     private long mPhotoRawContactId;
 
+    private String phonenumber;
+
+    private String phonename;
+
     @Override
     public void onCreate(Bundle savedState) {
         super.onCreate(savedState);
@@ -375,6 +384,47 @@ public class CompactContactEditorFragment extends ContactEditorBaseFragment impl
     protected boolean doSaveAction(int saveMode, boolean backPressed) {
         Log.d(TAG, "[doSaveAction] start ContactSaveService,saveMode = " + saveMode
                 + ",backPressed = " + backPressed);
+        Cursor cursor = this.getContext().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
+                null, null, null, null);
+            int contactIdIndex = 0;
+            int nameIndex = 0;
+            if(cursor.getCount() > 0) {
+                contactIdIndex = cursor.getColumnIndex(ContactsContract.Contacts._ID);
+                nameIndex = cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME);
+                }
+            while(cursor.moveToNext()) {
+                String contactId = cursor.getString(contactIdIndex);
+                phonename = cursor.getString(nameIndex);
+                Cursor phones = this.getContext().getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
+                        null,
+                        ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "=" + contactId,
+                        null, null);
+                int phoneIndex = 0;
+                if(phones.getCount() > 0) {
+                    phoneIndex = phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
+                    }
+                while(phones.moveToNext()) {
+                    phonenumber = phones.getString(phoneIndex).replaceAll("[^0-9]","");
+                    }
+                }
+            
+            for (int n = 0; n < mState.size(); n++) {
+                 RawContactDelta field = mState.get(n);
+                 ArrayList<ValuesDelta> dataname = field.getMimeEntries("vnd.android.cursor.item/name");
+                 ArrayList<ValuesDelta> datanumber = field.getMimeEntries("vnd.android.cursor.item/phone_v2");
+                if(dataname != null || datanumber !=null){
+                       for (int m = 0; m < dataname.size(); m++) {
+                          String name = dataname.get(m).getAsString("data1");
+                          String number = datanumber.get(m).getAsString("data1");
+                          String numberphone = number.replaceAll("[^0-9]","");
+                          if(name.equals(phonename) && numberphone.equals(phonenumber)){
+                              Toast.makeText(mContext, R.string.contacts_exist, Toast.LENGTH_SHORT).show();
+                              getActivity().finish();
+                              return false;
+                              }
+                          }
+                       }
+                }
         // Save contact. No need to pass the palette since we are finished editing after the save.
         final Intent intent = ContactSaveService.createSaveContactIntent(mContext, mState,
                 SAVE_MODE_EXTRA_KEY, saveMode, isEditingUserProfile(),
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值