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(),
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(),