Print HTML markup
This commit is contained in:
parent
ab67054f63
commit
d6e1adbbbc
@ -30,8 +30,11 @@ import android.support.annotation.NonNull;
|
|||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.print.PrintHelper;
|
import android.support.v4.print.PrintHelper;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
import android.webkit.WebViewClient;
|
||||||
|
|
||||||
import org.apache.cordova.engine.SystemWebView;
|
import org.apache.cordova.engine.SystemWebView;
|
||||||
|
import org.apache.cordova.engine.SystemWebViewClient;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@ -46,6 +49,8 @@ class PrintManager {
|
|||||||
// The application context
|
// The application context
|
||||||
private final @NonNull Context context;
|
private final @NonNull Context context;
|
||||||
|
|
||||||
|
private @Nullable WebView webView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
@ -140,7 +145,7 @@ class PrintManager {
|
|||||||
{
|
{
|
||||||
PrintOptions options = new PrintOptions(settings);
|
PrintOptions options = new PrintOptions(settings);
|
||||||
String jobName = options.getJobName();
|
String jobName = options.getJobName();
|
||||||
SystemWebView webView = (SystemWebView) view;
|
WebView webView = (WebView) view;
|
||||||
|
|
||||||
((Activity) context).runOnUiThread(() -> {
|
((Activity) context).runOnUiThread(() -> {
|
||||||
PrintDocumentAdapter adapter;
|
PrintDocumentAdapter adapter;
|
||||||
@ -153,7 +158,6 @@ class PrintManager {
|
|||||||
|
|
||||||
printAdapter(adapter, options);
|
printAdapter(adapter, options);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -165,7 +169,25 @@ class PrintManager {
|
|||||||
private void printHtml (@NonNull String content,
|
private void printHtml (@NonNull String content,
|
||||||
@NonNull JSONObject settings)
|
@NonNull JSONObject settings)
|
||||||
{
|
{
|
||||||
// TODO implement me
|
((Activity) context).runOnUiThread(() -> {
|
||||||
|
webView = new WebView(context);
|
||||||
|
|
||||||
|
webView.setWebViewClient(new WebViewClient() {
|
||||||
|
@Override
|
||||||
|
public boolean shouldOverrideUrlLoading (WebView view, String url) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPageFinished (WebView view, String url) {
|
||||||
|
printView(webView, settings);
|
||||||
|
webView = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
webView.loadDataWithBaseURL("file:///android_asset/www/", content, "text/html", "UTF-8",
|
||||||
|
null);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
package de.appplant.cordova.plugin.printer;
|
package de.appplant.cordova.plugin.printer;
|
||||||
|
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
import org.apache.cordova.CallbackContext;
|
import org.apache.cordova.CallbackContext;
|
||||||
import org.apache.cordova.CordovaPlugin;
|
import org.apache.cordova.CordovaPlugin;
|
||||||
@ -129,5 +130,4 @@ public class Printer extends CordovaPlugin {
|
|||||||
pm.print(content, settings, webView.getView(), callback::success);
|
pm.print(content, settings, webView.getView(), callback::success);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user