• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Help urgent help on coding.....Im working on recent call log....i want to remove consecutive duplicates

avavinash

Lurker
heres my code....i want to remove based on number and date and increse the count for each duplicate.....how to do it,....???




package com.example.call;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;


import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CallLog;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class MainActivity extends ListActivity {

private ArrayList<String> conNames;
private ArrayList<String> conNumbers;
private ArrayList<String> conTime;
private ArrayList<String> conDate;
private ArrayList<String> conType;
int count;
@override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

conNames = new ArrayList<String>();
conNumbers = new ArrayList<String>();
conTime = new ArrayList<String>();
conDate = new ArrayList<String>();
conType = new ArrayList<String>();






Cursor curLog = CallLogHelper.getAllCallLogs(getContentResolver());

setCallLogs(curLog);

setListAdapter(new MyAdapter(this, android.R.layout.simple_list_item_1,
R.id.tvNameMain, conNames));
}


private class MyAdapter extends ArrayAdapter<String> {

int count=0;
public MyAdapter(Context context, int count, int textViewResourceId,
ArrayList<String> conNames) {
super(context, count, textViewResourceId, conNames);
this.count=count;
}

@override
public View getView(int position, View convertView, ViewGroup parent) {

View row = setList(position, parent);
return row;
}

private View setList(int position, ViewGroup parent) {
LayoutInflater inf = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
count=0;
View row = inf.inflate(R.layout.liststyle, parent, false);

TextView tvName = (TextView) row.findViewById(R.id.tvNameMain);
TextView tvNumber = (TextView) row.findViewById(R.id.tvNumberMain);
TextView tvTime = (TextView) row.findViewById(R.id.tvTime);
TextView tvDate = (TextView) row.findViewById(R.id.tvDate);
TextView tvType = (TextView) row.findViewById(R.id.tvType);
TextView cout = (TextView) row.findViewById(R.id.countout);


tvName.setText(conNames.get(position));
tvNumber.setText(conNumbers.get(position));
tvTime.setText("( " + conTime.get(position) + "sec )");
tvDate.setText(conDate.get(position));
tvType.setText("( " + conType.get(position) + " )");
cout.setText(" "+this.count);

count++;
return row;

}

}

private void setCallLogs(Cursor curLog) {
while (curLog.moveToNext()) {
String callNumber = curLog.getString(curLog
.getColumnIndex(android.provider.CallLog.Calls.NUMBER));
conNumbers.add(callNumber);

String callName = curLog
.getString(curLog
.getColumnIndex(android.provider.CallLog.Calls.CACHED_NAME));
if (callName == null) {
conNames.add("Unknown");
} else
conNames.add(callName);

String callDate = curLog.getString(curLog
.getColumnIndex(android.provider.CallLog.Calls.DATE));
SimpleDateFormat formatter = new SimpleDateFormat(
"dd-MMM-yyyy HH:mm");
String dateString = formatter.format(new Date(Long
.parseLong(callDate)));
conDate.add(dateString);

String callType = curLog.getString(curLog
.getColumnIndex(android.provider.CallLog.Calls.TYPE));
if (callType.equals("1")) {
conType.add("Incoming");
} else if (callType.equals("2")) {
conType.add("Outgoing");
}
else
conType.add("Missed");

String duration = curLog.getString(curLog
.getColumnIndex(android.provider.CallLog.Calls.DURATION));
conTime.add(duration);

}
}

}










package com.example.call;

import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CallLog;
import android.util.Log;

public class CallLogHelper {

public static Cursor getAllCallLogs(ContentResolver cr) {
// reading all data in descending order according to DATE
String strOrder = android.provider.CallLog.Calls.DATE + " DESC";
Uri callUri = Uri.parse("content://call_log/calls");
Cursor curCallLogs = cr.query(callUri, null, null, null, strOrder);

return curCallLogs;
}

public static void insertPlaceholderCall(ContentResolver contentResolver,
String name, String number) {
ContentValues values = new ContentValues();
values.put(CallLog.Calls.NUMBER, number);
values.put(CallLog.Calls.DATE, System.currentTimeMillis());
values.put(CallLog.Calls.DURATION, 0);
values.put(CallLog.Calls.TYPE, CallLog.Calls.OUTGOING_TYPE);
values.put(CallLog.Calls.NEW, 1);
values.put(CallLog.Calls.CACHED_NAME, name);
values.put(CallLog.Calls.CACHED_NUMBER_TYPE, 0);
values.put(CallLog.Calls.CACHED_NUMBER_LABEL, "");
Log.d("Call Log", "Inserting call log placeholder for " + number);
contentResolver.insert(CallLog.Calls.CONTENT_URI, values);
}

}
 
Back
Top Bottom