Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
B
Browser 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
Browser White
Commits
031d0faf
Commit
031d0faf
authored
Sep 06, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
514b2cc0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
9 deletions
+96
-9
NotificationHelp.kt
...c/main/java/com/base/browserwhite/fcm/NotificationHelp.kt
+16
-4
NotificationUiUtil.kt
...main/java/com/base/browserwhite/fcm/NotificationUiUtil.kt
+64
-5
TimeUtils.kt
app/src/main/java/com/base/browserwhite/utils/TimeUtils.kt
+16
-0
No files found.
app/src/main/java/com/base/browserwhite/fcm/NotificationHelp.kt
View file @
031d0faf
...
...
@@ -54,16 +54,28 @@ object NotificationHelp {
}
ConstObject
.
ID_CONSTELLATION
->
{
// canPush = canPushConstellation()
canPush
=
canPushConstellation
()
}
ConstObject
.
ID_USAGE_REPORT
->
{
canPush
=
canPushUsageReport
()
}
}
return
canPush
}
// private fun canPushConstellation(): Boolean {
//
// }
private
fun
canPushUsageReport
():
Boolean
{
val
time
=
System
.
currentTimeMillis
().
formatTimeH
()
val
lashPushTime
=
AppPreferences
.
getInstance
().
getLong
(
"last_usage_notification_time"
,
0
).
formatTimeH
()
return
TimeUtils
.
isTimeBetweenWan17toWan23
()
&&
time
!=
lashPushTime
}
private
fun
canPushConstellation
():
Boolean
{
val
lastPushTime
=
AppPreferences
.
getInstance
().
getLong
(
"last_constellation_notification_time"
,
0
)
return
lastPushTime
==
0L
||
System
.
currentTimeMillis
()
-
lastPushTime
>
24
*
60
*
60
*
1000
}
//天气
...
...
app/src/main/java/com/base/browserwhite/fcm/NotificationUiUtil.kt
View file @
031d0faf
...
...
@@ -16,6 +16,7 @@ import android.view.View
import
android.widget.RemoteViews
import
androidx.core.app.NotificationCompat
import
androidx.core.graphics.drawable.IconCompat
import
androidx.core.graphics.drawable.toBitmap
import
com.base.browserwhite.MyApplication
import
com.base.browserwhite.R
import
com.base.browserwhite.bean.ConstObject.ID_APP_PROCESS_1
...
...
@@ -54,6 +55,10 @@ object NotificationUiUtil {
private
const
val
CHANNEL_ID
=
"browser_notification_id"
// 通知渠道ID
private
const
val
CHANNEL_NAME
=
"browser_fcm_channel"
// 通知渠道名称
var
saveNotificationTime
={
}
@SuppressLint
(
"RemoteViewLayout"
)
fun
sendNotification
(
context
:
Context
,
actionId
:
Int
)
{
when
(
actionId
)
{
...
...
@@ -204,12 +209,59 @@ object NotificationUiUtil {
val
pm
=
context
.
packageManager
val
apps
=
AppProcessActivity
.
fastGetAppIcon
(
context
)
LogEx
.
logDebug
(
"ID_USAGE_REPORT"
,
"${apps.size}"
)
val
size
=
context
.
resources
.
getDimensionPixelSize
(
R
.
dimen
.
dp_30
)
runCatching
{
val
app1
=
apps
[
0
]
val
drawable1
=
app1
.
applicationInfo
.
loadIcon
(
pm
)
val
bitmap
=
Bitmap
.
createBitmap
(
50
,
50
,
Bitmap
.
Config
.
ARGB_8888
)
LogEx
.
logDebug
(
"ID_USAGE_REPORT"
,
"${bitmap.height} ${bitmap.width}"
)
bigRemoteViews
.
setImageViewBitmap
(
R
.
id
.
iv_app_1
,
bitmap
)
val
bitmap1
=
drawable1
.
toBitmap
(
size
,
size
,
Bitmap
.
Config
.
ARGB_8888
)
bigRemoteViews
.
setImageViewBitmap
(
R
.
id
.
iv_app_1
,
bitmap1
)
val
app2
=
apps
[
1
]
val
drawable2
=
app2
.
applicationInfo
.
loadIcon
(
pm
)
val
bitmap2
=
drawable2
.
toBitmap
(
size
,
size
,
Bitmap
.
Config
.
ARGB_8888
)
bigRemoteViews
.
setImageViewBitmap
(
R
.
id
.
iv_app_2
,
bitmap2
)
val
app3
=
apps
[
2
]
val
drawable3
=
app3
.
applicationInfo
.
loadIcon
(
pm
)
val
bitmap3
=
drawable3
.
toBitmap
(
size
,
size
,
Bitmap
.
Config
.
ARGB_8888
)
bigRemoteViews
.
setImageViewBitmap
(
R
.
id
.
iv_app_3
,
bitmap3
)
val
app4
=
apps
[
3
]
val
drawable4
=
app4
.
applicationInfo
.
loadIcon
(
pm
)
val
bitmap4
=
drawable4
.
toBitmap
(
size
,
size
,
Bitmap
.
Config
.
ARGB_8888
)
bigRemoteViews
.
setImageViewBitmap
(
R
.
id
.
iv_app_4
,
bitmap4
)
val
app5
=
apps
[
4
]
val
drawable5
=
app5
.
applicationInfo
.
loadIcon
(
pm
)
val
bitmap5
=
drawable5
.
toBitmap
(
size
,
size
,
Bitmap
.
Config
.
ARGB_8888
)
bigRemoteViews
.
setImageViewBitmap
(
R
.
id
.
iv_app_5
,
bitmap5
)
val
app6
=
apps
[
5
]
val
drawable6
=
app6
.
applicationInfo
.
loadIcon
(
pm
)
val
bitmap6
=
drawable6
.
toBitmap
(
size
,
size
,
Bitmap
.
Config
.
ARGB_8888
)
bigRemoteViews
.
setImageViewBitmap
(
R
.
id
.
iv_app_6
,
bitmap6
)
val
app7
=
apps
[
6
]
val
drawable7
=
app7
.
applicationInfo
.
loadIcon
(
pm
)
val
bitmap7
=
drawable7
.
toBitmap
(
size
,
size
,
Bitmap
.
Config
.
ARGB_8888
)
bigRemoteViews
.
setImageViewBitmap
(
R
.
id
.
iv_app_7
,
bitmap7
)
val
app8
=
apps
[
7
]
val
drawable8
=
app8
.
applicationInfo
.
loadIcon
(
pm
)
val
bitmap8
=
drawable8
.
toBitmap
(
size
,
size
,
Bitmap
.
Config
.
ARGB_8888
)
bigRemoteViews
.
setImageViewBitmap
(
R
.
id
.
iv_app_8
,
bitmap8
)
val
app9
=
apps
[
8
]
val
drawable9
=
app9
.
applicationInfo
.
loadIcon
(
pm
)
val
bitmap9
=
drawable9
.
toBitmap
(
size
,
size
,
Bitmap
.
Config
.
ARGB_8888
)
bigRemoteViews
.
setImageViewBitmap
(
R
.
id
.
iv_app_9
,
bitmap9
)
val
app10
=
apps
[
9
]
val
drawable10
=
app10
.
applicationInfo
.
loadIcon
(
pm
)
val
bitmap10
=
drawable10
.
toBitmap
(
size
,
size
,
Bitmap
.
Config
.
ARGB_8888
)
bigRemoteViews
.
setImageViewBitmap
(
R
.
id
.
iv_app_10
,
bitmap10
)
}
sendNotificationUI
(
context
,
actionId
,
bigRemoteViews
,
smallRemoteViews
)
}
...
...
@@ -294,7 +346,9 @@ object NotificationUiUtil {
small
=
smallRemoteViews
}
// 设置小视图
builder
.
setCustomContentView
(
smallRemoteViews
)
builder
.
setContent
(
small
)
builder
.
setCustomHeadsUpContentView
(
small
)
builder
.
setCustomContentView
(
small
)
// 设置悬浮通知视图(Android 12 及以上)
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
S
)
{
...
...
@@ -304,7 +358,6 @@ object NotificationUiUtil {
// 设置大视图
builder
.
setCustomBigContentView
(
bigRemoteViews
)
notificationManager
.
notify
(
actionId
,
builder
.
build
())
if
(
actionId
==
ID_WEATHER
)
{
AppPreferences
.
getInstance
().
put
(
"last_weather_notification_time"
,
System
.
currentTimeMillis
())
...
...
@@ -318,6 +371,12 @@ object NotificationUiUtil {
if
(
actionId
==
ID_APP_PROCESS_1
)
{
AppPreferences
.
getInstance
().
put
(
"last_process_notification_time"
,
System
.
currentTimeMillis
())
}
if
(
actionId
==
ID_CONSTELLATION
)
{
AppPreferences
.
getInstance
().
put
(
"last_constellation_notification_time"
,
System
.
currentTimeMillis
())
}
if
(
actionId
==
ID_USAGE_REPORT
){
AppPreferences
.
getInstance
().
put
(
"last_usage_notification_time"
,
System
.
currentTimeMillis
())
}
}
}
\ No newline at end of file
app/src/main/java/com/base/browserwhite/utils/TimeUtils.kt
View file @
031d0faf
...
...
@@ -35,6 +35,22 @@ object TimeUtils {
return
hour
in
8
..
21
}
fun
isTimeBetweenWan17toWan23
():
Boolean
{
val
calendar
=
Calendar
.
getInstance
()
val
currentHour
=
calendar
.
get
(
Calendar
.
HOUR_OF_DAY
)
// 获取当前小时数(24小时制)
val
isEvening
=
currentHour
in
17
..
22
// Kotlin中的in运算符用于判断范围
return
if
(
isEvening
)
{
// 当前时间是晚上17点到23点之间
true
}
else
{
// 当前时间不是晚上17点到23点之间
false
}
}
@SuppressLint
(
"SimpleDateFormat"
)
fun
Long
.
formatTimeH
():
String
{
val
dateFormat
=
SimpleDateFormat
(
"yyyy-M-d H"
)
...
...
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