1b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav/* 2b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * Copyright (C) 2013 The Android Open Source Project 3b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * 4b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * Licensed under the Apache License, Version 2.0 (the "License"); 5b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * you may not use this file except in compliance with the License. 6b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * You may obtain a copy of the License at 7b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * 8b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * http://www.apache.org/licenses/LICENSE-2.0 9b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * 10b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * Unless required by applicable law or agreed to in writing, software 11b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * distributed under the License is distributed on an "AS IS" BASIS, 12b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * See the License for the specific language governing permissions and 14b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * limitations under the License. 15b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav */ 16b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 17b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslavpackage android.support.v4.print; 18b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 19b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslavimport android.content.Context; 20b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslavimport android.graphics.Bitmap; 21b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslavimport android.os.Build; 22b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslavimport android.net.Uri; 23b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 24b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslavimport java.io.FileNotFoundException; 25b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 26b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav/** 27b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * Helper for printing bitmaps. 28b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav */ 29b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslavpublic final class PrintHelper { 30b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav /** 31b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * image will be scaled but leave white space 32b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav */ 33b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav public static final int SCALE_MODE_FIT = 1; 3409ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov 35b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav /** 36b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * image will fill the paper and be cropped (default) 37b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav */ 38b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav public static final int SCALE_MODE_FILL = 2; 3909ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov 4009ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov /** 4109ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov * this is a black and white image 4209ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov */ 4309ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov public static final int COLOR_MODE_MONOCHROME = 1; 4409ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov 4509ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov /** 4609ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov * this is a color image (default) 4709ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov */ 4809ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov public static final int COLOR_MODE_COLOR = 2; 4909ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov 50975c49f182d754dfe1a38ba0457d6e603b125570John Hoford /** 51975c49f182d754dfe1a38ba0457d6e603b125570John Hoford * Print the image in landscape orientation (default). 52975c49f182d754dfe1a38ba0457d6e603b125570John Hoford */ 53975c49f182d754dfe1a38ba0457d6e603b125570John Hoford public static final int ORIENTATION_LANDSCAPE = 1; 54975c49f182d754dfe1a38ba0457d6e603b125570John Hoford 55975c49f182d754dfe1a38ba0457d6e603b125570John Hoford /** 56975c49f182d754dfe1a38ba0457d6e603b125570John Hoford * Print the image in portrait orientation. 57975c49f182d754dfe1a38ba0457d6e603b125570John Hoford */ 58975c49f182d754dfe1a38ba0457d6e603b125570John Hoford public static final int ORIENTATION_PORTRAIT = 2; 59975c49f182d754dfe1a38ba0457d6e603b125570John Hoford 60b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov /** 61b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * Callback for observing when a print operation is completed. 62b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * When print is finished either the system acquired the 63b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * document to print or printing was cancelled. 64b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov */ 65b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov public interface OnPrintFinishCallback { 66b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov 67b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov /** 68b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * Called when a print operation is finished. 69b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov */ 70b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov public void onFinish(); 71b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov } 72b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov 73b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav PrintHelperVersionImpl mImpl; 74b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 75b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav /** 76b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * Gets whether the system supports printing. 77b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * 78b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * @return True if printing is supported. 79b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav */ 80b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav public static boolean systemSupportsPrint() { 81b07ca601bba6ed850b7cf9fedcd44158d78a721fDianne Hackborn if (Build.VERSION.SDK_INT >= 19) { 82b07ca601bba6ed850b7cf9fedcd44158d78a721fDianne Hackborn // Supported on Android 4.4 or later. 83b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav return true; 84b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 85b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav return false; 86b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 87b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 88b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav /** 89b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * Interface implemented by classes that support printing 90b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav */ 91b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav static interface PrintHelperVersionImpl { 92b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 93b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav public void setScaleMode(int scaleMode); 94b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 95b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav public int getScaleMode(); 96b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 9709ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov public void setColorMode(int colorMode); 9809ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov 9909ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov public int getColorMode(); 10009ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov 101975c49f182d754dfe1a38ba0457d6e603b125570John Hoford public void setOrientation(int orientation); 102975c49f182d754dfe1a38ba0457d6e603b125570John Hoford 103975c49f182d754dfe1a38ba0457d6e603b125570John Hoford public int getOrientation(); 104975c49f182d754dfe1a38ba0457d6e603b125570John Hoford 105b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov public void printBitmap(String jobName, Bitmap bitmap, OnPrintFinishCallback callback); 106b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 107b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov public void printBitmap(String jobName, Uri imageFile, OnPrintFinishCallback callback) 108b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav throws FileNotFoundException; 109b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 110b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 111b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav /** 112b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * Implementation used when we do not support printing 113b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav */ 114b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav private static final class PrintHelperStubImpl implements PrintHelperVersionImpl { 11509ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov int mScaleMode = SCALE_MODE_FILL; 11609ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov int mColorMode = COLOR_MODE_COLOR; 117975c49f182d754dfe1a38ba0457d6e603b125570John Hoford int mOrientation = ORIENTATION_LANDSCAPE; 118b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav @Override 119b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav public void setScaleMode(int scaleMode) { 120b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav mScaleMode = scaleMode; 121b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 122b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 123b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav @Override 12409ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov public int getColorMode() { 12509ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov return mColorMode; 12609ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov } 12709ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov 12809ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov @Override 12909ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov public void setColorMode(int colorMode) { 13009ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov mColorMode = colorMode; 13109ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov } 13209ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov 13309ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov @Override 134975c49f182d754dfe1a38ba0457d6e603b125570John Hoford public void setOrientation(int orientation) { mOrientation = orientation; } 135975c49f182d754dfe1a38ba0457d6e603b125570John Hoford 136975c49f182d754dfe1a38ba0457d6e603b125570John Hoford @Override 137975c49f182d754dfe1a38ba0457d6e603b125570John Hoford public int getOrientation() { return mOrientation; } 138975c49f182d754dfe1a38ba0457d6e603b125570John Hoford 139975c49f182d754dfe1a38ba0457d6e603b125570John Hoford @Override 140b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav public int getScaleMode() { 141b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav return mScaleMode; 142b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 143b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 144b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav @Override 145b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov public void printBitmap(String jobName, Bitmap bitmap, OnPrintFinishCallback callback) { 146b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 147b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 148b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav @Override 149b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov public void printBitmap(String jobName, Uri imageFile, OnPrintFinishCallback callback) { 150b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 151b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 152b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 153b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav /** 154b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * Implementation used on KitKat (and above) 155b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav */ 156b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav private static final class PrintHelperKitkatImpl implements PrintHelperVersionImpl { 157975c49f182d754dfe1a38ba0457d6e603b125570John Hoford private final PrintHelperKitkat mPrintHelper; 158b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 159b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav PrintHelperKitkatImpl(Context context) { 160975c49f182d754dfe1a38ba0457d6e603b125570John Hoford mPrintHelper = new PrintHelperKitkat(context); 161b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 162b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 163b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav @Override 164b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav public void setScaleMode(int scaleMode) { 165975c49f182d754dfe1a38ba0457d6e603b125570John Hoford mPrintHelper.setScaleMode(scaleMode); 166b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 167b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 168b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav @Override 169b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav public int getScaleMode() { 170975c49f182d754dfe1a38ba0457d6e603b125570John Hoford return mPrintHelper.getScaleMode(); 171b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 172b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 173b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav @Override 17409ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov public void setColorMode(int colorMode) { 175975c49f182d754dfe1a38ba0457d6e603b125570John Hoford mPrintHelper.setColorMode(colorMode); 17609ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov } 17709ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov 17809ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov @Override 17909ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov public int getColorMode() { 180975c49f182d754dfe1a38ba0457d6e603b125570John Hoford return mPrintHelper.getColorMode(); 181975c49f182d754dfe1a38ba0457d6e603b125570John Hoford } 182975c49f182d754dfe1a38ba0457d6e603b125570John Hoford 183975c49f182d754dfe1a38ba0457d6e603b125570John Hoford @Override 184975c49f182d754dfe1a38ba0457d6e603b125570John Hoford public void setOrientation(int orientation) { 185975c49f182d754dfe1a38ba0457d6e603b125570John Hoford mPrintHelper.setOrientation(orientation); 186975c49f182d754dfe1a38ba0457d6e603b125570John Hoford } 187975c49f182d754dfe1a38ba0457d6e603b125570John Hoford 188975c49f182d754dfe1a38ba0457d6e603b125570John Hoford @Override 189975c49f182d754dfe1a38ba0457d6e603b125570John Hoford public int getOrientation() { 190975c49f182d754dfe1a38ba0457d6e603b125570John Hoford return mPrintHelper.getOrientation(); 19109ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov } 19209ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov 19309ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov @Override 194b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov public void printBitmap(String jobName, Bitmap bitmap, 195b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov final OnPrintFinishCallback callback) { 196f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov PrintHelperKitkat.OnPrintFinishCallback delegateCallback = null; 197f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov if (callback != null) { 198f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov delegateCallback = new PrintHelperKitkat.OnPrintFinishCallback() { 199f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov @Override 200f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov public void onFinish() { 201f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov callback.onFinish(); 202f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov } 203f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov }; 204f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov } 205f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov mPrintHelper.printBitmap(jobName, bitmap, delegateCallback); 206b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 207b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 208b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav @Override 209b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov public void printBitmap(String jobName, Uri imageFile, 210b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov final OnPrintFinishCallback callback) throws FileNotFoundException { 211f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov PrintHelperKitkat.OnPrintFinishCallback delegateCallback = null; 212f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov if (callback != null) { 213f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov delegateCallback = new PrintHelperKitkat.OnPrintFinishCallback() { 214f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov @Override 215f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov public void onFinish() { 216f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov callback.onFinish(); 217f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov } 218f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov }; 219f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov } 220f858b86418fc586d681e47c994d81f11c9d12ec2Svet Ganov mPrintHelper.printBitmap(jobName, imageFile, delegateCallback); 221b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 222b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 223b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 224b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav /** 225b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * Returns the PrintHelper that can be used to print images. 226b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * 227b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * @param context A context for accessing system resources. 228b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * @return the <code>PrintHelper</code> to support printing images. 229b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav */ 230b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav public PrintHelper(Context context) { 2315030ecfe56689afe327c82bb8a197999389dee13Svetoslav Ganov if (systemSupportsPrint()) { 232b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav mImpl = new PrintHelperKitkatImpl(context); 233b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } else { 234b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav mImpl = new PrintHelperStubImpl(); 235b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 236b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 237b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 238b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav /** 239b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * Selects whether the image will fill the paper and be cropped 240b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * {@link #SCALE_MODE_FIT} 241b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * or whether the image will be scaled but leave white space 242b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * {@link #SCALE_MODE_FILL}. 243b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * 244b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * @param scaleMode {@link #SCALE_MODE_FIT} or 245b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * {@link #SCALE_MODE_FILL} 246b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav */ 247b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav public void setScaleMode(int scaleMode) { 248b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav mImpl.setScaleMode(scaleMode); 249b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 250b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 251b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav /** 252b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * Returns the scale mode with which the image will fill the paper. 253b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * 254b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * @return The scale Mode: {@link #SCALE_MODE_FIT} or 255b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * {@link #SCALE_MODE_FILL} 256b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav */ 257b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav public int getScaleMode() { 258b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav return mImpl.getScaleMode(); 259b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 260b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 261b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav /** 26209ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov * Sets whether the image will be printed in color (default) 26309ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov * {@link #COLOR_MODE_COLOR} or in back and white 26409ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov * {@link #COLOR_MODE_MONOCHROME}. 26509ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov * 26609ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov * @param colorMode The color mode which is one of 26709ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov * {@link #COLOR_MODE_COLOR} and {@link #COLOR_MODE_MONOCHROME}. 26809ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov */ 26909ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov public void setColorMode(int colorMode) { 27009ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov mImpl.setColorMode(colorMode); 27109ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov } 27209ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov 27309ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov /** 27409ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov * Gets the color mode with which the image will be printed. 27509ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov * 27609ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov * @return The color mode which is one of {@link #COLOR_MODE_COLOR} 27709ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov * and {@link #COLOR_MODE_MONOCHROME}. 27809ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov */ 27909ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov public int getColorMode() { 28009ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov return mImpl.getColorMode(); 28109ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov } 28209ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov 28309ad64345349f27bdeb53c536f178e46bb7ce5acSvetoslav Ganov /** 284975c49f182d754dfe1a38ba0457d6e603b125570John Hoford * Sets whether the image will be printed in landscape {@link #ORIENTATION_LANDSCAPE} (default) 285975c49f182d754dfe1a38ba0457d6e603b125570John Hoford * or portrait {@link #ORIENTATION_PORTRAIT}. 286975c49f182d754dfe1a38ba0457d6e603b125570John Hoford * 287975c49f182d754dfe1a38ba0457d6e603b125570John Hoford * @param orientation The page orientation which is one of 288975c49f182d754dfe1a38ba0457d6e603b125570John Hoford * {@link #ORIENTATION_LANDSCAPE} or {@link #ORIENTATION_PORTRAIT}. 289975c49f182d754dfe1a38ba0457d6e603b125570John Hoford */ 290975c49f182d754dfe1a38ba0457d6e603b125570John Hoford public void setOrientation(int orientation) { 291975c49f182d754dfe1a38ba0457d6e603b125570John Hoford mImpl.setOrientation(orientation); 292975c49f182d754dfe1a38ba0457d6e603b125570John Hoford } 293975c49f182d754dfe1a38ba0457d6e603b125570John Hoford 294975c49f182d754dfe1a38ba0457d6e603b125570John Hoford /** 295975c49f182d754dfe1a38ba0457d6e603b125570John Hoford * Gets whether the image will be printed in landscape or portrait. 296975c49f182d754dfe1a38ba0457d6e603b125570John Hoford * 297975c49f182d754dfe1a38ba0457d6e603b125570John Hoford * @return The page orientation which is one of 298975c49f182d754dfe1a38ba0457d6e603b125570John Hoford * {@link #ORIENTATION_LANDSCAPE} or {@link #ORIENTATION_PORTRAIT}. 299975c49f182d754dfe1a38ba0457d6e603b125570John Hoford */ 300975c49f182d754dfe1a38ba0457d6e603b125570John Hoford public int getOrientation() { 301975c49f182d754dfe1a38ba0457d6e603b125570John Hoford return mImpl.getOrientation(); 302975c49f182d754dfe1a38ba0457d6e603b125570John Hoford } 303975c49f182d754dfe1a38ba0457d6e603b125570John Hoford 304b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov 305975c49f182d754dfe1a38ba0457d6e603b125570John Hoford /** 306b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * Prints a bitmap. 307b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * 308b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * @param jobName The print job name. 309b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * @param bitmap The bitmap to print. 310b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav */ 311b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav public void printBitmap(String jobName, Bitmap bitmap) { 312b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov mImpl.printBitmap(jobName, bitmap, null); 313b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov } 314b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov 315b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov /** 316b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * Prints a bitmap. 317b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * 318b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * @param jobName The print job name. 319b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * @param bitmap The bitmap to print. 320b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * @param callback Optional callback to observe when printing is finished. 321b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov */ 322b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov public void printBitmap(String jobName, Bitmap bitmap, OnPrintFinishCallback callback) { 323b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov mImpl.printBitmap(jobName, bitmap, callback); 324b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 325b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav 326b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav /** 327b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * Prints an image located at the Uri. Image types supported are those of 328b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) 329b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * android.graphics.BitmapFactory.decodeStream(java.io.InputStream)} 330b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * 331b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * @param jobName The print job name. 332b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * @param imageFile The <code>Uri</code> pointing to an image to print. 333b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav * @throws FileNotFoundException if <code>Uri</code> is not pointing to a valid image. 334b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav */ 335b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav public void printBitmap(String jobName, Uri imageFile) throws FileNotFoundException { 336b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov mImpl.printBitmap(jobName, imageFile, null); 337b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov } 338b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov 339b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov /** 340b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * Prints an image located at the Uri. Image types supported are those of 341b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) 342b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * android.graphics.BitmapFactory.decodeStream(java.io.InputStream)} 343b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * 344b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * @param jobName The print job name. 345b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * @param imageFile The <code>Uri</code> pointing to an image to print. 346b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * @throws FileNotFoundException if <code>Uri</code> is not pointing to a valid image. 347b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov * @param callback Optional callback to observe when printing is finished. 348b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov */ 349b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov public void printBitmap(String jobName, Uri imageFile, OnPrintFinishCallback callback) 350b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov throws FileNotFoundException { 351b4eb9c984f1c6ac8007c74fab239437cf9f6b474Svet Ganov mImpl.printBitmap(jobName, imageFile, callback); 352b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav } 353b363776d911abae9d067b9ef77fccc1c3c56e652Svetoslav}