PrinterCapabilitiesInfo.Builder

public static final class PrinterCapabilitiesInfo.Builder
extends Object

java.lang.Object
   ↳ android.print.PrinterCapabilitiesInfo.Builder


Builder for creating of a PrinterCapabilitiesInfo. This class is responsible to enforce that all required attributes have at least one default value. In other words, this class creates only well-formed PrinterCapabilitiesInfos.

Look at the individual methods for a reference whether a property is required or if it is optional.

Summary

Public constructors

PrinterCapabilitiesInfo.Builder(PrinterId printerId)

Creates a new instance.

Public methods

PrinterCapabilitiesInfo.Builder addMediaSize(PrintAttributes.MediaSize mediaSize, boolean isDefault)

Adds a supported media size.

PrinterCapabilitiesInfo.Builder addResolution(PrintAttributes.Resolution resolution, boolean isDefault)

Adds a supported resolution.

PrinterCapabilitiesInfo build()

Crates a new PrinterCapabilitiesInfo enforcing that all required properties have been specified.

PrinterCapabilitiesInfo.Builder setColorModes(int colorModes, int defaultColorMode)

Sets the color modes.

PrinterCapabilitiesInfo.Builder setDuplexModes(int duplexModes, int defaultDuplexMode)

Sets the duplex modes.

PrinterCapabilitiesInfo.Builder setMinMargins(PrintAttributes.Margins margins)

Sets the minimal margins.

Inherited methods

Public constructors

PrinterCapabilitiesInfo.Builder

added in API level 19
public PrinterCapabilitiesInfo.Builder (PrinterId printerId)

Creates a new instance.

Parameters
printerId PrinterId: The printer id. Cannot be null.

Throws
IllegalArgumentException If the printer id is null.

Public methods

addMediaSize

added in API level 19
public PrinterCapabilitiesInfo.Builder addMediaSize (PrintAttributes.MediaSize mediaSize, 
                boolean isDefault)

Adds a supported media size.

Required: Yes

Parameters
mediaSize PrintAttributes.MediaSize: A media size.

This value must never be null.

isDefault boolean: Whether this is the default.

Returns
PrinterCapabilitiesInfo.Builder This builder.

This value will never be null.

Throws
IllegalArgumentException If set as default and there is already a default.

addResolution

added in API level 19
public PrinterCapabilitiesInfo.Builder addResolution (PrintAttributes.Resolution resolution, 
                boolean isDefault)

Adds a supported resolution.

Required: Yes

Parameters
resolution PrintAttributes.Resolution: A resolution.

This value must never be null.

isDefault boolean: Whether this is the default.

Returns
PrinterCapabilitiesInfo.Builder This builder.

This value will never be null.

Throws
IllegalArgumentException If set as default and there is already a default.

build

added in API level 19
public PrinterCapabilitiesInfo build ()

Crates a new PrinterCapabilitiesInfo enforcing that all required properties have been specified. See individual methods in this class for reference about required attributes.

Note: If you do not add supported duplex modes, PrintAttributes.DUPLEX_MODE_NONE will set as the only supported mode and also as the default duplex mode.

Returns
PrinterCapabilitiesInfo A new PrinterCapabilitiesInfo.

This value will never be null.

Throws
IllegalStateException If a required attribute was not specified.

setColorModes

added in API level 19
public PrinterCapabilitiesInfo.Builder setColorModes (int colorModes, 
                int defaultColorMode)

Sets the color modes.

Required: Yes

Parameters
colorModes int: The color mode bit mask.

Value is either 0 or combination of COLOR_MODE_MONOCHROME or COLOR_MODE_COLOR.

defaultColorMode int: The default color mode.

Value is either 0 or combination of COLOR_MODE_MONOCHROME or COLOR_MODE_COLOR.

Returns
PrinterCapabilitiesInfo.Builder This builder.

Note: On platform version 19 (Kitkat) specifying only PrintAttributes#COLOR_MODE_MONOCHROME leads to a print spooler crash. Hence, you should declare either both color modes or PrintAttributes#COLOR_MODE_COLOR.

This value will never be null.

Throws
IllegalArgumentException If color modes contains an invalid mode bit or if the default color mode is invalid.

setDuplexModes

added in API level 23
public PrinterCapabilitiesInfo.Builder setDuplexModes (int duplexModes, 
                int defaultDuplexMode)

Sets the duplex modes.

Required: No

Parameters
duplexModes int: The duplex mode bit mask.

Value is either 0 or combination of DUPLEX_MODE_NONE, DUPLEX_MODE_LONG_EDGE or DUPLEX_MODE_SHORT_EDGE.

defaultDuplexMode int: The default duplex mode.

Value is either 0 or combination of DUPLEX_MODE_NONE, DUPLEX_MODE_LONG_EDGE or DUPLEX_MODE_SHORT_EDGE.

Returns
PrinterCapabilitiesInfo.Builder This builder.

This value will never be null.

Throws
IllegalArgumentException If duplex modes contains an invalid mode bit or if the default duplex mode is invalid.

setMinMargins

added in API level 19
public PrinterCapabilitiesInfo.Builder setMinMargins (PrintAttributes.Margins margins)

Sets the minimal margins. These are the minimal margins the printer physically supports.

Required: Yes

Parameters
margins PrintAttributes.Margins: The margins.

This value must never be null.

Returns
PrinterCapabilitiesInfo.Builder This builder.

This value will never be null.

Throws
IllegalArgumentException If margins are null.