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
Heinrich
2024-01-22 12:16:21 +1000
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
David PHAM-VAN
2024-01-27 12:30:17 -0400
Commit
459f38acc9f9b85e6bd8ea12cd43baccbbc04058
459f38ac
1 parent
e5a56e88
Changed Activity to Context
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
22 deletions
demo/android/build.gradle
printing/CHANGELOG.md
printing/android/src/main/java/net/nfet/flutter/printing/PrintingHandler.java
printing/android/src/main/java/net/nfet/flutter/printing/PrintingPlugin.java
demo/android/build.gradle
View file @
459f38a
...
...
@@ -26,6 +26,6 @@ subprojects {
project
.
evaluationDependsOn
(
':app'
)
}
task
clean
(
type:
Delete
)
{
task
s
.
register
(
"clean"
,
Delete
)
{
delete
rootProject
.
buildDir
}
...
...
printing/CHANGELOG.md
View file @
459f38a
...
...
@@ -6,6 +6,7 @@
-
Implement PdfActionBarTheme for actions bar and add method scrollToPage
[
Aleksei
]
-
Update cursors in zoom mode for web
[
Aleksei
]
-
Output image sized to cropBox instead of mediaBox (iOS)
[
garrettApproachableGeek
]
-
Replace Activity with Context for Service Compatibility (Android)
[
Heinrich
]
## 5.11.1
...
...
printing/android/src/main/java/net/nfet/flutter/printing/PrintingHandler.java
View file @
459f38a
package
net
.
nfet
.
flutter
.
printing
;
import
android.
app.Activity
;
import
android.
content.Context
;
import
android.os.Build
;
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
;
...
...
@@ -14,11 +15,11 @@ import io.flutter.plugin.common.MethodCall;
import
io.flutter.plugin.common.MethodChannel
;
public
class
PrintingHandler
implements
MethodChannel
.
MethodCallHandler
{
private
final
Activity
activity
;
private
final
Context
context
;
private
final
MethodChannel
channel
;
PrintingHandler
(
@NonNull
Activity
activity
,
@NonNull
MethodChannel
channel
)
{
this
.
activity
=
activity
;
PrintingHandler
(
@NonNull
Context
context
,
@NonNull
MethodChannel
channel
)
{
this
.
context
=
context
;
this
.
channel
=
channel
;
}
...
...
@@ -32,7 +33,7 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
Double
height
=
call
.
argument
(
"height"
);
final
PrintingJob
printJob
=
new
PrintingJob
(
activity
,
this
,
(
int
)
call
.
argument
(
"job"
));
new
PrintingJob
(
context
,
this
,
(
int
)
call
.
argument
(
"job"
));
assert
name
!=
null
;
printJob
.
printPdf
(
name
,
width
,
height
);
...
...
@@ -41,7 +42,7 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
}
case
"cancelJob"
:
{
final
PrintingJob
printJob
=
new
PrintingJob
(
activity
,
this
,
(
int
)
call
.
argument
(
"job"
));
new
PrintingJob
(
context
,
this
,
(
int
)
call
.
argument
(
"job"
));
printJob
.
cancelJob
(
null
);
result
.
success
(
1
);
break
;
...
...
@@ -52,7 +53,7 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
final
String
subject
=
call
.
argument
(
"subject"
);
final
String
body
=
call
.
argument
(
"body"
);
final
ArrayList
<
String
>
emails
=
call
.
argument
(
"emails"
);
PrintingJob
.
sharePdf
(
activity
,
document
,
name
,
subject
,
body
,
emails
);
PrintingJob
.
sharePdf
(
context
,
document
,
name
,
subject
,
body
,
emails
);
result
.
success
(
1
);
break
;
}
...
...
@@ -64,7 +65,7 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
Double
marginRight
=
call
.
argument
(
"marginRight"
);
Double
marginBottom
=
call
.
argument
(
"marginBottom"
);
final
PrintingJob
printJob
=
new
PrintingJob
(
activity
,
this
,
(
int
)
call
.
argument
(
"job"
));
new
PrintingJob
(
context
,
this
,
(
int
)
call
.
argument
(
"job"
));
assert
width
!=
null
;
assert
height
!=
null
;
...
...
@@ -98,7 +99,7 @@ public class PrintingHandler implements MethodChannel.MethodCallHandler {
final
ArrayList
<
Integer
>
pages
=
call
.
argument
(
"pages"
);
Double
scale
=
call
.
argument
(
"scale"
);
final
PrintingJob
printJob
=
new
PrintingJob
(
activity
,
this
,
(
int
)
call
.
argument
(
"job"
));
new
PrintingJob
(
context
,
this
,
(
int
)
call
.
argument
(
"job"
));
printJob
.
rasterPdf
(
document
,
pages
,
scale
);
result
.
success
(
1
);
break
;
...
...
printing/android/src/main/java/net/nfet/flutter/printing/PrintingPlugin.java
View file @
459f38a
...
...
@@ -16,10 +16,12 @@
package
net
.
nfet
.
flutter
.
printing
;
import
android.
app.Activity
;
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
;
...
...
@@ -30,20 +32,21 @@ import io.flutter.plugin.common.MethodChannel;
* PrintingPlugin
*/
public
class
PrintingPlugin
implements
FlutterPlugin
,
ActivityAware
{
private
Activity
activity
;
private
Context
context
;
private
MethodChannel
channel
;
private
PrintingHandler
handler
;
@Override
public
void
onAttachedToEngine
(
FlutterPluginBinding
binding
)
{
context
=
binding
.
getApplicationContext
();
onAttachedToEngine
(
binding
.
getBinaryMessenger
());
}
private
void
onAttachedToEngine
(
BinaryMessenger
messenger
)
{
channel
=
new
MethodChannel
(
messenger
,
"net.nfet.printing"
);
if
(
activity
!=
null
)
{
handler
=
new
PrintingHandler
(
activity
,
channel
);
if
(
context
!=
null
)
{
handler
=
new
PrintingHandler
(
context
,
channel
);
channel
.
setMethodCallHandler
(
handler
);
}
}
...
...
@@ -57,14 +60,16 @@ public class PrintingPlugin implements FlutterPlugin, ActivityAware {
@Override
public
void
onAttachedToActivity
(
ActivityPluginBinding
binding
)
{
onAttachedToActivity
(
binding
.
getActivity
());
if
(
context
!=
null
)
{
context
=
null
;
}
context
=
binding
.
getActivity
();
onAttachedToActivity
(
context
);
}
private
void
onAttachedToActivity
(
Activity
_activity
)
{
activity
=
_activity
;
if
(
activity
!=
null
&&
channel
!=
null
)
{
handler
=
new
PrintingHandler
(
activity
,
channel
);
private
void
onAttachedToActivity
(
Context
context
)
{
if
(
context
!=
null
&&
channel
!=
null
)
{
handler
=
new
PrintingHandler
(
context
,
channel
);
channel
.
setMethodCallHandler
(
handler
);
}
}
...
...
@@ -76,13 +81,15 @@ public class PrintingPlugin implements FlutterPlugin, ActivityAware {
@Override
public
void
onReattachedToActivityForConfigChanges
(
ActivityPluginBinding
binding
)
{
onAttachedToActivity
(
binding
.
getActivity
());
context
=
null
;
context
=
binding
.
getActivity
();
onAttachedToActivity
(
context
);
}
@Override
public
void
onDetachedFromActivity
()
{
channel
.
setMethodCallHandler
(
null
);
activity
=
null
;
context
=
null
;
handler
=
null
;
}
}
...
...
Please
register
or
login
to post a comment