package com.archer.calllog;

import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.CallLog.Calls;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.format.DateFormat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.EditText;
import android.widget.Filter;
import android.widget.ListView;
import android.widget.TextView;

public class CalllogActivity extends Activity {
/** Called when the activity is first created. */
EditText et_number;
ListView lv_call_log;
private final static String[] PROJECTION = new String[]{Calls._ID,Calls.NUMBER,Calls.DATE,Calls.TYPE};
CallsAdapter myAdapter = new CallsAdapter(this, null);
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
et_number = (EditText) findViewById(R.id.et_number);
lv_call_log = (ListView) findViewById(R.id.lv_call_log);

lv_call_log.setAdapter(myAdapter);
et_number.addTextChangedListener(new MyTextWatcher());
}
private final class MyTextWatcher implements TextWatcher{

public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
public void afterTextChanged(Editable s) {
Filter mFilter = myAdapter.getFilter();
mFilter.filter(s.toString(), lv_call_log);
}
}

private final class CallsAdapter extends CursorAdapter{

public CallsAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = getLayoutInflater().inflate(R.layout.item, null);
return view;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView tv_number = (TextView) view.findViewById(R.id.tv_number);
TextView tv_date = (TextView) view.findViewById(R.id.tv_date);
TextView tv_type = (TextView) view.findViewById(R.id.tv_type);


String number = cursor.getString(1);
long date = cursor.getLong(2);
int type = cursor.getInt(3);

tv_number.setText(number);
tv_date.setText(DateFormat.getDateFormat(context).format(date));
switch (type) {
case Calls.INCOMING_TYPE:
tv_type.setText("来电");
break;
case Calls.OUTGOING_TYPE:
tv_type.setText("去电");
break;
case Calls.MISSED_TYPE:
tv_type.setText("未接");
break;

default:
break;
}
}

@Override
public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
if(TextUtils.isEmpty(constraint)){
return null;
}
Uri uri = Calls.CONTENT_URI;
String selection = Calls.NUMBER + " like '%" + constraint + "%'";
Cursor cursor = getContentResolver().query(uri, PROJECTION, selection, null, Calls.DATE + " desc");

return cursor;
}
}
}

更多相关文章

  1. Android电话来电流程源码分析
  2. 在Android中监控来电和去电
  3. android实现电话状态监控
  4. [Android] 来电归属地查询的实现思路
  5. Android有未接来电后处理(判断未接来电)
  6. 【Android】监听电话状态
  7. android 来电自动接听和自动挂断
  8. android 来去电监听
  9. android 来电自动接听和自动挂断

随机推荐

  1. 关于Android加载网页的一些问题
  2. Android(安卓)仿美团大众字母索引实现
  3. Java和android的就业前景哪个好?
  4. (转)Android中ListView分页加载数据
  5. [置顶] 我的Android进阶之旅------>Andro
  6. Android(安卓)快速开发数据库greenDao
  7. android CircularSeekBar
  8. Android核心分析(15)--------Android输入
  9. 使用Genymotion代替原生模拟器
  10. Android入门进阶教程(3)-linux 开发环境