Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
F
File Recovery RecycleBin
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
File Recovery RecycleBin
Commits
c6baa046
Commit
c6baa046
authored
Jul 22, 2024
by
leichao.gao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
适配手机
parent
5c8e3b0d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
17 deletions
+8
-17
BackUpUtils.kt
...va/com/base/filerecoveryrecyclebin/service/BackUpUtils.kt
+4
-14
FileObserverExample.java
...e/filerecoveryrecyclebin/service/FileObserverExample.java
+4
-3
No files found.
app/src/main/java/com/base/filerecoveryrecyclebin/service/BackUpUtils.kt
View file @
c6baa046
...
...
@@ -21,7 +21,7 @@ import java.util.stream.Collectors
object
BackUpUtils
{
private
val
TAG
=
"
BackUpUtils
"
private
val
TAG
=
"
FileObserverExample
"
private
const
val
KEY
=
"backup_key"
...
...
@@ -32,23 +32,13 @@ object BackUpUtils {
try
{
val
recycleBinFile
=
File
(
getRecycleBinDir
(),
".$path"
)
LogEx
.
logDebug
(
TAG
,
"oo=$src ${src.length()}"
)
if
(
src
.
length
()
==
0L
)
{
return
}
val
ss
=
src
.
copyTo
(
recycleBinFile
,
true
)
LogEx
.
logDebug
(
TAG
,
"ss=$ss"
)
if
(
ss
.
length
()
==
0L
)
{
return
}
val
binBean
=
RecycleBinBean
(
path
,
src
.
path
,
recycleBinFile
.
absolutePath
,
0
,
src
.
length
(),
getFileExtension
(
src
),
false
)
val
binBean
=
RecycleBinBean
(
path
,
src
.
path
,
recycleBinFile
.
absolutePath
,
0
,
src
.
length
(),
getFileExtension
(
src
),
false
)
saveData
(
binBean
,
path
)
}
catch
(
e
:
Exception
)
{
...
...
@@ -88,7 +78,7 @@ object BackUpUtils {
fun
saveBackUpSp
(
hash
:
HashMap
<
String
,
RecycleBinBean
>)
{
val
str
=
Gson
().
toJson
(
hash
)
Log
.
d
(
"FileObserverExample"
,
str
)
Log
.
d
(
TAG
,
str
)
AppPreferences
.
getInstance
().
put
(
KEY
,
str
)
}
...
...
app/src/main/java/com/base/filerecoveryrecyclebin/service/FileObserverExample.java
View file @
c6baa046
...
...
@@ -54,7 +54,7 @@ public class FileObserverExample {
fileHandlerThread
=
new
HandlerThread
(
"FileObserverThread"
);
fileHandlerThread
.
start
();
fileHandler
=
new
Handler
(
fileHandlerThread
.
getLooper
());
fileObserver
=
new
FileObserver
(
watchList
,
FileObserver
.
CREATE
|
FileObserver
.
DELETE
|
FileObserver
.
DELETE_SELF
|
FileObserver
.
MOVED_FROM
|
FileObserver
.
MODIFY
|
ATTRIB
|
FileObserver
.
MOVED_TO
)
{
fileObserver
=
new
FileObserver
(
watchList
,
FileObserver
.
CREATE
|
FileObserver
.
DELETE
|
FileObserver
.
DELETE_SELF
|
FileObserver
.
MOVED_FROM
|
FileObserver
.
MOVED_TO
|
FileObserver
.
MODIFY
)
{
@Override
public
void
onEvent
(
int
event
,
String
path
)
{
Log
.
d
(
TAG
,
"onEvent "
+
event
+
" "
+
path
);
...
...
@@ -81,9 +81,10 @@ public class FileObserverExample {
Log
.
d
(
TAG
,
event
+
" "
+
FileObserver
.
DELETE_SELF
+
" "
+
path
);
// 检查文件扩展名是否在监听范围内
if
(
FILE_EXTENSIONS
.
contains
(
getFileExtension
(
path
)))
{
if
(
event
==
FileObserver
.
CREATE
||
event
==
FileObserver
.
MOVED_TO
)
{
if
(
event
==
FileObserver
.
CREATE
||
event
==
FileObserver
.
MOVED_TO
||
event
==
FileObserver
.
MODIFY
)
{
Log
.
d
(
TAG
,
"CREATE"
);
fileHandler
.
post
(()
->
handleFileCreation
(
path
));
fileHandler
.
removeCallbacksAndMessages
(
null
);
fileHandler
.
postDelayed
(()
->
handleFileCreation
(
path
),
2000
);
}
else
if
(
event
==
FileObserver
.
DELETE
||
event
==
FileObserver
.
DELETE_SELF
||
event
==
FileObserver
.
MOVED_FROM
)
{
Log
.
d
(
TAG
,
event
+
" DELETE:"
+
path
);
BackUpUtils
.
INSTANCE
.
deleteFile
(
path
);
...
...
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