Android Open Source - CallLog Phone Log






From Project

Back to project page CallLog.

License

The source code is released under:

GNU General Public License

If you think the Android project CallLog listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.kaosh.calllog;
/* w  ww  . j  a v  a  2 s.co  m*/
import java.util.ArrayList;
import java.util.Calendar;

import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;

public class PhoneLog {

  static public void update (Context context) {

    final SharedPreferences rate_settings = context.getSharedPreferences("Rate", 0);
    final SharedPreferences log = context.getSharedPreferences("log", 0);
    int vendorId = rate_settings.getInt("vendorId", 0);
    float innet = rate_settings.getFloat("innet", 0.06f);
    float outnet = rate_settings.getFloat("outnet", 0.1128f);
    float other = rate_settings.getFloat("other", 0.1056f);

      Calendar calendar = Calendar.getInstance();
      calendar.set(Calendar.DAY_OF_MONTH, 1);
      calendar.set(Calendar.HOUR_OF_DAY, 0);
      calendar.set(Calendar.MINUTE, 0);
      calendar.set(Calendar.SECOND, 0);
      long start_millis = calendar.getTimeInMillis();
      
    String fields[] = {android.provider.CallLog.Calls.NUMBER, android.provider.CallLog.Calls.DURATION};
    
    String selection = android.provider.CallLog.Calls.TYPE + "=?" +
              " AND " + android.provider.CallLog.Calls.DATE + ">=?";
    
    String selectionArgs[] = {
        "" + android.provider.CallLog.Calls.OUTGOING_TYPE,
        "" + start_millis
    };
    
    Cursor c = context.getContentResolver().query(
        android.provider.CallLog.Calls.CONTENT_URI,
        fields,
        selection,
        selectionArgs,
        android.provider.CallLog.Calls.DATE + " DESC"
        );
    
    int numberColumn = c.getColumnIndex(android.provider.CallLog.Calls.NUMBER);
    int durationColumn = c.getColumnIndex(android.provider.CallLog.Calls.DURATION);
    
    float costInnet = 0;
    float costOutnet = 0;
    float costOther = 0;
    float costHot = 0;
    int durationInnet = 0;
    int durationOutnet = 0;
    int durationOther = 0;
    int durationHot = 0;
    
    ArrayList <NPObj> nps = new ArrayList <NPObj>();
    NP.get_nps(context, nps);

    ArrayList <HotlineObj> hotlines = new ArrayList <HotlineObj>();
    Hotline.get_hotlines(context, hotlines);
    
    if (c.moveToFirst()) {
      do {
        String number = c.getString(numberColumn);
        long duration = c.getLong(durationColumn);
        int callVendorId = PhoneUtils.getVendorIdByNumber(number, nps);
        
        boolean isHotline = false;
        for (int i=0 ;i<hotlines.size() ;i++) {
          HotlineObj hotline = hotlines.get(i);
          if (number.equals(hotline.mNumber)) {
            costHot += hotline.mRate * duration;
            durationHot += duration;
            isHotline = true;
            break;
          }
        }
        
        if (isHotline)
          continue;
        
        if (callVendorId==800)
          continue;
        
        if (callVendorId == -1) {
          durationOther += duration;
        }
        else if (callVendorId == vendorId) {
          durationInnet += duration;
        }
        else {
          durationOutnet += duration;
        }
      } while (c.moveToNext());
    }
    
    costOther = other * durationOther;
    costInnet = innet * durationInnet;
    costOutnet = outnet * durationOutnet;
    
    c.close();
    
    log.edit()
    .putFloat("costInnet", costInnet)
    .putFloat("costOutnet", costOutnet)
    .putFloat("costOther", costOther)
    .putFloat("costHot", costHot)
    .putInt("durationInnet", durationInnet)
    .putInt("durationOutnet", durationOutnet)
    .putInt("durationOther", durationOther)
    .putInt("durationHot", durationHot)
    .commit();
  }
}




Java Source Code List

com.kaosh.calllog.CallLogActivity.java
com.kaosh.calllog.CallLogWidget.java
com.kaosh.calllog.DatabaseOpenHelper.java
com.kaosh.calllog.HotlineAdapter.java
com.kaosh.calllog.HotlineObj.java
com.kaosh.calllog.HotlineSettingActivity.java
com.kaosh.calllog.Hotline.java
com.kaosh.calllog.NPAdapter.java
com.kaosh.calllog.NPObj.java
com.kaosh.calllog.NPSettingActivity.java
com.kaosh.calllog.NP.java
com.kaosh.calllog.PhoneLog.java
com.kaosh.calllog.PhoneUtils.java
com.kaosh.calllog.RateSettingActivity.java
com.kaosh.calllog.SMSLog.java
com.kaosh.calllog.Utils.java