Example usage for android.print PrintAttributes COLOR_MODE_MONOCHROME

List of usage examples for android.print PrintAttributes COLOR_MODE_MONOCHROME

Introduction

In this page you can find the example usage for android.print PrintAttributes COLOR_MODE_MONOCHROME.

Prototype

int COLOR_MODE_MONOCHROME

To view the source code for android.print PrintAttributes COLOR_MODE_MONOCHROME.

Click Source Link

Document

Color mode: Monochrome color scheme, for example one color is used.

Usage

From source file:de.appplant.cordova.plugin.printer.Printer.java

/**
 * Creates the web view client which sets the print document.
 *
 * @param props/*from ww  w .  ja  va 2  s . c  om*/
 *      The JSON object with the containing page properties
 */
private void setWebViewClient(JSONObject props) {
    final String docName = props.optString("name", DEFAULT_DOC_NAME);
    final boolean landscape = props.optBoolean("landscape", false);
    final boolean graystyle = props.optBoolean("graystyle", false);

    view.setWebViewClient(new WebViewClient() {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }

        @Override
        public void onPageFinished(WebView webView, String url) {
            // Get a PrintManager instance
            PrintManager printManager = (PrintManager) cordova.getActivity()
                    .getSystemService(Context.PRINT_SERVICE);

            // Get a print adapter instance
            PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter();

            // Get a print builder instance
            PrintAttributes.Builder builder = new PrintAttributes.Builder();

            // The page does itself set its own margins
            builder.setMinMargins(PrintAttributes.Margins.NO_MARGINS);

            builder.setColorMode(
                    graystyle ? PrintAttributes.COLOR_MODE_MONOCHROME : PrintAttributes.COLOR_MODE_COLOR);

            builder.setMediaSize(landscape ? PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE
                    : PrintAttributes.MediaSize.UNKNOWN_PORTRAIT);

            // Create a print job with name and adapter instance
            PrintJob job = printManager.print(docName, printAdapter, builder.build());

            invokeCallbackOnceCompletedOrCanceled(job);

            view = null;
        }
    });
}