Preset contacts for android GB2/GB3 versions that cannot be edited or deleted

Source: Internet
Author: User

Preset contacts for android GB2/GB3 versions that cannot be edited or deleted
1. For versions such as GB2 and GB3, you can select Part one as the preset contact.
For example, the definition added at the beginning of the AbstractStartSIMService class is as follows:
Public static final int INSERT_NUMBER_COUNT = 4; // defines the number of contacts to be preset
Public static final String defaultNumbers [] = {"xxxx", "xxxx"}; // defines the number of the contact to be preset
Public static final String defaultNames [] = {"xxxxx", "xxxxx"}; // defines the name of the contact to be preset

2. Do not delete or edit these contacts after they are preset.
1. Modify the ContactsListActivity. java file as follows:
(1) In onCreateContextMenu () method
If (addEditAndDelete & simHasImported ){
Menu. add (0, MENU_ITEM_EDIT, 0, R. string. menu_editContact );
Menu. add (0, MENU_ITEM_DELETE, 0, R. string. menu_deleteContact );
}
The following sections are added before this section. The edit and delete options are invisible:
For (int I = 0; I <AbstractStartSIMService. INSERT_NUMBER_COUNT; I ++ ){
If (header. equals (AbstractStartSIMService. defaultNames [I]) {
AddEditAndDelete = false;
}
}

(2) In the onListItemClick () method
If (isHeader & id = 0) | (null! = PhoneOwner. getInstance () & id = PhoneOwner. getInstance (). getOwnerID ())){
......................
} Else {
If (mSearchMode & mAdapter. isSearchAllContactsItemPosition (position )){
DoSearch ();
} Else if (mMode = MODE_INSERT_OR_EDIT_CONTACT | mMode = MODE_QUERY_PICK_TO_EDIT ){
................
} Else if (mMode & MODE_MASK_CREATE_NEW) = MODE_MASK_CREATE_NEW & position = 0 ){
................
} Else if (mMode = MODE_JOIN_CONTACT & id = JOIN_MODE_SHOW_ALL_CONTACTS_ID ){
................
} Else if (id> 0 ){
................
If (mMode = MODE_DEFAULT & mDeleteState ){
Try {
...............
CheckBox cb = rootLayout. getCheckBox ();
ContactId = cursor. getInt (cursor. getColumnIndexOrThrow (Contacts. ID ));

// (2) modify the start point at the first step
String displayName = cursor. getString (SUMMARY_DISPLAY_NAME_PRIMARY_COLUMN_INDEX );
Boolean isdefacontact contact = false;
Log. d (TAG, "mtk ---- displayName:" + displayName );
If (! TextUtils. isEmpty (displayName )){
For (int I = 0; I <AbstractStartSIMService. INSERT_NUMBER_COUNT; I ++ ){
If (header. equals (AbstractStartSIMService. defaultNames [I]) {
IsDefaultContact = true;
Break;
}
}
}
// (2) End of step 1 Modification
...................
If (cbPrevState ){
Cb. setChecked (false );

// (2) modify the start point in step 2
If (isdefacontact contact ){
Cb. setVisibility (View. INVISIBLE );
}
// (2) End of the second modification
...............
} Else {
// (2) modify the start point in step 3
// Cb. setChecked (true );
// Indicate = cursor. getInt (cursor. getColumnIndexOrThrow (RawContacts. INDICATE_PHONE_SIM ));
// MToBeDeletedContacts. put (contactId, indicate );
// Index in SIM
// Long indexInSim = cursor. getLong (cursor. getColumnIndexOrThrow (Contacts. INDEX_IN_SIM ));
// MToBeDeletedContactsIndexInSim. put (contactId, indexInSim );
If (! IsDefaultContact ){
Cb. setChecked (true );
Cb. setVisibility (View. VISIBLE );
Indicate = cursor. getInt (cursor. getColumnIndexOrThrow (RawContacts. INDICATE_PHONE_SIM ));
MToBeDeletedContacts. put (contactId, indicate );
// Index in SIM
Long indexInSim = cursor. getLong (cursor. getColumnIndexOrThrow (Contacts. INDEX_IN_SIM ));
MToBeDeletedContactsIndexInSim. put (contactId, indexInSim );
} Else {
Cb. setChecked (false );
Cb. setVisibility (View. INVISIBLE );
}
// (2) End of the third step
........................
If (mSelected = mAllContacts. size ()){
MSelectAllToDel = true;

// (2) modify the start point in Step 4
// MSelectAllBox. setChecked (mSelectAllToDel );
If (! IsDefaultContact ){
MSelectAllBox. setChecked (mSelectAllToDel );
} Else {
MSelectAllBox. setChecked (false );
MSelectAllBox. setVisibility (View. INVISIBLE );
}
// (2) End of Step 4 Modification
MSelectAllButton. setText (mUnSelectText );
}
} // End else
.........................
} // End try
..................
}
...........
}
............
}
........................

(3) In onQueryComplete () method
// Mtk80909 start
If (activity. mDeleteState /*&&! Activity. mAllOrNone */){
................
If (tmpCursor. moveToFirst ()){
Do {
..................
Long indexInSim = tmpCursor. getInt (tmpCursor. getColumnIndexOrThrow (Contacts. INDEX_IN_SIM ));
// (3) Start of step Modification
// MAllContacts. put (currentID, indicate );
// MAllContactsIndexInSim. put (currentID, indexInSim); // index
// In
// Sim
String displayName = tmpCursor. getString (SUMMARY_DISPLAY_NAME_PRIMARY_COLUMN_INDEX );
Boolean isdefacontact contact = false;
Log. d (TAG, "mtk ---- displayName:" + displayName );
If (! TextUtils. isEmpty (displayName )){
For (int I = 0; I <AbstractStartSIMService. INSERT_NUMBER_COUNT; I ++ ){
If (displayName. equals (AbstractStartSIMService. defaultNames [I]) {
IsDefaultContact = true;
}
}
}
If (! IsDefaultContact ){
MAllContacts. put (currentID, indicate );
MAllContactsIndexInSim. put (currentID, indexInSim); // index in sim
}
// (3) End of step Modification
} While (tmpCursor. moveToNext ());
................
}
}

(4) bindView () method
If (mMode = MODE_DEFAULT & mDeleteState) {// [mtk80909]
Long currentID = cursor. getLong (SUMMARY_ID_COLUMN_INDEX );
// (4) Start of step 1 Modification
String displayName = cursor. getString (SUMMARY_DISPLAY_NAME_PRIMARY_COLUMN_INDEX );
Log. d (TAG, "displayName:" + displayName );
// (4) End of step 1 Modification

CheckBox cb = view. getCheckBox ();
If (cb! = Null ){
Cb. setVisibility (View. VISIBLE );
// (4) Start of step 2 Modification
For (int I = 0; I <AbstractStartSIMService. INSERT_NUMBER_COUNT; I ++ ){
If (displayName. equals (AbstractStartSIMService. defaultNames [I]) {
Cb. setVisibility (View. INVISIBLE );
Break;
}
}
// (4) End of step 2 Modification
.................

}
}

2. Modify the ViewContactActivity. java file as follows:
(1) In the onCreateContextMenu () method, remove the delete options for these numbers.
Modify menu. add (0, MENU_ITEM_REMOVE_NUMBER, 0, R. string. menu_remove_number); statement:
Int count = 0;
For (int I = 0; I <AbstractStartSIMService. INSERT_NUMBER_COUNT; I ++ ){
If (entry. data. equals (AbstractStartSIMService. defaultNumbers [I]) {
Count ++;
}
}
If (count = 0 ){
Menu. add (0, MENU_ITEM_REMOVE_NUMBER, 0, R. string. menu_remove_number );
}

(2) In the onPrepareOptionsMenu () method, remove the edit and Delete contact options in icon_menu.
Menu. findItem (R. id. menu_edit). setVisible (addEditAndDelete );
Menu. findItem (R. id. menu_delete). setVisible (addEditAndDelete); Add the following statement before the statement:
If (hasRawContact ){
For (Entity contactEntity: mEntities ){
For (NamedContentValues subValue: contactEntity. getSubValues ()){
Final ContentValues entryValues = subValue. values;
Final String mimeType = entryValues. getAsString (Data. MIMETYPE );
Final String data = entryValues. getAsString (Data. DATA1 );
Int count = 0;
For (int I = 0; I <AbstractStartSIMService. INSERT_NUMBER_COUNT; I ++ ){
If (data. equals (AbstractStartSIMService. defaultNumbers [I]) | data. equals (AbstractStartSIMService. defaultNames [I]) {
Count ++;
}
}
If (count! = 0 ){
AddEditAndDelete = false;
}
}
}
}

3. Modify the EditContactActivity. java and EditSimContactActivity. java files to prevent users from inserting contacts with the same name and number as the preset number.
(1) modify the EditContactActivity. java File
A. At the beginning of the file, import the following package
Import android. provider. ContactsContract. CommonDataKinds. StructuredName;
Import com. android. contacts. AbstractStartSIMService;
Import android. widget. Toast;

B. Define two global variables at the beginning of the class.
Boolean sameNumberExist = false;
Boolean sameNameExist = false;

C. In the onBackPressed () method
Modify the doSaveAction (SAVE_MODE_DEFAULT); statement:
DoSaveWithCheckField ();
If (sameNumberExist | sameNameExist ){
Finish ();
}

D. In the doSaveWithCheckField () method
ArrayList List = null;
// Start of the first modification
ArrayList ListName = null;
// The End Of The first modification
If (mState! = Null & mState. size ()> 0 ){
.............
// The start of the second modification
ListName = mState. get (0). getMimeEntries (StructuredName. CONTENT_ITEM_TYPE );
// The end of the second modification
}
String num;
// Start of the third modification
/* If (list! = Null ){
For (ValuesDelta delta: list ){...............}
}*/
String name1 = null;
String name2 = null;
String name = null;
SameNumberExist = false;
SameNameExist = false;
If (list! = Null ){
For (ValuesDelta delta: list ){
Num = delta. getAsString (Data. DATA1 );
If ("". equals (num )){
SameNumberExist = false;
}
If (! TextUtils. isEmpty (num )){
For (int I = 0; I <AbstractStartSIMService. INSERT_NUMBER_COUNT; I ++ ){
If (num. equals (AbstractStartSIMService. defaultNumbers [I]) {
SameNumberExist = true;
Break;
}
}
If (! SameNumberExist ){
NumberList. add (num );
}
}
}
}

If (listName! = Null &&! SameNumberExist ){
For (ValuesDelta delta: listName ){
Name1 = delta. getAsString (Data. DATA2 );
Name2 = delta. getAsString (Data. DATA3 );
If (name2 = null & name1! = Null ){
Name = name1;
} Else if (name2! = Null & name1 = null ){
Name = name2;
} Else if (name2! = Null & name1! = Null ){
Name = name2 + "" + name1;
}
If ("". equals (name )){
SameNameExist = false;
}
If (! TextUtils. isEmpty (name )){
For (int I = 0; I <AbstractStartSIMService. INSERT_NUMBER_COUNT; I ++ ){
If (name. equals (AbstractStartSIMService. defaultNames [I]) {
SameNameExist = true;
Break;
}
}
If (! SameNumberExist ){
NumberList. add (num );
}
}
}
}
// End of the third Modification
Bundle. putCharSequenceArrayList (KEY_PHONE_NUMBER, numberList );
Boolean hasCheckDuplicatePlugin = .........................
// Start of the fourth Modification
/* If (! HasCheckDuplicatePlugin ){
DoSaveAction (SAVE_MODE_DEFAULT );
}*/
If (! HasCheckDuplicatePlugin &&! SameNumberExist &&! SameNameExist ){
DoSaveAction (SAVE_MODE_DEFAULT );
} Else {
Toast. makeText (this, "Can not save a number or name the same as the default contact! ", Toast. LENGTH_LONG). show ();
}
// End of the Fourth Modification

(2) modify the EditSimContactActivity. java File
A. Import the following package at the beginning of the file
Import com. android. contacts. AbstractStartSIMService;
Import android. widget. Toast;

B. Define two global variables at the beginning of the class.
Boolean hasSameNumber = false;
Boolean hasSameName = false;

C. Add the method hassamenameornumberasdefacontcontacts () to the file ()
Private void hassamenameornumberasdefacontcontacts (){
HasSameNumber = false;
HasSameName = false;
UpdateName = edit_contact_name.getText (). toString ();
Updatephone = edit_phone_numbers.getText (). toString ();
If ("". equals (updatephone )){
HasSameNumber = false;
}
If ("". equals (updateName )){
HasSameName = false;
}
If (! TextUtils. isEmpty (updatephone )){
For (int I = 0; I <AbstractStartSIMService. INSERT_NUMBER_COUNT; I ++ ){
If (updatephone. equals (AbstractStartSIMService. defaultNumbers [I]) {
HasSameNumber = true;
Break;
}
}
}
If (! TextUtils. isEmpty (updateName )){
For (int I = 0; I <AbstractStartSIMService. INSERT_NUMBER_COUNT; I ++ ){
If (updateName. equals (AbstractStartSIMService. defaultNames [I]) {
HasSameName = true;
Break;
}
}
}

}

D. In The onClick () method
Case R. id. btn_sim1_done :{
Btn1.setClickable (false );
// The starting point of the Modification
// DoSaveAction (mMode );
Hassamenameornumberasdefacontcontacts ();
If (! HasSameNumber &&! HasSameName ){
DoSaveAction (mMode );
} Else {
Btn1.setClickable (true );
Toast. makeText (this, "Can not save a number or name the same as the default contact! ", Toast. LENGTH_LONG). show ();
}
// End of the Modification
Break;
}

In e. onBackPressed () method
DoSaveAction (mMode); statement modified
Hassamenameornumberasdefacontcontacts ();
If (! HasSameNumber &&! HasSameName ){
DoSaveAction (mMode );
} Else {
Toast. makeText (this, "Can not save a number or name the same as the default contact! ", Toast. LENGTH_LONG). show ();
Finish ();
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.