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;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
小程序源码 系统工具 通话时间统计器源码.rar
共54个文件
class:20个
java:11个
png:8个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 100 浏览量
2023-03-29
19:56:54
上传
评论
收藏 431KB RAR 举报
温馨提示
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,本人不对所涉及的版权问题或内容负法律责任。如有侵权,请举报或通知本人删除。
资源推荐
资源详情
资源评论
收起资源包目录
小程序源码 系统工具 通话时间统计器源码.rar (54个子文件)
Android 通话时间统计器源码
.classpath 280B
.settings
org.eclipse.jdt.core.prefs 208B
assets
src
com
milifan
adapter
CallCursorAdapter.java 3KB
portal
Settings.java 2KB
CalllogTabs.java 3KB
contact
TotalDisplay.java 6KB
MissedContactList.java 423B
base
BaseContactList.java 2KB
OutgoingContactList.java 441B
IncomingContactList.java 565B
util
Common.java 96B
SharedPreferencesHelper.java 671B
res
values
strings.xml 1KB
layout
setting.xml 2KB
callinfo.xml 2KB
list_layout.xml 856B
total_display.xml 7KB
drawable
about.png 52KB
mail.gif 975B
set.png 52KB
exit.png 53KB
incoming.png 52KB
missed.png 52KB
outgoing.png 52KB
total.png 53KB
split_line.xml 1KB
icon.png 50KB
bin
resources.ap_ 38KB
CallTimeRecorder.apk 49KB
classes.dex 18KB
com
milifan
adapter
CallCursorAdapter.class 3KB
R$string.class 1018B
R$layout.class 480B
R$id.class 2KB
R$attr.class 319B
R$color.class 553B
portal
Settings.class 2KB
CalllogTabs.class 4KB
Settings$1.class 777B
CalllogTabs$1.class 894B
Settings$2.class 775B
R$drawable.class 648B
contact
IncomingContactList.class 669B
TotalDisplay.class 5KB
OutgoingContactList.class 668B
base
BaseContactList.class 3KB
MissedContactList.class 646B
R.class 523B
util
Common.class 381B
SharedPreferencesHelper.class 1KB
default.properties 449B
.project 852B
AndroidManifest.xml 1KB
gen
com
milifan
R.java 5KB
共 54 条
- 1
资源评论
荣华富贵8
- 粉丝: 151
- 资源: 7649
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功