public final class PrintHelper extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
PrintHelper.OnPrintFinishCallback
Callback for observing when a print operation is completed.
|
Modifier and Type | Field and Description |
---|---|
static int |
COLOR_MODE_COLOR
this is a color image (default)
|
static int |
COLOR_MODE_MONOCHROME
this is a black and white image
|
static int |
ORIENTATION_LANDSCAPE
Print the image in landscape orientation (default).
|
static int |
ORIENTATION_PORTRAIT
Print the image in portrait orientation.
|
static int |
SCALE_MODE_FILL
image will fill the paper and be cropped (default)
|
static int |
SCALE_MODE_FIT
image will be scaled but leave white space
|
Constructor and Description |
---|
PrintHelper(Context context)
Returns the PrintHelper that can be used to print images.
|
Modifier and Type | Method and Description |
---|---|
int |
getColorMode()
Gets the color mode with which the image will be printed.
|
int |
getOrientation()
Gets whether the image will be printed in landscape or portrait.
|
int |
getScaleMode()
Returns the scale mode with which the image will fill the paper.
|
void |
printBitmap(String jobName,
Bitmap bitmap)
Prints a bitmap.
|
void |
printBitmap(String jobName,
Bitmap bitmap,
PrintHelper.OnPrintFinishCallback callback)
Prints a bitmap.
|
void |
printBitmap(String jobName,
Uri imageFile)
Prints an image located at the Uri.
|
void |
printBitmap(String jobName,
Uri imageFile,
PrintHelper.OnPrintFinishCallback callback)
Prints an image located at the Uri.
|
void |
setColorMode(int colorMode)
Sets whether the image will be printed in color (default)
COLOR_MODE_COLOR or in back and white
COLOR_MODE_MONOCHROME . |
void |
setOrientation(int orientation)
Sets whether the image will be printed in landscape
ORIENTATION_LANDSCAPE (default)
or portrait ORIENTATION_PORTRAIT . |
void |
setScaleMode(int scaleMode)
Selects whether the image will fill the paper and be cropped
SCALE_MODE_FIT
or whether the image will be scaled but leave white space
SCALE_MODE_FILL . |
static boolean |
systemSupportsPrint()
Gets whether the system supports printing.
|
public static final int SCALE_MODE_FIT
public static final int SCALE_MODE_FILL
public static final int COLOR_MODE_MONOCHROME
public static final int COLOR_MODE_COLOR
public static final int ORIENTATION_LANDSCAPE
public static final int ORIENTATION_PORTRAIT
public PrintHelper(Context context)
context
- A context for accessing system resources.public static boolean systemSupportsPrint()
public void setScaleMode(int scaleMode)
SCALE_MODE_FIT
or whether the image will be scaled but leave white space
SCALE_MODE_FILL
.scaleMode
- SCALE_MODE_FIT
or
SCALE_MODE_FILL
public int getScaleMode()
SCALE_MODE_FIT
or
SCALE_MODE_FILL
public void setColorMode(int colorMode)
COLOR_MODE_COLOR
or in back and white
COLOR_MODE_MONOCHROME
.colorMode
- The color mode which is one of
COLOR_MODE_COLOR
and COLOR_MODE_MONOCHROME
.public int getColorMode()
COLOR_MODE_COLOR
and COLOR_MODE_MONOCHROME
.public void setOrientation(int orientation)
ORIENTATION_LANDSCAPE
(default)
or portrait ORIENTATION_PORTRAIT
.orientation
- The page orientation which is one of
ORIENTATION_LANDSCAPE
or ORIENTATION_PORTRAIT
.public int getOrientation()
ORIENTATION_LANDSCAPE
or ORIENTATION_PORTRAIT
.public void printBitmap(String jobName, Bitmap bitmap)
jobName
- The print job name.bitmap
- The bitmap to print.public void printBitmap(String jobName, Bitmap bitmap, PrintHelper.OnPrintFinishCallback callback)
jobName
- The print job name.bitmap
- The bitmap to print.callback
- Optional callback to observe when printing is finished.public void printBitmap(String jobName, Uri imageFile) throws FileNotFoundException
android.graphics.BitmapFactory.decodeStream(java.io.InputStream)
jobName
- The print job name.imageFile
- The Uri
pointing to an image to print.FileNotFoundException
- if Uri
is not pointing to a valid image.public void printBitmap(String jobName, Uri imageFile, PrintHelper.OnPrintFinishCallback callback) throws FileNotFoundException
android.graphics.BitmapFactory.decodeStream(java.io.InputStream)
jobName
- The print job name.imageFile
- The Uri
pointing to an image to print.callback
- Optional callback to observe when printing is finished.FileNotFoundException
- if Uri
is not pointing to a valid image.