Example usage for android.print PrintAttributes COLOR_MODE_COLOR

List of usage examples for android.print PrintAttributes COLOR_MODE_COLOR

Introduction

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

Prototype

int COLOR_MODE_COLOR

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

Click Source Link

Document

Color mode: Color color scheme, for example many colors are used.

Usage

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

/**
 * Creates the web view client which sets the print document.
 *
 * @param props//w  w  w  .  j av a  2 s.  co  m
 *      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;
        }
    });
}