Rename maxPages to pageCount and partial support for Android
This commit is contained in:
parent
f29b519b90
commit
33814415db
@ -46,6 +46,9 @@ class PrintAdapter extends PrintDocumentAdapter {
|
|||||||
// The name of the print job
|
// The name of the print job
|
||||||
private final @NonNull String jobName;
|
private final @NonNull String jobName;
|
||||||
|
|
||||||
|
// Max page count
|
||||||
|
private final int pageCount;
|
||||||
|
|
||||||
// The input stream to render
|
// The input stream to render
|
||||||
private final @NonNull InputStream input;
|
private final @NonNull InputStream input;
|
||||||
|
|
||||||
@ -56,13 +59,16 @@ class PrintAdapter extends PrintDocumentAdapter {
|
|||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param jobName The name of the print job.
|
* @param jobName The name of the print job.
|
||||||
|
* @param pageCount The max page count.
|
||||||
* @param input The input stream to render.
|
* @param input The input stream to render.
|
||||||
* @param callback The callback to inform once the job is done.
|
* @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)
|
@NonNull PrintHelper.OnPrintFinishCallback callback)
|
||||||
{
|
{
|
||||||
this.jobName = jobName;
|
this.jobName = jobName;
|
||||||
|
this.pageCount = pageCount;
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
}
|
}
|
||||||
@ -81,6 +87,7 @@ class PrintAdapter extends PrintDocumentAdapter {
|
|||||||
|
|
||||||
pdi = new PrintDocumentInfo.Builder(jobName)
|
pdi = new PrintDocumentInfo.Builder(jobName)
|
||||||
.setContentType(CONTENT_TYPE_DOCUMENT)
|
.setContentType(CONTENT_TYPE_DOCUMENT)
|
||||||
|
.setPageCount(pageCount)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
boolean changed = !newAttributes.equals(oldAttributes);
|
boolean changed = !newAttributes.equals(oldAttributes);
|
||||||
|
@ -245,7 +245,8 @@ class PrintManager {
|
|||||||
|
|
||||||
PrintOptions options = new PrintOptions(settings);
|
PrintOptions options = new PrintOptions(settings);
|
||||||
String jobName = options.getJobName();
|
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);
|
printAdapter(adapter, options);
|
||||||
}
|
}
|
||||||
|
@ -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.Margins.NO_MARGINS;
|
||||||
import static android.print.PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE;
|
import static android.print.PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE;
|
||||||
import static android.print.PrintAttributes.MediaSize.UNKNOWN_PORTRAIT;
|
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_LANDSCAPE;
|
||||||
import static android.support.v4.print.PrintHelper.ORIENTATION_PORTRAIT;
|
import static android.support.v4.print.PrintHelper.ORIENTATION_PORTRAIT;
|
||||||
import static android.support.v4.print.PrintHelper.SCALE_MODE_FILL;
|
import static android.support.v4.print.PrintHelper.SCALE_MODE_FILL;
|
||||||
@ -72,6 +73,16 @@ class PrintOptions {
|
|||||||
return jobName;
|
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.
|
* Converts the options into a PrintAttributes object.
|
||||||
*/
|
*/
|
||||||
|
@ -65,7 +65,7 @@
|
|||||||
- (NSInteger) numberOfPages
|
- (NSInteger) numberOfPages
|
||||||
{
|
{
|
||||||
NSInteger num = [super numberOfPages];
|
NSInteger num = [super numberOfPages];
|
||||||
id maxPages = _settings[@"maxPages"];
|
id maxPages = _settings[@"pageCount"];
|
||||||
|
|
||||||
if (maxPages < 0)
|
if (maxPages < 0)
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@ exports._defaults = {
|
|||||||
// monochrome: false,
|
// monochrome: false,
|
||||||
|
|
||||||
// copies: 1,
|
// copies: 1,
|
||||||
// maxPages: 10,
|
// pageCount: 1,
|
||||||
|
|
||||||
// border: true,
|
// border: true,
|
||||||
// maxHeight: '10cm',
|
// maxHeight: '10cm',
|
||||||
|
Loading…
Reference in New Issue
Block a user