This source file includes following definitions.
- JNINamespace
- updatePrintingContextMap
- askUserForSettingsReply
- create
- getFileDescriptor
- getDpi
- getWidth
- getHeight
- pdfWritingDone
- getPages
- pageCountEstimationDone
- nativeAskUserForSettingsReply
package org.chromium.printing;
import android.print.PrintDocumentAdapter;
import android.util.SparseArray;
import org.chromium.base.CalledByNative;
import org.chromium.base.JNINamespace;
import org.chromium.base.ThreadUtils;
@JNINamespace("printing")
public class PrintingContext implements PrintingContextInterface {
private static final SparseArray<PrintingContext> PRINTING_CONTEXT_MAP =
new SparseArray<PrintingContext>();
private final PrintingController mController;
private final long mNativeObject;
private PrintingContext(long ptr) {
mController = PrintingControllerImpl.getInstance();
mNativeObject = ptr;
}
@Override
public void updatePrintingContextMap(int fileDescriptor, boolean delete) {
ThreadUtils.assertOnUiThread();
if (delete) {
PRINTING_CONTEXT_MAP.remove(fileDescriptor);
} else {
PRINTING_CONTEXT_MAP.put(fileDescriptor, this);
}
}
@Override
public void askUserForSettingsReply(boolean success) {
nativeAskUserForSettingsReply(mNativeObject, success);
}
@CalledByNative
public static PrintingContext create(int nativeObjectPointer) {
ThreadUtils.assertOnUiThread();
return new PrintingContext(nativeObjectPointer);
}
@CalledByNative
public int getFileDescriptor() {
ThreadUtils.assertOnUiThread();
return mController.getFileDescriptor();
}
@CalledByNative
public int getDpi() {
ThreadUtils.assertOnUiThread();
return mController.getDpi();
}
@CalledByNative
public int getWidth() {
ThreadUtils.assertOnUiThread();
return mController.getPageWidth();
}
@CalledByNative
public int getHeight() {
ThreadUtils.assertOnUiThread();
return mController.getPageHeight();
}
@CalledByNative
public static void pdfWritingDone(int fd, boolean success) {
ThreadUtils.assertOnUiThread();
if (PRINTING_CONTEXT_MAP.get(fd) != null) {
ThreadUtils.assertOnUiThread();
PrintingContext printingContext = PRINTING_CONTEXT_MAP.get(fd);
printingContext.mController.pdfWritingDone(success);
PRINTING_CONTEXT_MAP.remove(fd);
}
}
@CalledByNative
public int[] getPages() {
ThreadUtils.assertOnUiThread();
return mController.getPageNumbers();
}
@CalledByNative
public void pageCountEstimationDone(final int maxPages) {
ThreadUtils.assertOnUiThread();
if (mController.hasPrintingFinished()) {
nativeAskUserForSettingsReply(mNativeObject, false);
} else {
mController.setPrintingContext(this);
mController.pageCountEstimationDone(maxPages);
}
}
private native void nativeAskUserForSettingsReply(
long nativePrintingContextAndroid,
boolean success);