Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
L
location share white
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
location share white
Commits
5d198b5b
Commit
5d198b5b
authored
Oct 25, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
08f5a0d0
5a27f3c3
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
346 additions
and
10 deletions
+346
-10
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+8
-0
AdsMgr.kt
app/src/main/java/com/base/locationsharewhite/ads/AdsMgr.kt
+1
-1
AdInsertMgr.kt
...java/com/base/locationsharewhite/ads/admob/AdInsertMgr.kt
+7
-4
AdOpenMgr.kt
...n/java/com/base/locationsharewhite/ads/admob/AdOpenMgr.kt
+8
-4
LimitUtils.kt
.../java/com/base/locationsharewhite/ads/admob/LimitUtils.kt
+8
-1
BatteryStatusReceiver.kt
.../com/base/locationsharewhite/fcm/BatteryStatusReceiver.kt
+43
-0
FCMManager.java
...main/java/com/base/locationsharewhite/fcm/FCMManager.java
+49
-0
MessagingService.java
...ava/com/base/locationsharewhite/fcm/MessagingService.java
+23
-0
MsgMgr.kt
app/src/main/java/com/base/locationsharewhite/fcm/MsgMgr.kt
+28
-0
PackageStatusReceiver.kt
.../com/base/locationsharewhite/fcm/PackageStatusReceiver.kt
+38
-0
ScreenStatusReceiver.java
...com/base/locationsharewhite/fcm/ScreenStatusReceiver.java
+73
-0
TimerManager.java
...in/java/com/base/locationsharewhite/fcm/TimerManager.java
+60
-0
No files found.
app/src/main/AndroidManifest.xml
View file @
5d198b5b
...
@@ -112,6 +112,14 @@
...
@@ -112,6 +112,14 @@
<meta-data
<meta-data
android:name=
"com.facebook.sdk.ApplicationId"
android:name=
"com.facebook.sdk.ApplicationId"
android:value=
"@string/facebook_app_id"
/>
android:value=
"@string/facebook_app_id"
/>
<service
android:name=
".fcm.MessagingService"
android:exported=
"false"
>
<intent-filter>
<action
android:name=
"com.google.firebase.MESSAGING_EVENT"
/>
</intent-filter>
</service>
</application>
</application>
</manifest>
</manifest>
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/ads/AdsMgr.kt
View file @
5d198b5b
...
@@ -48,8 +48,8 @@ object AdsMgr {
...
@@ -48,8 +48,8 @@ object AdsMgr {
* @param context 这里最好是appContext,因为是耗时操作,等它初始化完毕马上加载开屏和插屏广告
* @param context 这里最好是appContext,因为是耗时操作,等它初始化完毕马上加载开屏和插屏广告
*/
*/
fun
init
(
context
:
Context
,
adsConfigBean
:
AdsConfigBean
)
{
fun
init
(
context
:
Context
,
adsConfigBean
:
AdsConfigBean
)
{
this
.
adsConfigBean
=
adsConfigBean
if
(
adsConfigBean
.
isInBlackList
)
return
if
(
adsConfigBean
.
isInBlackList
)
return
this
.
adsConfigBean
=
adsConfigBean
MobileAds
.
initialize
(
context
)
{
MobileAds
.
initialize
(
context
)
{
val
readyAdapter
=
it
.
adapterStatusMap
.
entries
.
find
{
entry
->
val
readyAdapter
=
it
.
adapterStatusMap
.
entries
.
find
{
entry
->
entry
.
value
.
initializationState
==
AdapterStatus
.
State
.
READY
entry
.
value
.
initializationState
==
AdapterStatus
.
State
.
READY
...
...
app/src/main/java/com/base/locationsharewhite/ads/admob/AdInsertMgr.kt
View file @
5d198b5b
...
@@ -19,6 +19,8 @@ import java.lang.ref.WeakReference
...
@@ -19,6 +19,8 @@ import java.lang.ref.WeakReference
*/
*/
class
AdInsertMgr
:
BaseAdMgr
<
InterstitialAd
>()
{
class
AdInsertMgr
:
BaseAdMgr
<
InterstitialAd
>()
{
private
var
lastOpenDate
:
Long
=
0
private
val
adLoadCallback
=
object
:
InterstitialAdLoadCallback
()
{
private
val
adLoadCallback
=
object
:
InterstitialAdLoadCallback
()
{
override
fun
onAdLoaded
(
ad
:
InterstitialAd
)
{
override
fun
onAdLoaded
(
ad
:
InterstitialAd
)
{
super
.
onAdLoaded
(
ad
)
super
.
onAdLoaded
(
ad
)
...
@@ -60,7 +62,9 @@ class AdInsertMgr : BaseAdMgr<InterstitialAd>() {
...
@@ -60,7 +62,9 @@ class AdInsertMgr : BaseAdMgr<InterstitialAd>() {
}
}
override
fun
show
(
activity
:
Activity
,
showCallBack
:
AdsShowCallBack
?)
{
override
fun
show
(
activity
:
Activity
,
showCallBack
:
AdsShowCallBack
?)
{
if
(
activity
.
isFinishing
||
activity
.
isDestroyed
||
!
LimitUtils
.
isAdShow
())
{
if
(
activity
.
isFinishing
||
activity
.
isDestroyed
||
!
LimitUtils
.
isAdShow
()||
LimitUtils
.
isIntervalLimited
(
lastOpenDate
))
{
showCallBack
?.
failed
()
showCallBack
?.
failed
()
return
return
}
}
...
@@ -88,6 +92,7 @@ class AdInsertMgr : BaseAdMgr<InterstitialAd>() {
...
@@ -88,6 +92,7 @@ class AdInsertMgr : BaseAdMgr<InterstitialAd>() {
fullScreenContentCallback
=
object
:
FullScreenContentCallback
()
{
fullScreenContentCallback
=
object
:
FullScreenContentCallback
()
{
override
fun
onAdShowedFullScreenContent
()
{
override
fun
onAdShowedFullScreenContent
()
{
super
.
onAdShowedFullScreenContent
()
super
.
onAdShowedFullScreenContent
()
lastOpenDate
=
System
.
currentTimeMillis
()
// 广告展示
// 广告展示
currentAd
=
null
currentAd
=
null
activityRef
=
null
activityRef
=
null
...
@@ -128,7 +133,5 @@ class AdInsertMgr : BaseAdMgr<InterstitialAd>() {
...
@@ -128,7 +133,5 @@ class AdInsertMgr : BaseAdMgr<InterstitialAd>() {
}
}
}
}
override
fun
adAvailable
():
Boolean
{
override
fun
adAvailable
()=((
System
.
currentTimeMillis
()
-
lastTime
)
/
1000
/
60
).
toInt
()
<
30
return
((
System
.
currentTimeMillis
()
-
lastTime
)
/
1000
/
60
).
toInt
()
<
30
}
}
}
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/ads/admob/AdOpenMgr.kt
View file @
5d198b5b
...
@@ -18,6 +18,8 @@ import java.lang.ref.WeakReference
...
@@ -18,6 +18,8 @@ import java.lang.ref.WeakReference
*/
*/
class
AdOpenMgr
:
BaseAdMgr
<
AppOpenAd
>()
{
class
AdOpenMgr
:
BaseAdMgr
<
AppOpenAd
>()
{
private
var
lastOpenDate
:
Long
=
0
private
val
adLoadCallback
=
object
:
AppOpenAd
.
AppOpenAdLoadCallback
()
{
private
val
adLoadCallback
=
object
:
AppOpenAd
.
AppOpenAdLoadCallback
()
{
override
fun
onAdLoaded
(
appOpenAd
:
AppOpenAd
)
{
override
fun
onAdLoaded
(
appOpenAd
:
AppOpenAd
)
{
super
.
onAdLoaded
(
appOpenAd
)
super
.
onAdLoaded
(
appOpenAd
)
...
@@ -59,7 +61,10 @@ class AdOpenMgr : BaseAdMgr<AppOpenAd>() {
...
@@ -59,7 +61,10 @@ class AdOpenMgr : BaseAdMgr<AppOpenAd>() {
}
}
override
fun
show
(
activity
:
Activity
,
showCallBack
:
AdsShowCallBack
?)
{
override
fun
show
(
activity
:
Activity
,
showCallBack
:
AdsShowCallBack
?)
{
if
(
activity
.
isFinishing
||
activity
.
isDestroyed
||
!
LimitUtils
.
isAdShow
())
{
if
(
activity
.
isFinishing
||
activity
.
isDestroyed
||
!
LimitUtils
.
isAdShow
()
||
LimitUtils
.
isIntervalLimited
(
lastOpenDate
)
)
{
showCallBack
?.
failed
()
showCallBack
?.
failed
()
return
return
}
}
...
@@ -87,6 +92,7 @@ class AdOpenMgr : BaseAdMgr<AppOpenAd>() {
...
@@ -87,6 +92,7 @@ class AdOpenMgr : BaseAdMgr<AppOpenAd>() {
fullScreenContentCallback
=
object
:
FullScreenContentCallback
()
{
fullScreenContentCallback
=
object
:
FullScreenContentCallback
()
{
override
fun
onAdShowedFullScreenContent
()
{
override
fun
onAdShowedFullScreenContent
()
{
super
.
onAdShowedFullScreenContent
()
super
.
onAdShowedFullScreenContent
()
lastOpenDate
=
System
.
currentTimeMillis
()
// 广告展示
// 广告展示
currentAd
=
null
currentAd
=
null
activityRef
=
null
activityRef
=
null
...
@@ -126,7 +132,5 @@ class AdOpenMgr : BaseAdMgr<AppOpenAd>() {
...
@@ -126,7 +132,5 @@ class AdOpenMgr : BaseAdMgr<AppOpenAd>() {
}
}
}
}
override
fun
adAvailable
():
Boolean
{
override
fun
adAvailable
()
=
((
System
.
currentTimeMillis
()
-
lastTime
)
/
1000
/
60
).
toInt
()
<
30
return
((
System
.
currentTimeMillis
()
-
lastTime
)
/
1000
/
60
).
toInt
()
<
30
}
}
}
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/ads/admob/LimitUtils.kt
View file @
5d198b5b
...
@@ -95,5 +95,12 @@ object LimitUtils {
...
@@ -95,5 +95,12 @@ object LimitUtils {
addNum
(
NUM_CLICK
)
addNum
(
NUM_CLICK
)
}
}
/**
* 开屏和插页广告的显示间隔限制
*
* @param lastTime 上一次显示的时间
*/
fun
isIntervalLimited
(
lastTime
:
Long
)
=
((
System
.
currentTimeMillis
()
-
lastTime
)
/
1000
/
60
).
toInt
()
<
(
AdsMgr
.
adsConfigBean
?.
timeInterval
?:
1
)
}
}
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/fcm/BatteryStatusReceiver.kt
0 → 100644
View file @
5d198b5b
package
com.base.locationsharewhite.fcm
import
android.content.BroadcastReceiver
import
android.content.Context
import
android.content.Intent
import
android.content.IntentFilter
import
android.os.BatteryManager
import
android.os.Build
/**
*电量监听
*/
class
BatteryStatusReceiver
:
BroadcastReceiver
()
{
companion
object
{
fun
registerBatteryReceiver
(
context
:
Context
)
{
val
intentFilter
=
IntentFilter
().
apply
{
addAction
(
Intent
.
ACTION_BATTERY_CHANGED
)
}
val
applicationContext
=
context
.
applicationContext
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
TIRAMISU
)
{
applicationContext
.
registerReceiver
(
BatteryStatusReceiver
(),
intentFilter
,
Context
.
RECEIVER_EXPORTED
)
}
else
{
applicationContext
.
registerReceiver
(
BatteryStatusReceiver
(),
intentFilter
)
}
}
}
override
fun
onReceive
(
context
:
Context
?,
intent
:
Intent
?)
{
val
action
=
intent
?.
action
if
(
action
==
Intent
.
ACTION_BATTERY_CHANGED
)
{
val
batteryLevel
=
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_LEVEL
,
-
1
)
val
batteryScale
=
intent
.
getIntExtra
(
BatteryManager
.
EXTRA_SCALE
,
-
1
)
val
batteryPercentage
=
(
batteryLevel
/
batteryScale
.
toFloat
())
*
100
}
}
}
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/fcm/FCMManager.java
0 → 100644
View file @
5d198b5b
package
com
.
base
.
locationsharewhite
.
fcm
;
import
android.content.Context
;
import
android.util.Log
;
import
androidx.annotation.NonNull
;
import
com.base.locationsharewhite.utils.LogEx
;
import
com.google.android.gms.tasks.OnCompleteListener
;
import
com.google.android.gms.tasks.Task
;
import
com.google.firebase.FirebaseApp
;
import
com.google.firebase.messaging.FirebaseMessaging
;
public
class
FCMManager
{
public
static
void
initFirebase
(
Context
context
)
{
FirebaseApp
.
initializeApp
(
context
);
}
public
static
void
subscribeToTopic
(
String
topic
)
{
FirebaseMessaging
.
getInstance
().
subscribeToTopic
(
topic
)
.
addOnCompleteListener
(
new
OnCompleteListener
<
Void
>()
{
@Override
public
void
onComplete
(
@NonNull
Task
<
Void
>
task
)
{
if
(
task
.
isSuccessful
())
{
LogEx
.
INSTANCE
.
logDebug
(
"FCMUtil"
,
"suc:"
+
topic
,
false
);
// EventUtils.INSTANCE.event("FCM_Topic_" + topic, null, null, false);
}
else
{
Log
.
d
(
"FCMUtil"
,
"fail"
);
}
}
});
}
public
static
void
unsubscribeFromTopic
(
String
topic
)
{
FirebaseMessaging
.
getInstance
().
unsubscribeFromTopic
(
topic
)
.
addOnCompleteListener
(
new
OnCompleteListener
<
Void
>()
{
@Override
public
void
onComplete
(
@NonNull
Task
<
Void
>
task
)
{
if
(
task
.
isSuccessful
())
{
}
else
{
}
}
});
}
}
app/src/main/java/com/base/locationsharewhite/fcm/MessagingService.java
0 → 100644
View file @
5d198b5b
package
com
.
base
.
locationsharewhite
.
fcm
;
import
android.annotation.SuppressLint
;
import
androidx.annotation.NonNull
;
import
com.google.firebase.messaging.FirebaseMessagingService
;
import
com.google.firebase.messaging.RemoteMessage
;
@SuppressLint
(
"MissingFirebaseInstanceTokenRefresh"
)
public
class
MessagingService
extends
FirebaseMessagingService
{
private
static
final
String
TAG
=
"MessagingService"
;
@Override
public
void
onMessageReceived
(
@NonNull
RemoteMessage
remoteMessage
)
{
super
.
onMessageReceived
(
remoteMessage
);
}
}
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/fcm/MsgMgr.kt
0 → 100644
View file @
5d198b5b
package
com.base.locationsharewhite.fcm
import
android.content.Context
import
com.base.locationsharewhite.helper.ConfigHelper
import
com.base.locationsharewhite.utils.AppPreferences
import
com.base.locationsharewhite.utils.KotlinExt.toFormatMinute
object
MsgMgr
{
/**
* FCM主题订阅 Topic 包名+首次启动的当前的分钟
*/
private
var
topic
get
()
=
AppPreferences
.
getInstance
().
getString
(
"topic"
,
""
)
set
(
value
)
=
AppPreferences
.
getInstance
().
put
(
"topic"
,
value
)
fun
init
(
context
:
Context
)
{
FCMManager
.
initFirebase
(
context
)
var
topic
=
this
.
topic
if
(
topic
.
isEmpty
())
{
val
topicNumber
=
System
.
currentTimeMillis
().
toFormatMinute
()
topic
=
ConfigHelper
.
packageName
+
"_$topicNumber"
this
.
topic
=
topic
}
FCMManager
.
subscribeToTopic
(
topic
)
}
}
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/fcm/PackageStatusReceiver.kt
0 → 100644
View file @
5d198b5b
package
com.base.locationsharewhite.fcm
import
android.content.BroadcastReceiver
import
android.content.Context
import
android.content.Intent
import
android.content.IntentFilter
import
android.os.Build
class
PackageStatusReceiver
:
BroadcastReceiver
()
{
companion
object
{
fun
registerBatteryReceiver
(
context
:
Context
)
{
val
intentFilter
=
IntentFilter
().
apply
{
addAction
(
Intent
.
ACTION_PACKAGE_ADDED
)
addAction
(
Intent
.
ACTION_PACKAGE_REMOVED
)
addDataScheme
(
"package"
)
}
val
applicationContext
=
context
.
applicationContext
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
TIRAMISU
)
{
applicationContext
.
registerReceiver
(
PackageStatusReceiver
(),
intentFilter
,
Context
.
RECEIVER_EXPORTED
)
}
else
{
applicationContext
.
registerReceiver
(
PackageStatusReceiver
(),
intentFilter
)
}
}
}
override
fun
onReceive
(
context
:
Context
?,
intent
:
Intent
?)
{
val
action
=
intent
?.
action
if
(
action
==
Intent
.
ACTION_PACKAGE_ADDED
||
action
==
Intent
.
ACTION_PACKAGE_REMOVED
)
{
}
}
}
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/fcm/ScreenStatusReceiver.java
0 → 100644
View file @
5d198b5b
package
com
.
base
.
locationsharewhite
.
fcm
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.IntentFilter
;
import
android.os.Build
;
import
com.base.locationsharewhite.utils.AppPreferences
;
import
java.util.Objects
;
public
class
ScreenStatusReceiver
extends
BroadcastReceiver
{
private
static
boolean
isDeviceInteractive
=
true
;
private
static
boolean
isSecureLockActive
=
false
;
public
static
void
setupScreenStatusListener
(
Context
context
)
{
IntentFilter
intentFilter
=
new
IntentFilter
();
intentFilter
.
addAction
(
Intent
.
ACTION_SCREEN_OFF
);
intentFilter
.
addAction
(
Intent
.
ACTION_SCREEN_ON
);
intentFilter
.
addAction
(
Intent
.
ACTION_USER_PRESENT
);
final
Context
applicationContext
=
context
.
getApplicationContext
();
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
TIRAMISU
)
{
applicationContext
.
registerReceiver
(
new
ScreenStatusReceiver
(),
intentFilter
,
Context
.
RECEIVER_EXPORTED
);
}
else
{
applicationContext
.
registerReceiver
(
new
ScreenStatusReceiver
(),
intentFilter
);
}
}
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
String
action
=
intent
.
getAction
();
switch
(
Objects
.
requireNonNull
(
action
))
{
case
Intent
.
ACTION_SCREEN_ON
:
setDeviceInteractive
(
true
);
break
;
case
Intent
.
ACTION_SCREEN_OFF
:
setDeviceInteractive
(
false
);
setSecureLockActive
(
true
);
break
;
case
Intent
.
ACTION_USER_PRESENT
:
setSecureLockActive
(
false
);
if
(
isDeviceInteractive
()
&&
!
isSecureLockActive
())
{
int
secureSetting
=
Integer
.
parseInt
(
AppPreferences
.
getInstance
().
getString
(
"lockS"
,
"1"
));
if
(
secureSetting
==
1
)
{
// String actionId = NotificationUiUtil.INSTANCE.getNextActionId();
// NotificationUiUtil.INSTANCE.sendNotificationIfCan(context, actionId, PopupConstObject.POPUP_WHERE_LOCK);
}
}
break
;
}
}
private
void
setDeviceInteractive
(
boolean
interactive
)
{
isDeviceInteractive
=
interactive
;
}
public
static
boolean
isDeviceInteractive
()
{
return
isDeviceInteractive
;
}
private
void
setSecureLockActive
(
boolean
active
)
{
isSecureLockActive
=
active
;
}
public
static
boolean
isSecureLockActive
()
{
return
isSecureLockActive
;
}
}
\ No newline at end of file
app/src/main/java/com/base/locationsharewhite/fcm/TimerManager.java
0 → 100644
View file @
5d198b5b
package
com
.
base
.
locationsharewhite
.
fcm
;
import
android.util.Log
;
import
java.util.Timer
;
import
java.util.TimerTask
;
public
class
TimerManager
{
private
static
TimerManager
instance
;
private
Timer
taskTimer
;
private
boolean
isTimerActive
;
private
TimerManager
()
{
// 私有构造方法
}
public
static
synchronized
TimerManager
getInstance
()
{
if
(
instance
==
null
)
{
instance
=
new
TimerManager
();
}
return
instance
;
}
public
void
scheduleTask
(
long
delay
,
long
period
)
{
synchronized
(
TimerManager
.
class
)
{
ensureTimerIsStopped
();
// 确保定时器未运行
taskTimer
=
new
Timer
();
// 创建新的 Timer 实例
TimerTask
task
=
new
TimerTask
()
{
@Override
public
void
run
()
{
Log
.
d
(
"glc"
,
"Scheduled task is running"
);
// 确保设备处于交互状态,未锁定,且应用未暂停
}
};
taskTimer
.
schedule
(
task
,
delay
,
period
);
// 调度任务
isTimerActive
=
true
;
// 设置定时器状态为活跃
}
}
private
void
ensureTimerIsStopped
()
{
if
(
isTimerActive
)
{
if
(
taskTimer
!=
null
)
{
taskTimer
.
cancel
();
taskTimer
.
purge
();
// 清除所有取消的任务
}
isTimerActive
=
false
;
// 重置定时器状态
}
}
public
void
stopTaskTimer
()
{
synchronized
(
TimerManager
.
class
)
{
ensureTimerIsStopped
();
// 停止定时器
}
}
public
boolean
isTaskTimerActive
()
{
return
isTimerActive
;
}
}
\ No newline at end of file
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