PrintDocumentAdapter Class

Definition

Base class that provides the content of a document to be printed.

[Android.Runtime.Register("android/print/PrintDocumentAdapter", DoNotGenerateAcw=true)]
public abstract class PrintDocumentAdapter : Java.Lang.Object
[<Android.Runtime.Register("android/print/PrintDocumentAdapter", DoNotGenerateAcw=true)>]
type PrintDocumentAdapter = class
    inherit Object
Inheritance
PrintDocumentAdapter
Attributes

Remarks

Base class that provides the content of a document to be printed.

<h3>Lifecycle</h3>

<ul> <li> Initially, you will receive a call to #onStart(). This callback can be used to allocate resources. </li> <li> Next, you will get one or more calls to #onLayout(PrintAttributes, PrintAttributes, CancellationSignal, LayoutResultCallback, Bundle) to inform you that the print attributes (page size, density, etc) changed giving you an opportunity to layout the content to match the new constraints. </li> <li> After every call to #onLayout(PrintAttributes, PrintAttributes, CancellationSignal, LayoutResultCallback, Bundle), you <strong>may</strong> get a call to #onWrite(PageRange[], ParcelFileDescriptor, CancellationSignal, WriteResultCallback) asking you to write a PDF file with the content for specific pages. </li> <li> Finally, you will receive a call to #onFinish(). You can use this callback to release resources allocated in #onStart(). </li> </ul>

The #onStart() callback is always the first call you will receive and is useful for doing one time setup or resource allocation before printing. You will not receive a subsequent call here.

The #onLayout(PrintAttributes, PrintAttributes, CancellationSignal, LayoutResultCallback, Bundle) callback requires that you layout the content based on the current PrintAttributes. The execution of this method is not considered completed until you invoke one of the methods on the passed in callback instance. Hence, you will not receive a subsequent call to any other method of this class until the execution of this method is complete by invoking one of the callback methods.

The #onWrite(PageRange[], ParcelFileDescriptor, CancellationSignal, WriteResultCallback) requires that you render and write the content of some pages to the provided destination. The execution of this method is not considered complete until you invoke one of the methods on the passed in callback instance. Hence, you will not receive a subsequent call to any other method of this class until the execution of this method is complete by invoking one of the callback methods. You will never receive a sequence of one or more calls to this method without a previous call to #onLayout(PrintAttributes, PrintAttributes, CancellationSignal, LayoutResultCallback, Bundle).

The #onFinish() callback is always the last call you will receive and is useful for doing one time cleanup or resource deallocation after printing. You will not receive a subsequent call here.

</p> <h3>Implementation</h3>

The APIs defined in this class are designed to enable doing part or all of the work on an arbitrary thread. For example, if the printed content does not depend on the UI state, i.e. on what is shown on the screen, then you can offload the entire work on a dedicated thread, thus making your application interactive while the print work is being performed. Note that while your activity is covered by the system print UI and a user cannot interact with it, doing the printing work on the main application thread may affect the performance of your other application components as they are also executed on that thread.

You can also do work on different threads, for example if you print UI content, you can handle #onStart() and #onLayout(PrintAttributes, PrintAttributes, CancellationSignal, LayoutResultCallback, Bundle) on the UI thread (assuming onStart initializes resources needed for layout). This will ensure that the UI does not change while you are laying out the printed content. Then you can handle #onWrite(PageRange[], ParcelFileDescriptor, CancellationSignal, WriteResultCallback) and #onFinish() on another thread. This will ensure that the main thread is busy for a minimal amount of time. Also this assumes that you will generate the printed content in #onLayout(PrintAttributes, PrintAttributes, CancellationSignal, LayoutResultCallback, Bundle) which is not mandatory. If you use multiple threads, you are responsible for proper synchronization.

Java documentation for android.print.PrintDocumentAdapter.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

PrintDocumentAdapter()
PrintDocumentAdapter(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Fields

ExtraPrintPreview

Extra: mapped to a boolean value that is true if the current layout is for a print preview, false otherwise.

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
OnFinish()

Called when printing finishes.

OnLayout(PrintAttributes, PrintAttributes, CancellationSignal, PrintDocumentAdapter+LayoutResultCallback, Bundle)

Called when the print attributes (page size, density, etc) changed giving you a chance to layout the content such that it matches the new constraints.

OnStart()

Called when printing starts.

OnWrite(PageRange[], ParcelFileDescriptor, CancellationSignal, PrintDocumentAdapter+WriteResultCallback)

Called when specific pages of the content should be written in the form of a PDF file to the given file descriptor.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to