883
京东网上商城
一个不错的定时程序,写的很好的
“本文参与趣米杯征文活动,如需转载请注明出处和作者”。
quitesleep是一款android手机的小软件。它可以设定在你睡觉的时候,当有电话打进来的时候。自动挂断或者设定为静音,并给打电话的人回复你之前设定好的邮件或者短信。保证你睡觉的时候不受打扰。
软件运行界面如下:






从各个界面已经开到软件设计的思路非常的清晰。首先首次运行的时候,可以把你手机的联系人同步到软件。可以设置你需要阻止的手机来电类型。可以设置你需要阻止来电的时间。拦截到来电以后回复的短信内容或者是邮件内容。还可以查看你拦截的电话日志。
代码实现上也比较简单:
就是设置一个PhoneStateReceiver,监听电话的状态。
- @Override
- public void onReceive (Context context, Intent intent) {
-
- if (QSLog.DEBUG_D)QSLog.d(CLASS_NAME, "BroadcastReceive. Tipo: " + intent.getAction());
-
- //------------- LISTEN FOR BOOT COMPLETED ------------------//
- if (intent.getAction().equals(BOOT_COMPLETED)) {
- listenBootCompleted(context);
- }
-
- //---------- LISTEN FOR INCOMING CALLS ------------------//
- else if (intent.getAction().equals(PHONE_STATE)) {
- //ITelephony telephonyService = createITelephonyImp();
- listenIncomingCalls(context);
- }
-
- //----------- LISTEN FOR INCOMING SMS ----------------------//
- else if (intent.getAction().equals(SMS_RECEIVED)) {
- //listenIncomingSMS(context, intent);
- }
-
- }
自定义MyPhoneStateListener。在电话状态变化时,进行处理。
- public void onCallStateChanged (int state, String incomingNumber) {
-
- try {
-
- switch (state) {
-
- //------------- CALL_STATE_IDLE ----------------------//
- //Device call state: No activity.
- case TelephonyManager.CALL_STATE_IDLE:
- processCallStateIdle();
- break;
-
- //----------------- CALL_STATE_OFFHOOK --------------//
- //Device call state: Off-hook. At least one call exists that is
- //dialing, active, or on hold, and no calls are ringing or waiting.
- case TelephonyManager.CALL_STATE_OFFHOOK:
- processCallStateOffhook();
- break;
-
- //----------------- CALL_STATE_RINGING --------------//
- //Device call state: Ringing. A new call arrived and is ringing
- //or waiting. In the latter case, another call is already active.
- case TelephonyManager.CALL_STATE_RINGING:
- processCallStateRinging(incomingNumber);
- break;
-
- default:
- break;
- }
-
- }catch (Exception e) {
- if (QSLog.DEBUG_E)QSLog.e(CLASS_NAME, ExceptionUtils.exceptionTraceToString(
- e.toString(),
- e.getStackTrace()));
- }
- }
最后在IncomingCallOperations根据电话的来电时间是否在设置需要拦截的时间里。进行静音或者挂掉处理。并回复短信或者邮件。
- public synchronized void silentIncomingCall () {
-
- try {
-
- ClientDDBB clientDDBB = new ClientDDBB();
-
- QSLog.d(CLASS_NAME, "IncomingNuber: " + incomingCallNumber);
-
- String phoneNumberWhithoutDashes =
- TokenizerUtils.tokenizerPhoneNumber(incomingCallNumber, null);
-
- QSLog.d(CLASS_NAME, "IncomingNumberFormated: " + phoneNumberWhithoutDashes);
-
- //create the CallLog object for log calls.
- CallLog callLog = new CallLog();
-
- //check if the call is in the interval time
- boolean isInInterval = checkSchedule(callLog, clientDDBB);
-
- if (isInInterval) {
-
- //Put the mobile phone in silent mode (sound+vibration)
- //putRingerModeSilent();
-
- //End call using the ITelephony implementation
- //telephonyService.endCall();
-
- BCBean bcBean = processBlockedActionType(
- clientDDBB,
- phoneNumberWhithoutDashes);
-
- if (QSLog.DEBUG_D)QSLog.d(CLASS_NAME, "BloquedContactBean: " + bcBean);
-
-
- /* Check if the mail service is running, if it is true
- * create a SendMail object for try to send one or more
- * email to the contact with the incoming number
- */
- if (bcBean != null)
- sendMail(incomingCallNumber, callLog, clientDDBB);
-
- /* Check if the sms service is running, if it is true
- * create a SendSMS object for try to send a SMS to
- * the contact with the incoming number
- */
- if (bcBean != null)
- sendSMS(incomingCallNumber, callLog, clientDDBB);
-
- if (bcBean != null)
- //Save the callLog object in the ddbb if is appropriate.
- saveCallLog(
- clientDDBB,
- callLog,
- incomingCallNumber,
- bcBean.getUsedContact());
- }
- //If the call isn't in the interval range
- else
- if (QSLog.DEBUG_D)QSLog.d(CLASS_NAME, "No está en el intervalo");
-
- //close the ddbb.
- clientDDBB.close();
-
-
- }catch (Exception e) {
- if (QSLog.DEBUG_E)QSLog.e(CLASS_NAME, ExceptionUtils.exceptionTraceToString(
- e.toString(),
- e.getStackTrace()));
- }
- }
-
quitesleep代码都比较清晰简单。但是里面用到了一个比较方便的数据存储的方式。对象型数据库db4o.db4o无需建表,无需写sql直接对对象进行增删改查操作,爽快吧。
db4o特性
db4o的目标是提供一个功能强大的,适合嵌入的数据库引擎,可以工作在设备,移动产品,桌面以及服务器等各种平台。主要特性如下:
-
开源模式。与其他 ODBMS不同,db4o为开源软件,通过开源社区的力量驱动开发db4o产品。
-
原生数据库。db4o是100原生的面向对象数据库,直接使用编程语言来操作数据库。程序员无需进行OR映射来存储对象,大大节省了程序员在存储数据的开发时间。
-
高性能。 db4o官方基准测试数据
-
Quitesleep中对db4o进行了封装。ClientDDBB中有以下4个对象,分别负责进行增删改查protectedSelects selects;protectedInserts inserts;protectedUpdates updates;protectedDeletes deletes;我们只需要定义好数据对象。对数据的增删改查就是以下这么简单。 -
- //新增联系人
- //Create the db4o contact object.
- Contact contact = new Contact(contactId, contactName);
-
- //insert the contact object
- clientDDBB.getInserts().insertContact(contact);
- //删除联系人
- ClientDDBB clientDDBB = new ClientDDBB();
-
- int deleteContacts = clientDDBB.getDeletes().deleteAllContacts();
- //更新联系人
- Contact contact = clientDDBB.getSelects().selectContactForName(contactName);
- contact.setBanned(false);
- clientDDBB.getUpdates().insertContact(contact);
- //根据号码查询联系人
- Contact usedContact = clientDDBB.getSelects().
- selectContactForPhoneNumber(incomingNumber);
-
quitesleep.zip (4.95 MB, 下载次数: 17)
昨天 14:20 上传点击文件名下载附件
下载积分: 下载豆 -2 - //新增联系人
最后更新:2017-04-03 12:54:31