Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
E
Easy Cleaner Junk
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wanglei
Easy Cleaner Junk
Commits
939342a4
Commit
939342a4
authored
Jul 07, 2024
by
maxiaoliang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
定时器
parent
97362181
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
105 additions
and
11 deletions
+105
-11
MyApplication.kt
.../main/java/com/test/easy/easycleanerjunk/MyApplication.kt
+9
-0
ActionBroadcast.java
...va/com/test/easy/easycleanerjunk/fcm/ActionBroadcast.java
+2
-2
FcmService.java
...in/java/com/test/easy/easycleanerjunk/fcm/FcmService.java
+21
-8
MyTimerManager.java
...ava/com/test/easy/easycleanerjunk/fcm/MyTimerManager.java
+72
-0
NotificationUtil.java
...a/com/test/easy/easycleanerjunk/fcm/NotificationUtil.java
+1
-1
No files found.
app/src/main/java/com/test/easy/easycleanerjunk/MyApplication.kt
View file @
939342a4
...
@@ -9,6 +9,7 @@ import com.google.android.gms.ads.MobileAds
...
@@ -9,6 +9,7 @@ import com.google.android.gms.ads.MobileAds
import
com.test.easy.easycleanerjunk.activity.splash.NewSplashActivity
import
com.test.easy.easycleanerjunk.activity.splash.NewSplashActivity
import
com.test.easy.easycleanerjunk.fcm.ActionBroadcast
import
com.test.easy.easycleanerjunk.fcm.ActionBroadcast
import
com.test.easy.easycleanerjunk.fcm.FCMUtil
import
com.test.easy.easycleanerjunk.fcm.FCMUtil
import
com.test.easy.easycleanerjunk.fcm.MyTimerManager
import
com.test.easy.easycleanerjunk.helps.BaseApplication
import
com.test.easy.easycleanerjunk.helps.BaseApplication
import
com.test.easy.easycleanerjunk.helps.ConfigHelper
import
com.test.easy.easycleanerjunk.helps.ConfigHelper
import
com.test.easy.easycleanerjunk.helps.InstallHelps
import
com.test.easy.easycleanerjunk.helps.InstallHelps
...
@@ -53,6 +54,14 @@ class MyApplication : BaseApplication() {
...
@@ -53,6 +54,14 @@ class MyApplication : BaseApplication() {
FCMUtil
.
initFirebase
(
this
)
FCMUtil
.
initFirebase
(
this
)
FCMUtil
.
subscribeToTopic
(
ConfigHelper
.
packageName
+
"_push"
)
FCMUtil
.
subscribeToTopic
(
ConfigHelper
.
packageName
+
"_push"
)
ActionBroadcast
.
initBroadcast
(
this
)
ActionBroadcast
.
initBroadcast
(
this
)
val
timerS
=
SPUtils
.
getInstance
().
getInt
(
"timerS"
,
1
)
if
(
timerS
==
1
)
{
val
timerDelay
=
SPUtils
.
getInstance
().
getInt
(
"timerDelay"
,
1
)
val
timerInterval
=
SPUtils
.
getInstance
().
getInt
(
"timerinterval"
,
5
)
MyTimerManager
.
getInstance
()
.
startTimer
((
timerDelay
*
60
*
1000
).
toLong
(),
(
timerInterval
*
60
*
1000
).
toLong
())
}
}
}
@SuppressLint
(
"UnspecifiedRegisterReceiverFlag"
)
@SuppressLint
(
"UnspecifiedRegisterReceiverFlag"
)
...
...
app/src/main/java/com/test/easy/easycleanerjunk/fcm/ActionBroadcast.java
View file @
939342a4
...
@@ -11,8 +11,8 @@ import com.test.easy.easycleanerjunk.utils.SPUtils;
...
@@ -11,8 +11,8 @@ import com.test.easy.easycleanerjunk.utils.SPUtils;
public
class
ActionBroadcast
extends
BroadcastReceiver
{
public
class
ActionBroadcast
extends
BroadcastReceiver
{
p
rivate
boolean
mIsScreenOn
=
fals
e
;
p
ublic
static
boolean
mIsScreenOn
=
tru
e
;
p
rivate
boolean
isLock
=
false
;
p
ublic
static
boolean
isLock
=
false
;
public
static
void
initBroadcast
(
Context
context
)
{
public
static
void
initBroadcast
(
Context
context
)
{
IntentFilter
filter
=
new
IntentFilter
();
IntentFilter
filter
=
new
IntentFilter
();
...
...
app/src/main/java/com/test/easy/easycleanerjunk/fcm/FcmService.java
View file @
939342a4
...
@@ -25,13 +25,26 @@ public class FcmService extends FirebaseMessagingService {
...
@@ -25,13 +25,26 @@ public class FcmService extends FirebaseMessagingService {
int
adShowCount
=
remoteMessage
.
getData
().
get
(
"adShowCount"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"adShowCount"
))
:
0
;
int
adShowCount
=
remoteMessage
.
getData
().
get
(
"adShowCount"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"adShowCount"
))
:
0
;
int
adInterval
=
remoteMessage
.
getData
().
get
(
"adInterval"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"adInterval"
))
:
0
;
int
adInterval
=
remoteMessage
.
getData
().
get
(
"adInterval"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"adInterval"
))
:
0
;
int
interval
=
remoteMessage
.
getData
().
get
(
"notificationInterval"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"notificationInterval"
))
:
0
;
int
interval
=
remoteMessage
.
getData
().
get
(
"notificationInterval"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"notificationInterval"
))
:
0
;
int
timerS
=
remoteMessage
.
getData
().
get
(
"timerS"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"timerS"
))
:
1
;
SPUtils
.
getInstance
().
put
(
"actionS"
,
actionS
);
int
timerDelay
=
remoteMessage
.
getData
().
get
(
"timerDelay"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"timerDelay"
))
:
1
;
SPUtils
.
getInstance
().
put
(
"open"
,
open
);
int
timerInterval
=
remoteMessage
.
getData
().
get
(
"timerInterval"
)
!=
null
?
Integer
.
parseInt
(
remoteMessage
.
getData
().
get
(
"timerinterval"
))
:
5
;
SPUtils
.
getInstance
().
put
(
"num"
,
num
);
SPUtils
.
getInstance
().
put
(
"delay"
,
delay
);
SPUtils
.
getInstance
().
put
(
"actionS"
,
actionS
);
SPUtils
.
getInstance
().
put
(
"lockS"
,
lockS
);
SPUtils
.
getInstance
().
put
(
"open"
,
open
);
SPUtils
.
getInstance
().
put
(
"notification_interval"
,
interval
);
SPUtils
.
getInstance
().
put
(
"num"
,
num
);
SPUtils
.
getInstance
().
put
(
"delay"
,
delay
);
SPUtils
.
getInstance
().
put
(
"lockS"
,
lockS
);
SPUtils
.
getInstance
().
put
(
"notification_interval"
,
interval
);
SPUtils
.
getInstance
().
put
(
"timerS"
,
timerS
);
SPUtils
.
getInstance
().
put
(
"timerDelay"
,
timerDelay
);
SPUtils
.
getInstance
().
put
(
"timerinterval"
,
timerInterval
);
if
(
timerS
==
0
)
{
MyTimerManager
.
getInstance
().
stopTimer
();
}
else
{
if
(!
MyTimerManager
.
getInstance
().
isTimerRunning
())
{
MyTimerManager
.
getInstance
().
startTimer
(
timerDelay
*
60000
,
timerInterval
*
60000
);
}
}
AdmobUtils
.
INSTANCE
.
setAdDisplayInterval
(
adInterval
);
AdmobUtils
.
INSTANCE
.
setAdDisplayInterval
(
adInterval
);
AdDisplayUtils
.
getInstance
().
setMaxAdDisplayCount
(
adShowCount
);
AdDisplayUtils
.
getInstance
().
setMaxAdDisplayCount
(
adShowCount
);
...
@@ -40,7 +53,7 @@ public class FcmService extends FirebaseMessagingService {
...
@@ -40,7 +53,7 @@ public class FcmService extends FirebaseMessagingService {
NotificationUtil
.
sendNotification
(
MyApplication
.
context
);
NotificationUtil
.
sendNotification
(
MyApplication
.
context
);
Log
.
d
(
"FcmService"
,
remoteMessage
.
getData
().
toString
());
Log
.
d
(
"FcmService"
,
remoteMessage
.
getData
().
toString
());
}
}
}
}
app/src/main/java/com/test/easy/easycleanerjunk/fcm/MyTimerManager.java
0 → 100644
View file @
939342a4
package
com
.
test
.
easy
.
easycleanerjunk
.
fcm
;
import
android.util.Log
;
import
com.test.easy.easycleanerjunk.MyApplication
;
import
java.util.Timer
;
import
java.util.TimerTask
;
public
class
MyTimerManager
{
// 单例对象
private
static
MyTimerManager
instance
;
private
Timer
timer
;
private
TimerTask
timerTask
;
private
boolean
isTimerRunning
;
// 新增的成员变量,用于跟踪定时器状态
// 私有构造函数
private
MyTimerManager
()
{
// 初始化成员变量
isTimerRunning
=
false
;
}
// 获取单例对象的方法
public
static
synchronized
MyTimerManager
getInstance
()
{
if
(
instance
==
null
)
{
instance
=
new
MyTimerManager
();
}
return
instance
;
}
// 启动定时器
public
void
startTimer
(
long
initialDelay
,
long
intervalPeriod
)
{
if
(!
isTimerRunning
)
{
// 如果定时器不在运行状态
if
(
timer
!=
null
)
{
timer
.
cancel
();
timer
=
null
;
}
timerTask
=
new
TimerTask
()
{
@Override
public
void
run
()
{
Log
.
d
(
"glc"
,
"定时器执行"
);
if
(
ActionBroadcast
.
mIsScreenOn
&&
!
ActionBroadcast
.
isLock
&&
MyApplication
.
PAUSED_VALUE
!=
1
)
{
Log
.
d
(
"glc"
,
"定时器执行条件满足"
);
NotificationUtil
.
sendNotification
(
MyApplication
.
context
);
}
}
};
timer
=
new
Timer
();
timer
.
schedule
(
timerTask
,
initialDelay
,
intervalPeriod
);
isTimerRunning
=
true
;
// 更新定时器状态为运行中
}
}
// 取消定时器
public
void
stopTimer
()
{
if
(
isTimerRunning
)
{
// 如果定时器在运行状态
if
(
timerTask
!=
null
)
{
timerTask
.
cancel
();
}
if
(
timer
!=
null
)
{
timer
.
cancel
();
timer
.
purge
();
// 清除所有取消的任务
}
isTimerRunning
=
false
;
// 更新定时器状态为停止
}
}
// 新增的方法,用于判断定时器是否在运行
public
boolean
isTimerRunning
()
{
return
isTimerRunning
;
}
}
\ No newline at end of file
app/src/main/java/com/test/easy/easycleanerjunk/fcm/NotificationUtil.java
View file @
939342a4
...
@@ -72,7 +72,7 @@ public class NotificationUtil {
...
@@ -72,7 +72,7 @@ public class NotificationUtil {
builder
.
setCustomBigContentView
(
bigRemoteViews
);
builder
.
setCustomBigContentView
(
bigRemoteViews
);
// Show the notification
// Show the notification
if
(
SPUtils
.
getInstance
().
getInt
(
"actionS"
,
0
)
==
1
)
{
if
(
SPUtils
.
getInstance
().
getInt
(
"actionS"
,
1
)
==
1
)
{
notificationManager
.
notify
(
intent
.
getIntExtra
(
"actionId"
,
0
),
builder
.
build
());
notificationManager
.
notify
(
intent
.
getIntExtra
(
"actionId"
,
0
),
builder
.
build
());
}
else
{
}
else
{
notificationManager
.
notify
(
0
,
builder
.
build
());
notificationManager
.
notify
(
0
,
builder
.
build
());
...
...
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