添加移除常用联系功能,需要修改的另外一个应用程序是com.android.contacts。
在MTK6575平台上,需要修改的文件有:
modified
:
packages
/
apps
/
Contacts
/
src
/
com
/
android
/
contacts
/
activities
/
DialtactsActivity
.
java
modified
:
packages
/
apps
/
Contacts
/
src
/
com
/
android
/
contacts
/
activities
/
PeopleActivity
.
java
modified
:
packages
/
apps
/
Contacts
/
src
/
com
/
android
/
contacts
/
group
/
GroupDetailFragment
.
java
modified
:
packages
/
apps
/
Contacts
/
src
/
com
/
android
/
contacts
/
list
/
ContactTileAdapter
.
java
modified
:
packages
/
apps
/
Contacts
/
src
/
com
/
android
/
contacts
/
list
/
ContactTileListFragment
.
java
modified
:
packages
/
apps
/
Contacts
/
src
/
com
/
android
/
contacts
/
list
/
ContactTileView
.
java
modified
:
packages
/
apps
/
Contacts
/
src
/
com
/
android
/
contacts
/
list
/
PhoneFavoriteFragment
.
java
modified
:
packages
/
apps
/
Contacts
/
res
/
values
-
zh
-
rCN
/
strings
.
xml
modified
:
packages
/
apps
/
Contacts
/
res
/
values
-
zh
-
rTW
/
strings
.
xml
modified
:
packages
/
apps
/
Contacts
/
res
/
values
/
strings
.
xml
文件packages/apps/Contacts/src/com/android/contacts/activities/DialtactsActivity.java的主要修改如下:
@@
-
935
,
17
+
939
,
95
@@
public
class
DialtactsActivity
extends
TransactionSafeActivity
implements
Provid
enterSearchUi
();
}
};
-
+
/*robin_20120509*/
private
PhoneFavoriteFragment
.
Listener
mPhoneFavoriteListener
=
new
PhoneFavoriteFragment
.
Listener
()
{
@Override
-
public
void
onContactSelected
(
Uri
contactUri
)
{
+
public
void
onContactClick
(
Uri
contactUri
)
{
PhoneNumberInteraction
.
startInteractionForPhoneCall
(
DialtactsActivity
.
this
,
contactUri
,
CALL_ORIGIN_DIALTACTS
);
}
+
@Override
+
public
boolean
onContactLongClick
(
Uri
contactUri
,
int
type
)
{
+
if
(
type
==
ViewTypes
.
FREQUENT
)
+
{
+
final
Uri
contactLookUpUri
=
contactUri
;
+
Runnable
r
=
new
Runnable
(){
+
+
@Override
+
public
void
run
()
{
+
removeFrequentContact
(
contactLookUpUri
);
+
}};
+
showRemoveFrequentContactAlertDialog
(
r
);
+
return
true
;
+
}
+
return
false
;
+
}
};
+
Handler
handler
=
new
Handler
();
+
IContentProvider
mContentProvider
;
+
final
static
String
ContactsProvider_CALL_METHOD_UPDATE_FAKE_TIMES_USED
=
"CALL_METHOD_update_FAKE_TIMES_USED_Stat"
;
+
void
removeFrequentContact
(
Uri
contactUri
)
+
{
+
IContentProvider
cp
=
null
;
+
synchronized
(
this
)
{
+
cp
=
mContentProvider
;
+
if
(
cp
==
null
)
{
+
cp
=
mContentProvider
=
getContentResolver
().
acquireProvider
(
ContactsContract
.
AUTHORITY
);
+
}
+
}
+
try
{
+
Bundle
bundle
=
new
Bundle
();
+
bundle
.
putString
(
"Uri"
,
contactUri
.
toString
());
+
Bundle
b
=
cp
.
call
(
ContactsProvider_CALL_METHOD_UPDATE_FAKE_TIMES_USED
,
""
,
bundle
);
+
if
(
b
!=
null
)
{
+
int
v
=
b
.
getInt
(
"count"
,
0
);
+
if
(
v
>
0
)
+
{
+
Toast
.
makeText
(
this
,
R
.
string
.
remove_frequent_contact_succes
,
Toast
.
LENGTH_SHORT
).
show
();
+
return
;
+
}
+
}
+
Toast
.
makeText
(
this
,
R
.
string
.
remove_frequent_contact_fail
,
Toast
.
LENGTH_SHORT
).
show
();
+
// If the response Bundle is null, we fall through
+ // to the query interface below.
+ } catch (RemoteException e) {
+ Log.w(TAG, "", e);
+ // Not supported by the remote side? Fall through
+ // to query().
+ }
+ }
+
+AlertDialog removeFrequentContactAlertDialog;
+void showRemoveFrequentContactAlertDialog(final Runnable runnable)
+{
+ AlertDialog.Builder dialogBuilder=new AlertDialog.Builder(this);
+ dialogBuilder.setMessage(R.string.remove_frequent_contact_alert);
+ dialogBuilder.setCancelable(true);
+ DialogInterface.OnClickListener negativeListener=new DialogInterface.OnClickListener(){
+
+ @Override
+ public void onClick(DialogInterface arg0, int arg1) {
+
+ }};
+ DialogInterface.OnClickListener positiveListener=new DialogInterface.OnClickListener(){
+ @Override
+ public void onClick(DialogInterface arg0, int arg1) {
+ handler.post(runnable);
+
+ }
+ };
+ dialogBuilder.setNegativeButton(android.R.string.cancel, negativeListener);
+ dialogBuilder.setPositiveButton(android.R.string.ok, positiveListener);
+ removeFrequentContactAlertDialog=dialogBuilder.create();
+ removeFrequentContactAlertDialog.show();
+}
+/*robin_20120509*/
文件packages/apps/Contacts/src/com/android/contacts/activities/PeopleActivity.java的主要修改如下:
@@
-
1340
,
19
+
1345
,
97
@@
public
class
PeopleActivity
extends
ContactsActivity
startActivity
(
new
Intent
(
Settings
.
ACTION_MANAGE_APPLICATIONS_SETTINGS
));
}
}
-
+
/*[robin_20120509*/
private
final
class
StrequentContactListFragmentListener
implements
ContactTileListFragment
.
Listener
{
@Override
-
public
void
onContactSelected
(
Uri
contactUri
,
Rect
targetRect
)
{
+
public
void
onContactClick
(
Uri
contactUri
,
Rect
targetRect
)
{
if
(
PhoneCapabilityTester
.
isUsingTwoPanes
(
PeopleActivity
.
this
))
{
QuickContact
.
showQuickContact
(
PeopleActivity
.
this
,
targetRect
,
contactUri
,
0
,
null
);
}
else
{
startActivity
(
new
Intent
(
Intent
.
ACTION_VIEW
,
contactUri
));
}
}
+
@Override
+
public
boolean
onContactLongClick
(
Uri
contactUri
,
Rect
targetRect
,
int
type
)
{
+
if
(
type
==
ViewTypes
.
FREQUENT
)
+
{
+
final
Uri
contactLookUpUri
=
contactUri
;
+
Runnable
r
=
new
Runnable
(){
+
+
@Override
+
public
void
run
()
{
+
// TODO Auto-generated method stub
+ removeFrequentContact(contactLookUpUri);
+ }};
+ showRemoveFrequentContactAlertDialog(r);
+ return true;
+ }
+ return false;
+ }
+ }
+ Handler handler=new Handler();
+ IContentProvider mContentProvider;
+ final static String ContactsProvider_CALL_METHOD_UPDATE_FAKE_TIMES_USED="CALL_METHOD_update_FAKE_TIMES_USED_Stat";
+ void removeFrequentContact(Uri contactUri)
+ {
+ IContentProvider cp = null;
+ synchronized (this) {
+ cp = mContentProvider;
+ if (cp == null) {
+ cp = mContentProvider =getContentResolver().acquireProvider(ContactsContract.AUTHORITY);
+ }
+ }
+ try {
+ Bundle bundle=new Bundle();
+ bundle.putString("Uri", contactUri.toString());
+ Bundle b = cp.call(ContactsProvider_CALL_METHOD_UPDATE_FAKE_TIMES_USED, "ID_TYPE_CONTACT", bundle);
+ if (b != null) {
+ int v = b.getInt("count",0);
+ if(v>0)
+ {
+ Toast.makeText(this, R.string.remove_frequent_contact_succes, Toast.LENGTH_SHORT).show();
+ return;
+ }
+ }
+ Toast.makeText(this, R.string.remove_frequent_contact_fail, Toast.LENGTH_SHORT).show();
+ /* If the response Bundle is null, we fall through
+ to the query interface below.*/
+ } catch (RemoteException e) {
+ Log.w(TAG, "", e);
+ /** Not supported by the remote side? Fall through
+ to query().*/
+ }
}
+AlertDialog removeFrequentContactAlertDialog;
+void showRemoveFrequentContactAlertDialog(final Runnable runnable)
+{
+ AlertDialog.Builder dialogBuilder=new AlertDialog.Builder(this);
+ dialogBuilder.setMessage(R.string.remove_frequent_contact_alert);
+ dialogBuilder.setCancelable(true);
+ DialogInterface.OnClickListener negativeListener=new DialogInterface.OnClickListener(){
+
+ @Override
+ public void onClick(DialogInterface arg0, int arg1) {
+ /* TODO Auto-generated method stub*/
+
+ }};
+ DialogInterface.OnClickListener positiveListener=new DialogInterface.OnClickListener(){
+
+ @Override
+ public void onClick(DialogInterface arg0, int arg1) {
+ /* TODO Auto-generated method stub*/
+ handler.post(runnable);
+
+ }
+ };
+ dialogBuilder.setNegativeButton(android.R.string.cancel, negativeListener);
+ dialogBuilder.setPositiveButton(android.R.string.ok, positiveListener);
+ removeFrequentContactAlertDialog=dialogBuilder.create();
+ removeFrequentContactAlertDialog.show();
+}
+/*robin_20120509]*/
private final class GroupBrowserActionListener implements OnGroupBrowserActionListener {
packages/apps/Contacts/src/com/android/contacts/calllog/CallLogAdapter.java文件修改如下
@@
-
398
,
7
+
398
,
18
@@
implements
CallLogGroupBuilder
.
GroupCreator
,
OnScrollListener
{
if
(
OperatorUtils
.
getOptrProperties
().
equals
(
"OP02"
))
{
contactInfo
.
photoId
=
(
slotId
==
0
)
?
-
3
:
-
4
;
}
else
{
-
contactInfo
.
photoId
=
SimCardUtils
.
isSimUsimType
(
slotId
)
?
-
2
:
-
1
;
+
// contactInfo.photoId = SimCardUtils.isSimUsimType(slotId) ? -2 : -1;
+ if(SimCardUtils.isSimUsimType(slotId)){
+ if(slotId == 0)
+ contactInfo.photoId = -5;
+ else
+ contactInfo.photoId = -6;
+ }else{
+ if(slotId == 0)
+ contactInfo.photoId = -7;
+ else
+ contactInfo.photoId = -8;
+ }
}
}
文件packages/apps/Contacts/src/com/android/contacts/list/ContactTileAdapter.java的主要修改如下:
@@
-
276
,
12
+
277
,
20
@@
public
class
ContactTileAdapter
extends
BaseAdapter
{
}
else
{
boolean
isUsim
=
SimCardUtils
.
isSimUsimType
(
slotId
);
if
(
isUsim
)
{
-
Log
.
i
(
TAG
,
"-----------usim"
);
-
contact
.
photoUri
=
Uri
.
parse
(
"content://usim"
);
+
//Log.i(TAG, "-----------usim");
+ //contact.photoUri = Uri.parse("content://usim");
+ if(slotId == 0)
+ contact.photoUri = Uri.parse("content://usim1");
+ else
+ contact.photoUri = Uri.parse("content://usim2");
} else {
- Log.i(TAG, "-----------sim");
- contact.photoUri = Uri.parse("content://sim");
- }
+ //Log.i(TAG, "-----------sim");
+ //contact.photoUri = Uri.parse("content://sim");
+ if(slotId == 0)
+ contact.photoUri = Uri.parse("content://sim1");
+ else
+ contact.photoUri = Uri.parse("content://sim2");
+ }
}
/*
* New feature by Mediatek End
@@ -524,10 +533,28 @@ public class ContactTileAdapter extends BaseAdapter {
@Override
public void onClick(ContactTileView contactTileView) {
if (mListener != null) {
- mListener.onContactSelected(contactTileView.getLookupUri(),
+ mListener.onContactClick(contactTileView.getLookupUri(),
ContactsUtils.getTargetRectFromView(mContext, contactTileView));
}
}
+ /*robin_20120509*/
+ @Override
+ public boolean onLongClick(ContactTileView contactTileView) {
+ ContactTileRow v=null;
+ int type=-1;
+ ViewParent p=contactTileView.getParent();
+ if(p instanceof ContactTileRow)
+ {
+ v=(ContactTileRow)p;
+ type=v.getItemViewType();
+ if (type==ViewTypes.FREQUENT&&mListener != null) {
+ return mListener.onContactLongClick(contactTileView.getLookupUri(),
+ ContactsUtils.getTargetRectFromView(mContext, contactTileView),type);
+ }
+ }
+ return false;
+ }
+ //robin_20120509]
};
/**
@@ -544,7 +571,10 @@ public class ContactTileAdapter extends BaseAdapter {
mItemViewType = itemViewType;
mLayoutResId = getLayoutResourceId(mItemViewType);
}
-
+ int getItemViewType()
+ {
+ return mItemViewType;
+ }
/**
* Configures the row to add {@link ContactEntry}s information to the views
*/
@@ -707,7 +737,7 @@ public class ContactTileAdapter extends BaseAdapter {
public int indexSimOrPhone;
}
- private static class ViewTypes {
+ public static class ViewTypes {
public static final int COUNT = 4;
public static final int STARRED = 0;
public static final int DIVIDER = 1;
@@ -716,7 +746,8 @@ public class ContactTileAdapter extends BaseAdapter {
}
public interface Listener {
- public void onContactSelected(Uri contactUri, Rect targetRect);
+ public void onContactClick(Uri contactUri, Rect targetRect);
+ public boolean onContactLongClick(Uri contactUri, Rect targetRect,int type);
}
文件apps/Contacts/src/com/android/contacts/list/ContactTileListFragment.java主要修改如下:
@@
-
56
,
7
+
56
,
8
@@
public
class
ContactTileListFragment
extends
Fragment
{
private
static
final
String
TAG
=
ContactTileListFragment
.
class
.
getSimpleName
();
public
interface
Listener
{
-
public
void
onContactSelected
(
Uri
contactUri
,
Rect
targetRect
);
+
public
void
onContactClick
(
Uri
contactUri
,
Rect
targetRect
);
+
public
boolean
onContactLongClick
(
Uri
contactUri
,
Rect
targetRect
,
int
type
);
}
private
static
int
LOADER_CONTACTS
=
1
;
@@
-
221
,
11
+
222
,
18
@@
public
class
ContactTileListFragment
extends
Fragment
{
private
ContactTileAdapter
.
Listener
mAdapterListener
=
new
ContactTileAdapter
.
Listener
()
{
@Override
-
public
void
onContactSelected
(
Uri
contactUri
,
Rect
targetRect
)
{
+
public
void
onContactClick
(
Uri
contactUri
,
Rect
targetRect
)
{
if
(
mListener
!=
null
)
{
-
mListener
.
onContactSelected
(
contactUri
,
targetRect
);
+
mListener
.
onContactClick
(
contactUri
,
targetRect
);
}
}
+
@Override
+
public
boolean
onContactLongClick
(
Uri
contactUri
,
Rect
targetRect
,
int
type
)
{
+
if
(
mListener
!=
null
)
{
+
return
mListener
.
onContactLongClick
(
contactUri
,
targetRect
,
type
);
+
}
+
return
false
;
+
}
};
文件packages/apps/Contacts/src/com/android/contacts/list/ContactTileView.java修改如下: