This source file includes following definitions.
- onLayout
- onWrite
package org.chromium.android_webview;
import android.os.Bundle;
import android.os.CancellationSignal;
import android.os.ParcelFileDescriptor;
import android.print.PageRange;
import android.print.PrintAttributes;
import android.print.PrintDocumentAdapter;
import android.print.PrintDocumentInfo;
import android.webkit.ValueCallback;
public class AwPrintDocumentAdapter extends PrintDocumentAdapter {
private AwPdfExporter mPdfExporter;
private PrintAttributes mAttributes;
private String mDocumentName;
public AwPrintDocumentAdapter(AwPdfExporter pdfExporter) {
this(pdfExporter, "default");
}
public AwPrintDocumentAdapter(AwPdfExporter pdfExporter, String documentName) {
mPdfExporter = pdfExporter;
mDocumentName = documentName;
}
@Override
public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
CancellationSignal cancellationSignal, LayoutResultCallback callback,
Bundle metadata) {
mAttributes = newAttributes;
PrintDocumentInfo documentInfo = new PrintDocumentInfo
.Builder(mDocumentName)
.build();
callback.onLayoutFinished(documentInfo, true);
}
@Override
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination,
CancellationSignal cancellationSignal, final WriteResultCallback callback) {
mPdfExporter.exportToPdf(destination, mAttributes, new ValueCallback<Boolean>() {
@Override
public void onReceiveValue(Boolean value) {
if (value) {
callback.onWriteFinished(new PageRange[] { PageRange.ALL_PAGES });
} else {
callback.onWriteFailed(null);
}
}
}, cancellationSignal);
}
}