Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
odakyuToiletSignage
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
kddi
odakyuToiletSignage
Commits
95473f47
Commit
95473f47
authored
Jan 27, 2018
by
Kim Jinsung
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
端末の時間が初期化された場合、実行中のタスクを再作成するスレッド追加
parent
74123084
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
27 deletions
+57
-27
app/src/main/java/jp/odakyu/toiletsignage/application/ToiletApplication.java
+23
-1
app/src/main/java/jp/odakyu/toiletsignage/task/UpdateToiletInfoTask.java
+3
-26
app/src/main/java/jp/odakyu/toiletsignage/util/CommonUtil.java
+22
-0
app/src/main/java/jp/odakyu/toiletsignage/util/DateTimeUtil.java
+9
-0
No files found.
app/src/main/java/jp/odakyu/toiletsignage/application/ToiletApplication.java
View file @
95473f47
...
@@ -4,6 +4,7 @@ import android.app.ActivityManager;
...
@@ -4,6 +4,7 @@ import android.app.ActivityManager;
import
android.app.Application
;
import
android.app.Application
;
import
android.content.Context
;
import
android.content.Context
;
import
android.os.Environment
;
import
android.os.Environment
;
import
android.os.Handler
;
import
java.io.File
;
import
java.io.File
;
import
java.util.List
;
import
java.util.List
;
...
@@ -11,7 +12,9 @@ import java.util.Timer;
...
@@ -11,7 +12,9 @@ import java.util.Timer;
import
jp.odakyu.toiletsignage.log.Logger
;
import
jp.odakyu.toiletsignage.log.Logger
;
import
jp.odakyu.toiletsignage.task.UpdateToiletInfoTask
;
import
jp.odakyu.toiletsignage.task.UpdateToiletInfoTask
;
import
jp.odakyu.toiletsignage.util.FileUtil
;
import
jp.odakyu.toiletsignage.util.CommonUtil
;
import
jp.odakyu.toiletsignage.util.DateTimeFormat
;
import
jp.odakyu.toiletsignage.util.DateTimeUtil
;
import
static
jp
.
odakyu
.
toiletsignage
.
constants
.
ToiletConstants
.
APP_LOG_PATH
;
import
static
jp
.
odakyu
.
toiletsignage
.
constants
.
ToiletConstants
.
APP_LOG_PATH
;
...
@@ -32,6 +35,8 @@ public class ToiletApplication extends Application {
...
@@ -32,6 +35,8 @@ public class ToiletApplication extends Application {
String
logPath
=
downloadFilePath
.
getPath
()
+
"/"
+
APP_LOG_PATH
;
String
logPath
=
downloadFilePath
.
getPath
()
+
"/"
+
APP_LOG_PATH
;
logger
.
setLogPathFormat
(
logPath
);
logger
.
setLogPathFormat
(
logPath
);
Logger
.
i
(
TAG
,
"onCreate"
);
Logger
.
i
(
TAG
,
"onCreate"
);
taskManagerThread
();
}
}
public
synchronized
void
stopTimer
()
{
public
synchronized
void
stopTimer
()
{
...
@@ -73,4 +78,21 @@ public class ToiletApplication extends Application {
...
@@ -73,4 +78,21 @@ public class ToiletApplication extends Application {
}
}
return
isForeground
;
return
isForeground
;
}
}
private
void
taskManagerThread
()
{
final
Handler
handler
=
new
Handler
();
handler
.
post
(
new
Runnable
()
{
@Override
public
void
run
()
{
String
currentDateString
=
DateTimeUtil
.
toString
(
DateTimeUtil
.
getCurrentDate
(),
DateTimeFormat
.
yyyyMMddHHmmss_hyphen
);
Logger
.
d
(
TAG
,
"*** currentDate = "
+
currentDateString
);
if
(
DateTimeUtil
.
isAbnormalYear
()
&&
CommonUtil
.
isNetworkAvailable
(
getApplicationContext
()))
{
stopTimer
();
startTimer
();
Logger
.
d
(
TAG
,
"*** ReStartTime currentDate = "
+
currentDateString
);
}
handler
.
postDelayed
(
this
,
10000
);
//10秒後に再度実行
}
});
}
}
}
app/src/main/java/jp/odakyu/toiletsignage/task/UpdateToiletInfoTask.java
View file @
95473f47
...
@@ -2,7 +2,6 @@ package jp.odakyu.toiletsignage.task;
...
@@ -2,7 +2,6 @@ package jp.odakyu.toiletsignage.task;
import
android.content.Context
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.net.ConnectivityManager
;
import
org.json.JSONArray
;
import
org.json.JSONArray
;
import
org.json.JSONException
;
import
org.json.JSONException
;
...
@@ -10,12 +9,9 @@ import org.json.JSONObject;
...
@@ -10,12 +9,9 @@ import org.json.JSONObject;
import
java.io.DataOutputStream
;
import
java.io.DataOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
android.content.pm.PackageManager
;
import
android.content.pm.PackageManager.NameNotFoundException
;
import
java.sql.Timestamp
;
import
java.sql.Timestamp
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.TimerTask
;
import
java.util.TimerTask
;
import
jp.odakyu.toiletsignage.connection.NtpServerConnection
;
import
jp.odakyu.toiletsignage.connection.NtpServerConnection
;
...
@@ -25,6 +21,7 @@ import jp.odakyu.toiletsignage.info.ToiletInfo;
...
@@ -25,6 +21,7 @@ import jp.odakyu.toiletsignage.info.ToiletInfo;
import
jp.odakyu.toiletsignage.json.ResultToiletJson
;
import
jp.odakyu.toiletsignage.json.ResultToiletJson
;
import
jp.odakyu.toiletsignage.json.USBToiletDefaultJson
;
import
jp.odakyu.toiletsignage.json.USBToiletDefaultJson
;
import
jp.odakyu.toiletsignage.log.Logger
;
import
jp.odakyu.toiletsignage.log.Logger
;
import
jp.odakyu.toiletsignage.util.CommonUtil
;
import
jp.odakyu.toiletsignage.util.DateTimeFormat
;
import
jp.odakyu.toiletsignage.util.DateTimeFormat
;
import
jp.odakyu.toiletsignage.util.DateTimeUtil
;
import
jp.odakyu.toiletsignage.util.DateTimeUtil
;
...
@@ -34,7 +31,6 @@ import jp.odakyu.toiletsignage.util.DateTimeUtil;
...
@@ -34,7 +31,6 @@ import jp.odakyu.toiletsignage.util.DateTimeUtil;
public
class
UpdateToiletInfoTask
extends
TimerTask
{
public
class
UpdateToiletInfoTask
extends
TimerTask
{
private
static
final
String
TAG
=
"UpdateToiletInfoTask"
;
private
static
final
String
TAG
=
"UpdateToiletInfoTask"
;
private
static
final
int
TWO_THOUSAND_YEARS
=
2000
;
private
int
errorCount
=
0
;
private
int
errorCount
=
0
;
private
Context
applicationContext
;
private
Context
applicationContext
;
private
ToiletInfo
toiletInfo
;
private
ToiletInfo
toiletInfo
;
...
@@ -52,7 +48,7 @@ public class UpdateToiletInfoTask extends TimerTask {
...
@@ -52,7 +48,7 @@ public class UpdateToiletInfoTask extends TimerTask {
Logger
.
i
(
TAG
,
"Thread Start"
);
Logger
.
i
(
TAG
,
"Thread Start"
);
boolean
isNetworkConnect
=
true
;
boolean
isNetworkConnect
=
true
;
//インターネット接続チェック
//インターネット接続チェック
if
(
isNetworkAvailable
(
applicationContext
))
{
if
(
CommonUtil
.
isNetworkAvailable
(
applicationContext
))
{
ArrayList
<
USBToiletDefaultJson
>
toiletInfoArray
=
toiletInfo
.
getToiletDefaultJsonArray
();
ArrayList
<
USBToiletDefaultJson
>
toiletInfoArray
=
toiletInfo
.
getToiletDefaultJsonArray
();
boolean
isError
=
false
;
boolean
isError
=
false
;
boolean
isNtpServerCheck
=
false
;
boolean
isNtpServerCheck
=
false
;
...
@@ -107,30 +103,11 @@ public class UpdateToiletInfoTask extends TimerTask {
...
@@ -107,30 +103,11 @@ public class UpdateToiletInfoTask extends TimerTask {
}
}
/**
/**
* インターネット(Wifi)チェック
* @param context Application Context
* @return internet check
*/
private
boolean
isNetworkAvailable
(
Context
context
)
{
final
ConnectivityManager
connectivityManager
=
((
ConnectivityManager
)
context
.
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
));
return
connectivityManager
.
getActiveNetworkInfo
()
!=
null
&&
connectivityManager
.
getActiveNetworkInfo
().
isConnected
();
}
/**
* 端末時刻が異常かチェック(2000年未満)
* @return
*/
private
boolean
isAbnormalYear
()
{
int
currentYear
=
Integer
.
parseInt
(
DateTimeUtil
.
toStringInTimeZone
(
new
Date
(),
DateTimeFormat
.
yyyy
,
"UTC"
));
return
currentYear
<
TWO_THOUSAND_YEARS
;
}
/**
* NTPサーバーの時刻を取得し、端末時刻にセット
* NTPサーバーの時刻を取得し、端末時刻にセット
* @throws IOException
* @throws IOException
*/
*/
private
void
synchronizingNtpServerDate
()
throws
IOException
,
JSONException
{
private
void
synchronizingNtpServerDate
()
throws
IOException
,
JSONException
{
if
(
isAbnormalYear
())
{
if
(
DateTimeUtil
.
isAbnormalYear
())
{
String
jsonString
=
NtpServerConnection
.
connectionNtpServer
();
String
jsonString
=
NtpServerConnection
.
connectionNtpServer
();
JSONObject
jsonObject
=
new
JSONObject
(
jsonString
);
JSONObject
jsonObject
=
new
JSONObject
(
jsonString
);
Long
ntpTimeMillis
=
(
long
)
((
Double
)
jsonObject
.
get
(
"st"
)
*
1000
);
Long
ntpTimeMillis
=
(
long
)
((
Double
)
jsonObject
.
get
(
"st"
)
*
1000
);
...
...
app/src/main/java/jp/odakyu/toiletsignage/util/CommonUtil.java
0 → 100644
View file @
95473f47
package
jp
.
odakyu
.
toiletsignage
.
util
;
import
android.content.Context
;
import
android.net.ConnectivityManager
;
import
java.util.Date
;
/**
* Created by agentec on 2018/01/26.
*/
public
class
CommonUtil
{
/**
* インターネット(Wifi)チェック
* @param context Application Context
* @return internet check
*/
public
static
boolean
isNetworkAvailable
(
Context
context
)
{
final
ConnectivityManager
connectivityManager
=
((
ConnectivityManager
)
context
.
getSystemService
(
Context
.
CONNECTIVITY_SERVICE
));
return
connectivityManager
.
getActiveNetworkInfo
()
!=
null
&&
connectivityManager
.
getActiveNetworkInfo
().
isConnected
();
}
}
app/src/main/java/jp/odakyu/toiletsignage/util/DateTimeUtil.java
View file @
95473f47
...
@@ -538,4 +538,13 @@ public class DateTimeUtil {
...
@@ -538,4 +538,13 @@ public class DateTimeUtil {
df
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT"
));
df
.
setTimeZone
(
TimeZone
.
getTimeZone
(
"GMT"
));
return
df
.
format
(
date
)+
" GMT"
;
return
df
.
format
(
date
)+
" GMT"
;
}
}
/**
* 端末時刻が異常かチェック(2000年未満)
* @return
*/
public
static
boolean
isAbnormalYear
()
{
int
currentYear
=
Integer
.
parseInt
(
DateTimeUtil
.
toStringInTimeZone
(
new
Date
(),
DateTimeFormat
.
yyyy
,
"UTC"
));
return
currentYear
<
2000
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment