I am writing an code for fetching missed call list on selected date using Datepicker dialog. I am using button to display selected date. I am able to fetch the missed call list and able to select the date but i am not sure how to pass the selected date in to the Cursor query to fetch the missed call list for that date.
public class missnew extends ActionBarActivity implements View.OnClickListener,DatePickerDialog.OnDateSetListener,SwipeRefreshLayout.OnRefreshListener{
private int day;
private int month;
private int year;
private Calendar calender;
private Button button;
private TextView textView;
private ScrollView scrollview;
private DatePickerDialog datePickerDialog;
private SwipeRefreshLayout swipeRefreshLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_missnew);
button = (Button)findViewById(R.id.button);
textView = (TextView)findViewById(R.id.textview);
scrollview = (ScrollView)findViewById(R.id.scrollView);
swipeRefreshLayout = (SwipeRefreshLayout)findViewById(R.id.swipe);
swipeRefreshLayout.setOnRefreshListener(this);
//swipeRefreshLayout.setColorSchemeColors(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
// android.R.color.holo_orange_light, android.R.color.holo_red_light);
swipeRefreshLayout.setDistanceToTriggerSync(20);
swipeRefreshLayout.setSize(1);
calender = Calendar.getInstance(Locale.getDefault());
button.setOnClickListener(this);
day=calender.get(Calendar.DAY_OF_MONTH);
month=calender.get(Calendar.MONTH);
year=calender.get(Calendar.YEAR);
setupdate(day, month, year);
// calender.set(year,month,day);
//String fromDate = String.valueOf(calender.getTimeInMillis());
getCallDetails();
}
private void getCallDetails()
{
StringBuffer sb = new StringBuffer();
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
String Fdate = (day+"-"+(month+1) +"-"+year);
// String selection = CallLog.Calls.DATE + ">?", new String[] { String.valueOf(Fdate.getBytes())};
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyy");
// Long l = Long.parseLong(Fdate);
Cursor managedCursor = getContentResolver().
query(
android.provider.CallLog.Calls.CONTENT_URI,
null,
null,
null,
strOrder);
sb.append("Missed Calls :");
while (managedCursor.moveToNext())
{
String phNumber = managedCursor.getString(managedCursor.getColumnIndex(CallLog.Calls.NUMBER));
String callType = managedCursor.getString(managedCursor.getColumnIndex(CallLog.Calls.TYPE));
String callDate = managedCursor.getString((managedCursor.getColumnIndex(CallLog.Calls.DATE)));
String callname= managedCursor.getString(managedCursor.getColumnIndex(CallLog.Calls.CACHED_NAME));
Date callDayTime = new Date(Long.valueOf(callDate));
String Tdate=formatter.format(callDayTime);
String dir = null;
int dircode = Integer.parseInt(callType);
if(dircode==CallLog.Calls.MISSED_TYPE){
sb.append("\nPhone Number:--- " + phNumber +
" \nCall Date:--- " + l + "\nName:---" +callname);
sb.append("\n----------------------------------"); }
}//managedCursor.close();
textView.setText(sb);
}
private void setupdate(int day, int month, int year) {
button.setText(String.valueOf(day) + "/" + String.valueOf(month + 1) + "/" +String.valueOf(year));
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.button:
showdate();
break;
default:
//do nothing
break;
}
}
private void showdate() {
datePickerDialog = new DatePickerDialog(
this
,missnew.this
,year
,month
,day);
datePickerDialog.show();
}
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
setupdate(year,monthOfYear,dayOfMonth);
}
@Override
public void onRefresh() {
(new Handler()).postDelayed(new Runnable() {
@Override
public void run() {
swipeRefreshLayout.setRefreshing(false);
getCallDetails();
}
}, 5000);
}
}
Aucun commentaire:
Enregistrer un commentaire