Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
石璀亮
/
agenew_a16_sos
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 21dc55ba
authored
Jul 30, 2019
by
cuiliang.shi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
时间段控制 下次触发时间更新
1 parent
6f2c82a4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
137 additions
and
18 deletions
app/build.gradle
app/src/main/java/com/toscl/location/hengfeng/LocationService.java
app/src/main/java/com/toscl/location/hengfeng/util/PhoneUtils.java
app/src/test/java/com/toscl/location/hengfeng/ExampleUnitTest.java
app/build.gradle
View file @
21dc55b
...
...
@@ -6,8 +6,8 @@ android {
applicationId
"com.toscl.location.hengfeng"
minSdkVersion
23
targetSdkVersion
28
versionCode
3
versionName
"0.
3
"
versionCode
4
versionName
"0.
4
"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes
{
...
...
app/src/main/java/com/toscl/location/hengfeng/LocationService.java
View file @
21dc55b
...
...
@@ -277,7 +277,7 @@ public class LocationService extends Service {
}
}
if
(
mRequestLocationCount
>
1
5
)
{
if
(
mRequestLocationCount
>
1
2
)
{
if
(
mWifiLatitude
!=
0
&&
mWifiLongitude
!=
0
&&
mGpsLatitude
!=
0
&&
mGpsLongitude
!=
0
)
{
LatLng
wifiLatLng
=
new
LatLng
(
mWifiLatitude
,
mWifiLongitude
);
...
...
app/src/main/java/com/toscl/location/hengfeng/util/PhoneUtils.java
View file @
21dc55b
...
...
@@ -262,7 +262,7 @@ public class PhoneUtils {
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
+
"
00
:00:00"
);
Date
endTime
=
new
SimpleDateFormat
(
format
).
parse
(
dateEnd
+
"
24
:00:00"
);
if
(
isEffectiveDate
(
nowTime
,
startTime
,
endTime
))
{
runFlag
=
true
;
...
...
@@ -278,24 +278,24 @@ public class PhoneUtils {
}
public
static
int
getNextDateStartInterval
(
Context
context
)
{
int
interval
=
10
;
String
format
=
"yyyy-MM-dd HH:mm:ss"
;
SimpleDateFormat
sf
=
new
SimpleDateFormat
(
format
);
String
currentDateTime
=
sf
.
format
(
new
Date
());
int
interval
;
int
begin
=
PreferencesUtil
.
getInstance
(
context
)
.
getInt
(
PreferencesUtil
.
HENG_FENG_BEGIN
,
PreferencesUtil
.
HENG_FENG_DEFAULT_BEGIN
);
String
dateStart
=
PreferencesUtil
.
getInstance
(
context
)
.
getString
(
PreferencesUtil
.
HENG_FENG_DATA_START
,
""
);
int
currentHour
=
Integer
.
parseInt
(
new
SimpleDateFormat
(
"HH"
).
format
(
new
Date
()));
int
currentMinute
=
Integer
.
parseInt
(
new
SimpleDateFormat
(
"mm"
).
format
(
new
Date
())
);
try
{
Date
nowTime
=
new
SimpleDateFormat
(
format
).
parse
(
currentDateTime
);
Date
startTime
=
new
SimpleDateFormat
(
format
).
parse
(
dateStart
+
" 00:00:00"
);
int
intervalForHour
;
interval
=
(
int
)
((
startTime
.
getTime
()
-
nowTime
.
getTime
())/
1000
/
60
);
}
catch
(
ParseException
e
)
{
e
.
printStackTrace
();
if
(
currentHour
>
begin
){
intervalForHour
=
(
24
-
currentHour
+
begin
)*
60
;
}
else
{
intervalForHour
=
(
begin
-
currentHour
)*
60
;
}
interval
=
intervalForHour
-
currentMinute
;
Log
.
d
(
TAG
,
"getNextDateStartInterval: interval:"
+
interval
);
return
interval
;
...
...
app/src/test/java/com/toscl/location/hengfeng/ExampleUnitTest.java
View file @
21dc55b
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
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.Calendar
;
import
java.util.Date
;
import
static
org
.
junit
.
Assert
.*;
/**
...
...
@@ -12,6 +23,113 @@ import static org.junit.Assert.*;
public
class
ExampleUnitTest
{
@Test
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
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment