Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.print; |
| 18 | |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 19 | import android.annotation.IntDef; |
| 20 | import android.annotation.IntRange; |
| 21 | import android.annotation.NonNull; |
| 22 | import android.annotation.Nullable; |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 23 | import android.annotation.StringRes; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 24 | import android.content.pm.PackageManager; |
| 25 | import android.content.pm.PackageManager.NameNotFoundException; |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 26 | import android.content.res.Resources.NotFoundException; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 27 | import android.os.Parcel; |
| 28 | import android.os.Parcelable; |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 29 | import android.service.print.PrintAttributesProto; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 30 | import android.text.TextUtils; |
Svetoslav Ganov | 7be27ac | 2013-09-30 09:04:50 -0700 | [diff] [blame] | 31 | import android.util.ArrayMap; |
Philip P. Moltmann | 4959caf | 2016-01-21 14:30:56 -0800 | [diff] [blame] | 32 | import android.util.ArraySet; |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 33 | import android.util.Log; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 34 | |
| 35 | import com.android.internal.R; |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 36 | import com.android.internal.util.Preconditions; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 37 | |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 38 | import java.lang.annotation.Retention; |
| 39 | import java.lang.annotation.RetentionPolicy; |
Svetoslav Ganov | 7be27ac | 2013-09-30 09:04:50 -0700 | [diff] [blame] | 40 | import java.util.Map; |
| 41 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 42 | /** |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 43 | * This class represents the attributes of a print job. These attributes |
| 44 | * describe how the printed content should be laid out. For example, the |
| 45 | * print attributes may state that the content should be laid out on a |
| 46 | * letter size with 300 DPI (dots per inch) resolution, have a margin of |
| 47 | * 10 mills (thousand of an inch) on all sides, and be black and white. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 48 | */ |
| 49 | public final class PrintAttributes implements Parcelable { |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 50 | /** @hide */ |
| 51 | @Retention(RetentionPolicy.SOURCE) |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 52 | @IntDef(flag = true, prefix = { "COLOR_MODE_" }, value = { |
| 53 | COLOR_MODE_MONOCHROME, |
| 54 | COLOR_MODE_COLOR |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 55 | }) |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 56 | @interface ColorMode { |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 57 | } |
Svetoslav Ganov | 22cb917 | 2013-08-29 17:42:07 -0700 | [diff] [blame] | 58 | /** Color mode: Monochrome color scheme, for example one color is used. */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 59 | public static final int COLOR_MODE_MONOCHROME = PrintAttributesProto.COLOR_MODE_MONOCHROME; |
Svetoslav Ganov | 22cb917 | 2013-08-29 17:42:07 -0700 | [diff] [blame] | 60 | /** Color mode: Color color scheme, for example many colors are used. */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 61 | public static final int COLOR_MODE_COLOR = PrintAttributesProto.COLOR_MODE_COLOR; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 62 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 63 | private static final int VALID_COLOR_MODES = |
| 64 | COLOR_MODE_MONOCHROME | COLOR_MODE_COLOR; |
| 65 | |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 66 | /** @hide */ |
| 67 | @Retention(RetentionPolicy.SOURCE) |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 68 | @IntDef(flag = true, prefix = { "DUPLEX_MODE_" }, value = { |
| 69 | DUPLEX_MODE_NONE, |
| 70 | DUPLEX_MODE_LONG_EDGE, |
| 71 | DUPLEX_MODE_SHORT_EDGE |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 72 | }) |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 73 | @interface DuplexMode { |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 74 | } |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 75 | /** Duplex mode: No duplexing. */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 76 | public static final int DUPLEX_MODE_NONE = PrintAttributesProto.DUPLEX_MODE_NONE; |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 77 | /** Duplex mode: Pages are turned sideways along the long edge - like a book. */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 78 | public static final int DUPLEX_MODE_LONG_EDGE = PrintAttributesProto.DUPLEX_MODE_LONG_EDGE; |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 79 | /** Duplex mode: Pages are turned upwards along the short edge - like a notpad. */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 80 | public static final int DUPLEX_MODE_SHORT_EDGE = PrintAttributesProto.DUPLEX_MODE_SHORT_EDGE; |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 81 | |
| 82 | private static final int VALID_DUPLEX_MODES = |
| 83 | DUPLEX_MODE_NONE | DUPLEX_MODE_LONG_EDGE | DUPLEX_MODE_SHORT_EDGE; |
| 84 | |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 85 | private @Nullable MediaSize mMediaSize; |
| 86 | private @Nullable Resolution mResolution; |
| 87 | private @Nullable Margins mMinMargins; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 88 | |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 89 | private @IntRange(from = 0) int mColorMode; |
| 90 | private @IntRange(from = 0) int mDuplexMode; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 91 | |
| 92 | PrintAttributes() { |
| 93 | /* hide constructor */ |
| 94 | } |
| 95 | |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 96 | private PrintAttributes(@NonNull Parcel parcel) { |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 97 | mMediaSize = (parcel.readInt() == 1) ? MediaSize.createFromParcel(parcel) : null; |
| 98 | mResolution = (parcel.readInt() == 1) ? Resolution.createFromParcel(parcel) : null; |
| 99 | mMinMargins = (parcel.readInt() == 1) ? Margins.createFromParcel(parcel) : null; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 100 | mColorMode = parcel.readInt(); |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 101 | if (mColorMode != 0) { |
| 102 | enforceValidColorMode(mColorMode); |
| 103 | } |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 104 | mDuplexMode = parcel.readInt(); |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 105 | if (mDuplexMode != 0) { |
| 106 | enforceValidDuplexMode(mDuplexMode); |
| 107 | } |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Gets the media size. |
| 112 | * |
| 113 | * @return The media size or <code>null</code> if not set. |
| 114 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 115 | public @Nullable MediaSize getMediaSize() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 116 | return mMediaSize; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Sets the media size. |
| 121 | * |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 122 | * @param mediaSize The media size. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 123 | * |
| 124 | * @hide |
| 125 | */ |
| 126 | public void setMediaSize(MediaSize mediaSize) { |
| 127 | mMediaSize = mediaSize; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Gets the resolution. |
| 132 | * |
| 133 | * @return The resolution or <code>null</code> if not set. |
| 134 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 135 | public @Nullable Resolution getResolution() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 136 | return mResolution; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Sets the resolution. |
| 141 | * |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 142 | * @param resolution The resolution. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 143 | * |
| 144 | * @hide |
| 145 | */ |
| 146 | public void setResolution(Resolution resolution) { |
| 147 | mResolution = resolution; |
| 148 | } |
| 149 | |
| 150 | /** |
Svetoslav | 651dd4e | 2013-09-12 14:37:47 -0700 | [diff] [blame] | 151 | * Gets the minimal margins. If the content does not fit |
| 152 | * these margins it will be clipped. |
Svet Ganov | 525a66b | 2014-06-14 22:29:00 -0700 | [diff] [blame] | 153 | * <p> |
| 154 | * <strong>These margins are physically imposed by the printer and they |
| 155 | * are <em>not</em> rotated, i.e. they are the same for both portrait and |
| 156 | * landscape. For example, a printer may not be able to print in a stripe |
| 157 | * on both left and right sides of the page. |
| 158 | * </strong> |
| 159 | * </p> |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 160 | * |
| 161 | * @return The margins or <code>null</code> if not set. |
| 162 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 163 | public @Nullable Margins getMinMargins() { |
Svetoslav | 651dd4e | 2013-09-12 14:37:47 -0700 | [diff] [blame] | 164 | return mMinMargins; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | /** |
Svetoslav | 651dd4e | 2013-09-12 14:37:47 -0700 | [diff] [blame] | 168 | * Sets the minimal margins. If the content does not fit |
| 169 | * these margins it will be clipped. |
Svet Ganov | 525a66b | 2014-06-14 22:29:00 -0700 | [diff] [blame] | 170 | * <p> |
| 171 | * <strong>These margins are physically imposed by the printer and they |
| 172 | * are <em>not</em> rotated, i.e. they are the same for both portrait and |
| 173 | * landscape. For example, a printer may not be able to print in a stripe |
| 174 | * on both left and right sides of the page. |
| 175 | * </strong> |
| 176 | * </p> |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 177 | * |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 178 | * @param margins The margins. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 179 | * |
| 180 | * @hide |
| 181 | */ |
Svetoslav | 651dd4e | 2013-09-12 14:37:47 -0700 | [diff] [blame] | 182 | public void setMinMargins(Margins margins) { |
| 183 | mMinMargins = margins; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /** |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 187 | * Gets the color mode. |
| 188 | * |
| 189 | * @return The color mode or zero if not set. |
| 190 | * |
| 191 | * @see #COLOR_MODE_COLOR |
| 192 | * @see #COLOR_MODE_MONOCHROME |
| 193 | */ |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 194 | public @IntRange(from = 0) int getColorMode() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 195 | return mColorMode; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Sets the color mode. |
| 200 | * |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 201 | * @param colorMode The color mode. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 202 | * |
| 203 | * @see #COLOR_MODE_MONOCHROME |
| 204 | * @see #COLOR_MODE_COLOR |
| 205 | * |
| 206 | * @hide |
| 207 | */ |
| 208 | public void setColorMode(int colorMode) { |
| 209 | enforceValidColorMode(colorMode); |
| 210 | mColorMode = colorMode; |
| 211 | } |
| 212 | |
Svetoslav | a798c0a | 2014-05-15 10:47:19 -0700 | [diff] [blame] | 213 | /** |
| 214 | * Gets whether this print attributes are in portrait orientation, |
| 215 | * which is the media size is in portrait and all orientation dependent |
| 216 | * attributes such as resolution and margins are properly adjusted. |
| 217 | * |
| 218 | * @return Whether this print attributes are in portrait. |
| 219 | * |
| 220 | * @hide |
| 221 | */ |
| 222 | public boolean isPortrait() { |
| 223 | return mMediaSize.isPortrait(); |
| 224 | } |
| 225 | |
| 226 | /** |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 227 | * Gets the duplex mode. |
| 228 | * |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 229 | * @return The duplex mode or zero if not set. |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 230 | * |
| 231 | * @see #DUPLEX_MODE_NONE |
| 232 | * @see #DUPLEX_MODE_LONG_EDGE |
| 233 | * @see #DUPLEX_MODE_SHORT_EDGE |
| 234 | */ |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 235 | public @IntRange(from = 0) int getDuplexMode() { |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 236 | return mDuplexMode; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Sets the duplex mode. |
| 241 | * |
| 242 | * @param duplexMode The duplex mode. |
| 243 | * |
| 244 | * @see #DUPLEX_MODE_NONE |
| 245 | * @see #DUPLEX_MODE_LONG_EDGE |
| 246 | * @see #DUPLEX_MODE_SHORT_EDGE |
| 247 | * |
| 248 | * @hide |
| 249 | */ |
| 250 | public void setDuplexMode(int duplexMode) { |
| 251 | enforceValidDuplexMode(duplexMode); |
| 252 | mDuplexMode = duplexMode; |
| 253 | } |
| 254 | |
| 255 | /** |
Svetoslav | a798c0a | 2014-05-15 10:47:19 -0700 | [diff] [blame] | 256 | * Gets a new print attributes instance which is in portrait orientation, |
| 257 | * which is the media size is in portrait and all orientation dependent |
| 258 | * attributes such as resolution and margins are properly adjusted. |
| 259 | * |
| 260 | * @return New instance in portrait orientation if this one is in |
| 261 | * landscape, otherwise this instance. |
| 262 | * |
| 263 | * @hide |
| 264 | */ |
| 265 | public PrintAttributes asPortrait() { |
| 266 | if (isPortrait()) { |
| 267 | return this; |
| 268 | } |
| 269 | |
| 270 | PrintAttributes attributes = new PrintAttributes(); |
| 271 | |
| 272 | // Rotate the media size. |
| 273 | attributes.setMediaSize(getMediaSize().asPortrait()); |
| 274 | |
| 275 | // Rotate the resolution. |
| 276 | Resolution oldResolution = getResolution(); |
| 277 | Resolution newResolution = new Resolution( |
| 278 | oldResolution.getId(), |
| 279 | oldResolution.getLabel(), |
| 280 | oldResolution.getVerticalDpi(), |
| 281 | oldResolution.getHorizontalDpi()); |
| 282 | attributes.setResolution(newResolution); |
| 283 | |
Svet Ganov | 525a66b | 2014-06-14 22:29:00 -0700 | [diff] [blame] | 284 | // Do not rotate the physical margins. |
| 285 | attributes.setMinMargins(getMinMargins()); |
Svetoslav | a798c0a | 2014-05-15 10:47:19 -0700 | [diff] [blame] | 286 | |
| 287 | attributes.setColorMode(getColorMode()); |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 288 | attributes.setDuplexMode(getDuplexMode()); |
Svetoslav | a798c0a | 2014-05-15 10:47:19 -0700 | [diff] [blame] | 289 | |
| 290 | return attributes; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Gets a new print attributes instance which is in landscape orientation, |
| 295 | * which is the media size is in landscape and all orientation dependent |
| 296 | * attributes such as resolution and margins are properly adjusted. |
| 297 | * |
| 298 | * @return New instance in landscape orientation if this one is in |
| 299 | * portrait, otherwise this instance. |
| 300 | * |
| 301 | * @hide |
| 302 | */ |
| 303 | public PrintAttributes asLandscape() { |
| 304 | if (!isPortrait()) { |
| 305 | return this; |
| 306 | } |
| 307 | |
| 308 | PrintAttributes attributes = new PrintAttributes(); |
| 309 | |
| 310 | // Rotate the media size. |
| 311 | attributes.setMediaSize(getMediaSize().asLandscape()); |
| 312 | |
| 313 | // Rotate the resolution. |
| 314 | Resolution oldResolution = getResolution(); |
| 315 | Resolution newResolution = new Resolution( |
| 316 | oldResolution.getId(), |
| 317 | oldResolution.getLabel(), |
| 318 | oldResolution.getVerticalDpi(), |
| 319 | oldResolution.getHorizontalDpi()); |
| 320 | attributes.setResolution(newResolution); |
| 321 | |
Svet Ganov | 525a66b | 2014-06-14 22:29:00 -0700 | [diff] [blame] | 322 | // Do not rotate the physical margins. |
| 323 | attributes.setMinMargins(getMinMargins()); |
Svetoslav | a798c0a | 2014-05-15 10:47:19 -0700 | [diff] [blame] | 324 | |
| 325 | attributes.setColorMode(getColorMode()); |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 326 | attributes.setDuplexMode(getDuplexMode()); |
Svetoslav | a798c0a | 2014-05-15 10:47:19 -0700 | [diff] [blame] | 327 | |
| 328 | return attributes; |
| 329 | } |
| 330 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 331 | @Override |
| 332 | public void writeToParcel(Parcel parcel, int flags) { |
| 333 | if (mMediaSize != null) { |
| 334 | parcel.writeInt(1); |
| 335 | mMediaSize.writeToParcel(parcel); |
| 336 | } else { |
| 337 | parcel.writeInt(0); |
| 338 | } |
| 339 | if (mResolution != null) { |
| 340 | parcel.writeInt(1); |
| 341 | mResolution.writeToParcel(parcel); |
| 342 | } else { |
| 343 | parcel.writeInt(0); |
| 344 | } |
Svetoslav | 651dd4e | 2013-09-12 14:37:47 -0700 | [diff] [blame] | 345 | if (mMinMargins != null) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 346 | parcel.writeInt(1); |
Svetoslav | 651dd4e | 2013-09-12 14:37:47 -0700 | [diff] [blame] | 347 | mMinMargins.writeToParcel(parcel); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 348 | } else { |
| 349 | parcel.writeInt(0); |
| 350 | } |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 351 | parcel.writeInt(mColorMode); |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 352 | parcel.writeInt(mDuplexMode); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | @Override |
| 356 | public int describeContents() { |
| 357 | return 0; |
| 358 | } |
| 359 | |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 360 | @Override |
| 361 | public int hashCode() { |
| 362 | final int prime = 31; |
| 363 | int result = 1; |
| 364 | result = prime * result + mColorMode; |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 365 | result = prime * result + mDuplexMode; |
Svetoslav | 651dd4e | 2013-09-12 14:37:47 -0700 | [diff] [blame] | 366 | result = prime * result + ((mMinMargins == null) ? 0 : mMinMargins.hashCode()); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 367 | result = prime * result + ((mMediaSize == null) ? 0 : mMediaSize.hashCode()); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 368 | result = prime * result + ((mResolution == null) ? 0 : mResolution.hashCode()); |
| 369 | return result; |
| 370 | } |
| 371 | |
| 372 | @Override |
| 373 | public boolean equals(Object obj) { |
| 374 | if (this == obj) { |
| 375 | return true; |
| 376 | } |
| 377 | if (obj == null) { |
| 378 | return false; |
| 379 | } |
| 380 | if (getClass() != obj.getClass()) { |
| 381 | return false; |
| 382 | } |
| 383 | PrintAttributes other = (PrintAttributes) obj; |
| 384 | if (mColorMode != other.mColorMode) { |
| 385 | return false; |
| 386 | } |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 387 | if (mDuplexMode != other.mDuplexMode) { |
| 388 | return false; |
| 389 | } |
Svetoslav | 651dd4e | 2013-09-12 14:37:47 -0700 | [diff] [blame] | 390 | if (mMinMargins == null) { |
| 391 | if (other.mMinMargins != null) { |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 392 | return false; |
| 393 | } |
Svetoslav | 651dd4e | 2013-09-12 14:37:47 -0700 | [diff] [blame] | 394 | } else if (!mMinMargins.equals(other.mMinMargins)) { |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 395 | return false; |
| 396 | } |
| 397 | if (mMediaSize == null) { |
| 398 | if (other.mMediaSize != null) { |
| 399 | return false; |
| 400 | } |
| 401 | } else if (!mMediaSize.equals(other.mMediaSize)) { |
| 402 | return false; |
| 403 | } |
| 404 | if (mResolution == null) { |
| 405 | if (other.mResolution != null) { |
| 406 | return false; |
| 407 | } |
| 408 | } else if (!mResolution.equals(other.mResolution)) { |
| 409 | return false; |
| 410 | } |
| 411 | return true; |
| 412 | } |
| 413 | |
| 414 | @Override |
| 415 | public String toString() { |
| 416 | StringBuilder builder = new StringBuilder(); |
| 417 | builder.append("PrintAttributes{"); |
| 418 | builder.append("mediaSize: ").append(mMediaSize); |
Svetoslav | cc65b0c | 2013-09-10 21:08:32 -0700 | [diff] [blame] | 419 | if (mMediaSize != null) { |
| 420 | builder.append(", orientation: ").append(mMediaSize.isPortrait() |
| 421 | ? "portrait" : "landscape"); |
| 422 | } else { |
| 423 | builder.append(", orientation: ").append("null"); |
| 424 | } |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 425 | builder.append(", resolution: ").append(mResolution); |
Svetoslav | 651dd4e | 2013-09-12 14:37:47 -0700 | [diff] [blame] | 426 | builder.append(", minMargins: ").append(mMinMargins); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 427 | builder.append(", colorMode: ").append(colorModeToString(mColorMode)); |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 428 | builder.append(", duplexMode: ").append(duplexModeToString(mDuplexMode)); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 429 | builder.append("}"); |
| 430 | return builder.toString(); |
| 431 | } |
| 432 | |
Svetoslav | 81d4014 | 2013-09-18 14:38:26 -0700 | [diff] [blame] | 433 | /** @hide */ |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 434 | public void clear() { |
| 435 | mMediaSize = null; |
| 436 | mResolution = null; |
Svetoslav | 651dd4e | 2013-09-12 14:37:47 -0700 | [diff] [blame] | 437 | mMinMargins = null; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 438 | mColorMode = 0; |
Philip P. Moltmann | b4efdb4 | 2015-11-10 14:58:44 -0800 | [diff] [blame] | 439 | mDuplexMode = 0; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /** |
Svetoslav Ganov | 0d1daa5 | 2013-07-23 13:29:31 -0700 | [diff] [blame] | 443 | * @hide |
| 444 | */ |
| 445 | public void copyFrom(PrintAttributes other) { |
| 446 | mMediaSize = other.mMediaSize; |
| 447 | mResolution = other.mResolution; |
Svetoslav | 651dd4e | 2013-09-12 14:37:47 -0700 | [diff] [blame] | 448 | mMinMargins = other.mMinMargins; |
Svetoslav Ganov | 0d1daa5 | 2013-07-23 13:29:31 -0700 | [diff] [blame] | 449 | mColorMode = other.mColorMode; |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 450 | mDuplexMode = other.mDuplexMode; |
Svetoslav Ganov | 0d1daa5 | 2013-07-23 13:29:31 -0700 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | /** |
Svetoslav Ganov | 22cb917 | 2013-08-29 17:42:07 -0700 | [diff] [blame] | 454 | * This class specifies a supported media size. Media size is the |
| 455 | * dimension of the media on which the content is printed. For |
| 456 | * example, the {@link #NA_LETTER} media size designates a page |
| 457 | * with size 8.5" x 11". |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 458 | */ |
| 459 | public static final class MediaSize { |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 460 | private static final String LOG_TAG = "MediaSize"; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 461 | |
Svetoslav Ganov | 7be27ac | 2013-09-30 09:04:50 -0700 | [diff] [blame] | 462 | private static final Map<String, MediaSize> sIdToMediaSizeMap = |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 463 | new ArrayMap<>(); |
Svetoslav Ganov | 7be27ac | 2013-09-30 09:04:50 -0700 | [diff] [blame] | 464 | |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 465 | /** |
| 466 | * Unknown media size in portrait mode. |
| 467 | * <p> |
| 468 | * <strong>Note: </strong>This is for specifying orientation without media |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 469 | * size. You should not use the dimensions reported by this instance. |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 470 | * </p> |
| 471 | */ |
| 472 | public static final MediaSize UNKNOWN_PORTRAIT = |
| 473 | new MediaSize("UNKNOWN_PORTRAIT", "android", |
Svetoslav Ganov | b2420c9 | 2013-10-06 19:44:14 -0700 | [diff] [blame] | 474 | R.string.mediasize_unknown_portrait, 1, Integer.MAX_VALUE); |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 475 | |
| 476 | /** |
| 477 | * Unknown media size in landscape mode. |
| 478 | * <p> |
| 479 | * <strong>Note: </strong>This is for specifying orientation without media |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 480 | * size. You should not use the dimensions reported by this instance. |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 481 | * </p> |
| 482 | */ |
| 483 | public static final MediaSize UNKNOWN_LANDSCAPE = |
| 484 | new MediaSize("UNKNOWN_LANDSCAPE", "android", |
Svetoslav Ganov | b2420c9 | 2013-10-06 19:44:14 -0700 | [diff] [blame] | 485 | R.string.mediasize_unknown_landscape, Integer.MAX_VALUE, 1); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 486 | |
| 487 | // ISO sizes |
| 488 | |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 489 | /** ISO A0 media size: 841mm x 1189mm (33.11" x 46.81") */ |
| 490 | public static final MediaSize ISO_A0 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 491 | new MediaSize("ISO_A0", "android", R.string.mediasize_iso_a0, 33110, 46810); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 492 | /** ISO A1 media size: 594mm x 841mm (23.39" x 33.11") */ |
| 493 | public static final MediaSize ISO_A1 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 494 | new MediaSize("ISO_A1", "android", R.string.mediasize_iso_a1, 23390, 33110); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 495 | /** ISO A2 media size: 420mm x 594mm (16.54" x 23.39") */ |
| 496 | public static final MediaSize ISO_A2 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 497 | new MediaSize("ISO_A2", "android", R.string.mediasize_iso_a2, 16540, 23390); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 498 | /** ISO A3 media size: 297mm x 420mm (11.69" x 16.54") */ |
| 499 | public static final MediaSize ISO_A3 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 500 | new MediaSize("ISO_A3", "android", R.string.mediasize_iso_a3, 11690, 16540); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 501 | /** ISO A4 media size: 210mm x 297mm (8.27" x 11.69") */ |
| 502 | public static final MediaSize ISO_A4 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 503 | new MediaSize("ISO_A4", "android", R.string.mediasize_iso_a4, 8270, 11690); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 504 | /** ISO A5 media size: 148mm x 210mm (5.83" x 8.27") */ |
| 505 | public static final MediaSize ISO_A5 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 506 | new MediaSize("ISO_A5", "android", R.string.mediasize_iso_a5, 5830, 8270); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 507 | /** ISO A6 media size: 105mm x 148mm (4.13" x 5.83") */ |
| 508 | public static final MediaSize ISO_A6 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 509 | new MediaSize("ISO_A6", "android", R.string.mediasize_iso_a6, 4130, 5830); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 510 | /** ISO A7 media size: 74mm x 105mm (2.91" x 4.13") */ |
| 511 | public static final MediaSize ISO_A7 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 512 | new MediaSize("ISO_A7", "android", R.string.mediasize_iso_a7, 2910, 4130); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 513 | /** ISO A8 media size: 52mm x 74mm (2.05" x 2.91") */ |
| 514 | public static final MediaSize ISO_A8 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 515 | new MediaSize("ISO_A8", "android", R.string.mediasize_iso_a8, 2050, 2910); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 516 | /** ISO A9 media size: 37mm x 52mm (1.46" x 2.05") */ |
| 517 | public static final MediaSize ISO_A9 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 518 | new MediaSize("ISO_A9", "android", R.string.mediasize_iso_a9, 1460, 2050); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 519 | /** ISO A10 media size: 26mm x 37mm (1.02" x 1.46") */ |
| 520 | public static final MediaSize ISO_A10 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 521 | new MediaSize("ISO_A10", "android", R.string.mediasize_iso_a10, 1020, 1460); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 522 | |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 523 | /** ISO B0 media size: 1000mm x 1414mm (39.37" x 55.67") */ |
| 524 | public static final MediaSize ISO_B0 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 525 | new MediaSize("ISO_B0", "android", R.string.mediasize_iso_b0, 39370, 55670); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 526 | /** ISO B1 media size: 707mm x 1000mm (27.83" x 39.37") */ |
| 527 | public static final MediaSize ISO_B1 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 528 | new MediaSize("ISO_B1", "android", R.string.mediasize_iso_b1, 27830, 39370); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 529 | /** ISO B2 media size: 500mm x 707mm (19.69" x 27.83") */ |
| 530 | public static final MediaSize ISO_B2 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 531 | new MediaSize("ISO_B2", "android", R.string.mediasize_iso_b2, 19690, 27830); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 532 | /** ISO B3 media size: 353mm x 500mm (13.90" x 19.69") */ |
| 533 | public static final MediaSize ISO_B3 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 534 | new MediaSize("ISO_B3", "android", R.string.mediasize_iso_b3, 13900, 19690); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 535 | /** ISO B4 media size: 250mm x 353mm (9.84" x 13.90") */ |
| 536 | public static final MediaSize ISO_B4 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 537 | new MediaSize("ISO_B4", "android", R.string.mediasize_iso_b4, 9840, 13900); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 538 | /** ISO B5 media size: 176mm x 250mm (6.93" x 9.84") */ |
| 539 | public static final MediaSize ISO_B5 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 540 | new MediaSize("ISO_B5", "android", R.string.mediasize_iso_b5, 6930, 9840); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 541 | /** ISO B6 media size: 125mm x 176mm (4.92" x 6.93") */ |
| 542 | public static final MediaSize ISO_B6 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 543 | new MediaSize("ISO_B6", "android", R.string.mediasize_iso_b6, 4920, 6930); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 544 | /** ISO B7 media size: 88mm x 125mm (3.46" x 4.92") */ |
| 545 | public static final MediaSize ISO_B7 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 546 | new MediaSize("ISO_B7", "android", R.string.mediasize_iso_b7, 3460, 4920); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 547 | /** ISO B8 media size: 62mm x 88mm (2.44" x 3.46") */ |
| 548 | public static final MediaSize ISO_B8 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 549 | new MediaSize("ISO_B8", "android", R.string.mediasize_iso_b8, 2440, 3460); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 550 | /** ISO B9 media size: 44mm x 62mm (1.73" x 2.44") */ |
| 551 | public static final MediaSize ISO_B9 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 552 | new MediaSize("ISO_B9", "android", R.string.mediasize_iso_b9, 1730, 2440); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 553 | /** ISO B10 media size: 31mm x 44mm (1.22" x 1.73") */ |
| 554 | public static final MediaSize ISO_B10 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 555 | new MediaSize("ISO_B10", "android", R.string.mediasize_iso_b10, 1220, 1730); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 556 | |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 557 | /** ISO C0 media size: 917mm x 1297mm (36.10" x 51.06") */ |
| 558 | public static final MediaSize ISO_C0 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 559 | new MediaSize("ISO_C0", "android", R.string.mediasize_iso_c0, 36100, 51060); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 560 | /** ISO C1 media size: 648mm x 917mm (25.51" x 36.10") */ |
| 561 | public static final MediaSize ISO_C1 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 562 | new MediaSize("ISO_C1", "android", R.string.mediasize_iso_c1, 25510, 36100); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 563 | /** ISO C2 media size: 458mm x 648mm (18.03" x 25.51") */ |
| 564 | public static final MediaSize ISO_C2 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 565 | new MediaSize("ISO_C2", "android", R.string.mediasize_iso_c2, 18030, 25510); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 566 | /** ISO C3 media size: 324mm x 458mm (12.76" x 18.03") */ |
| 567 | public static final MediaSize ISO_C3 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 568 | new MediaSize("ISO_C3", "android", R.string.mediasize_iso_c3, 12760, 18030); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 569 | /** ISO C4 media size: 229mm x 324mm (9.02" x 12.76") */ |
| 570 | public static final MediaSize ISO_C4 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 571 | new MediaSize("ISO_C4", "android", R.string.mediasize_iso_c4, 9020, 12760); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 572 | /** ISO C5 media size: 162mm x 229mm (6.38" x 9.02") */ |
| 573 | public static final MediaSize ISO_C5 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 574 | new MediaSize("ISO_C5", "android", R.string.mediasize_iso_c5, 6380, 9020); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 575 | /** ISO C6 media size: 114mm x 162mm (4.49" x 6.38") */ |
| 576 | public static final MediaSize ISO_C6 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 577 | new MediaSize("ISO_C6", "android", R.string.mediasize_iso_c6, 4490, 6380); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 578 | /** ISO C7 media size: 81mm x 114mm (3.19" x 4.49") */ |
| 579 | public static final MediaSize ISO_C7 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 580 | new MediaSize("ISO_C7", "android", R.string.mediasize_iso_c7, 3190, 4490); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 581 | /** ISO C8 media size: 57mm x 81mm (2.24" x 3.19") */ |
| 582 | public static final MediaSize ISO_C8 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 583 | new MediaSize("ISO_C8", "android", R.string.mediasize_iso_c8, 2240, 3190); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 584 | /** ISO C9 media size: 40mm x 57mm (1.57" x 2.24") */ |
| 585 | public static final MediaSize ISO_C9 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 586 | new MediaSize("ISO_C9", "android", R.string.mediasize_iso_c9, 1570, 2240); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 587 | /** ISO C10 media size: 28mm x 40mm (1.10" x 1.57") */ |
| 588 | public static final MediaSize ISO_C10 = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 589 | new MediaSize("ISO_C10", "android", R.string.mediasize_iso_c10, 1100, 1570); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 590 | |
| 591 | // North America |
| 592 | |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 593 | /** North America Letter media size: 8.5" x 11" (279mm x 216mm) */ |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 594 | public static final MediaSize NA_LETTER = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 595 | new MediaSize("NA_LETTER", "android", R.string.mediasize_na_letter, 8500, 11000); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 596 | /** North America Government-Letter media size: 8.0" x 10.5" (203mm x 267mm) */ |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 597 | public static final MediaSize NA_GOVT_LETTER = |
| 598 | new MediaSize("NA_GOVT_LETTER", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 599 | R.string.mediasize_na_gvrnmt_letter, 8000, 10500); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 600 | /** North America Legal media size: 8.5" x 14" (216mm x 356mm) */ |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 601 | public static final MediaSize NA_LEGAL = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 602 | new MediaSize("NA_LEGAL", "android", R.string.mediasize_na_legal, 8500, 14000); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 603 | /** North America Junior Legal media size: 8.0" x 5.0" (203mm × 127mm) */ |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 604 | public static final MediaSize NA_JUNIOR_LEGAL = |
| 605 | new MediaSize("NA_JUNIOR_LEGAL", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 606 | R.string.mediasize_na_junior_legal, 8000, 5000); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 607 | /** North America Ledger media size: 17" x 11" (432mm × 279mm) */ |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 608 | public static final MediaSize NA_LEDGER = |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 609 | new MediaSize("NA_LEDGER", "android", R.string.mediasize_na_ledger, 17000, 11000); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 610 | /** North America Tabloid media size: 11" x 17" (279mm × 432mm) */ |
Svetoslav | 013b816 | 2013-09-18 12:31:23 -0700 | [diff] [blame] | 611 | public static final MediaSize NA_TABLOID = |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 612 | new MediaSize("NA_TABLOID", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 613 | R.string.mediasize_na_tabloid, 11000, 17000); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 614 | /** North America Index Card 3x5 media size: 3" x 5" (76mm x 127mm) */ |
| 615 | public static final MediaSize NA_INDEX_3X5 = |
| 616 | new MediaSize("NA_INDEX_3X5", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 617 | R.string.mediasize_na_index_3x5, 3000, 5000); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 618 | /** North America Index Card 4x6 media size: 4" x 6" (102mm x 152mm) */ |
| 619 | public static final MediaSize NA_INDEX_4X6 = |
| 620 | new MediaSize("NA_INDEX_4X6", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 621 | R.string.mediasize_na_index_4x6, 4000, 6000); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 622 | /** North America Index Card 5x8 media size: 5" x 8" (127mm x 203mm) */ |
| 623 | public static final MediaSize NA_INDEX_5X8 = |
| 624 | new MediaSize("NA_INDEX_5X8", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 625 | R.string.mediasize_na_index_5x8, 5000, 8000); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 626 | /** North America Monarch media size: 7.25" x 10.5" (184mm x 267mm) */ |
| 627 | public static final MediaSize NA_MONARCH = |
| 628 | new MediaSize("NA_MONARCH", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 629 | R.string.mediasize_na_monarch, 7250, 10500); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 630 | /** North America Quarto media size: 8" x 10" (203mm x 254mm) */ |
| 631 | public static final MediaSize NA_QUARTO = |
| 632 | new MediaSize("NA_QUARTO", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 633 | R.string.mediasize_na_quarto, 8000, 10000); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 634 | /** North America Foolscap media size: 8" x 13" (203mm x 330mm) */ |
| 635 | public static final MediaSize NA_FOOLSCAP = |
| 636 | new MediaSize("NA_FOOLSCAP", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 637 | R.string.mediasize_na_foolscap, 8000, 13000); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 638 | |
| 639 | // Chinese |
| 640 | |
| 641 | /** Chinese ROC 8K media size: 270mm x 390mm (10.629" x 15.3543") */ |
| 642 | public static final MediaSize ROC_8K = |
| 643 | new MediaSize("ROC_8K", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 644 | R.string.mediasize_chinese_roc_8k, 10629, 15354); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 645 | /** Chinese ROC 16K media size: 195mm x 270mm (7.677" x 10.629") */ |
| 646 | public static final MediaSize ROC_16K = |
| 647 | new MediaSize("ROC_16K", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 648 | R.string.mediasize_chinese_roc_16k, 7677, 10629); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 649 | |
| 650 | /** Chinese PRC 1 media size: 102mm x 165mm (4.015" x 6.496") */ |
| 651 | public static final MediaSize PRC_1 = |
| 652 | new MediaSize("PRC_1", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 653 | R.string.mediasize_chinese_prc_1, 4015, 6496); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 654 | /** Chinese PRC 2 media size: 102mm x 176mm (4.015" x 6.929") */ |
| 655 | public static final MediaSize PRC_2 = |
| 656 | new MediaSize("PRC_2", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 657 | R.string.mediasize_chinese_prc_2, 4015, 6929); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 658 | /** Chinese PRC 3 media size: 125mm x 176mm (4.921" x 6.929") */ |
| 659 | public static final MediaSize PRC_3 = |
| 660 | new MediaSize("PRC_3", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 661 | R.string.mediasize_chinese_prc_3, 4921, 6929); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 662 | /** Chinese PRC 4 media size: 110mm x 208mm (4.330" x 8.189") */ |
| 663 | public static final MediaSize PRC_4 = |
| 664 | new MediaSize("PRC_4", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 665 | R.string.mediasize_chinese_prc_4, 4330, 8189); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 666 | /** Chinese PRC 5 media size: 110mm x 220mm (4.330" x 8.661") */ |
| 667 | public static final MediaSize PRC_5 = |
| 668 | new MediaSize("PRC_5", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 669 | R.string.mediasize_chinese_prc_5, 4330, 8661); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 670 | /** Chinese PRC 6 media size: 120mm x 320mm (4.724" x 12.599") */ |
| 671 | public static final MediaSize PRC_6 = |
| 672 | new MediaSize("PRC_6", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 673 | R.string.mediasize_chinese_prc_6, 4724, 12599); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 674 | /** Chinese PRC 7 media size: 160mm x 230mm (6.299" x 9.055") */ |
| 675 | public static final MediaSize PRC_7 = |
| 676 | new MediaSize("PRC_7", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 677 | R.string.mediasize_chinese_prc_7, 6299, 9055); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 678 | /** Chinese PRC 8 media size: 120mm x 309mm (4.724" x 12.165") */ |
| 679 | public static final MediaSize PRC_8 = |
| 680 | new MediaSize("PRC_8", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 681 | R.string.mediasize_chinese_prc_8, 4724, 12165); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 682 | /** Chinese PRC 9 media size: 229mm x 324mm (9.016" x 12.756") */ |
| 683 | public static final MediaSize PRC_9 = |
| 684 | new MediaSize("PRC_9", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 685 | R.string.mediasize_chinese_prc_9, 9016, 12756); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 686 | /** Chinese PRC 10 media size: 324mm x 458mm (12.756" x 18.032") */ |
| 687 | public static final MediaSize PRC_10 = |
| 688 | new MediaSize("PRC_10", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 689 | R.string.mediasize_chinese_prc_10, 12756, 18032); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 690 | |
| 691 | /** Chinese PRC 16k media size: 146mm x 215mm (5.749" x 8.465") */ |
Svetoslav Ganov | 7be27ac | 2013-09-30 09:04:50 -0700 | [diff] [blame] | 692 | public static final MediaSize PRC_16K = |
| 693 | new MediaSize("PRC_16K", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 694 | R.string.mediasize_chinese_prc_16k, 5749, 8465); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 695 | /** Chinese Pa Kai media size: 267mm x 389mm (10.512" x 15.315") */ |
| 696 | public static final MediaSize OM_PA_KAI = |
| 697 | new MediaSize("OM_PA_KAI", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 698 | R.string.mediasize_chinese_om_pa_kai, 10512, 15315); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 699 | /** Chinese Dai Pa Kai media size: 275mm x 395mm (10.827" x 15.551") */ |
| 700 | public static final MediaSize OM_DAI_PA_KAI = |
| 701 | new MediaSize("OM_DAI_PA_KAI", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 702 | R.string.mediasize_chinese_om_dai_pa_kai, 10827, 15551); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 703 | /** Chinese Jurro Ku Kai media size: 198mm x 275mm (7.796" x 10.827") */ |
| 704 | public static final MediaSize OM_JUURO_KU_KAI = |
| 705 | new MediaSize("OM_JUURO_KU_KAI", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 706 | R.string.mediasize_chinese_om_jurro_ku_kai, 7796, 10827); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 707 | |
| 708 | // Japanese |
| 709 | |
| 710 | /** Japanese JIS B10 media size: 32mm x 45mm (1.259" x 1.772") */ |
| 711 | public static final MediaSize JIS_B10 = |
| 712 | new MediaSize("JIS_B10", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 713 | R.string.mediasize_japanese_jis_b10, 1259, 1772); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 714 | /** Japanese JIS B9 media size: 45mm x 64mm (1.772" x 2.52") */ |
| 715 | public static final MediaSize JIS_B9 = |
| 716 | new MediaSize("JIS_B9", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 717 | R.string.mediasize_japanese_jis_b9, 1772, 2520); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 718 | /** Japanese JIS B8 media size: 64mm x 91mm (2.52" x 3.583") */ |
| 719 | public static final MediaSize JIS_B8 = |
| 720 | new MediaSize("JIS_B8", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 721 | R.string.mediasize_japanese_jis_b8, 2520, 3583); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 722 | /** Japanese JIS B7 media size: 91mm x 128mm (3.583" x 5.049") */ |
| 723 | public static final MediaSize JIS_B7 = |
| 724 | new MediaSize("JIS_B7", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 725 | R.string.mediasize_japanese_jis_b7, 3583, 5049); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 726 | /** Japanese JIS B6 media size: 128mm x 182mm (5.049" x 7.165") */ |
| 727 | public static final MediaSize JIS_B6 = |
| 728 | new MediaSize("JIS_B6", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 729 | R.string.mediasize_japanese_jis_b6, 5049, 7165); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 730 | /** Japanese JIS B5 media size: 182mm x 257mm (7.165" x 10.118") */ |
| 731 | public static final MediaSize JIS_B5 = |
| 732 | new MediaSize("JIS_B5", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 733 | R.string.mediasize_japanese_jis_b5, 7165, 10118); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 734 | /** Japanese JIS B4 media size: 257mm x 364mm (10.118" x 14.331") */ |
| 735 | public static final MediaSize JIS_B4 = |
| 736 | new MediaSize("JIS_B4", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 737 | R.string.mediasize_japanese_jis_b4, 10118, 14331); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 738 | /** Japanese JIS B3 media size: 364mm x 515mm (14.331" x 20.276") */ |
| 739 | public static final MediaSize JIS_B3 = |
| 740 | new MediaSize("JIS_B3", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 741 | R.string.mediasize_japanese_jis_b3, 14331, 20276); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 742 | /** Japanese JIS B2 media size: 515mm x 728mm (20.276" x 28.661") */ |
| 743 | public static final MediaSize JIS_B2 = |
| 744 | new MediaSize("JIS_B2", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 745 | R.string.mediasize_japanese_jis_b2, 20276, 28661); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 746 | /** Japanese JIS B1 media size: 728mm x 1030mm (28.661" x 40.551") */ |
| 747 | public static final MediaSize JIS_B1 = |
| 748 | new MediaSize("JIS_B1", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 749 | R.string.mediasize_japanese_jis_b1, 28661, 40551); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 750 | /** Japanese JIS B0 media size: 1030mm x 1456mm (40.551" x 57.323") */ |
| 751 | public static final MediaSize JIS_B0 = |
| 752 | new MediaSize("JIS_B0", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 753 | R.string.mediasize_japanese_jis_b0, 40551, 57323); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 754 | |
| 755 | /** Japanese JIS Exec media size: 216mm x 330mm (8.504" x 12.992") */ |
| 756 | public static final MediaSize JIS_EXEC = |
| 757 | new MediaSize("JIS_EXEC", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 758 | R.string.mediasize_japanese_jis_exec, 8504, 12992); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 759 | |
| 760 | /** Japanese Chou4 media size: 90mm x 205mm (3.543" x 8.071") */ |
| 761 | public static final MediaSize JPN_CHOU4 = |
| 762 | new MediaSize("JPN_CHOU4", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 763 | R.string.mediasize_japanese_chou4, 3543, 8071); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 764 | /** Japanese Chou3 media size: 120mm x 235mm (4.724" x 9.252") */ |
| 765 | public static final MediaSize JPN_CHOU3 = |
| 766 | new MediaSize("JPN_CHOU3", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 767 | R.string.mediasize_japanese_chou3, 4724, 9252); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 768 | /** Japanese Chou2 media size: 111.1mm x 146mm (4.374" x 5.748") */ |
| 769 | public static final MediaSize JPN_CHOU2 = |
| 770 | new MediaSize("JPN_CHOU2", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 771 | R.string.mediasize_japanese_chou2, 4374, 5748); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 772 | |
| 773 | /** Japanese Hagaki media size: 100mm x 148mm (3.937" x 5.827") */ |
| 774 | public static final MediaSize JPN_HAGAKI = |
| 775 | new MediaSize("JPN_HAGAKI", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 776 | R.string.mediasize_japanese_hagaki, 3937, 5827); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 777 | /** Japanese Oufuku media size: 148mm x 200mm (5.827" x 7.874") */ |
| 778 | public static final MediaSize JPN_OUFUKU = |
| 779 | new MediaSize("JPN_OUFUKU", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 780 | R.string.mediasize_japanese_oufuku, 5827, 7874); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 781 | |
| 782 | /** Japanese Kahu media size: 240mm x 322.1mm (9.449" x 12.681") */ |
| 783 | public static final MediaSize JPN_KAHU = |
| 784 | new MediaSize("JPN_KAHU", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 785 | R.string.mediasize_japanese_kahu, 9449, 12681); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 786 | /** Japanese Kaku2 media size: 240mm x 332mm (9.449" x 13.071") */ |
| 787 | public static final MediaSize JPN_KAKU2 = |
| 788 | new MediaSize("JPN_KAKU2", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 789 | R.string.mediasize_japanese_kaku2, 9449, 13071); |
Svetoslav Ganov | fa77ece | 2013-09-17 09:44:40 -0700 | [diff] [blame] | 790 | |
| 791 | /** Japanese You4 media size: 105mm x 235mm (4.134" x 9.252") */ |
| 792 | public static final MediaSize JPN_YOU4 = |
| 793 | new MediaSize("JPN_YOU4", "android", |
Svetoslav | d8f391b | 2013-09-20 16:25:52 -0700 | [diff] [blame] | 794 | R.string.mediasize_japanese_you4, 4134, 9252); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 795 | |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 796 | private final @NonNull String mId; |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 797 | /**@hide */ |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 798 | public final @NonNull String mLabel; |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 799 | /**@hide */ |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 800 | public final @Nullable String mPackageName; |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 801 | /**@hide */ |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 802 | public final @StringRes int mLabelResId; |
| 803 | private final @IntRange(from = 1) int mWidthMils; |
| 804 | private final @IntRange(from = 1) int mHeightMils; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 805 | |
| 806 | /** |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 807 | * Creates a new instance. |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 808 | * |
| 809 | * @param id The unique media size id. |
| 810 | * @param packageName The name of the creating package. |
| 811 | * @param labelResId The resource if of a human readable label. |
Philip P. Moltmann | 823715d | 2016-04-21 16:28:02 -0700 | [diff] [blame] | 812 | * @param widthMils The width in mils (thousandths of an inch). |
| 813 | * @param heightMils The height in mils (thousandths of an inch). |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 814 | * |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 815 | * @throws IllegalArgumentException If the id is empty or the label |
| 816 | * is empty or the widthMils is less than or equal to zero or the |
| 817 | * heightMils is less than or equal to zero. |
Svetoslav | a76233a | 2013-09-05 09:38:02 -0700 | [diff] [blame] | 818 | * |
| 819 | * @hide |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 820 | */ |
| 821 | public MediaSize(String id, String packageName, int labelResId, |
| 822 | int widthMils, int heightMils) { |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 823 | this(id, null, packageName, widthMils, heightMils, labelResId); |
Svetoslav Ganov | 7be27ac | 2013-09-30 09:04:50 -0700 | [diff] [blame] | 824 | |
| 825 | // Build this mapping only for predefined media sizes. |
| 826 | sIdToMediaSizeMap.put(mId, this); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | /** |
Svetoslav | a76233a | 2013-09-05 09:38:02 -0700 | [diff] [blame] | 830 | * Creates a new instance. |
Svetoslav | 17b7f6e | 2013-06-24 18:29:33 -0700 | [diff] [blame] | 831 | * |
Svetoslav Ganov | 22cb917 | 2013-08-29 17:42:07 -0700 | [diff] [blame] | 832 | * @param id The unique media size id. It is unique amongst other media sizes |
| 833 | * supported by the printer. |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 834 | * @param label The <strong>localized</strong> human readable label. |
Philip P. Moltmann | 823715d | 2016-04-21 16:28:02 -0700 | [diff] [blame] | 835 | * @param widthMils The width in mils (thousandths of an inch). |
| 836 | * @param heightMils The height in mils (thousandths of an inch). |
Svetoslav | 17b7f6e | 2013-06-24 18:29:33 -0700 | [diff] [blame] | 837 | * |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 838 | * @throws IllegalArgumentException If the id is empty or the label is empty |
| 839 | * or the widthMils is less than or equal to zero or the heightMils is less |
| 840 | * than or equal to zero. |
Svetoslav | 17b7f6e | 2013-06-24 18:29:33 -0700 | [diff] [blame] | 841 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 842 | public MediaSize(@NonNull String id, @NonNull String label, |
| 843 | @IntRange(from = 1) int widthMils, @IntRange(from = 1) int heightMils) { |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 844 | this(id, label, null, widthMils, heightMils, 0); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 845 | } |
| 846 | |
Philip P. Moltmann | 4959caf | 2016-01-21 14:30:56 -0800 | [diff] [blame] | 847 | /** |
| 848 | * Get the Id of all predefined media sizes beside the {@link #UNKNOWN_PORTRAIT} and |
| 849 | * {@link #UNKNOWN_LANDSCAPE}. |
| 850 | * |
| 851 | * @return List of all predefined media sizes |
| 852 | * |
| 853 | * @hide |
| 854 | */ |
| 855 | public static @NonNull ArraySet<MediaSize> getAllPredefinedSizes() { |
| 856 | ArraySet<MediaSize> definedMediaSizes = new ArraySet<>(sIdToMediaSizeMap.values()); |
| 857 | |
| 858 | definedMediaSizes.remove(UNKNOWN_PORTRAIT); |
| 859 | definedMediaSizes.remove(UNKNOWN_LANDSCAPE); |
| 860 | |
| 861 | return definedMediaSizes; |
| 862 | } |
| 863 | |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 864 | /** |
| 865 | * Creates a new instance. |
| 866 | * |
| 867 | * @param id The unique media size id. It is unique amongst other media sizes |
| 868 | * supported by the printer. |
| 869 | * @param label The <strong>localized</strong> human readable label. |
| 870 | * @param packageName The name of the creating package. |
Philip P. Moltmann | 823715d | 2016-04-21 16:28:02 -0700 | [diff] [blame] | 871 | * @param widthMils The width in mils (thousandths of an inch). |
| 872 | * @param heightMils The height in mils (thousandths of an inch). |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 873 | * @param labelResId The resource if of a human readable label. |
| 874 | * |
| 875 | * @throws IllegalArgumentException If the id is empty or the label is unset |
| 876 | * or the widthMils is less than or equal to zero or the heightMils is less |
| 877 | * than or equal to zero. |
| 878 | * |
| 879 | * @hide |
| 880 | */ |
| 881 | public MediaSize(String id, String label, String packageName, int widthMils, int heightMils, |
| 882 | int labelResId) { |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 883 | mPackageName = packageName; |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 884 | mId = Preconditions.checkStringNotEmpty(id, "id cannot be empty."); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 885 | mLabelResId = labelResId; |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 886 | mWidthMils = Preconditions.checkArgumentPositive(widthMils, "widthMils cannot be " + |
| 887 | "less than or equal to zero."); |
| 888 | mHeightMils = Preconditions.checkArgumentPositive(heightMils, "heightMils cannot be " + |
| 889 | "less than or equal to zero."); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 890 | mLabel = label; |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 891 | |
| 892 | // The label has to be either a string ot a StringRes |
| 893 | Preconditions.checkArgument(!TextUtils.isEmpty(label) != |
| 894 | (!TextUtils.isEmpty(packageName) && labelResId != 0), "label cannot be empty."); |
Svetoslav | 17b7f6e | 2013-06-24 18:29:33 -0700 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | /** |
Svetoslav Ganov | 22cb917 | 2013-08-29 17:42:07 -0700 | [diff] [blame] | 898 | * Gets the unique media size id. It is unique amongst other media sizes |
| 899 | * supported by the printer. |
| 900 | * <p> |
| 901 | * This id is defined by the client that generated the media size |
| 902 | * instance and should not be interpreted by other parties. |
| 903 | * </p> |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 904 | * |
| 905 | * @return The unique media size id. |
| 906 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 907 | public @NonNull String getId() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 908 | return mId; |
| 909 | } |
| 910 | |
| 911 | /** |
| 912 | * Gets the human readable media size label. |
| 913 | * |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 914 | * @param packageManager The package manager for loading the label. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 915 | * @return The human readable label. |
| 916 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 917 | public @NonNull String getLabel(@NonNull PackageManager packageManager) { |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 918 | if (!TextUtils.isEmpty(mPackageName) && mLabelResId > 0) { |
| 919 | try { |
| 920 | return packageManager.getResourcesForApplication( |
| 921 | mPackageName).getString(mLabelResId); |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 922 | } catch (NotFoundException | NameNotFoundException e) { |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 923 | Log.w(LOG_TAG, "Could not load resouce" + mLabelResId |
| 924 | + " from package " + mPackageName); |
| 925 | } |
| 926 | } |
Svetoslav | 17b7f6e | 2013-06-24 18:29:33 -0700 | [diff] [blame] | 927 | return mLabel; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | /** |
Philip P. Moltmann | 823715d | 2016-04-21 16:28:02 -0700 | [diff] [blame] | 931 | * Gets the media width in mils (thousandths of an inch). |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 932 | * |
| 933 | * @return The media width. |
| 934 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 935 | public @IntRange(from = 1) int getWidthMils() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 936 | return mWidthMils; |
| 937 | } |
| 938 | |
| 939 | /** |
Philip P. Moltmann | 823715d | 2016-04-21 16:28:02 -0700 | [diff] [blame] | 940 | * Gets the media height in mils (thousandths of an inch). |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 941 | * |
| 942 | * @return The media height. |
| 943 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 944 | public @IntRange(from = 1) int getHeightMils() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 945 | return mHeightMils; |
| 946 | } |
| 947 | |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 948 | /** |
| 949 | * Gets whether this media size is in portrait which is the |
| 950 | * height is greater or equal to the width. |
| 951 | * |
| 952 | * @return True if the media size is in portrait, false if |
| 953 | * it is in landscape. |
| 954 | */ |
| 955 | public boolean isPortrait() { |
| 956 | return mHeightMils >= mWidthMils; |
| 957 | } |
| 958 | |
| 959 | /** |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 960 | * Returns a new media size instance in a portrait orientation, |
Svetoslav | a76233a | 2013-09-05 09:38:02 -0700 | [diff] [blame] | 961 | * which is the height is the greater dimension. |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 962 | * |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 963 | * @return New instance in landscape orientation if this one |
| 964 | * is in landscape, otherwise this instance. |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 965 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 966 | public @NonNull MediaSize asPortrait() { |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 967 | if (isPortrait()) { |
| 968 | return this; |
| 969 | } |
Svetoslav | a36285f | 2013-09-05 11:27:45 -0700 | [diff] [blame] | 970 | return new MediaSize(mId, mLabel, mPackageName, |
Svetoslav | a76233a | 2013-09-05 09:38:02 -0700 | [diff] [blame] | 971 | Math.min(mWidthMils, mHeightMils), |
| 972 | Math.max(mWidthMils, mHeightMils), |
| 973 | mLabelResId); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | /** |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 977 | * Returns a new media size instance in a landscape orientation, |
Svetoslav | a76233a | 2013-09-05 09:38:02 -0700 | [diff] [blame] | 978 | * which is the height is the lesser dimension. |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 979 | * |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 980 | * @return New instance in landscape orientation if this one |
| 981 | * is in portrait, otherwise this instance. |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 982 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 983 | public @NonNull MediaSize asLandscape() { |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 984 | if (!isPortrait()) { |
| 985 | return this; |
| 986 | } |
Svetoslav | a36285f | 2013-09-05 11:27:45 -0700 | [diff] [blame] | 987 | return new MediaSize(mId, mLabel, mPackageName, |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 988 | Math.max(mWidthMils, mHeightMils), |
Svetoslav | a76233a | 2013-09-05 09:38:02 -0700 | [diff] [blame] | 989 | Math.min(mWidthMils, mHeightMils), |
| 990 | mLabelResId); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 991 | } |
| 992 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 993 | void writeToParcel(Parcel parcel) { |
| 994 | parcel.writeString(mId); |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 995 | parcel.writeString(mLabel); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 996 | parcel.writeString(mPackageName); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 997 | parcel.writeInt(mWidthMils); |
| 998 | parcel.writeInt(mHeightMils); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 999 | parcel.writeInt(mLabelResId); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1000 | } |
| 1001 | |
| 1002 | static MediaSize createFromParcel(Parcel parcel) { |
| 1003 | return new MediaSize( |
| 1004 | parcel.readString(), |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 1005 | parcel.readString(), |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 1006 | parcel.readString(), |
| 1007 | parcel.readInt(), |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1008 | parcel.readInt(), |
| 1009 | parcel.readInt()); |
| 1010 | } |
| 1011 | |
| 1012 | @Override |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 1013 | public int hashCode() { |
| 1014 | final int prime = 31; |
| 1015 | int result = 1; |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 1016 | result = prime * result + mWidthMils; |
| 1017 | result = prime * result + mHeightMils; |
| 1018 | return result; |
| 1019 | } |
| 1020 | |
| 1021 | @Override |
| 1022 | public boolean equals(Object obj) { |
| 1023 | if (this == obj) { |
| 1024 | return true; |
| 1025 | } |
| 1026 | if (obj == null) { |
| 1027 | return false; |
| 1028 | } |
| 1029 | if (getClass() != obj.getClass()) { |
| 1030 | return false; |
| 1031 | } |
| 1032 | MediaSize other = (MediaSize) obj; |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 1033 | if (mWidthMils != other.mWidthMils) { |
| 1034 | return false; |
| 1035 | } |
| 1036 | if (mHeightMils != other.mHeightMils) { |
| 1037 | return false; |
| 1038 | } |
| 1039 | return true; |
| 1040 | } |
| 1041 | |
| 1042 | @Override |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1043 | public String toString() { |
| 1044 | StringBuilder builder = new StringBuilder(); |
| 1045 | builder.append("MediaSize{"); |
| 1046 | builder.append("id: ").append(mId); |
Svetoslav | 17b7f6e | 2013-06-24 18:29:33 -0700 | [diff] [blame] | 1047 | builder.append(", label: ").append(mLabel); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 1048 | builder.append(", packageName: ").append(mPackageName); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1049 | builder.append(", heightMils: ").append(mHeightMils); |
| 1050 | builder.append(", widthMils: ").append(mWidthMils); |
Svetoslav | 773f54d | 2013-09-03 14:01:43 -0700 | [diff] [blame] | 1051 | builder.append(", labelResId: ").append(mLabelResId); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1052 | builder.append("}"); |
| 1053 | return builder.toString(); |
| 1054 | } |
Svetoslav Ganov | 7be27ac | 2013-09-30 09:04:50 -0700 | [diff] [blame] | 1055 | |
| 1056 | /** |
| 1057 | * Gets a standard media size given its id. |
| 1058 | * |
| 1059 | * @param id The media size id. |
| 1060 | * @return The media size for the given id or null. |
| 1061 | * |
| 1062 | * @hide |
| 1063 | */ |
| 1064 | public static MediaSize getStandardMediaSizeById(String id) { |
| 1065 | return sIdToMediaSizeMap.get(id); |
| 1066 | } |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | /** |
Svetoslav Ganov | 22cb917 | 2013-08-29 17:42:07 -0700 | [diff] [blame] | 1070 | * This class specifies a supported resolution in DPI (dots per inch). |
| 1071 | * Resolution defines how many points with different color can be placed |
| 1072 | * on one inch in horizontal or vertical direction of the target media. |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 1073 | * For example, a printer with 600 DPI can produce higher quality images |
| 1074 | * the one with 300 DPI resolution. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1075 | */ |
| 1076 | public static final class Resolution { |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 1077 | private final @NonNull String mId; |
| 1078 | private final @NonNull String mLabel; |
| 1079 | private final @IntRange(from = 1) int mHorizontalDpi; |
| 1080 | private final @IntRange(from = 1) int mVerticalDpi; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1081 | |
| 1082 | /** |
Svetoslav | a76233a | 2013-09-05 09:38:02 -0700 | [diff] [blame] | 1083 | * Creates a new instance. |
Svetoslav | 17b7f6e | 2013-06-24 18:29:33 -0700 | [diff] [blame] | 1084 | * |
Svetoslav Ganov | 22cb917 | 2013-08-29 17:42:07 -0700 | [diff] [blame] | 1085 | * @param id The unique resolution id. It is unique amongst other resolutions |
| 1086 | * supported by the printer. |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 1087 | * @param label The <strong>localized</strong> human readable label. |
Svetoslav Ganov | 22cb917 | 2013-08-29 17:42:07 -0700 | [diff] [blame] | 1088 | * @param horizontalDpi The horizontal resolution in DPI (dots per inch). |
| 1089 | * @param verticalDpi The vertical resolution in DPI (dots per inch). |
Svetoslav | 17b7f6e | 2013-06-24 18:29:33 -0700 | [diff] [blame] | 1090 | * |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 1091 | * @throws IllegalArgumentException If the id is empty or the label is empty |
| 1092 | * or the horizontalDpi is less than or equal to zero or the verticalDpi is |
| 1093 | * less than or equal to zero. |
Svetoslav | 17b7f6e | 2013-06-24 18:29:33 -0700 | [diff] [blame] | 1094 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 1095 | public Resolution(@NonNull String id, @NonNull String label, |
| 1096 | @IntRange(from = 1) int horizontalDpi, @IntRange(from = 1) int verticalDpi) { |
Svetoslav | 17b7f6e | 2013-06-24 18:29:33 -0700 | [diff] [blame] | 1097 | if (TextUtils.isEmpty(id)) { |
| 1098 | throw new IllegalArgumentException("id cannot be empty."); |
| 1099 | } |
| 1100 | if (TextUtils.isEmpty(label)) { |
| 1101 | throw new IllegalArgumentException("label cannot be empty."); |
| 1102 | } |
| 1103 | if (horizontalDpi <= 0) { |
| 1104 | throw new IllegalArgumentException("horizontalDpi " |
| 1105 | + "cannot be less than or equal to zero."); |
| 1106 | } |
| 1107 | if (verticalDpi <= 0) { |
| 1108 | throw new IllegalArgumentException("verticalDpi" |
| 1109 | + " cannot be less than or equal to zero."); |
| 1110 | } |
| 1111 | mId = id; |
| 1112 | mLabel = label; |
| 1113 | mHorizontalDpi = horizontalDpi; |
| 1114 | mVerticalDpi = verticalDpi; |
| 1115 | } |
| 1116 | |
| 1117 | /** |
Svetoslav Ganov | 22cb917 | 2013-08-29 17:42:07 -0700 | [diff] [blame] | 1118 | * Gets the unique resolution id. It is unique amongst other resolutions |
| 1119 | * supported by the printer. |
| 1120 | * <p> |
| 1121 | * This id is defined by the client that generated the resolution |
| 1122 | * instance and should not be interpreted by other parties. |
| 1123 | * </p> |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1124 | * |
| 1125 | * @return The unique resolution id. |
| 1126 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 1127 | public @NonNull String getId() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1128 | return mId; |
| 1129 | } |
| 1130 | |
| 1131 | /** |
| 1132 | * Gets the resolution human readable label. |
| 1133 | * |
| 1134 | * @return The human readable label. |
| 1135 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 1136 | public @NonNull String getLabel() { |
Svetoslav | 17b7f6e | 2013-06-24 18:29:33 -0700 | [diff] [blame] | 1137 | return mLabel; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | /** |
Svetoslav Ganov | 22cb917 | 2013-08-29 17:42:07 -0700 | [diff] [blame] | 1141 | * Gets the horizontal resolution in DPI (dots per inch). |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1142 | * |
| 1143 | * @return The horizontal resolution. |
| 1144 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 1145 | public @IntRange(from = 1) int getHorizontalDpi() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1146 | return mHorizontalDpi; |
| 1147 | } |
| 1148 | |
| 1149 | /** |
Svetoslav Ganov | 22cb917 | 2013-08-29 17:42:07 -0700 | [diff] [blame] | 1150 | * Gets the vertical resolution in DPI (dots per inch). |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1151 | * |
| 1152 | * @return The vertical resolution. |
| 1153 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 1154 | public @IntRange(from = 1) int getVerticalDpi() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1155 | return mVerticalDpi; |
| 1156 | } |
| 1157 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1158 | void writeToParcel(Parcel parcel) { |
| 1159 | parcel.writeString(mId); |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 1160 | parcel.writeString(mLabel); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1161 | parcel.writeInt(mHorizontalDpi); |
| 1162 | parcel.writeInt(mVerticalDpi); |
| 1163 | } |
| 1164 | |
| 1165 | static Resolution createFromParcel(Parcel parcel) { |
| 1166 | return new Resolution( |
| 1167 | parcel.readString(), |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 1168 | parcel.readString(), |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1169 | parcel.readInt(), |
| 1170 | parcel.readInt()); |
| 1171 | } |
| 1172 | |
| 1173 | @Override |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 1174 | public int hashCode() { |
| 1175 | final int prime = 31; |
| 1176 | int result = 1; |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 1177 | result = prime * result + mHorizontalDpi; |
| 1178 | result = prime * result + mVerticalDpi; |
| 1179 | return result; |
| 1180 | } |
| 1181 | |
| 1182 | @Override |
| 1183 | public boolean equals(Object obj) { |
| 1184 | if (this == obj) { |
| 1185 | return true; |
| 1186 | } |
| 1187 | if (obj == null) { |
| 1188 | return false; |
| 1189 | } |
| 1190 | if (getClass() != obj.getClass()) { |
| 1191 | return false; |
| 1192 | } |
| 1193 | Resolution other = (Resolution) obj; |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 1194 | if (mHorizontalDpi != other.mHorizontalDpi) { |
| 1195 | return false; |
| 1196 | } |
| 1197 | if (mVerticalDpi != other.mVerticalDpi) { |
| 1198 | return false; |
| 1199 | } |
| 1200 | return true; |
| 1201 | } |
| 1202 | |
| 1203 | @Override |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1204 | public String toString() { |
| 1205 | StringBuilder builder = new StringBuilder(); |
| 1206 | builder.append("Resolution{"); |
| 1207 | builder.append("id: ").append(mId); |
Svetoslav | 17b7f6e | 2013-06-24 18:29:33 -0700 | [diff] [blame] | 1208 | builder.append(", label: ").append(mLabel); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1209 | builder.append(", horizontalDpi: ").append(mHorizontalDpi); |
| 1210 | builder.append(", verticalDpi: ").append(mVerticalDpi); |
| 1211 | builder.append("}"); |
| 1212 | return builder.toString(); |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | /** |
Svetoslav Ganov | 22cb917 | 2013-08-29 17:42:07 -0700 | [diff] [blame] | 1217 | * This class specifies content margins. Margins define the white space |
| 1218 | * around the content where the left margin defines the amount of white |
| 1219 | * space on the left of the content and so on. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1220 | */ |
| 1221 | public static final class Margins { |
Svetoslav Ganov | aec1417 | 2013-08-27 00:30:54 -0700 | [diff] [blame] | 1222 | public static final Margins NO_MARGINS = new Margins(0, 0, 0, 0); |
| 1223 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1224 | private final int mLeftMils; |
| 1225 | private final int mTopMils; |
| 1226 | private final int mRightMils; |
| 1227 | private final int mBottomMils; |
| 1228 | |
| 1229 | /** |
Svetoslav | 17b7f6e | 2013-06-24 18:29:33 -0700 | [diff] [blame] | 1230 | * Creates a new instance. |
| 1231 | * |
Philip P. Moltmann | 823715d | 2016-04-21 16:28:02 -0700 | [diff] [blame] | 1232 | * @param leftMils The left margin in mils (thousandths of an inch). |
| 1233 | * @param topMils The top margin in mils (thousandths of an inch). |
| 1234 | * @param rightMils The right margin in mils (thousandths of an inch). |
| 1235 | * @param bottomMils The bottom margin in mils (thousandths of an inch). |
Svetoslav | 17b7f6e | 2013-06-24 18:29:33 -0700 | [diff] [blame] | 1236 | */ |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 1237 | public Margins(int leftMils, int topMils, int rightMils, int bottomMils) { |
Svetoslav | 17b7f6e | 2013-06-24 18:29:33 -0700 | [diff] [blame] | 1238 | mTopMils = topMils; |
| 1239 | mLeftMils = leftMils; |
| 1240 | mRightMils = rightMils; |
| 1241 | mBottomMils = bottomMils; |
| 1242 | } |
| 1243 | |
| 1244 | /** |
Philip P. Moltmann | 823715d | 2016-04-21 16:28:02 -0700 | [diff] [blame] | 1245 | * Gets the left margin in mils (thousandths of an inch). |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1246 | * |
| 1247 | * @return The left margin. |
| 1248 | */ |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 1249 | public int getLeftMils() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1250 | return mLeftMils; |
| 1251 | } |
| 1252 | |
| 1253 | /** |
Philip P. Moltmann | 823715d | 2016-04-21 16:28:02 -0700 | [diff] [blame] | 1254 | * Gets the top margin in mils (thousandths of an inch). |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1255 | * |
| 1256 | * @return The top margin. |
| 1257 | */ |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 1258 | public int getTopMils() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1259 | return mTopMils; |
| 1260 | } |
| 1261 | |
| 1262 | /** |
Philip P. Moltmann | 823715d | 2016-04-21 16:28:02 -0700 | [diff] [blame] | 1263 | * Gets the right margin in mils (thousandths of an inch). |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1264 | * |
| 1265 | * @return The right margin. |
| 1266 | */ |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 1267 | public int getRightMils() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1268 | return mRightMils; |
| 1269 | } |
| 1270 | |
| 1271 | /** |
Philip P. Moltmann | 823715d | 2016-04-21 16:28:02 -0700 | [diff] [blame] | 1272 | * Gets the bottom margin in mils (thousandths of an inch). |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1273 | * |
| 1274 | * @return The bottom margin. |
| 1275 | */ |
Philip P. Moltmann | aa8a4fe | 2016-03-30 09:07:36 -0700 | [diff] [blame] | 1276 | public int getBottomMils() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1277 | return mBottomMils; |
| 1278 | } |
| 1279 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1280 | void writeToParcel(Parcel parcel) { |
| 1281 | parcel.writeInt(mLeftMils); |
| 1282 | parcel.writeInt(mTopMils); |
| 1283 | parcel.writeInt(mRightMils); |
| 1284 | parcel.writeInt(mBottomMils); |
| 1285 | } |
| 1286 | |
| 1287 | static Margins createFromParcel(Parcel parcel) { |
| 1288 | return new Margins( |
| 1289 | parcel.readInt(), |
| 1290 | parcel.readInt(), |
| 1291 | parcel.readInt(), |
| 1292 | parcel.readInt()); |
| 1293 | } |
| 1294 | |
| 1295 | @Override |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 1296 | public int hashCode() { |
| 1297 | final int prime = 31; |
| 1298 | int result = 1; |
| 1299 | result = prime * result + mBottomMils; |
| 1300 | result = prime * result + mLeftMils; |
| 1301 | result = prime * result + mRightMils; |
| 1302 | result = prime * result + mTopMils; |
| 1303 | return result; |
| 1304 | } |
| 1305 | |
| 1306 | @Override |
| 1307 | public boolean equals(Object obj) { |
| 1308 | if (this == obj) { |
| 1309 | return true; |
| 1310 | } |
| 1311 | if (obj == null) { |
| 1312 | return false; |
| 1313 | } |
| 1314 | if (getClass() != obj.getClass()) { |
| 1315 | return false; |
| 1316 | } |
| 1317 | Margins other = (Margins) obj; |
| 1318 | if (mBottomMils != other.mBottomMils) { |
| 1319 | return false; |
| 1320 | } |
| 1321 | if (mLeftMils != other.mLeftMils) { |
| 1322 | return false; |
| 1323 | } |
| 1324 | if (mRightMils != other.mRightMils) { |
| 1325 | return false; |
| 1326 | } |
| 1327 | if (mTopMils != other.mTopMils) { |
| 1328 | return false; |
| 1329 | } |
| 1330 | return true; |
| 1331 | } |
| 1332 | |
| 1333 | @Override |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1334 | public String toString() { |
| 1335 | StringBuilder builder = new StringBuilder(); |
| 1336 | builder.append("Margins{"); |
| 1337 | builder.append("leftMils: ").append(mLeftMils); |
| 1338 | builder.append(", topMils: ").append(mTopMils); |
| 1339 | builder.append(", rightMils: ").append(mRightMils); |
| 1340 | builder.append(", bottomMils: ").append(mBottomMils); |
| 1341 | builder.append("}"); |
| 1342 | return builder.toString(); |
| 1343 | } |
| 1344 | } |
| 1345 | |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 1346 | static String colorModeToString(int colorMode) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1347 | switch (colorMode) { |
| 1348 | case COLOR_MODE_MONOCHROME: { |
| 1349 | return "COLOR_MODE_MONOCHROME"; |
| 1350 | } |
| 1351 | case COLOR_MODE_COLOR: { |
| 1352 | return "COLOR_MODE_COLOR"; |
| 1353 | } |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 1354 | default: { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1355 | return "COLOR_MODE_UNKNOWN"; |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 1356 | } |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | static String duplexModeToString(int duplexMode) { |
| 1361 | switch (duplexMode) { |
| 1362 | case DUPLEX_MODE_NONE: { |
| 1363 | return "DUPLEX_MODE_NONE"; |
| 1364 | } |
| 1365 | case DUPLEX_MODE_LONG_EDGE: { |
| 1366 | return "DUPLEX_MODE_LONG_EDGE"; |
| 1367 | } |
| 1368 | case DUPLEX_MODE_SHORT_EDGE: { |
| 1369 | return "DUPLEX_MODE_SHORT_EDGE"; |
| 1370 | } |
| 1371 | default: { |
| 1372 | return "DUPLEX_MODE_UNKNOWN"; |
| 1373 | } |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1374 | } |
| 1375 | } |
| 1376 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1377 | static void enforceValidColorMode(int colorMode) { |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 1378 | if ((colorMode & VALID_COLOR_MODES) == 0 || Integer.bitCount(colorMode) != 1) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1379 | throw new IllegalArgumentException("invalid color mode: " + colorMode); |
| 1380 | } |
| 1381 | } |
| 1382 | |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 1383 | static void enforceValidDuplexMode(int duplexMode) { |
| 1384 | if ((duplexMode & VALID_DUPLEX_MODES) == 0 || Integer.bitCount(duplexMode) != 1) { |
| 1385 | throw new IllegalArgumentException("invalid duplex mode: " + duplexMode); |
| 1386 | } |
| 1387 | } |
| 1388 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1389 | /** |
| 1390 | * Builder for creating {@link PrintAttributes}. |
| 1391 | */ |
| 1392 | public static final class Builder { |
| 1393 | private final PrintAttributes mAttributes = new PrintAttributes(); |
| 1394 | |
| 1395 | /** |
| 1396 | * Sets the media size. |
| 1397 | * |
| 1398 | * @param mediaSize The media size. |
| 1399 | * @return This builder. |
| 1400 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 1401 | public @NonNull Builder setMediaSize(@NonNull MediaSize mediaSize) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1402 | mAttributes.setMediaSize(mediaSize); |
| 1403 | return this; |
| 1404 | } |
| 1405 | |
| 1406 | /** |
| 1407 | * Sets the resolution. |
| 1408 | * |
| 1409 | * @param resolution The resolution. |
| 1410 | * @return This builder. |
| 1411 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 1412 | public @NonNull Builder setResolution(@NonNull Resolution resolution) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1413 | mAttributes.setResolution(resolution); |
| 1414 | return this; |
| 1415 | } |
| 1416 | |
| 1417 | /** |
Svetoslav | 651dd4e | 2013-09-12 14:37:47 -0700 | [diff] [blame] | 1418 | * Sets the minimal margins. If the content does not fit |
| 1419 | * these margins it will be clipped. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1420 | * |
| 1421 | * @param margins The margins. |
| 1422 | * @return This builder. |
| 1423 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 1424 | public @NonNull Builder setMinMargins(@NonNull Margins margins) { |
Svetoslav | 651dd4e | 2013-09-12 14:37:47 -0700 | [diff] [blame] | 1425 | mAttributes.setMinMargins(margins); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1426 | return this; |
| 1427 | } |
| 1428 | |
| 1429 | /** |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1430 | * Sets the color mode. |
| 1431 | * |
| 1432 | * @param colorMode A valid color mode or zero. |
| 1433 | * @return This builder. |
| 1434 | * |
| 1435 | * @see PrintAttributes#COLOR_MODE_MONOCHROME |
| 1436 | * @see PrintAttributes#COLOR_MODE_COLOR |
| 1437 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 1438 | public @NonNull Builder setColorMode(@ColorMode int colorMode) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1439 | mAttributes.setColorMode(colorMode); |
| 1440 | return this; |
| 1441 | } |
| 1442 | |
| 1443 | /** |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 1444 | * Sets the duplex mode. |
| 1445 | * |
| 1446 | * @param duplexMode A valid duplex mode or zero. |
| 1447 | * @return This builder. |
| 1448 | * |
| 1449 | * @see PrintAttributes#DUPLEX_MODE_NONE |
| 1450 | * @see PrintAttributes#DUPLEX_MODE_LONG_EDGE |
| 1451 | * @see PrintAttributes#DUPLEX_MODE_SHORT_EDGE |
| 1452 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 1453 | public @NonNull Builder setDuplexMode(@DuplexMode int duplexMode) { |
Svetoslav | 948c9a6 | 2015-02-02 19:47:04 -0800 | [diff] [blame] | 1454 | mAttributes.setDuplexMode(duplexMode); |
| 1455 | return this; |
| 1456 | } |
| 1457 | |
| 1458 | /** |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1459 | * Creates a new {@link PrintAttributes} instance. |
| 1460 | * |
| 1461 | * @return The new instance. |
| 1462 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 1463 | public @NonNull PrintAttributes build() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1464 | return mAttributes; |
| 1465 | } |
| 1466 | } |
| 1467 | |
| 1468 | public static final Parcelable.Creator<PrintAttributes> CREATOR = |
| 1469 | new Creator<PrintAttributes>() { |
| 1470 | @Override |
| 1471 | public PrintAttributes createFromParcel(Parcel parcel) { |
| 1472 | return new PrintAttributes(parcel); |
| 1473 | } |
| 1474 | |
| 1475 | @Override |
| 1476 | public PrintAttributes[] newArray(int size) { |
| 1477 | return new PrintAttributes[size]; |
| 1478 | } |
| 1479 | }; |
| 1480 | } |