Rename maxPages to pageCount and partial support for Android

This commit is contained in:
Sebastián Katzer 2019-02-11 12:05:09 +01:00
parent f29b519b90
commit 33814415db
5 changed files with 29 additions and 10 deletions

View File

@ -46,6 +46,9 @@ class PrintAdapter extends PrintDocumentAdapter {
// The name of the print job
private final @NonNull String jobName;
// Max page count
private final int pageCount;
// The input stream to render
private final @NonNull InputStream input;
@ -56,13 +59,16 @@ class PrintAdapter extends PrintDocumentAdapter {
* Constructor
*
* @param jobName The name of the print job.
* @param pageCount The max page count.
* @param input The input stream to render.
* @param callback The callback to inform once the job is done.
*/
PrintAdapter (@NonNull String jobName, @NonNull InputStream input,
PrintAdapter (@NonNull String jobName, int pageCount,
@NonNull InputStream input,
@NonNull PrintHelper.OnPrintFinishCallback callback)
{
this.jobName = jobName;
this.pageCount = pageCount;
this.input = input;
this.callback = callback;
}
@ -81,6 +87,7 @@ class PrintAdapter extends PrintDocumentAdapter {
pdi = new PrintDocumentInfo.Builder(jobName)
.setContentType(CONTENT_TYPE_DOCUMENT)
.setPageCount(pageCount)
.build();
boolean changed = !newAttributes.equals(oldAttributes);

View File

@ -245,7 +245,8 @@ class PrintManager {
PrintOptions options = new PrintOptions(settings);
String jobName = options.getJobName();
PrintAdapter adapter = new PrintAdapter(jobName, stream, () -> callback.onFinish(isPrintJobCompleted(jobName)));
Integer pageCount = options.getPageCount();
PrintAdapter adapter = new PrintAdapter(jobName, pageCount, stream, () -> callback.onFinish(isPrintJobCompleted(jobName)));
printAdapter(adapter, options);
}

View File

@ -34,6 +34,7 @@ import static android.print.PrintAttributes.DUPLEX_MODE_SHORT_EDGE;
import static android.print.PrintAttributes.Margins.NO_MARGINS;
import static android.print.PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE;
import static android.print.PrintAttributes.MediaSize.UNKNOWN_PORTRAIT;
import static android.print.PrintDocumentInfo.PAGE_COUNT_UNKNOWN;
import static android.support.v4.print.PrintHelper.ORIENTATION_LANDSCAPE;
import static android.support.v4.print.PrintHelper.ORIENTATION_PORTRAIT;
import static android.support.v4.print.PrintHelper.SCALE_MODE_FILL;
@ -72,6 +73,16 @@ class PrintOptions {
return jobName;
}
/**
* Returns the max page count.
*/
int getPageCount()
{
int count = spec.optInt("pageCount", PAGE_COUNT_UNKNOWN);
return count <= 0 ? PAGE_COUNT_UNKNOWN : count;
}
/**
* Converts the options into a PrintAttributes object.
*/

View File

@ -65,7 +65,7 @@
- (NSInteger) numberOfPages
{
NSInteger num = [super numberOfPages];
id maxPages = _settings[@"maxPages"];
id maxPages = _settings[@"pageCount"];
if (maxPages < 0)
{

View File

@ -32,7 +32,7 @@ exports._defaults = {
// monochrome: false,
// copies: 1,
// maxPages: 10,
// pageCount: 1,
// border: true,
// maxHeight: '10cm',