Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
P
PDF Viewer Scanner White ago
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
kuxulei
PDF Viewer Scanner White ago
Commits
12e4231e
Commit
12e4231e
authored
Oct 11, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...
parent
a9bd4b14
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
326 additions
and
26 deletions
+326
-26
AdmobHelper.kt
...in/java/com/base/pdfviewerscannerwhite/ads/AdmobHelper.kt
+0
-26
ConstObject.kt
...n/java/com/base/pdfviewerscannerwhite/bean/ConstObject.kt
+2
-0
NotificationUiUtil.kt
.../com/base/pdfviewerscannerwhite/fcm/NotificationUiUtil.kt
+190
-0
PopupConstObject.kt
...va/com/base/pdfviewerscannerwhite/fcm/PopupConstObject.kt
+38
-0
MeidaContentObserver.kt
...ase/pdfviewerscannerwhite/service/MeidaContentObserver.kt
+71
-0
StayNotificationService.kt
.../pdfviewerscannerwhite/service/StayNotificationService.kt
+22
-0
notification_message.xml
app/src/main/res/layout/notification_message.xml
+1
-0
strings.xml
app/src/main/res/values/strings.xml
+2
-0
No files found.
app/src/main/java/com/base/pdfviewerscannerwhite/ads/AdmobHelper.kt
View file @
12e4231e
...
@@ -23,32 +23,6 @@ object AdmobHelper {
...
@@ -23,32 +23,6 @@ object AdmobHelper {
const
val
native_limit_show
=
"native_limit_show"
const
val
native_limit_show
=
"native_limit_show"
const
val
native_limit_click
=
"native_limit_click"
const
val
native_limit_click
=
"native_limit_click"
//推送总数量现在
val
popup_count
=
"popup_count"
//所有常规推送的当日推送次数限制,0 为不限制
//推送总开关 0 关 1开
val
popup_status
=
"popup_status"
//推送样式一配置
val
popup_style1_start
=
"popup_style1_start"
val
popup_style1_end
=
"popup_style1_end"
val
popup_style1_status
=
"popup_style1_status"
val
popup_style1_count
=
"popup_style1_count"
val
popup_style1_interval
=
"popup_style1_interval"
//推送样式二配置
val
popup_style2_start
=
"popup_style2_start"
val
popup_style2_end
=
"popup_style2_end"
val
popup_style2_status
=
"popup_style2_status"
val
popup_style2_count
=
"popup_style2_count"
val
popup_style2_interval
=
"popup_style2_interval"
//推送样式三配置
val
popup_style3_start
=
"popup_style3_start"
val
popup_style3_end
=
"popup_style3_end"
val
popup_style3_status
=
"popup_style3_status"
val
popup_style3_count
=
"popup_style3_count"
val
popup_style3_interval
=
"popup_style3_interval"
//是否展示多语言
//是否展示多语言
...
...
app/src/main/java/com/base/pdfviewerscannerwhite/bean/ConstObject.kt
View file @
12e4231e
...
@@ -43,6 +43,8 @@ object ConstObject {
...
@@ -43,6 +43,8 @@ object ConstObject {
const
val
NOTIFICATION_ACTION_LOG
=
"notification_action_log"
const
val
NOTIFICATION_ACTION_LOG
=
"notification_action_log"
const
val
NOTIFICATION_ACTION_DOCUMENT
=
"notification_action_document"
const
val
NOTIFICATION_ACTION_DOCUMENT
=
"notification_action_document"
const
val
NOTIFICATION_ACTION_BOOKMARK
=
"notification_action_bookmark"
const
val
NOTIFICATION_ACTION_BOOKMARK
=
"notification_action_bookmark"
const
val
NOTIFICATION_ACTION_NEW_IMAGE_PDF
=
"notification_action_new_image_pdf"
const
val
SHORTCUT_SCAN_PDF
=
"shortcut_scan_pdf"
const
val
SHORTCUT_SCAN_PDF
=
"shortcut_scan_pdf"
const
val
SHORTCUT_SPLIT_PDF
=
"shortcut_split_pdf"
const
val
SHORTCUT_SPLIT_PDF
=
"shortcut_split_pdf"
const
val
SHORTCUT_MERGE_PDF
=
"shortcut_merge_pdf"
const
val
SHORTCUT_MERGE_PDF
=
"shortcut_merge_pdf"
...
...
app/src/main/java/com/base/pdfviewerscannerwhite/fcm/NotificationUiUtil.kt
0 → 100644
View file @
12e4231e
package
com.base.pdfviewerscannerwhite.fcm
import
android.annotation.SuppressLint
import
android.app.NotificationChannel
import
android.app.NotificationManager
import
android.app.PendingIntent
import
android.content.Context
import
android.content.Intent
import
android.graphics.drawable.Icon
import
android.os.Build
import
android.widget.RemoteViews
import
androidx.core.app.NotificationCompat
import
androidx.core.graphics.drawable.IconCompat
import
com.base.pdfviewerscannerwhite.R
import
com.base.pdfviewerscannerwhite.bean.ConstObject.NOTIFICATION_ACTION_NEW_IMAGE_PDF
import
com.base.pdfviewerscannerwhite.fcm.PopupConstObject.popup_count
import
com.base.pdfviewerscannerwhite.fcm.PopupConstObject.popup_end
import
com.base.pdfviewerscannerwhite.fcm.PopupConstObject.popup_interval
import
com.base.pdfviewerscannerwhite.fcm.PopupConstObject.popup_start
import
com.base.pdfviewerscannerwhite.fcm.PopupConstObject.popup_status
import
com.base.pdfviewerscannerwhite.helper.MyApplication
import
com.base.pdfviewerscannerwhite.ui.splash.SplashActivity
import
com.base.pdfviewerscannerwhite.utils.AppPreferences
import
com.base.pdfviewerscannerwhite.utils.LogEx
import
java.text.SimpleDateFormat
import
java.util.Calendar
import
java.util.Locale
import
kotlin.random.Random
/**
* 构建发送通知 UI
* 用的actionId代替notificationId使用
*/
object
NotificationUiUtil
{
private
val
TAG
=
"NotificationUiUtil"
private
const
val
CHANNEL_ID
=
"browser_notification_id"
// 通知渠道ID
private
const
val
CHANNEL_NAME
=
"browser_fcm_channel"
// 通知渠道名称
var
NOTIFICATION_ID
=
8999
private
fun
currentDate
():
String
{
val
dateFormat
=
SimpleDateFormat
(
"yyyy-MM-dd"
,
Locale
.
getDefault
())
val
currentDate
=
Calendar
.
getInstance
().
time
return
dateFormat
.
format
(
currentDate
)
}
//当天推送次数
var
dayPopupCount
=
0
get
()
{
return
AppPreferences
.
getInstance
().
getInt
(
"dayPopupCount_${currentDate()}"
,
field
)
}
set
(
value
)
{
field
=
value
AppPreferences
.
getInstance
().
put
(
"dayPopupCount_${currentDate()}"
,
value
,
true
)
}
var
lastPopupTime
=
0L
get
()
{
return
AppPreferences
.
getInstance
().
getLong
(
"lastPopupTime"
,
field
)
}
set
(
value
)
{
field
=
value
AppPreferences
.
getInstance
().
put
(
"lastPopupTime"
,
value
,
true
)
}
fun
canSendNotification
():
Boolean
{
//是否开启推送
val
status
=
AppPreferences
.
getInstance
().
getString
(
popup_status
,
"1"
).
toInt
()
if
(
status
==
0
)
{
LogEx
.
logDebug
(
"canSendNotification"
,
"status"
)
return
false
}
//当天推送次数
val
count
=
AppPreferences
.
getInstance
().
getString
(
popup_count
,
"20"
).
toInt
()
if
(
dayPopupCount
>
count
)
{
LogEx
.
logDebug
(
"canSendNotification"
,
"count"
)
return
false
}
//判断是否在时间区域
val
start
=
AppPreferences
.
getInstance
().
getString
(
popup_start
,
"0"
).
toInt
()
val
end
=
AppPreferences
.
getInstance
().
getString
(
popup_end
,
"24"
).
toInt
()
val
calendar
=
Calendar
.
getInstance
()
val
currentHour
=
calendar
.
get
(
Calendar
.
HOUR_OF_DAY
)
if
(
currentHour
!
in
start
until
end
)
{
LogEx
.
logDebug
(
"canSendNotification"
,
"start end"
)
return
false
}
//单位分钟
val
interval
=
AppPreferences
.
getInstance
().
getString
(
popup_interval
,
"1"
).
toInt
()
if
(
System
.
currentTimeMillis
()
-
lastPopupTime
<
interval
*
60
*
1000L
)
{
LogEx
.
logDebug
(
"canSendNotification"
,
"interval"
)
return
false
}
return
true
}
@SuppressLint
(
"RemoteViewLayout"
)
fun
sendNotification
(
context
:
Context
,
actionId
:
String
)
{
if
(!
canSendNotification
())
return
val
bigRemoteViews
=
RemoteViews
(
MyApplication
.
context
.
packageName
,
R
.
layout
.
notification_message
)
val
smallRemoteViews
=
RemoteViews
(
MyApplication
.
context
.
packageName
,
R
.
layout
.
notification_message
)
val
intent
=
Intent
(
context
,
SplashActivity
::
class
.
java
)
intent
.
putExtra
(
"actionId"
,
actionId
)
when
(
actionId
)
{
NOTIFICATION_ACTION_NEW_IMAGE_PDF
->
{
val
tittle
=
context
.
getString
(
R
.
string
.
new_image_for_creating_pdf
)
val
desc
=
context
.
getString
(
R
.
string
.
edit_images_to_create_pdf_files
)
bigRemoteViews
.
setTextViewText
(
R
.
id
.
tv_tittle
,
tittle
)
smallRemoteViews
.
setTextViewText
(
R
.
id
.
tv_tittle
,
tittle
)
bigRemoteViews
.
setTextViewText
(
R
.
id
.
tv_desc
,
desc
)
smallRemoteViews
.
setTextViewText
(
R
.
id
.
tv_desc
,
desc
)
sendCustomNotification
(
context
,
intent
,
bigRemoteViews
,
smallRemoteViews
)
}
}
}
private
fun
sendCustomNotification
(
context
:
Context
,
intent
:
Intent
,
bigRemoteViews
:
RemoteViews
,
smallRemoteViews
:
RemoteViews
)
{
val
notificationManager
=
context
.
getSystemService
(
Context
.
NOTIFICATION_SERVICE
)
as
NotificationManager
//创建channel
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
O
)
{
val
channel
=
NotificationChannel
(
CHANNEL_ID
,
CHANNEL_NAME
,
NotificationManager
.
IMPORTANCE_HIGH
)
channel
.
lockscreenVisibility
=
NotificationCompat
.
VISIBILITY_PUBLIC
notificationManager
.
createNotificationChannel
(
channel
)
}
// Create the notification
val
builder
:
NotificationCompat
.
Builder
=
NotificationCompat
.
Builder
(
context
,
CHANNEL_ID
)
//设置状态栏内的小图标
val
smallIcon
=
IconCompat
.
createFromIcon
(
context
,
Icon
.
createWithResource
(
context
,
R
.
mipmap
.
logo
)
)
smallIcon
?.
let
{
builder
.
setSmallIcon
(
smallIcon
)
}
builder
.
setContentTitle
(
context
.
resources
.
getString
(
R
.
string
.
app_name
))
.
setContentText
(
"notification"
)
val
requestCode
=
Random
.
nextInt
(
1000
)
val
pendingIntent
=
PendingIntent
.
getActivity
(
context
,
requestCode
,
intent
,
PendingIntent
.
FLAG_IMMUTABLE
)
builder
.
setContentIntent
(
pendingIntent
)
.
setPriority
(
NotificationCompat
.
PRIORITY_MAX
)
.
setAutoCancel
(
true
)
var
small
:
RemoteViews
?
=
bigRemoteViews
//Android 12以下需要适配小RemoteViews
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
S
)
{
small
=
smallRemoteViews
}
// 设置小视图
builder
.
setCustomContentView
(
smallRemoteViews
)
// 设置悬浮通知视图(Android 12 及以上)
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
S
)
{
builder
.
setCustomHeadsUpContentView
(
bigRemoteViews
)
}
// 设置大视图
builder
.
setCustomBigContentView
(
bigRemoteViews
)
notificationManager
.
notify
(
NOTIFICATION_ID
,
builder
.
build
())
//当天次数加一
dayPopupCount
+=
dayPopupCount
+
1
//推送时间
lastPopupTime
=
System
.
currentTimeMillis
()
}
}
\ No newline at end of file
app/src/main/java/com/base/pdfviewerscannerwhite/fcm/PopupConstObject.kt
0 → 100644
View file @
12e4231e
package
com.base.pdfviewerscannerwhite.fcm
object
PopupConstObject
{
//推送总开关 0 关 1开
val
popup_status
=
"popup_status"
//推送总数量现在
val
popup_count
=
"popup_count"
//所有常规推送的当日推送次数限制,0 为不限制
val
popup_start
=
"popup_start"
val
popup_end
=
"popup_start"
val
popup_interval
=
"popup_interval"
//推送样式一配置
val
popup_style1_start
=
"popup_style1_start"
val
popup_style1_end
=
"popup_style1_end"
val
popup_style1_status
=
"popup_style1_status"
val
popup_style1_count
=
"popup_style1_count"
val
popup_style1_interval
=
"popup_style1_interval"
//推送样式二配置
val
popup_style2_start
=
"popup_style2_start"
val
popup_style2_end
=
"popup_style2_end"
val
popup_style2_status
=
"popup_style2_status"
val
popup_style2_count
=
"popup_style2_count"
val
popup_style2_interval
=
"popup_style2_interval"
//推送样式三配置
val
popup_style3_start
=
"popup_style3_start"
val
popup_style3_end
=
"popup_style3_end"
val
popup_style3_status
=
"popup_style3_status"
val
popup_style3_count
=
"popup_style3_count"
val
popup_style3_interval
=
"popup_style3_interval"
}
\ No newline at end of file
app/src/main/java/com/base/pdfviewerscannerwhite/service/MeidaContentObserver.kt
0 → 100644
View file @
12e4231e
package
com.base.pdfviewerscannerwhite.service
import
android.annotation.SuppressLint
import
android.content.Context
import
android.database.ContentObserver
import
android.database.Cursor
import
android.net.Uri
import
android.provider.MediaStore
import
com.base.pdfviewerscannerwhite.bean.ConstObject
import
com.base.pdfviewerscannerwhite.fcm.NotificationUiUtil
import
com.base.pdfviewerscannerwhite.utils.LogEx
/**
* Observer MediaContent add
*/
class
MediaContentObserver
(
val
context
:
Context
)
:
ContentObserver
(
null
)
{
private
val
TAG
=
"MediaContentObserver"
override
fun
onChange
(
selfChange
:
Boolean
,
uri
:
Uri
?)
{
super
.
onChange
(
selfChange
,
uri
)
LogEx
.
logDebug
(
TAG
,
"uri=${uri.toString()}"
)
if
(
uri
.
toString
().
contains
(
"images"
))
{
NotificationUiUtil
.
sendNotification
(
context
,
ConstObject
.
NOTIFICATION_ACTION_NEW_IMAGE_PDF
)
}
// uri?.let { queryNewMediaFiles(it) }
}
@SuppressLint
(
"Range"
)
private
fun
queryNewMediaFiles
(
uri
:
Uri
)
=
Thread
{
// 查询新添加的媒体文件
val
projection
=
arrayOf
(
MediaStore
.
MediaColumns
.
DISPLAY_NAME
,
MediaStore
.
MediaColumns
.
DATA
,
MediaStore
.
MediaColumns
.
MIME_TYPE
,
MediaStore
.
MediaColumns
.
SIZE
,
)
val
cursor
:
Cursor
?
=
context
.
contentResolver
.
query
(
uri
,
projection
,
null
,
null
,
null
)
if
(
cursor
!=
null
)
{
LogEx
.
logDebug
(
TAG
,
"cursor=$cursor"
)
try
{
if
(
cursor
.
count
>
0
)
{
while
(
cursor
.
moveToNext
())
{
val
name
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
MediaColumns
.
DISPLAY_NAME
))
val
path
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
MediaColumns
.
DATA
))
val
mimeType
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
MediaColumns
.
MIME_TYPE
))
val
size
=
cursor
.
getString
(
cursor
.
getColumnIndex
(
MediaStore
.
MediaColumns
.
SIZE
))
LogEx
.
logDebug
(
TAG
,
"path=$path"
)
// 处理新文件路径
}
}
else
{
LogEx
.
logDebug
(
TAG
,
"count=0 deleted file uri"
)
}
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
LogEx
.
logDebug
(
TAG
,
"Exception=$e"
)
}
finally
{
cursor
.
close
()
}
}
else
{
LogEx
.
logDebug
(
TAG
,
"cursor=$cursor"
)
}
}.
start
()
}
app/src/main/java/com/base/pdfviewerscannerwhite/service/StayNotificationService.kt
View file @
12e4231e
...
@@ -12,6 +12,7 @@ import android.graphics.BitmapFactory
...
@@ -12,6 +12,7 @@ import android.graphics.BitmapFactory
import
android.graphics.drawable.Icon
import
android.graphics.drawable.Icon
import
android.os.Build
import
android.os.Build
import
android.os.IBinder
import
android.os.IBinder
import
android.provider.MediaStore
import
android.widget.RemoteViews
import
android.widget.RemoteViews
import
androidx.core.app.NotificationCompat
import
androidx.core.app.NotificationCompat
import
androidx.core.graphics.drawable.IconCompat
import
androidx.core.graphics.drawable.IconCompat
...
@@ -22,6 +23,7 @@ import com.base.pdfviewerscannerwhite.helper.MyApplication
...
@@ -22,6 +23,7 @@ import com.base.pdfviewerscannerwhite.helper.MyApplication
import
com.base.pdfviewerscannerwhite.ui.main.MainActivity
import
com.base.pdfviewerscannerwhite.ui.main.MainActivity
import
com.base.pdfviewerscannerwhite.ui.splash.SplashActivity
import
com.base.pdfviewerscannerwhite.ui.splash.SplashActivity
import
com.base.pdfviewerscannerwhite.utils.LogEx
import
com.base.pdfviewerscannerwhite.utils.LogEx
import
com.cherry.lib.doc.office.system.IFind
import
kotlin.random.Random
import
kotlin.random.Random
...
@@ -155,6 +157,11 @@ class StayNotificationService : Service() {
...
@@ -155,6 +157,11 @@ class StayNotificationService : Service() {
if
(!
isRunning
)
{
if
(!
isRunning
)
{
LogEx
.
logDebug
(
TAG
,
"onStartCommand startForeground"
)
LogEx
.
logDebug
(
TAG
,
"onStartCommand startForeground"
)
startForeground
()
startForeground
()
//监听媒体库变化
observerMediaContentObserver
()
isRunning
=
true
isRunning
=
true
}
}
...
@@ -182,4 +189,19 @@ class StayNotificationService : Service() {
...
@@ -182,4 +189,19 @@ class StayNotificationService : Service() {
}
}
private
var
mediaContentObserver
:
MediaContentObserver
?
=
null
private
fun
observerMediaContentObserver
()
{
if
(
mediaContentObserver
==
null
)
{
LogEx
.
logDebug
(
TAG
,
"observerMediaContentObserver"
)
mediaContentObserver
=
MediaContentObserver
(
this
)
mediaContentObserver
?.
let
{
this
.
contentResolver
.
registerContentObserver
(
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
,
true
,
it
)
}
}
}
}
}
\ No newline at end of file
app/src/main/res/layout/notification_message.xml
View file @
12e4231e
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
tools:text=
"New file available for view"
/>
tools:text=
"New file available for view"
/>
<TextView
<TextView
android:id=
"@+id/tv_desc"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@id/tv_tittle"
android:layout_below=
"@id/tv_tittle"
...
...
app/src/main/res/values/strings.xml
View file @
12e4231e
...
@@ -83,5 +83,7 @@
...
@@ -83,5 +83,7 @@
<string
name=
"click_this_button_to_use_the_scanning_feature"
>
Click this button to use the\nscanning feature
</string>
<string
name=
"click_this_button_to_use_the_scanning_feature"
>
Click this button to use the\nscanning feature
</string>
<string
name=
"try_using_it"
>
Try using it
</string>
<string
name=
"try_using_it"
>
Try using it
</string>
<string
name=
"preparing_advertisement"
>
Preparing advertisement...
</string>
<string
name=
"preparing_advertisement"
>
Preparing advertisement...
</string>
<string
name=
"new_image_for_creating_pdf"
>
New image for creating PDF
</string>
<string
name=
"edit_images_to_create_pdf_files"
>
Edit images to create PDF files
</string>
</resources>
</resources>
\ 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