Contacts知识要点

1:将ListView上的每条Item转换成Cursor,以便从数据库中查询数据(一般用于数据绑定的情况下,即ListView与Adapter的结合使用)

Cursor getItemForView(View view){
ListView listView = getListView();
int index = listView.getPositionForView(view);
if (index < 0){
return null;
}
return (Cursor)listView.getAdapter( ).getItem( index);
}

2:全选,反选的处理
private OnClickListener selectAllListener = new OnClickListener(){
public void onClick(View v){
if (!selectAll){
selectAll = true;
}else{
selectAll = false;
}
mAdapter.notifyDataSetChanged( );
}
};

private OnClickListener selectAllOkListener = new OnClickListener(){
public vlid onClick(View v){
if (selectAll){
mNewDialog = new NewDialog(mContext,
getString(R.string.menu_deleteContact),
deleteContactsListener, deleteContactsCancelListener);
}else{
boolean findleatOneContact = false;
for (int i = 0; i < selectPeopleId.length; i++){
if (selectPeopleId[i] != null){
findleatOneContact = true;
break;
}
}

if (!findleatOneContact){
mNewDialog = new NewDialog(mContext,
getString(R.string.atleastonecontact),
sureListener, null);
}else{
mNewDialog = new NewDialog(mContext,
getString(R.string.menu_deleteContact),
deleteContactsListener, deleteContactsCancelListener);
}
}
mNewDialog.setCancelable(false);
mNewDialog.show();
}
};

3:删除多个联系人处理
private View.OnClickListener deleteContactsListener = new View.OnClickListener(){
public void onClick(View v){
if (selectAll){
getContentResolver().delete(People.CONTENT_URI, null, null);
}else{
ContentResolver resolver = getContentResolver();
for (int i = 0; i < selectPeopleId.length; i++){
if (selectPeopleId[i] != null){
Uri uri = Uri.parse(People.CONTENT_URI + "/" + selectPeopleId[i]);
resolver.delete(uri, null, null);
}
}
}
mNewDialog.cancel();
}
}

四:编辑联系人时号码类型选择与切换
private OnClickListener numberTypeListener = new OnClickListener(){
public void onClick(View v){
if (currentType == PHONETYPE){
mNumberType.setText(type[1]);
currentType = FAMILYTYPE;
}else if (currentTyep == FAMILYTYPE){
mNumberType.setText(type[2]);
currentType = COMPANYTYPE;
}else{
mNumberType.setText(type[0]);
currentType = PHONETYPE;
}
}
};
五:拨号键盘旋转动画
public boolean onTouchEvent(MotionEvent event){
int action = event.getAction();
int x = (int)event.getX();
int y = (int)event.getY();
switch(action){
case MotionEvent.ACTION_UP:
if ((x >= 321 && x <= 321 + 61)
&& (y >= 250 && y <= 250 + 61)){
startRotateAnimation(1);
}else if (){
}else if (){
}

case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
return true;
}
return false;
}

private Animation rotateAnimation;
private ImageView mDialpanel;
mDialpanel = (ImageView)findViewById(R.id.dialpanel);
private void startRotateAnimation(int index){
switch(index){
case 1:
rotateAnimation = AnimationUtils.loadAnimation(
TwelveKeyDialerAnimation.this, R.anim.rotate_1);
break;
case 2:

}
mDialpanel.startAnimation(rotateAnimation);
}

rotate_1.xml
<?xml version="1.0" encoding="utf-8" ?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:repeatcount="1"
android:repeatMode="reverse"
android:fromDegress="0"
android:toDegress="38"
android:pivotX="48.2%"
android:pivotY="48.2%"
android:duration="500" />

你可能感兴趣的:(on)