From: snickersun Date: Mon, 3 Aug 2020 16:53:46 +0000 (+0800) Subject: 添加 久坐提醒,可以通过action设置久坐检测时间,以及久坐广播提醒。 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=98cce3ecf9180f373bb62fd4d6549e34f4d88405;p=protocol_srv.git 添加 久坐提醒,可以通过action设置久坐检测时间,以及久坐广播提醒。 睡眠数据上抱歉的检查 --- diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 3d7913c0..05c4691c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -162,7 +162,7 @@ - + diff --git a/app/src/main/java/com/enqualcomm/support/Config.java b/app/src/main/java/com/enqualcomm/support/Config.java index 1d120935..2dbddfaf 100644 --- a/app/src/main/java/com/enqualcomm/support/Config.java +++ b/app/src/main/java/com/enqualcomm/support/Config.java @@ -376,7 +376,7 @@ public class Config { }else if ((custom_branch_name.equals("l004")) ) { noPushTxtNotifyDialog=true; noSMSNotifyDialog=true; - noVoiceNotifyDialog=false; + noVoiceNotifyDialog=true; needBroadcastAntiAlarm=true; noPPGSensor=false; noTempSensor=false; @@ -550,5 +550,10 @@ public class Config { public static void setSleepScore(Context context,int score){ SharPreferenceUtil.setPrefInt(context,Constants.SHAREKEY_SETTING_SLEEP_SCORE,score); } + + /** + * 参考数据,平均每分钟步数来判断,大于 KeepSitJudgementRefValue 认为没有坐着。小于等于这个值认为坐着。 + */ + public static int KeepSitJudgementRefValue=30; } diff --git a/app/src/main/java/com/enqualcomm/support/Constants.java b/app/src/main/java/com/enqualcomm/support/Constants.java index 769221bb..8a32cf23 100644 --- a/app/src/main/java/com/enqualcomm/support/Constants.java +++ b/app/src/main/java/com/enqualcomm/support/Constants.java @@ -349,5 +349,16 @@ public interface Constants { public static String KEY_SIT_RANGE = "sit_range"; + /*** + * 内部定时器用action alarm + */ + public static String ACTION_SIT_ALARM = "com.ic.action.sit_alarm_local"; + + /** + * 发送给app做显示用 + */ + public static String ACTION_KEEPSIT_ALARM = "com.ic.action.keep_sit_alarm"; + + } diff --git a/app/src/main/java/com/enqualcomm/support/CoreService.java b/app/src/main/java/com/enqualcomm/support/CoreService.java index d8ec1ac2..ec6c2ff6 100644 --- a/app/src/main/java/com/enqualcomm/support/CoreService.java +++ b/app/src/main/java/com/enqualcomm/support/CoreService.java @@ -676,6 +676,32 @@ public class CoreService extends Service { CoreService.getInstance().connection.DeliverCMDMessageToSystem(cmd,""); } + public void checkKeepSitting(){ + String dateyyyyMMDDhhmmss=TimeUtil.getSystemTime4(); + String sleepdate=TimeUtil.getCurrentSleepRecordDate(dateyyyyMMDDhhmmss); + if(TimeUtil.isInSleepRange == false) { //不在睡眠时间就是久坐时间段。 + if (Runtime.lastSitCheckStepCount == -1){ + Runtime.lastSitCheckStepCount=runtime.getTotalStepCount(); + Runtime.lastSitCheckTiimeyyyyMMddHHmmss=TimeUtil.getSystemTime3(); + } + int minutes=(int)TimeUtil.diffBetween2DateInMinutes(Runtime.lastSitCheckTiimeyyyyMMddHHmmss,dateyyyyMMDDhhmmss); + if (minutes > Config.getKeepSitRangeInMinutes(this)){ + if ( (runtime.getTotalStepCount() - Runtime.lastSitCheckStepCount)/minutes < Config.KeepSitJudgementRefValue){ + //平均 每分钟活动数 小于参考久坐计步值,表示久坐 + runtime.getContextProxy().sendBroadcastSitLongAlarm(); //广播久坐消息 + }else{ + //只要 平均每分钟活动数大于参考值,则重置 lastCheckSitTime 以及 lastSitCheckStepCount + Runtime.lastSitCheckStepCount=runtime.getTotalStepCount(); + Runtime.lastSitCheckTiimeyyyyMMddHHmmss=TimeUtil.getSystemTime3(); + + } + } + }else{ + Runtime.lastSitCheckStepCount=-1; //不在时间段就重置数据,以便下一次使用能过重新开始计数。 + } + + + } public void updateSleepDate(){ String dateyyyyMMDDhhmmss=TimeUtil.getSystemTime4(); @@ -684,34 +710,41 @@ public class CoreService extends Service { runtime.getDbHelper().insertSleepRecord(new SleepRecord(dateyyyyMMDDhhmmss,sleepdate,runtime.getTotalStepCount())); runtime.sleepDataReported=false; //只要记录过数据 就证明有数据没有report }else{ - if (runtime.sleepDataReported == false){ + if (runtime.sleepDataReported == false) { //calculate sleep data and report it randomly within 1 hour - SleepInfo si=SleepInfo.getInstance(); - si.setDate(sleepdate); - si.calculate_sleepInfo(runtime); - runtime.getDbHelper().updateSleepInfo(si); - runtime.sleepDataReported=true; - Config.setSleepDate(this,sleepdate); - Config.setSleepScore(this,si.getScore()); - Random r = new Random(); - int randomint = r.nextInt(30 - 1) + 1; - ICLogger.i("Delayed " +randomint +" minutes , send sleep info " + si.getCurrentDate() - +" deep "+ si.getDeepsleep_minutes() - +" light "+ si.getLightsleep_minutes() - +" score "+ si.getScore() - ); - Observable.timer(randomint * 60 * 1000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { - public void call(Long param1Long) { + runtime.sleepDataReported = true; + int score = runtime.getDbHelper().querySleepScore(sleepdate); + if (score > 0) { + ICLogger.i("已经有"+sleepdate+"的睡眠数据!"); + } else { + SleepInfo si = SleepInfo.getInstance(); + si.setDate(sleepdate); + si.calculate_sleepInfo(runtime); + + runtime.getDbHelper().updateSleepInfo(si); + + Config.setSleepDate(this, sleepdate); + Config.setSleepScore(this, si.getScore()); + Random r = new Random(); + int randomint = r.nextInt(30 - 1) + 1; + ICLogger.i("Delayed " + randomint + " minutes , send sleep info " + si.getCurrentDate() + + " deep " + si.getDeepsleep_minutes() + + " light " + si.getLightsleep_minutes() + + " score " + si.getScore() + ); + Observable.timer(randomint * 60 * 1000L, TimeUnit.MILLISECONDS).subscribe(new Action1() { + public void call(Long param1Long) { // connection.send(protocolAPIHelper); - ICLogger.i("Send sleep info " + si.getCurrentDate() - +" deep "+ si.getDeepsleep_minutes() - +" light "+ si.getLightsleep_minutes() - +" score "+ si.getScore() - ); - Deliver.sendLocationMSG(protocolAPIHelper.getSleepMSG(SleepInfo.getInstance())); - } - }); + ICLogger.i("Send sleep info " + si.getCurrentDate() + + " deep " + si.getDeepsleep_minutes() + + " light " + si.getLightsleep_minutes() + + " score " + si.getScore() + ); + Deliver.sendLocationMSG(protocolAPIHelper.getSleepMSG(SleepInfo.getInstance())); + } + }); + } } } } @@ -840,7 +873,8 @@ public class CoreService extends Service { } else if (HEART_ALARM.equals(paramIntent.getAction())) { locationClient.updateStepCount(); - updateSleepDate(); + updateSleepDate(); //检查睡眠 + checkKeepSitting();//检查久坐 if (this.mKeepAlive != null) { if (connection.isServerConnected() && runtime.isServerProtocolConnected()) { this.mKeepAlive.onHeartAlarm(this.connection, this.runtime); diff --git a/app/src/main/java/com/enqualcomm/support/bean/Runtime.java b/app/src/main/java/com/enqualcomm/support/bean/Runtime.java index 43b2fd01..f26332ee 100644 --- a/app/src/main/java/com/enqualcomm/support/bean/Runtime.java +++ b/app/src/main/java/com/enqualcomm/support/bean/Runtime.java @@ -627,5 +627,9 @@ public class Runtime { public boolean sleepDataReported=false; + public static String lastSitCheckTiimeyyyyMMddHHmmss=""; + public static long lastSitCheckStepCount=0; + + } diff --git a/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java b/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java index 03baabd5..286c90da 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java +++ b/app/src/main/java/com/enqualcomm/support/utils/ContextProxy.java @@ -18,6 +18,7 @@ import android.util.Log; import com.enqualcomm.support.Config; +import com.enqualcomm.support.Constants; import com.enqualcomm.support.ICContentProvider; import com.enqualcomm.support.bean.Alarm; import com.enqualcomm.support.bean.NoticeContent; @@ -38,6 +39,8 @@ import rx.functions.Action1; import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; import static com.enqualcomm.support.Constants.ACTION_ISCONNECTED; +import static com.enqualcomm.support.Constants.ACTION_KEEPSIT_ALARM; +import static com.enqualcomm.support.Constants.ACTION_SIT_ALARM; import static com.enqualcomm.support.Constants.DIALOG_ACTION; public class ContextProxy { @@ -394,6 +397,11 @@ public class ContextProxy { intent.putExtra("stheartRateType", paramInt); this.context.sendBroadcast(intent, "com.eqc.broadcast.permission"); } + public void sendBroadcastSitLongAlarm() { + Intent intent = new Intent(); + intent.setAction(ACTION_KEEPSIT_ALARM); + this.context.sendBroadcast(intent); + } } diff --git a/app/src/main/java/com/enqualcomm/support/utils/ProcessReceiver.java b/app/src/main/java/com/enqualcomm/support/utils/ProcessReceiver.java index 5ab1decb..b0d52f83 100644 --- a/app/src/main/java/com/enqualcomm/support/utils/ProcessReceiver.java +++ b/app/src/main/java/com/enqualcomm/support/utils/ProcessReceiver.java @@ -20,6 +20,8 @@ import android.view.View; import android.view.WindowManager; +import com.enqualcomm.support.Config; +import com.enqualcomm.support.Constants; import com.enqualcomm.support.CoreService; import com.enqualcomm.support.LocationClient; import com.enqualcomm.support.R; @@ -50,6 +52,7 @@ import static com.enqualcomm.support.Constants.ACTION_PLAYTIME; import static com.enqualcomm.support.Constants.ACTION_REMOTE_CAMERA; import static com.enqualcomm.support.Constants.ACTION_SEND_EMEGENCY_LOCATION_START; import static com.enqualcomm.support.Constants.ACTION_SEND_SOS_MSG; +import static com.enqualcomm.support.Constants.ACTION_SET_SIT_RANGE; import static com.enqualcomm.support.Constants.ACTION_SHUTDOWN; import static com.enqualcomm.support.Constants.ACTION_TEMP_RESULT; import static com.enqualcomm.support.Constants.DIALOG_ACTION; @@ -333,18 +336,18 @@ public class ProcessReceiver extends BroadcastReceiver { this.screenOn(paramContext); } }else if (paramIntent.hasExtra("pushtxt")) { - String sms = paramIntent.getStringExtra("pushtxt"); - SharPreferenceUtil.getPrefBoolean(paramContext, "key_is_resume", false); - isSilence = SharPreferenceUtil.getPrefBoolean(paramContext, "KEY_ISSILENCE", false); - if (sms != null && !isSilence) { - if (!DeviceInfoUtil.isTopActivity(paramContext)) { - this.initMyDialog(paramContext, null, 4,sms); - this.playNotificationVoice(paramContext); - VibrateUtil.getInstance(paramContext).VibrateOn(true); + String sms = paramIntent.getStringExtra("pushtxt"); + SharPreferenceUtil.getPrefBoolean(paramContext, "key_is_resume", false); + isSilence = SharPreferenceUtil.getPrefBoolean(paramContext, "KEY_ISSILENCE", false); + if (sms != null && !isSilence) { + if (!DeviceInfoUtil.isTopActivity(paramContext)) { + this.initMyDialog(paramContext, null, 4, sms); + this.playNotificationVoice(paramContext); + VibrateUtil.getInstance(paramContext).VibrateOn(true); + } + + this.screenOn(paramContext); } - - this.screenOn(paramContext); - } }else if (paramIntent.hasExtra("findDev")) { String finddevtxt = paramIntent.getStringExtra("findDev"); SharPreferenceUtil.getPrefBoolean(paramContext, "key_is_resume", false); @@ -362,12 +365,17 @@ public class ProcessReceiver extends BroadcastReceiver { } }else if (ACTION_TEMP_RESULT.equals(str)) { - double wrist_temp=paramIntent.getDoubleExtra(KEY_TEMP_WRIST,0.0f); - double body_temp=paramIntent.getDoubleExtra(KEY_TEMP_BODY,0.0f); - String temperatureMsg= protocolAPIHelper.getTemperatureMSG(wrist_temp,body_temp); - ICLogger.i("发送体温测量值 "+temperatureMsg); - Deliver.sendLocationMSG(temperatureMsg); - + double wrist_temp = paramIntent.getDoubleExtra(KEY_TEMP_WRIST, 0.0f); + double body_temp = paramIntent.getDoubleExtra(KEY_TEMP_BODY, 0.0f); + String temperatureMsg = protocolAPIHelper.getTemperatureMSG(wrist_temp, body_temp); + ICLogger.i("发送体温测量值 " + temperatureMsg); + Deliver.sendLocationMSG(temperatureMsg); + }else if (ACTION_SET_SIT_RANGE.equals(str)) { + if (paramIntent.hasExtra( Constants.KEY_SIT_RANGE)){ + int sitrange=paramIntent.getIntExtra(Constants.KEY_SIT_RANGE,0); + Config.setKeepSitRangeInMinutes(paramContext,sitrange); + ICLogger.i("set KeepSitRange int "+sitrange+" minutes!"); + } } else { //如果来电了,还有未读的消息,干脆关掉,防止影响接电话。 if (mCustomDialog != null && mCustomDialog.isShowing()) { @@ -378,8 +386,6 @@ public class ProcessReceiver extends BroadcastReceiver { this.mCustomNotification.dismiss(); } } - - } public void sendStheartRateBroadcast(Context paramContext, String actionStr, int paramInt) {