Changes

Jump to: navigation, search

An Android Studio Custom Document Printing Example

21 bytes added, 19:56, 27 October 2016
m
Text replacement - "<table border="0" cellspacing="0">" to "<table border="0" cellspacing="0" width="100%">"
<htmlet>androidstudio_a6androidstudio</htmlet>
=== Custom Print Adapters ===
<googlehtmlet>ADSDAQBOX_FLOWadsdaqbox_flow</googlehtmlet>
The role of the print adapter is to provide the Printing framework with the content to be printed, and to ensure that it is formatted correctly for the user’s chosen preferences (taking into consideration factors such as paper size and page orientation).
As previously outlined, when the onWrite() method is called it is passed an array of PageRange objects indicating the ranges of pages within the document that are to be printed. The PageRange class is designed to store the start and end pages of a page range which, in turn, may be accessed via the getStart() and getEnd() methods of the class.
<htmlet>androidstudio_a6androidstudio</htmlet>
When the onWrite() method was implemented in the previous section, a call was made to a method named pageInRange(), which takes as arguments an array of PageRange objects and a page number. The role of the pageInRange() method is to identify whether the specified page number is within the ranges specified and may be implemented within the MyPrintDocumentAdapter class in the CustomPrintActivity.java class as follows:
<htmlet>androidstudio_a6androidstudio</htmlet>
 
<htmlet>ezoicbottom</htmlet>
<hr>
<table border="0" cellspacing="0" width="100%">

Navigation menu