Commit 21dc55ba by cuiliang.shi

时间段控制 下次触发时间更新

1 parent 6f2c82a4
...@@ -6,8 +6,8 @@ android { ...@@ -6,8 +6,8 @@ android {
applicationId "com.toscl.location.hengfeng" applicationId "com.toscl.location.hengfeng"
minSdkVersion 23 minSdkVersion 23
targetSdkVersion 28 targetSdkVersion 28
versionCode 3 versionCode 4
versionName "0.3" versionName "0.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
} }
buildTypes { buildTypes {
......
...@@ -277,7 +277,7 @@ public class LocationService extends Service { ...@@ -277,7 +277,7 @@ public class LocationService extends Service {
} }
} }
if (mRequestLocationCount > 15) { if (mRequestLocationCount > 12) {
if (mWifiLatitude != 0 && mWifiLongitude != 0 if (mWifiLatitude != 0 && mWifiLongitude != 0
&& mGpsLatitude != 0 && mGpsLongitude != 0) { && mGpsLatitude != 0 && mGpsLongitude != 0) {
LatLng wifiLatLng = new LatLng(mWifiLatitude, mWifiLongitude); LatLng wifiLatLng = new LatLng(mWifiLatitude, mWifiLongitude);
......
...@@ -262,7 +262,7 @@ public class PhoneUtils { ...@@ -262,7 +262,7 @@ public class PhoneUtils {
try { try {
Date nowTime = new SimpleDateFormat(format).parse(currentDateTime); Date nowTime = new SimpleDateFormat(format).parse(currentDateTime);
Date startTime = new SimpleDateFormat(format).parse(dateStart + " 00:00:00"); Date startTime = new SimpleDateFormat(format).parse(dateStart + " 00:00:00");
Date endTime = new SimpleDateFormat(format).parse(dateEnd + " 00:00:00"); Date endTime = new SimpleDateFormat(format).parse(dateEnd + " 24:00:00");
if (isEffectiveDate(nowTime, startTime, endTime)) { if (isEffectiveDate(nowTime, startTime, endTime)) {
runFlag = true; runFlag = true;
...@@ -278,24 +278,24 @@ public class PhoneUtils { ...@@ -278,24 +278,24 @@ public class PhoneUtils {
} }
public static int getNextDateStartInterval(Context context) { public static int getNextDateStartInterval(Context context) {
int interval = 10; int interval;
int begin = PreferencesUtil.getInstance(context)
.getInt(PreferencesUtil.HENG_FENG_BEGIN, PreferencesUtil.HENG_FENG_DEFAULT_BEGIN);
String format = "yyyy-MM-dd HH:mm:ss"; int currentHour = Integer.parseInt(new SimpleDateFormat("HH").format(new Date()));
SimpleDateFormat sf = new SimpleDateFormat(format); int currentMinute = Integer.parseInt(new SimpleDateFormat("mm").format(new Date()));
String currentDateTime = sf.format(new Date());
String dateStart = PreferencesUtil.getInstance(context)
.getString(PreferencesUtil.HENG_FENG_DATA_START, "");
try { int intervalForHour;
Date nowTime = new SimpleDateFormat(format).parse(currentDateTime);
Date startTime = new SimpleDateFormat(format).parse(dateStart + " 00:00:00");
interval = (int) ((startTime.getTime() - nowTime.getTime())/1000/60); if (currentHour > begin){
} catch (ParseException e) { intervalForHour = (24 - currentHour + begin)*60;
e.printStackTrace(); }else{
intervalForHour = (begin - currentHour)*60;
} }
interval = intervalForHour - currentMinute;
Log.d(TAG, "getNextDateStartInterval: interval:" + interval); Log.d(TAG, "getNextDateStartInterval: interval:" + interval);
return interval; return interval;
......
package com.toscl.location.hengfeng; package com.toscl.location.hengfeng;
import android.content.Context;
import android.util.Log;
import com.toscl.location.hengfeng.util.PhoneUtils;
import com.toscl.location.hengfeng.util.PreferencesUtil;
import org.junit.Test; import org.junit.Test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import static org.junit.Assert.*; import static org.junit.Assert.*;
/** /**
...@@ -12,6 +23,113 @@ import static org.junit.Assert.*; ...@@ -12,6 +23,113 @@ import static org.junit.Assert.*;
public class ExampleUnitTest { public class ExampleUnitTest {
@Test @Test
public void addition_isCorrect() { public void addition_isCorrect() {
assertEquals(4, 2 + 2); // assertEquals(4, 2 + 2);
if(hengdaServiceAvailable()){
if (isCurrentTimeInThePeriod()){
}else{
getNextDateStartInterval();
}
}
}
public static boolean hengdaServiceAvailable() {
String format = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat sf = new SimpleDateFormat(format);
String currentDateTime = "2019-7-30 23:00:00";
String dateStart = "2019-07-30";
String dateEnd = "2019-07-30";
boolean runFlag = false;
try {
Date nowTime = new SimpleDateFormat(format).parse(currentDateTime);
Date startTime = new SimpleDateFormat(format).parse(dateStart + " 00:00:00");
Date endTime = new SimpleDateFormat(format).parse(dateEnd + " 24:00:00");
if (isEffectiveDate(nowTime, startTime, endTime)) {
runFlag = true;
}
} catch (java.text.ParseException e) {
e.printStackTrace();
}
System.out.println("ServiceAvailable : runFlag: " + runFlag);
return runFlag;
}
public static int getNextDateStartInterval() {
int interval;
int begin = PreferencesUtil.HENG_FENG_DEFAULT_BEGIN;
int currentHour = 1;
int currentMinute = 22;
int intervalForHour;
if (currentHour > begin){
intervalForHour = (24 - currentHour + begin)*60;
}else{
intervalForHour = (begin - currentHour)*60;
}
interval = intervalForHour - currentMinute;
System.out.println("getNextDateStartInterval: interval:" + interval);
return interval;
}
public static boolean isCurrentTimeInThePeriod() {
String format = "HH:mm:ss";
SimpleDateFormat sf = new SimpleDateFormat(format);
String currentDateTime = "1:22:00";
boolean runFlag = false;
try {
Date nowTime = new SimpleDateFormat(format).parse(currentDateTime);
int begin = PreferencesUtil.HENG_FENG_DEFAULT_BEGIN;
int end =PreferencesUtil.HENG_FENG_DEFAULT_END;
Date startTime = new SimpleDateFormat(format).parse(begin + ":00:00");
Date endTime = new SimpleDateFormat(format).parse(end + ":00:00");
if (isEffectiveDate(nowTime, startTime, endTime)) {
runFlag = true;
}
} catch (java.text.ParseException e) {
e.printStackTrace();
}
System.out.println("isCurrentTimeInThePeriod - runFlag: " + runFlag);
return runFlag;
}
private static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
if (nowTime.getTime() == startTime.getTime()
|| nowTime.getTime() == endTime.getTime()) {
return true;
}
Calendar date = Calendar.getInstance();
date.setTime(nowTime);
Calendar begin = Calendar.getInstance();
begin.setTime(startTime);
Calendar end = Calendar.getInstance();
end.setTime(endTime);
return date.after(begin) && date.before(end);
} }
} }
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!