Android Open Source - CallLog S M S 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 w  w .java2 s .c o  m
import java.util.ArrayList;
import java.util.Calendar;

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

public class SMSLog {

  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("innetsms", 1.1707f);
    float outnet = rate_settings.getFloat("outnetsms", 1.5353f);

      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[] = {"date", "address"};
    
    String selection = "date>=?";
    
    String selectionArgs[] = {
        "" + start_millis
    };
    
    Cursor c = context.getContentResolver().query(
        Uri.parse("content://sms/sent/"),
        fields,
        selection,
        selectionArgs,
        "date DESC"
        );
    
    int numberColumn = c.getColumnIndex("address");
    
    float costInnet = 0;
    float costOutnet = 0;
    int countInnet = 0;
    int countOutnet = 0;
    int countMMS = 0;
    
    ArrayList <NPObj> nps = new ArrayList <NPObj>();
    NP.get_nps(context, nps);

    if (c.moveToFirst()) {
      do {
        String number = c.getString(numberColumn);
        int callVendorId = PhoneUtils.getVendorIdByNumber(number, nps);
      
        if (callVendorId == vendorId) {
          costInnet += innet;
          countInnet += 1;
        }
        else {
          costOutnet += outnet;
          countOutnet += 1;
        }
      } while (c.moveToNext());
    }
    
    c.close();
    
    log.edit()
    .putFloat("costInnetSMS", costInnet)
    .putFloat("costOutnetSMS", costOutnet)
    .putInt("countInnetSMS", countInnet)
    .putInt("countOutnetSMS", countOutnet)
    .putInt("countMMS", countMMS)
    .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