FileDocCategorySizeDatePackage
PrintHelper.javaAPI DocAndroid 5.1 API10877Thu Mar 12 22:22:56 GMT 2015android.support.v4.print

PrintHelper

public final class PrintHelper extends Object
Helper for printing bitmaps.

Fields Summary
public static final int
SCALE_MODE_FIT
image will be scaled but leave white space
public static final int
SCALE_MODE_FILL
image will fill the paper and be cropped (default)
public static final int
COLOR_MODE_MONOCHROME
this is a black and white image
public static final int
COLOR_MODE_COLOR
this is a color image (default)
public static final int
ORIENTATION_LANDSCAPE
Print the image in landscape orientation (default).
public static final int
ORIENTATION_PORTRAIT
Print the image in portrait orientation.
PrintHelperVersionImpl
mImpl
Constructors Summary
public PrintHelper(android.content.Context context)
Returns the PrintHelper that can be used to print images.

param
context A context for accessing system resources.
return
the PrintHelper to support printing images.

        if (systemSupportsPrint()) {
            mImpl = new PrintHelperKitkatImpl(context);
        } else {
            mImpl = new PrintHelperStubImpl();
        }
    
Methods Summary
public intgetColorMode()
Gets the color mode with which the image will be printed.

return
The color mode which is one of {@link #COLOR_MODE_COLOR} and {@link #COLOR_MODE_MONOCHROME}.

        return mImpl.getColorMode();
    
public intgetOrientation()
Gets whether the image will be printed in landscape or portrait.

return
The page orientation which is one of {@link #ORIENTATION_LANDSCAPE} or {@link #ORIENTATION_PORTRAIT}.

        return mImpl.getOrientation();
    
public intgetScaleMode()
Returns the scale mode with which the image will fill the paper.

return
The scale Mode: {@link #SCALE_MODE_FIT} or {@link #SCALE_MODE_FILL}

        return mImpl.getScaleMode();
    
public voidprintBitmap(java.lang.String jobName, android.graphics.Bitmap bitmap, android.support.v4.print.PrintHelper$OnPrintFinishCallback callback)
Prints a bitmap.

param
jobName The print job name.
param
bitmap The bitmap to print.
param
callback Optional callback to observe when printing is finished.

        mImpl.printBitmap(jobName, bitmap, callback);
    
public voidprintBitmap(java.lang.String jobName, android.net.Uri imageFile)
Prints an image located at the Uri. Image types supported are those of {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) android.graphics.BitmapFactory.decodeStream(java.io.InputStream)}

param
jobName The print job name.
param
imageFile The Uri pointing to an image to print.
throws
FileNotFoundException if Uri is not pointing to a valid image.

        mImpl.printBitmap(jobName, imageFile, null);
    
public voidprintBitmap(java.lang.String jobName, android.net.Uri imageFile, android.support.v4.print.PrintHelper$OnPrintFinishCallback callback)
Prints an image located at the Uri. Image types supported are those of {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) android.graphics.BitmapFactory.decodeStream(java.io.InputStream)}

param
jobName The print job name.
param
imageFile The Uri pointing to an image to print.
throws
FileNotFoundException if Uri is not pointing to a valid image.
param
callback Optional callback to observe when printing is finished.

        mImpl.printBitmap(jobName, imageFile, callback);
    
public voidprintBitmap(java.lang.String jobName, android.graphics.Bitmap bitmap)
Prints a bitmap.

param
jobName The print job name.
param
bitmap The bitmap to print.

        mImpl.printBitmap(jobName, bitmap, null);
    
public voidsetColorMode(int colorMode)
Sets whether the image will be printed in color (default) {@link #COLOR_MODE_COLOR} or in back and white {@link #COLOR_MODE_MONOCHROME}.

param
colorMode The color mode which is one of {@link #COLOR_MODE_COLOR} and {@link #COLOR_MODE_MONOCHROME}.

        mImpl.setColorMode(colorMode);
    
public voidsetOrientation(int orientation)
Sets whether the image will be printed in landscape {@link #ORIENTATION_LANDSCAPE} (default) or portrait {@link #ORIENTATION_PORTRAIT}.

param
orientation The page orientation which is one of {@link #ORIENTATION_LANDSCAPE} or {@link #ORIENTATION_PORTRAIT}.

        mImpl.setOrientation(orientation);
    
public voidsetScaleMode(int scaleMode)
Selects whether the image will fill the paper and be cropped {@link #SCALE_MODE_FIT} or whether the image will be scaled but leave white space {@link #SCALE_MODE_FILL}.

param
scaleMode {@link #SCALE_MODE_FIT} or {@link #SCALE_MODE_FILL}

        mImpl.setScaleMode(scaleMode);
    
public static booleansystemSupportsPrint()
Gets whether the system supports printing.

return
True if printing is supported.


                     
        
        if (Build.VERSION.SDK_INT >= 19) {
            // Supported on Android 4.4 or later.
            return true;
        }
        return false;