Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
dart_pdf
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
David PHAM-VAN
2024-01-31 08:57:14 -0400
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
fb29442f5e85404d8759573326da6d1801fac320
fb29442f
1 parent
adf4ff1d
Android lint
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
53 deletions
printing/android/src/main/java/net/nfet/flutter/printing/PrintingHandler.java
printing/android/src/main/java/net/nfet/flutter/printing/PrintingJob.java
printing/android/src/main/java/net/nfet/flutter/printing/PrintingPlugin.java
printing/android/src/main/java/net/nfet/flutter/printing/PrintingHandler.java
View file @
fb29442
...
...
@@ -7,7 +7,6 @@ import android.print.PrintAttributes;
import
androidx.annotation.NonNull
;
import
androidx.annotation.RequiresApi
;
import
java.lang.ref.WeakReference
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
...
...
@@ -35,6 +34,8 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
final
PrintingJob
printJob
=
new
PrintingJob
(
context
,
this
,
(
int
)
call
.
argument
(
"job"
));
assert
name
!=
null
;
assert
width
!=
null
;
assert
height
!=
null
;
printJob
.
printPdf
(
name
,
width
,
height
);
result
.
success
(
1
);
...
...
@@ -138,7 +139,7 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
}
@Override
public
void
error
(
String
errorCode
,
String
errorMessage
,
Object
errorDetails
)
{
public
void
error
(
@NonNull
String
errorCode
,
String
errorMessage
,
Object
errorDetails
)
{
printJob
.
cancelJob
(
errorMessage
);
}
...
...
printing/android/src/main/java/net/nfet/flutter/printing/PrintingJob.java
View file @
fb29442
...
...
@@ -137,17 +137,12 @@ public class PrintingJob extends PrintDocumentAdapter {
@Override
public
void
onFinish
()
{
Thread
thread
=
new
Thread
(
new
Runnable
()
{
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
LOLLIPOP
)
@Override
public
void
run
()
{
Thread
thread
=
new
Thread
(()
->
{
try
{
final
boolean
[]
wait
=
{
true
};
int
count
=
5
*
60
*
10
;
// That's 10 minutes.
while
(
wait
[
0
])
{
new
Handler
(
Looper
.
getMainLooper
()).
post
(
new
Runnable
()
{
@Override
public
void
run
()
{
new
Handler
(
Looper
.
getMainLooper
()).
post
(()
->
{
int
state
=
printJob
==
null
?
PrintJobInfo
.
STATE_FAILED
:
printJob
.
getInfo
().
getState
();
...
...
@@ -158,11 +153,9 @@ public class PrintingJob extends PrintDocumentAdapter {
printing
.
onCompleted
(
PrintingJob
.
this
,
false
,
null
);
wait
[
0
]
=
false
;
}
else
if
(
state
==
PrintJobInfo
.
STATE_FAILED
)
{
printing
.
onCompleted
(
PrintingJob
.
this
,
false
,
"Unable to print"
);
printing
.
onCompleted
(
PrintingJob
.
this
,
false
,
"Unable to print"
);
wait
[
0
]
=
false
;
}
}
});
if
(--
count
<=
0
)
{
...
...
@@ -174,17 +167,14 @@ public class PrintingJob extends PrintDocumentAdapter {
}
}
}
catch
(
final
Exception
e
)
{
new
Handler
(
Looper
.
getMainLooper
()).
post
(
new
Runnable
()
{
@Override
public
void
run
()
{
printing
.
onCompleted
(
PrintingJob
.
this
,
printJob
!=
null
&&
printJob
.
isCompleted
(),
e
.
getMessage
());
}
});
new
Handler
(
Looper
.
getMainLooper
())
.
post
(()
->
printing
.
onCompleted
(
PrintingJob
.
this
,
printJob
!=
null
&&
printJob
.
isCompleted
(),
e
.
getMessage
()));
}
printJob
=
null
;
}
});
thread
.
start
();
...
...
@@ -439,10 +429,7 @@ public class PrintingJob extends PrintDocumentAdapter {
return
;
}
Thread
thread
=
new
Thread
(
new
Runnable
()
{
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
LOLLIPOP
)
@Override
public
void
run
()
{
Thread
thread
=
new
Thread
(()
->
{
String
error
=
null
;
try
{
File
tempDir
=
context
.
getCacheDir
();
...
...
@@ -472,8 +459,7 @@ public class PrintingJob extends PrintDocumentAdapter {
Bitmap
bitmap
=
Bitmap
.
createBitmap
(
width
,
height
,
Bitmap
.
Config
.
ARGB_8888
);
page
.
render
(
bitmap
,
null
,
transform
,
PdfRenderer
.
Page
.
RENDER_MODE_FOR_DISPLAY
);
page
.
render
(
bitmap
,
null
,
transform
,
PdfRenderer
.
Page
.
RENDER_MODE_FOR_DISPLAY
);
page
.
close
();
...
...
@@ -481,13 +467,10 @@ public class PrintingJob extends PrintDocumentAdapter {
bitmap
.
copyPixelsToBuffer
(
buf
);
bitmap
.
recycle
();
new
Handler
(
Looper
.
getMainLooper
()).
post
(
new
Runnable
()
{
@Override
public
void
run
()
{
printing
.
onPageRasterized
(
PrintingJob
.
this
,
buf
.
array
(),
width
,
height
);
}
});
new
Handler
(
Looper
.
getMainLooper
())
.
post
(()
->
printing
.
onPageRasterized
(
PrintingJob
.
this
,
buf
.
array
(),
width
,
height
));
}
renderer
.
close
();
...
...
@@ -499,26 +482,14 @@ public class PrintingJob extends PrintDocumentAdapter {
}
final
String
finalError
=
error
;
new
Handler
(
Looper
.
getMainLooper
()).
post
(
new
Runnable
()
{
@Override
public
void
run
()
{
printing
.
onPageRasterEnd
(
PrintingJob
.
this
,
finalError
);
}
});
}
new
Handler
(
Looper
.
getMainLooper
())
.
post
(()
->
printing
.
onPageRasterEnd
(
PrintingJob
.
this
,
finalError
));
});
thread
.
setUncaughtExceptionHandler
(
new
Thread
.
UncaughtExceptionHandler
()
{
@Override
public
void
uncaughtException
(
Thread
t
,
Throwable
e
)
{
thread
.
setUncaughtExceptionHandler
((
t
,
e
)
->
{
final
String
finalError
=
e
.
getMessage
();
new
Handler
(
Looper
.
getMainLooper
()).
post
(
new
Runnable
()
{
@Override
public
void
run
()
{
printing
.
onPageRasterEnd
(
PrintingJob
.
this
,
finalError
);
}
});
}
new
Handler
(
Looper
.
getMainLooper
())
.
post
(()
->
printing
.
onPageRasterEnd
(
PrintingJob
.
this
,
finalError
));
});
thread
.
start
();
...
...
printing/android/src/main/java/net/nfet/flutter/printing/PrintingPlugin.java
View file @
fb29442
...
...
@@ -20,8 +20,6 @@ import android.content.Context;
import
androidx.annotation.NonNull
;
import
java.lang.ref.WeakReference
;
import
io.flutter.embedding.engine.plugins.FlutterPlugin
;
import
io.flutter.embedding.engine.plugins.activity.ActivityAware
;
import
io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
;
...
...
@@ -59,7 +57,7 @@ public class PrintingPlugin implements FlutterPlugin, ActivityAware {
}
@Override
public
void
onAttachedToActivity
(
ActivityPluginBinding
binding
)
{
public
void
onAttachedToActivity
(
@NonNull
ActivityPluginBinding
binding
)
{
if
(
context
!=
null
)
{
context
=
null
;
}
...
...
Please
register
or
login
to post a comment