package com.milifan.contact;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import android.app.Activity;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.CallLog;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.milifan.R;
import com.milifan.contact.base.BaseContactList;
import com.milifan.util.Common;
import com.milifan.util.SharedPreferencesHelper;
public class TotalDisplay extends Activity {
boolean isrun = false;
SharedPreferencesHelper sp;
// private final String duration = "1"; //通话时长一小时
@Override
protected void onCreate(Bundle savedInstanceState) {
// String sql =
// "_id in(select total._id from (select _id,sum(duration) as duration from calls where date>="+beforeTime+" and date<="+newTime+" group by number) as total where total.duration>="+duration+")";
super.onCreate(savedInstanceState);
setContentView(R.layout.total_display);
// setProperties();
}
@Override
protected void onResume() {
super.onResume();
setProperties();
}
private void setProperties() {
int outOfmonth, timesPerMonth, outOfToday, outOfWeek, inOfToday, inOfWeek, inOfMonth, missOfToday, missOfWeek, missOfMonth;
TextView textView;
GregorianCalendar calendar = new GregorianCalendar();
Date now = new Date();
calendar.setTime(now);
calendar.setFirstDayOfWeek(GregorianCalendar.MONDAY);// 设置一个星期的第一天为星期1,默认是星期日
calendar.set(GregorianCalendar.DAY_OF_WEEK, GregorianCalendar.MONDAY);
SimpleDateFormat dateutil = new SimpleDateFormat("yyyy-MM-dd");
String dayOfWeek = dateutil.format(calendar.getTime()) + " 00:00:00";// 获取本周一得时间
int actualMaxOfMonth = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);// 获取当月有多少天
int currentDay = calendar.get(calendar.DAY_OF_MONTH);// 取当前日期;
// 获取所设置的月套餐包含通话时长
sp = new SharedPreferencesHelper(this, "callTimeRecorder");
timesPerMonth = sp.getValue("month_total");
// 获取本月已拨通话时长
String where = "type=2 and datetime(substr(date,1,10),'unixepoch','localtime')>datetime('now','start of month')";
outOfmonth = this.getCallTimeByWhere(where);
textView = (TextView) this.findViewById(R.id.outofmonth);
textView.setText(String.valueOf(outOfmonth));
// 获取本周已拨通话时长
where = "type=2 and datetime(substr(date,1,10),'unixepoch','localtime')>datetime('"
+ dayOfWeek + "')";
// Log.v("SQL", where);
outOfWeek = this.getCallTimeByWhere(where);
textView = (TextView) this.findViewById(R.id.outofweek);
textView.setText(String.valueOf(outOfWeek));
// 获取当日已拨通话时长
where = "type=2 and datetime(substr(date,1,10),'unixepoch','localtime')>date('now','localtime')||' 00:00:00'";
outOfToday = this.getCallTimeByWhere(where);
textView = (TextView) this.findViewById(R.id.outoftoday);
textView.setText(String.valueOf(outOfToday));
// 获取当日已接通话时长
where = "type=1 and datetime(substr(date,1,10),'unixepoch','localtime')>date('now','localtime')||' 00:00:00'";
inOfToday = this.getCallTimeByWhere(where);
textView = (TextView) this.findViewById(R.id.inoftoday);
textView.setText(String.valueOf(inOfToday));
// 获取本周已接通话时长
where = "type=1 and datetime(substr(date,1,10),'unixepoch','localtime')>datetime('"
+ dayOfWeek + "')";
inOfWeek = this.getCallTimeByWhere(where);
textView = (TextView) this.findViewById(R.id.inofweek);
textView.setText(String.valueOf(inOfWeek));
// 获取本月已接通话时长
where = "type=1 and datetime(substr(date,1,10),'unixepoch','localtime')>datetime('now','start of month')";
inOfMonth = this.getCallTimeByWhere(where);
textView = (TextView) this.findViewById(R.id.inofmonth);
textView.setText(String.valueOf(inOfMonth));
// 获取已拨所占月套餐的百分比
double persent = (double) outOfmonth * 100 / (double) timesPerMonth;
java.text.DecimalFormat df = new java.text.DecimalFormat("########.000");
persent = (new Double(df.format(persent))).doubleValue();
// 设置月套餐包含拨出通话时长
textView = (TextView) this.findViewById(R.id.txt_total);
textView.setText(String.valueOf(timesPerMonth));
// 设置本月已拨出通话时长
textView = (TextView) this.findViewById(R.id.txt_reality);
textView.setText(String.valueOf(outOfmonth));
// 设置拨出占月套餐通话时长的百分比
textView = (TextView) this.findViewById(R.id.txt_proportions);
textView.setText(String.valueOf(persent) + "%");
// 设置按目前情况下预计所拨出电话时长
int estimated = outOfmonth * actualMaxOfMonth / currentDay;
textView = (TextView) this.findViewById(R.id.txt_estimated);
textView.setText(String.valueOf(estimated));
//设置预计时长textView的颜色
// if(estimated>timesPerMonth)
// textView.setBackgroundColor(R.color.orange);
// 设置拨出和接入总计时长
textView = (TextView) this.findViewById(R.id.totaloftoday);
textView.setText(String.valueOf(outOfToday + inOfToday));
textView = (TextView) this.findViewById(R.id.totalofweek);
textView.setText(String.valueOf(outOfWeek + inOfWeek));
textView = (TextView) this.findViewById(R.id.totalofmonth);
textView.setText(String.valueOf(outOfmonth + inOfMonth));
// 设置进度条
ProgressBar progressBar = (ProgressBar) this
.findViewById(R.id.pbar_process);
progressBar.setMax(timesPerMonth);
progressBar.setProgress(outOfmonth);
//progressBar.setTag(persent);
}
private int getCallTimeByWhere(String where) {
int total = 0;
final Cursor cursor = getContentResolver().query(
CallLog.Calls.CONTENT_URI,
new String[] { CallLog.Calls.NUMBER, CallLog.Calls.DURATION },
where, null, CallLog.Calls.DEFAULT_SORT_ORDER);
// startManagingCursor(cursor)
for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToPosition(i);
int duration = 0;
try {
duration = Integer.parseInt(cursor.getString(cursor
.getColumnIndex(CallLog.Calls.DURATION)));
if (duration % 60 > 0)
duration = duration / 60 + 1;
else
duration = duration / 60;
} catch (Exception e) {
duration = 1;
}
total += duration;
}
return total;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Android应用源码通话时间统计器[实例,源代码].zip项目安卓应用源码下载Android应用源码通话时间统计器[实例,源代码].zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
资源推荐
资源详情
资源评论
收起资源包目录
Android应用源码通话时间统计器[实例,源代码].zip (56个子文件)
Android应用源码通话时间统计器[实例,源代码]
Android应用源码通话时间统计器[实例,源代码]
android通话时间统计器[实例,源代码]
CallTimeRecorder.rar 425KB
CallTimeRecorder
bin
classes.dex 18KB
CallTimeRecorder.apk 49KB
com
milifan
R$layout.class 480B
R$id.class 2KB
R$drawable.class 648B
R$attr.class 319B
contact
base
BaseContactList.class 3KB
OutgoingContactList.class 668B
MissedContactList.class 646B
TotalDisplay.class 5KB
IncomingContactList.class 669B
R.class 523B
adapter
CallCursorAdapter.class 3KB
R$string.class 1018B
portal
Settings.class 2KB
Settings$1.class 777B
CalllogTabs.class 4KB
Settings$2.class 775B
CalllogTabs$1.class 894B
R$color.class 553B
util
SharedPreferencesHelper.class 1KB
Common.class 381B
resources.ap_ 38KB
res
drawable
total.png 53KB
set.png 52KB
outgoing.png 52KB
about.png 52KB
split_line.xml 1KB
missed.png 52KB
incoming.png 52KB
icon.png 50KB
exit.png 53KB
mail.gif 975B
values
strings.xml 1KB
layout
callinfo.xml 2KB
list_layout.xml 856B
setting.xml 2KB
total_display.xml 7KB
default.properties 449B
gen
com
milifan
R.java 5KB
.settings
org.eclipse.jdt.core.prefs 208B
src
com
milifan
contact
TotalDisplay.java 6KB
base
BaseContactList.java 2KB
MissedContactList.java 423B
IncomingContactList.java 565B
OutgoingContactList.java 441B
adapter
CallCursorAdapter.java 3KB
portal
Settings.java 2KB
CalllogTabs.java 3KB
util
SharedPreferencesHelper.java 671B
Common.java 96B
.project 852B
.classpath 280B
AndroidManifest.xml 1KB
1009171452127d7f63b4881763.jpg 24KB
共 56 条
- 1
资源评论
yxkfw
- 粉丝: 76
- 资源: 2万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功