blob: e9c196d0cdad868034c9e63205ce2e9d0e298cfa [file] [log] [blame]
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001/*
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
17package android.print;
18
Philip P. Moltmannc43639c2015-12-18 13:58:40 -080019import android.annotation.IntDef;
20import android.annotation.IntRange;
21import android.annotation.NonNull;
22import android.annotation.Nullable;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070023import android.content.pm.PackageManager;
24import android.content.pm.PackageManager.NameNotFoundException;
Svetoslav773f54d2013-09-03 14:01:43 -070025import android.content.res.Resources.NotFoundException;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070026import android.os.Parcel;
27import android.os.Parcelable;
28import android.text.TextUtils;
Svetoslav Ganov7be27ac2013-09-30 09:04:50 -070029import android.util.ArrayMap;
Philip P. Moltmann4959caf2016-01-21 14:30:56 -080030import android.util.ArraySet;
Svetoslav773f54d2013-09-03 14:01:43 -070031import android.util.Log;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070032
33import com.android.internal.R;
34
Philip P. Moltmannc43639c2015-12-18 13:58:40 -080035import java.lang.annotation.Retention;
36import java.lang.annotation.RetentionPolicy;
Svetoslav Ganov7be27ac2013-09-30 09:04:50 -070037import java.util.Map;
38
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070039/**
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -070040 * This class represents the attributes of a print job. These attributes
41 * describe how the printed content should be laid out. For example, the
42 * print attributes may state that the content should be laid out on a
43 * letter size with 300 DPI (dots per inch) resolution, have a margin of
44 * 10 mills (thousand of an inch) on all sides, and be black and white.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070045 */
46public final class PrintAttributes implements Parcelable {
Philip P. Moltmannc43639c2015-12-18 13:58:40 -080047 /** @hide */
48 @Retention(RetentionPolicy.SOURCE)
49 @IntDef(flag = true, value = {
50 COLOR_MODE_MONOCHROME, COLOR_MODE_COLOR
51 })
52 public @interface ColorMode {
53 }
Svetoslav Ganov22cb9172013-08-29 17:42:07 -070054 /** Color mode: Monochrome color scheme, for example one color is used. */
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070055 public static final int COLOR_MODE_MONOCHROME = 1 << 0;
Svetoslav Ganov22cb9172013-08-29 17:42:07 -070056 /** Color mode: Color color scheme, for example many colors are used. */
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070057 public static final int COLOR_MODE_COLOR = 1 << 1;
58
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070059 private static final int VALID_COLOR_MODES =
60 COLOR_MODE_MONOCHROME | COLOR_MODE_COLOR;
61
Philip P. Moltmannc43639c2015-12-18 13:58:40 -080062 /** @hide */
63 @Retention(RetentionPolicy.SOURCE)
64 @IntDef(flag = true, value = {
65 DUPLEX_MODE_NONE, DUPLEX_MODE_LONG_EDGE, DUPLEX_MODE_SHORT_EDGE
66 })
67 public @interface DuplexMode {
68 }
Svetoslav948c9a62015-02-02 19:47:04 -080069 /** Duplex mode: No duplexing. */
70 public static final int DUPLEX_MODE_NONE = 1 << 0;
71 /** Duplex mode: Pages are turned sideways along the long edge - like a book. */
72 public static final int DUPLEX_MODE_LONG_EDGE = 1 << 1;
73 /** Duplex mode: Pages are turned upwards along the short edge - like a notpad. */
74 public static final int DUPLEX_MODE_SHORT_EDGE = 1 << 2;
75
76 private static final int VALID_DUPLEX_MODES =
77 DUPLEX_MODE_NONE | DUPLEX_MODE_LONG_EDGE | DUPLEX_MODE_SHORT_EDGE;
78
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070079 private MediaSize mMediaSize;
80 private Resolution mResolution;
Svetoslav651dd4e2013-09-12 14:37:47 -070081 private Margins mMinMargins;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070082
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070083 private int mColorMode;
Philip P. Moltmannb4efdb42015-11-10 14:58:44 -080084 private int mDuplexMode;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070085
86 PrintAttributes() {
87 /* hide constructor */
88 }
89
Philip P. Moltmannc43639c2015-12-18 13:58:40 -080090 private PrintAttributes(@NonNull Parcel parcel) {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070091 mMediaSize = (parcel.readInt() == 1) ? MediaSize.createFromParcel(parcel) : null;
92 mResolution = (parcel.readInt() == 1) ? Resolution.createFromParcel(parcel) : null;
Svetoslav651dd4e2013-09-12 14:37:47 -070093 mMinMargins = (parcel.readInt() == 1) ? Margins.createFromParcel(parcel) : null;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070094 mColorMode = parcel.readInt();
Svetoslav948c9a62015-02-02 19:47:04 -080095 mDuplexMode = parcel.readInt();
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070096 }
97
98 /**
99 * Gets the media size.
100 *
101 * @return The media size or <code>null</code> if not set.
102 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800103 public @Nullable MediaSize getMediaSize() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700104 return mMediaSize;
105 }
106
107 /**
108 * Sets the media size.
109 *
Svetoslav948c9a62015-02-02 19:47:04 -0800110 * @param mediaSize The media size.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700111 *
112 * @hide
113 */
114 public void setMediaSize(MediaSize mediaSize) {
115 mMediaSize = mediaSize;
116 }
117
118 /**
119 * Gets the resolution.
120 *
121 * @return The resolution or <code>null</code> if not set.
122 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800123 public @Nullable Resolution getResolution() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700124 return mResolution;
125 }
126
127 /**
128 * Sets the resolution.
129 *
Svetoslav948c9a62015-02-02 19:47:04 -0800130 * @param resolution The resolution.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700131 *
132 * @hide
133 */
134 public void setResolution(Resolution resolution) {
135 mResolution = resolution;
136 }
137
138 /**
Svetoslav651dd4e2013-09-12 14:37:47 -0700139 * Gets the minimal margins. If the content does not fit
140 * these margins it will be clipped.
Svet Ganov525a66b2014-06-14 22:29:00 -0700141 * <p>
142 * <strong>These margins are physically imposed by the printer and they
143 * are <em>not</em> rotated, i.e. they are the same for both portrait and
144 * landscape. For example, a printer may not be able to print in a stripe
145 * on both left and right sides of the page.
146 * </strong>
147 * </p>
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700148 *
149 * @return The margins or <code>null</code> if not set.
150 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800151 public @Nullable Margins getMinMargins() {
Svetoslav651dd4e2013-09-12 14:37:47 -0700152 return mMinMargins;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700153 }
154
155 /**
Svetoslav651dd4e2013-09-12 14:37:47 -0700156 * Sets the minimal margins. If the content does not fit
157 * these margins it will be clipped.
Svet Ganov525a66b2014-06-14 22:29:00 -0700158 * <p>
159 * <strong>These margins are physically imposed by the printer and they
160 * are <em>not</em> rotated, i.e. they are the same for both portrait and
161 * landscape. For example, a printer may not be able to print in a stripe
162 * on both left and right sides of the page.
163 * </strong>
164 * </p>
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700165 *
Svetoslav948c9a62015-02-02 19:47:04 -0800166 * @param margins The margins.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700167 *
168 * @hide
169 */
Svetoslav651dd4e2013-09-12 14:37:47 -0700170 public void setMinMargins(Margins margins) {
171 mMinMargins = margins;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700172 }
173
174 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700175 * Gets the color mode.
176 *
177 * @return The color mode or zero if not set.
178 *
179 * @see #COLOR_MODE_COLOR
180 * @see #COLOR_MODE_MONOCHROME
181 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800182 public @ColorMode int getColorMode() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700183 return mColorMode;
184 }
185
186 /**
187 * Sets the color mode.
188 *
Svetoslav948c9a62015-02-02 19:47:04 -0800189 * @param colorMode The color mode.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700190 *
191 * @see #COLOR_MODE_MONOCHROME
192 * @see #COLOR_MODE_COLOR
193 *
194 * @hide
195 */
196 public void setColorMode(int colorMode) {
197 enforceValidColorMode(colorMode);
198 mColorMode = colorMode;
199 }
200
Svetoslava798c0a2014-05-15 10:47:19 -0700201 /**
202 * Gets whether this print attributes are in portrait orientation,
203 * which is the media size is in portrait and all orientation dependent
204 * attributes such as resolution and margins are properly adjusted.
205 *
206 * @return Whether this print attributes are in portrait.
207 *
208 * @hide
209 */
210 public boolean isPortrait() {
211 return mMediaSize.isPortrait();
212 }
213
214 /**
Svetoslav948c9a62015-02-02 19:47:04 -0800215 * Gets the duplex mode.
216 *
217 * @return The duplex mode.
218 *
219 * @see #DUPLEX_MODE_NONE
220 * @see #DUPLEX_MODE_LONG_EDGE
221 * @see #DUPLEX_MODE_SHORT_EDGE
222 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800223 public @DuplexMode int getDuplexMode() {
Svetoslav948c9a62015-02-02 19:47:04 -0800224 return mDuplexMode;
225 }
226
227 /**
228 * Sets the duplex mode.
229 *
230 * @param duplexMode The duplex mode.
231 *
232 * @see #DUPLEX_MODE_NONE
233 * @see #DUPLEX_MODE_LONG_EDGE
234 * @see #DUPLEX_MODE_SHORT_EDGE
235 *
236 * @hide
237 */
238 public void setDuplexMode(int duplexMode) {
239 enforceValidDuplexMode(duplexMode);
240 mDuplexMode = duplexMode;
241 }
242
243 /**
Svetoslava798c0a2014-05-15 10:47:19 -0700244 * Gets a new print attributes instance which is in portrait orientation,
245 * which is the media size is in portrait and all orientation dependent
246 * attributes such as resolution and margins are properly adjusted.
247 *
248 * @return New instance in portrait orientation if this one is in
249 * landscape, otherwise this instance.
250 *
251 * @hide
252 */
253 public PrintAttributes asPortrait() {
254 if (isPortrait()) {
255 return this;
256 }
257
258 PrintAttributes attributes = new PrintAttributes();
259
260 // Rotate the media size.
261 attributes.setMediaSize(getMediaSize().asPortrait());
262
263 // Rotate the resolution.
264 Resolution oldResolution = getResolution();
265 Resolution newResolution = new Resolution(
266 oldResolution.getId(),
267 oldResolution.getLabel(),
268 oldResolution.getVerticalDpi(),
269 oldResolution.getHorizontalDpi());
270 attributes.setResolution(newResolution);
271
Svet Ganov525a66b2014-06-14 22:29:00 -0700272 // Do not rotate the physical margins.
273 attributes.setMinMargins(getMinMargins());
Svetoslava798c0a2014-05-15 10:47:19 -0700274
275 attributes.setColorMode(getColorMode());
Svetoslav948c9a62015-02-02 19:47:04 -0800276 attributes.setDuplexMode(getDuplexMode());
Svetoslava798c0a2014-05-15 10:47:19 -0700277
278 return attributes;
279 }
280
281 /**
282 * Gets a new print attributes instance which is in landscape orientation,
283 * which is the media size is in landscape and all orientation dependent
284 * attributes such as resolution and margins are properly adjusted.
285 *
286 * @return New instance in landscape orientation if this one is in
287 * portrait, otherwise this instance.
288 *
289 * @hide
290 */
291 public PrintAttributes asLandscape() {
292 if (!isPortrait()) {
293 return this;
294 }
295
296 PrintAttributes attributes = new PrintAttributes();
297
298 // Rotate the media size.
299 attributes.setMediaSize(getMediaSize().asLandscape());
300
301 // Rotate the resolution.
302 Resolution oldResolution = getResolution();
303 Resolution newResolution = new Resolution(
304 oldResolution.getId(),
305 oldResolution.getLabel(),
306 oldResolution.getVerticalDpi(),
307 oldResolution.getHorizontalDpi());
308 attributes.setResolution(newResolution);
309
Svet Ganov525a66b2014-06-14 22:29:00 -0700310 // Do not rotate the physical margins.
311 attributes.setMinMargins(getMinMargins());
Svetoslava798c0a2014-05-15 10:47:19 -0700312
313 attributes.setColorMode(getColorMode());
Svetoslav948c9a62015-02-02 19:47:04 -0800314 attributes.setDuplexMode(getDuplexMode());
Svetoslava798c0a2014-05-15 10:47:19 -0700315
316 return attributes;
317 }
318
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700319 @Override
320 public void writeToParcel(Parcel parcel, int flags) {
321 if (mMediaSize != null) {
322 parcel.writeInt(1);
323 mMediaSize.writeToParcel(parcel);
324 } else {
325 parcel.writeInt(0);
326 }
327 if (mResolution != null) {
328 parcel.writeInt(1);
329 mResolution.writeToParcel(parcel);
330 } else {
331 parcel.writeInt(0);
332 }
Svetoslav651dd4e2013-09-12 14:37:47 -0700333 if (mMinMargins != null) {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700334 parcel.writeInt(1);
Svetoslav651dd4e2013-09-12 14:37:47 -0700335 mMinMargins.writeToParcel(parcel);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700336 } else {
337 parcel.writeInt(0);
338 }
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700339 parcel.writeInt(mColorMode);
Svetoslav948c9a62015-02-02 19:47:04 -0800340 parcel.writeInt(mDuplexMode);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700341 }
342
343 @Override
344 public int describeContents() {
345 return 0;
346 }
347
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700348 @Override
349 public int hashCode() {
350 final int prime = 31;
351 int result = 1;
352 result = prime * result + mColorMode;
Svetoslav948c9a62015-02-02 19:47:04 -0800353 result = prime * result + mDuplexMode;
Svetoslav651dd4e2013-09-12 14:37:47 -0700354 result = prime * result + ((mMinMargins == null) ? 0 : mMinMargins.hashCode());
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700355 result = prime * result + ((mMediaSize == null) ? 0 : mMediaSize.hashCode());
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700356 result = prime * result + ((mResolution == null) ? 0 : mResolution.hashCode());
357 return result;
358 }
359
360 @Override
361 public boolean equals(Object obj) {
362 if (this == obj) {
363 return true;
364 }
365 if (obj == null) {
366 return false;
367 }
368 if (getClass() != obj.getClass()) {
369 return false;
370 }
371 PrintAttributes other = (PrintAttributes) obj;
372 if (mColorMode != other.mColorMode) {
373 return false;
374 }
Svetoslav948c9a62015-02-02 19:47:04 -0800375 if (mDuplexMode != other.mDuplexMode) {
376 return false;
377 }
Svetoslav651dd4e2013-09-12 14:37:47 -0700378 if (mMinMargins == null) {
379 if (other.mMinMargins != null) {
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700380 return false;
381 }
Svetoslav651dd4e2013-09-12 14:37:47 -0700382 } else if (!mMinMargins.equals(other.mMinMargins)) {
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700383 return false;
384 }
385 if (mMediaSize == null) {
386 if (other.mMediaSize != null) {
387 return false;
388 }
389 } else if (!mMediaSize.equals(other.mMediaSize)) {
390 return false;
391 }
392 if (mResolution == null) {
393 if (other.mResolution != null) {
394 return false;
395 }
396 } else if (!mResolution.equals(other.mResolution)) {
397 return false;
398 }
399 return true;
400 }
401
402 @Override
403 public String toString() {
404 StringBuilder builder = new StringBuilder();
405 builder.append("PrintAttributes{");
406 builder.append("mediaSize: ").append(mMediaSize);
Svetoslavcc65b0c2013-09-10 21:08:32 -0700407 if (mMediaSize != null) {
408 builder.append(", orientation: ").append(mMediaSize.isPortrait()
409 ? "portrait" : "landscape");
410 } else {
411 builder.append(", orientation: ").append("null");
412 }
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700413 builder.append(", resolution: ").append(mResolution);
Svetoslav651dd4e2013-09-12 14:37:47 -0700414 builder.append(", minMargins: ").append(mMinMargins);
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700415 builder.append(", colorMode: ").append(colorModeToString(mColorMode));
Svetoslav948c9a62015-02-02 19:47:04 -0800416 builder.append(", duplexMode: ").append(duplexModeToString(mDuplexMode));
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700417 builder.append("}");
418 return builder.toString();
419 }
420
Svetoslav81d40142013-09-18 14:38:26 -0700421 /** @hide */
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700422 public void clear() {
423 mMediaSize = null;
424 mResolution = null;
Svetoslav651dd4e2013-09-12 14:37:47 -0700425 mMinMargins = null;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700426 mColorMode = 0;
Philip P. Moltmannb4efdb42015-11-10 14:58:44 -0800427 mDuplexMode = 0;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700428 }
429
430 /**
Svetoslav Ganov0d1daa52013-07-23 13:29:31 -0700431 * @hide
432 */
433 public void copyFrom(PrintAttributes other) {
434 mMediaSize = other.mMediaSize;
435 mResolution = other.mResolution;
Svetoslav651dd4e2013-09-12 14:37:47 -0700436 mMinMargins = other.mMinMargins;
Svetoslav Ganov0d1daa52013-07-23 13:29:31 -0700437 mColorMode = other.mColorMode;
Svetoslav948c9a62015-02-02 19:47:04 -0800438 mDuplexMode = other.mDuplexMode;
Svetoslav Ganov0d1daa52013-07-23 13:29:31 -0700439 }
440
441 /**
Svetoslav Ganov22cb9172013-08-29 17:42:07 -0700442 * This class specifies a supported media size. Media size is the
443 * dimension of the media on which the content is printed. For
444 * example, the {@link #NA_LETTER} media size designates a page
445 * with size 8.5" x 11".
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700446 */
447 public static final class MediaSize {
Svetoslav773f54d2013-09-03 14:01:43 -0700448 private static final String LOG_TAG = "MediaSize";
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700449
Svetoslav Ganov7be27ac2013-09-30 09:04:50 -0700450 private static final Map<String, MediaSize> sIdToMediaSizeMap =
451 new ArrayMap<String, MediaSize>();
452
Svetoslavd8f391b2013-09-20 16:25:52 -0700453 /**
454 * Unknown media size in portrait mode.
455 * <p>
456 * <strong>Note: </strong>This is for specifying orientation without media
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700457 * size. You should not use the dimensions reported by this instance.
Svetoslavd8f391b2013-09-20 16:25:52 -0700458 * </p>
459 */
460 public static final MediaSize UNKNOWN_PORTRAIT =
461 new MediaSize("UNKNOWN_PORTRAIT", "android",
Svetoslav Ganovb2420c92013-10-06 19:44:14 -0700462 R.string.mediasize_unknown_portrait, 1, Integer.MAX_VALUE);
Svetoslavd8f391b2013-09-20 16:25:52 -0700463
464 /**
465 * Unknown media size in landscape mode.
466 * <p>
467 * <strong>Note: </strong>This is for specifying orientation without media
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700468 * size. You should not use the dimensions reported by this instance.
Svetoslavd8f391b2013-09-20 16:25:52 -0700469 * </p>
470 */
471 public static final MediaSize UNKNOWN_LANDSCAPE =
472 new MediaSize("UNKNOWN_LANDSCAPE", "android",
Svetoslav Ganovb2420c92013-10-06 19:44:14 -0700473 R.string.mediasize_unknown_landscape, Integer.MAX_VALUE, 1);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700474
475 // ISO sizes
476
Svetoslav773f54d2013-09-03 14:01:43 -0700477 /** ISO A0 media size: 841mm x 1189mm (33.11" x 46.81") */
478 public static final MediaSize ISO_A0 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700479 new MediaSize("ISO_A0", "android", R.string.mediasize_iso_a0, 33110, 46810);
Svetoslav773f54d2013-09-03 14:01:43 -0700480 /** ISO A1 media size: 594mm x 841mm (23.39" x 33.11") */
481 public static final MediaSize ISO_A1 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700482 new MediaSize("ISO_A1", "android", R.string.mediasize_iso_a1, 23390, 33110);
Svetoslav773f54d2013-09-03 14:01:43 -0700483 /** ISO A2 media size: 420mm x 594mm (16.54" x 23.39") */
484 public static final MediaSize ISO_A2 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700485 new MediaSize("ISO_A2", "android", R.string.mediasize_iso_a2, 16540, 23390);
Svetoslav773f54d2013-09-03 14:01:43 -0700486 /** ISO A3 media size: 297mm x 420mm (11.69" x 16.54") */
487 public static final MediaSize ISO_A3 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700488 new MediaSize("ISO_A3", "android", R.string.mediasize_iso_a3, 11690, 16540);
Svetoslav773f54d2013-09-03 14:01:43 -0700489 /** ISO A4 media size: 210mm x 297mm (8.27" x 11.69") */
490 public static final MediaSize ISO_A4 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700491 new MediaSize("ISO_A4", "android", R.string.mediasize_iso_a4, 8270, 11690);
Svetoslav773f54d2013-09-03 14:01:43 -0700492 /** ISO A5 media size: 148mm x 210mm (5.83" x 8.27") */
493 public static final MediaSize ISO_A5 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700494 new MediaSize("ISO_A5", "android", R.string.mediasize_iso_a5, 5830, 8270);
Svetoslav773f54d2013-09-03 14:01:43 -0700495 /** ISO A6 media size: 105mm x 148mm (4.13" x 5.83") */
496 public static final MediaSize ISO_A6 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700497 new MediaSize("ISO_A6", "android", R.string.mediasize_iso_a6, 4130, 5830);
Svetoslav773f54d2013-09-03 14:01:43 -0700498 /** ISO A7 media size: 74mm x 105mm (2.91" x 4.13") */
499 public static final MediaSize ISO_A7 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700500 new MediaSize("ISO_A7", "android", R.string.mediasize_iso_a7, 2910, 4130);
Svetoslav773f54d2013-09-03 14:01:43 -0700501 /** ISO A8 media size: 52mm x 74mm (2.05" x 2.91") */
502 public static final MediaSize ISO_A8 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700503 new MediaSize("ISO_A8", "android", R.string.mediasize_iso_a8, 2050, 2910);
Svetoslav773f54d2013-09-03 14:01:43 -0700504 /** ISO A9 media size: 37mm x 52mm (1.46" x 2.05") */
505 public static final MediaSize ISO_A9 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700506 new MediaSize("ISO_A9", "android", R.string.mediasize_iso_a9, 1460, 2050);
Svetoslav773f54d2013-09-03 14:01:43 -0700507 /** ISO A10 media size: 26mm x 37mm (1.02" x 1.46") */
508 public static final MediaSize ISO_A10 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700509 new MediaSize("ISO_A10", "android", R.string.mediasize_iso_a10, 1020, 1460);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700510
Svetoslav773f54d2013-09-03 14:01:43 -0700511 /** ISO B0 media size: 1000mm x 1414mm (39.37" x 55.67") */
512 public static final MediaSize ISO_B0 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700513 new MediaSize("ISO_B0", "android", R.string.mediasize_iso_b0, 39370, 55670);
Svetoslav773f54d2013-09-03 14:01:43 -0700514 /** ISO B1 media size: 707mm x 1000mm (27.83" x 39.37") */
515 public static final MediaSize ISO_B1 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700516 new MediaSize("ISO_B1", "android", R.string.mediasize_iso_b1, 27830, 39370);
Svetoslav773f54d2013-09-03 14:01:43 -0700517 /** ISO B2 media size: 500mm x 707mm (19.69" x 27.83") */
518 public static final MediaSize ISO_B2 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700519 new MediaSize("ISO_B2", "android", R.string.mediasize_iso_b2, 19690, 27830);
Svetoslav773f54d2013-09-03 14:01:43 -0700520 /** ISO B3 media size: 353mm x 500mm (13.90" x 19.69") */
521 public static final MediaSize ISO_B3 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700522 new MediaSize("ISO_B3", "android", R.string.mediasize_iso_b3, 13900, 19690);
Svetoslav773f54d2013-09-03 14:01:43 -0700523 /** ISO B4 media size: 250mm x 353mm (9.84" x 13.90") */
524 public static final MediaSize ISO_B4 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700525 new MediaSize("ISO_B4", "android", R.string.mediasize_iso_b4, 9840, 13900);
Svetoslav773f54d2013-09-03 14:01:43 -0700526 /** ISO B5 media size: 176mm x 250mm (6.93" x 9.84") */
527 public static final MediaSize ISO_B5 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700528 new MediaSize("ISO_B5", "android", R.string.mediasize_iso_b5, 6930, 9840);
Svetoslav773f54d2013-09-03 14:01:43 -0700529 /** ISO B6 media size: 125mm x 176mm (4.92" x 6.93") */
530 public static final MediaSize ISO_B6 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700531 new MediaSize("ISO_B6", "android", R.string.mediasize_iso_b6, 4920, 6930);
Svetoslav773f54d2013-09-03 14:01:43 -0700532 /** ISO B7 media size: 88mm x 125mm (3.46" x 4.92") */
533 public static final MediaSize ISO_B7 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700534 new MediaSize("ISO_B7", "android", R.string.mediasize_iso_b7, 3460, 4920);
Svetoslav773f54d2013-09-03 14:01:43 -0700535 /** ISO B8 media size: 62mm x 88mm (2.44" x 3.46") */
536 public static final MediaSize ISO_B8 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700537 new MediaSize("ISO_B8", "android", R.string.mediasize_iso_b8, 2440, 3460);
Svetoslav773f54d2013-09-03 14:01:43 -0700538 /** ISO B9 media size: 44mm x 62mm (1.73" x 2.44") */
539 public static final MediaSize ISO_B9 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700540 new MediaSize("ISO_B9", "android", R.string.mediasize_iso_b9, 1730, 2440);
Svetoslav773f54d2013-09-03 14:01:43 -0700541 /** ISO B10 media size: 31mm x 44mm (1.22" x 1.73") */
542 public static final MediaSize ISO_B10 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700543 new MediaSize("ISO_B10", "android", R.string.mediasize_iso_b10, 1220, 1730);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700544
Svetoslav773f54d2013-09-03 14:01:43 -0700545 /** ISO C0 media size: 917mm x 1297mm (36.10" x 51.06") */
546 public static final MediaSize ISO_C0 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700547 new MediaSize("ISO_C0", "android", R.string.mediasize_iso_c0, 36100, 51060);
Svetoslav773f54d2013-09-03 14:01:43 -0700548 /** ISO C1 media size: 648mm x 917mm (25.51" x 36.10") */
549 public static final MediaSize ISO_C1 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700550 new MediaSize("ISO_C1", "android", R.string.mediasize_iso_c1, 25510, 36100);
Svetoslav773f54d2013-09-03 14:01:43 -0700551 /** ISO C2 media size: 458mm x 648mm (18.03" x 25.51") */
552 public static final MediaSize ISO_C2 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700553 new MediaSize("ISO_C2", "android", R.string.mediasize_iso_c2, 18030, 25510);
Svetoslav773f54d2013-09-03 14:01:43 -0700554 /** ISO C3 media size: 324mm x 458mm (12.76" x 18.03") */
555 public static final MediaSize ISO_C3 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700556 new MediaSize("ISO_C3", "android", R.string.mediasize_iso_c3, 12760, 18030);
Svetoslav773f54d2013-09-03 14:01:43 -0700557 /** ISO C4 media size: 229mm x 324mm (9.02" x 12.76") */
558 public static final MediaSize ISO_C4 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700559 new MediaSize("ISO_C4", "android", R.string.mediasize_iso_c4, 9020, 12760);
Svetoslav773f54d2013-09-03 14:01:43 -0700560 /** ISO C5 media size: 162mm x 229mm (6.38" x 9.02") */
561 public static final MediaSize ISO_C5 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700562 new MediaSize("ISO_C5", "android", R.string.mediasize_iso_c5, 6380, 9020);
Svetoslav773f54d2013-09-03 14:01:43 -0700563 /** ISO C6 media size: 114mm x 162mm (4.49" x 6.38") */
564 public static final MediaSize ISO_C6 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700565 new MediaSize("ISO_C6", "android", R.string.mediasize_iso_c6, 4490, 6380);
Svetoslav773f54d2013-09-03 14:01:43 -0700566 /** ISO C7 media size: 81mm x 114mm (3.19" x 4.49") */
567 public static final MediaSize ISO_C7 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700568 new MediaSize("ISO_C7", "android", R.string.mediasize_iso_c7, 3190, 4490);
Svetoslav773f54d2013-09-03 14:01:43 -0700569 /** ISO C8 media size: 57mm x 81mm (2.24" x 3.19") */
570 public static final MediaSize ISO_C8 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700571 new MediaSize("ISO_C8", "android", R.string.mediasize_iso_c8, 2240, 3190);
Svetoslav773f54d2013-09-03 14:01:43 -0700572 /** ISO C9 media size: 40mm x 57mm (1.57" x 2.24") */
573 public static final MediaSize ISO_C9 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700574 new MediaSize("ISO_C9", "android", R.string.mediasize_iso_c9, 1570, 2240);
Svetoslav773f54d2013-09-03 14:01:43 -0700575 /** ISO C10 media size: 28mm x 40mm (1.10" x 1.57") */
576 public static final MediaSize ISO_C10 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700577 new MediaSize("ISO_C10", "android", R.string.mediasize_iso_c10, 1100, 1570);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700578
579 // North America
580
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700581 /** North America Letter media size: 8.5" x 11" (279mm x 216mm) */
Svetoslav773f54d2013-09-03 14:01:43 -0700582 public static final MediaSize NA_LETTER =
Svetoslavd8f391b2013-09-20 16:25:52 -0700583 new MediaSize("NA_LETTER", "android", R.string.mediasize_na_letter, 8500, 11000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700584 /** North America Government-Letter media size: 8.0" x 10.5" (203mm x 267mm) */
Svetoslav773f54d2013-09-03 14:01:43 -0700585 public static final MediaSize NA_GOVT_LETTER =
586 new MediaSize("NA_GOVT_LETTER", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700587 R.string.mediasize_na_gvrnmt_letter, 8000, 10500);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700588 /** North America Legal media size: 8.5" x 14" (216mm x 356mm) */
Svetoslav773f54d2013-09-03 14:01:43 -0700589 public static final MediaSize NA_LEGAL =
Svetoslavd8f391b2013-09-20 16:25:52 -0700590 new MediaSize("NA_LEGAL", "android", R.string.mediasize_na_legal, 8500, 14000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700591 /** North America Junior Legal media size: 8.0" x 5.0" (203mm × 127mm) */
Svetoslav773f54d2013-09-03 14:01:43 -0700592 public static final MediaSize NA_JUNIOR_LEGAL =
593 new MediaSize("NA_JUNIOR_LEGAL", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700594 R.string.mediasize_na_junior_legal, 8000, 5000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700595 /** North America Ledger media size: 17" x 11" (432mm × 279mm) */
Svetoslav773f54d2013-09-03 14:01:43 -0700596 public static final MediaSize NA_LEDGER =
Svetoslavd8f391b2013-09-20 16:25:52 -0700597 new MediaSize("NA_LEDGER", "android", R.string.mediasize_na_ledger, 17000, 11000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700598 /** North America Tabloid media size: 11" x 17" (279mm × 432mm) */
Svetoslav013b8162013-09-18 12:31:23 -0700599 public static final MediaSize NA_TABLOID =
Svetoslav773f54d2013-09-03 14:01:43 -0700600 new MediaSize("NA_TABLOID", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700601 R.string.mediasize_na_tabloid, 11000, 17000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700602 /** North America Index Card 3x5 media size: 3" x 5" (76mm x 127mm) */
603 public static final MediaSize NA_INDEX_3X5 =
604 new MediaSize("NA_INDEX_3X5", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700605 R.string.mediasize_na_index_3x5, 3000, 5000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700606 /** North America Index Card 4x6 media size: 4" x 6" (102mm x 152mm) */
607 public static final MediaSize NA_INDEX_4X6 =
608 new MediaSize("NA_INDEX_4X6", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700609 R.string.mediasize_na_index_4x6, 4000, 6000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700610 /** North America Index Card 5x8 media size: 5" x 8" (127mm x 203mm) */
611 public static final MediaSize NA_INDEX_5X8 =
612 new MediaSize("NA_INDEX_5X8", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700613 R.string.mediasize_na_index_5x8, 5000, 8000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700614 /** North America Monarch media size: 7.25" x 10.5" (184mm x 267mm) */
615 public static final MediaSize NA_MONARCH =
616 new MediaSize("NA_MONARCH", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700617 R.string.mediasize_na_monarch, 7250, 10500);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700618 /** North America Quarto media size: 8" x 10" (203mm x 254mm) */
619 public static final MediaSize NA_QUARTO =
620 new MediaSize("NA_QUARTO", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700621 R.string.mediasize_na_quarto, 8000, 10000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700622 /** North America Foolscap media size: 8" x 13" (203mm x 330mm) */
623 public static final MediaSize NA_FOOLSCAP =
624 new MediaSize("NA_FOOLSCAP", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700625 R.string.mediasize_na_foolscap, 8000, 13000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700626
627 // Chinese
628
629 /** Chinese ROC 8K media size: 270mm x 390mm (10.629" x 15.3543") */
630 public static final MediaSize ROC_8K =
631 new MediaSize("ROC_8K", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700632 R.string.mediasize_chinese_roc_8k, 10629, 15354);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700633 /** Chinese ROC 16K media size: 195mm x 270mm (7.677" x 10.629") */
634 public static final MediaSize ROC_16K =
635 new MediaSize("ROC_16K", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700636 R.string.mediasize_chinese_roc_16k, 7677, 10629);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700637
638 /** Chinese PRC 1 media size: 102mm x 165mm (4.015" x 6.496") */
639 public static final MediaSize PRC_1 =
640 new MediaSize("PRC_1", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700641 R.string.mediasize_chinese_prc_1, 4015, 6496);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700642 /** Chinese PRC 2 media size: 102mm x 176mm (4.015" x 6.929") */
643 public static final MediaSize PRC_2 =
644 new MediaSize("PRC_2", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700645 R.string.mediasize_chinese_prc_2, 4015, 6929);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700646 /** Chinese PRC 3 media size: 125mm x 176mm (4.921" x 6.929") */
647 public static final MediaSize PRC_3 =
648 new MediaSize("PRC_3", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700649 R.string.mediasize_chinese_prc_3, 4921, 6929);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700650 /** Chinese PRC 4 media size: 110mm x 208mm (4.330" x 8.189") */
651 public static final MediaSize PRC_4 =
652 new MediaSize("PRC_4", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700653 R.string.mediasize_chinese_prc_4, 4330, 8189);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700654 /** Chinese PRC 5 media size: 110mm x 220mm (4.330" x 8.661") */
655 public static final MediaSize PRC_5 =
656 new MediaSize("PRC_5", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700657 R.string.mediasize_chinese_prc_5, 4330, 8661);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700658 /** Chinese PRC 6 media size: 120mm x 320mm (4.724" x 12.599") */
659 public static final MediaSize PRC_6 =
660 new MediaSize("PRC_6", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700661 R.string.mediasize_chinese_prc_6, 4724, 12599);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700662 /** Chinese PRC 7 media size: 160mm x 230mm (6.299" x 9.055") */
663 public static final MediaSize PRC_7 =
664 new MediaSize("PRC_7", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700665 R.string.mediasize_chinese_prc_7, 6299, 9055);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700666 /** Chinese PRC 8 media size: 120mm x 309mm (4.724" x 12.165") */
667 public static final MediaSize PRC_8 =
668 new MediaSize("PRC_8", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700669 R.string.mediasize_chinese_prc_8, 4724, 12165);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700670 /** Chinese PRC 9 media size: 229mm x 324mm (9.016" x 12.756") */
671 public static final MediaSize PRC_9 =
672 new MediaSize("PRC_9", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700673 R.string.mediasize_chinese_prc_9, 9016, 12756);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700674 /** Chinese PRC 10 media size: 324mm x 458mm (12.756" x 18.032") */
675 public static final MediaSize PRC_10 =
676 new MediaSize("PRC_10", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700677 R.string.mediasize_chinese_prc_10, 12756, 18032);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700678
679 /** Chinese PRC 16k media size: 146mm x 215mm (5.749" x 8.465") */
Svetoslav Ganov7be27ac2013-09-30 09:04:50 -0700680 public static final MediaSize PRC_16K =
681 new MediaSize("PRC_16K", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700682 R.string.mediasize_chinese_prc_16k, 5749, 8465);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700683 /** Chinese Pa Kai media size: 267mm x 389mm (10.512" x 15.315") */
684 public static final MediaSize OM_PA_KAI =
685 new MediaSize("OM_PA_KAI", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700686 R.string.mediasize_chinese_om_pa_kai, 10512, 15315);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700687 /** Chinese Dai Pa Kai media size: 275mm x 395mm (10.827" x 15.551") */
688 public static final MediaSize OM_DAI_PA_KAI =
689 new MediaSize("OM_DAI_PA_KAI", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700690 R.string.mediasize_chinese_om_dai_pa_kai, 10827, 15551);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700691 /** Chinese Jurro Ku Kai media size: 198mm x 275mm (7.796" x 10.827") */
692 public static final MediaSize OM_JUURO_KU_KAI =
693 new MediaSize("OM_JUURO_KU_KAI", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700694 R.string.mediasize_chinese_om_jurro_ku_kai, 7796, 10827);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700695
696 // Japanese
697
698 /** Japanese JIS B10 media size: 32mm x 45mm (1.259" x 1.772") */
699 public static final MediaSize JIS_B10 =
700 new MediaSize("JIS_B10", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700701 R.string.mediasize_japanese_jis_b10, 1259, 1772);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700702 /** Japanese JIS B9 media size: 45mm x 64mm (1.772" x 2.52") */
703 public static final MediaSize JIS_B9 =
704 new MediaSize("JIS_B9", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700705 R.string.mediasize_japanese_jis_b9, 1772, 2520);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700706 /** Japanese JIS B8 media size: 64mm x 91mm (2.52" x 3.583") */
707 public static final MediaSize JIS_B8 =
708 new MediaSize("JIS_B8", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700709 R.string.mediasize_japanese_jis_b8, 2520, 3583);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700710 /** Japanese JIS B7 media size: 91mm x 128mm (3.583" x 5.049") */
711 public static final MediaSize JIS_B7 =
712 new MediaSize("JIS_B7", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700713 R.string.mediasize_japanese_jis_b7, 3583, 5049);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700714 /** Japanese JIS B6 media size: 128mm x 182mm (5.049" x 7.165") */
715 public static final MediaSize JIS_B6 =
716 new MediaSize("JIS_B6", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700717 R.string.mediasize_japanese_jis_b6, 5049, 7165);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700718 /** Japanese JIS B5 media size: 182mm x 257mm (7.165" x 10.118") */
719 public static final MediaSize JIS_B5 =
720 new MediaSize("JIS_B5", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700721 R.string.mediasize_japanese_jis_b5, 7165, 10118);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700722 /** Japanese JIS B4 media size: 257mm x 364mm (10.118" x 14.331") */
723 public static final MediaSize JIS_B4 =
724 new MediaSize("JIS_B4", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700725 R.string.mediasize_japanese_jis_b4, 10118, 14331);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700726 /** Japanese JIS B3 media size: 364mm x 515mm (14.331" x 20.276") */
727 public static final MediaSize JIS_B3 =
728 new MediaSize("JIS_B3", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700729 R.string.mediasize_japanese_jis_b3, 14331, 20276);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700730 /** Japanese JIS B2 media size: 515mm x 728mm (20.276" x 28.661") */
731 public static final MediaSize JIS_B2 =
732 new MediaSize("JIS_B2", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700733 R.string.mediasize_japanese_jis_b2, 20276, 28661);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700734 /** Japanese JIS B1 media size: 728mm x 1030mm (28.661" x 40.551") */
735 public static final MediaSize JIS_B1 =
736 new MediaSize("JIS_B1", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700737 R.string.mediasize_japanese_jis_b1, 28661, 40551);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700738 /** Japanese JIS B0 media size: 1030mm x 1456mm (40.551" x 57.323") */
739 public static final MediaSize JIS_B0 =
740 new MediaSize("JIS_B0", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700741 R.string.mediasize_japanese_jis_b0, 40551, 57323);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700742
743 /** Japanese JIS Exec media size: 216mm x 330mm (8.504" x 12.992") */
744 public static final MediaSize JIS_EXEC =
745 new MediaSize("JIS_EXEC", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700746 R.string.mediasize_japanese_jis_exec, 8504, 12992);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700747
748 /** Japanese Chou4 media size: 90mm x 205mm (3.543" x 8.071") */
749 public static final MediaSize JPN_CHOU4 =
750 new MediaSize("JPN_CHOU4", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700751 R.string.mediasize_japanese_chou4, 3543, 8071);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700752 /** Japanese Chou3 media size: 120mm x 235mm (4.724" x 9.252") */
753 public static final MediaSize JPN_CHOU3 =
754 new MediaSize("JPN_CHOU3", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700755 R.string.mediasize_japanese_chou3, 4724, 9252);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700756 /** Japanese Chou2 media size: 111.1mm x 146mm (4.374" x 5.748") */
757 public static final MediaSize JPN_CHOU2 =
758 new MediaSize("JPN_CHOU2", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700759 R.string.mediasize_japanese_chou2, 4374, 5748);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700760
761 /** Japanese Hagaki media size: 100mm x 148mm (3.937" x 5.827") */
762 public static final MediaSize JPN_HAGAKI =
763 new MediaSize("JPN_HAGAKI", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700764 R.string.mediasize_japanese_hagaki, 3937, 5827);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700765 /** Japanese Oufuku media size: 148mm x 200mm (5.827" x 7.874") */
766 public static final MediaSize JPN_OUFUKU =
767 new MediaSize("JPN_OUFUKU", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700768 R.string.mediasize_japanese_oufuku, 5827, 7874);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700769
770 /** Japanese Kahu media size: 240mm x 322.1mm (9.449" x 12.681") */
771 public static final MediaSize JPN_KAHU =
772 new MediaSize("JPN_KAHU", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700773 R.string.mediasize_japanese_kahu, 9449, 12681);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700774 /** Japanese Kaku2 media size: 240mm x 332mm (9.449" x 13.071") */
775 public static final MediaSize JPN_KAKU2 =
776 new MediaSize("JPN_KAKU2", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700777 R.string.mediasize_japanese_kaku2, 9449, 13071);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700778
779 /** Japanese You4 media size: 105mm x 235mm (4.134" x 9.252") */
780 public static final MediaSize JPN_YOU4 =
781 new MediaSize("JPN_YOU4", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700782 R.string.mediasize_japanese_you4, 4134, 9252);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700783
784 private final String mId;
Svetoslav773f54d2013-09-03 14:01:43 -0700785 /**@hide */
786 public final String mLabel;
787 /**@hide */
788 public final String mPackageName;
789 /**@hide */
790 public final int mLabelResId;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700791 private final int mWidthMils;
792 private final int mHeightMils;
793
794 /**
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700795 * Creates a new instance.
Svetoslav773f54d2013-09-03 14:01:43 -0700796 *
797 * @param id The unique media size id.
798 * @param packageName The name of the creating package.
799 * @param labelResId The resource if of a human readable label.
800 * @param widthMils The width in mils (thousands of an inch).
801 * @param heightMils The height in mils (thousands of an inch).
802 *
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700803 * @throws IllegalArgumentException If the id is empty or the label
804 * is empty or the widthMils is less than or equal to zero or the
805 * heightMils is less than or equal to zero.
Svetoslava76233a2013-09-05 09:38:02 -0700806 *
807 * @hide
Svetoslav773f54d2013-09-03 14:01:43 -0700808 */
809 public MediaSize(String id, String packageName, int labelResId,
810 int widthMils, int heightMils) {
811 if (TextUtils.isEmpty(id)) {
812 throw new IllegalArgumentException("id cannot be empty.");
813 }
814 if (TextUtils.isEmpty(packageName)) {
815 throw new IllegalArgumentException("packageName cannot be empty.");
816 }
817 if (labelResId <= 0) {
818 throw new IllegalArgumentException("labelResId must be greater than zero.");
819 }
820 if (widthMils <= 0) {
821 throw new IllegalArgumentException("widthMils "
822 + "cannot be less than or equal to zero.");
823 }
824 if (heightMils <= 0) {
825 throw new IllegalArgumentException("heightMils "
826 + "cannot be less than or euqual to zero.");
827 }
828 mPackageName = packageName;
829 mId = id;
830 mLabelResId = labelResId;
831 mWidthMils = widthMils;
832 mHeightMils = heightMils;
833 mLabel = null;
Svetoslav Ganov7be27ac2013-09-30 09:04:50 -0700834
835 // Build this mapping only for predefined media sizes.
836 sIdToMediaSizeMap.put(mId, this);
Svetoslav773f54d2013-09-03 14:01:43 -0700837 }
838
839 /**
Svetoslava76233a2013-09-05 09:38:02 -0700840 * Creates a new instance.
Svetoslav17b7f6e2013-06-24 18:29:33 -0700841 *
Svetoslav Ganov22cb9172013-08-29 17:42:07 -0700842 * @param id The unique media size id. It is unique amongst other media sizes
843 * supported by the printer.
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700844 * @param label The <strong>localized</strong> human readable label.
Svetoslav17b7f6e2013-06-24 18:29:33 -0700845 * @param widthMils The width in mils (thousands of an inch).
846 * @param heightMils The height in mils (thousands of an inch).
847 *
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700848 * @throws IllegalArgumentException If the id is empty or the label is empty
849 * or the widthMils is less than or equal to zero or the heightMils is less
850 * than or equal to zero.
Svetoslav17b7f6e2013-06-24 18:29:33 -0700851 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800852 public MediaSize(@NonNull String id, @NonNull String label,
853 @IntRange(from = 1) int widthMils, @IntRange(from = 1) int heightMils) {
Svetoslav17b7f6e2013-06-24 18:29:33 -0700854 if (TextUtils.isEmpty(id)) {
855 throw new IllegalArgumentException("id cannot be empty.");
856 }
857 if (TextUtils.isEmpty(label)) {
858 throw new IllegalArgumentException("label cannot be empty.");
859 }
860 if (widthMils <= 0) {
861 throw new IllegalArgumentException("widthMils "
862 + "cannot be less than or equal to zero.");
863 }
864 if (heightMils <= 0) {
865 throw new IllegalArgumentException("heightMils "
866 + "cannot be less than or euqual to zero.");
867 }
868 mId = id;
869 mLabel = label;
870 mWidthMils = widthMils;
871 mHeightMils = heightMils;
Svetoslav773f54d2013-09-03 14:01:43 -0700872 mLabelResId = 0;
873 mPackageName = null;
874 }
875
Philip P. Moltmann4959caf2016-01-21 14:30:56 -0800876 /**
877 * Get the Id of all predefined media sizes beside the {@link #UNKNOWN_PORTRAIT} and
878 * {@link #UNKNOWN_LANDSCAPE}.
879 *
880 * @return List of all predefined media sizes
881 *
882 * @hide
883 */
884 public static @NonNull ArraySet<MediaSize> getAllPredefinedSizes() {
885 ArraySet<MediaSize> definedMediaSizes = new ArraySet<>(sIdToMediaSizeMap.values());
886
887 definedMediaSizes.remove(UNKNOWN_PORTRAIT);
888 definedMediaSizes.remove(UNKNOWN_LANDSCAPE);
889
890 return definedMediaSizes;
891 }
892
Svetoslav773f54d2013-09-03 14:01:43 -0700893 /** @hide */
894 public MediaSize(String id, String label, String packageName,
895 int widthMils, int heightMils, int labelResId) {
896 mPackageName = packageName;
897 mId = id;
898 mLabelResId = labelResId;
899 mWidthMils = widthMils;
900 mHeightMils = heightMils;
901 mLabel = label;
Svetoslav17b7f6e2013-06-24 18:29:33 -0700902 }
903
904 /**
Svetoslav Ganov22cb9172013-08-29 17:42:07 -0700905 * Gets the unique media size id. It is unique amongst other media sizes
906 * supported by the printer.
907 * <p>
908 * This id is defined by the client that generated the media size
909 * instance and should not be interpreted by other parties.
910 * </p>
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700911 *
912 * @return The unique media size id.
913 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800914 public @NonNull String getId() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700915 return mId;
916 }
917
918 /**
919 * Gets the human readable media size label.
920 *
Svetoslav773f54d2013-09-03 14:01:43 -0700921 * @param packageManager The package manager for loading the label.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700922 * @return The human readable label.
923 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800924 public @NonNull String getLabel(@NonNull PackageManager packageManager) {
Svetoslav773f54d2013-09-03 14:01:43 -0700925 if (!TextUtils.isEmpty(mPackageName) && mLabelResId > 0) {
926 try {
927 return packageManager.getResourcesForApplication(
928 mPackageName).getString(mLabelResId);
929 } catch (NotFoundException nfe) {
930 Log.w(LOG_TAG, "Could not load resouce" + mLabelResId
931 + " from package " + mPackageName);
932 } catch (NameNotFoundException nnfee) {
933 Log.w(LOG_TAG, "Could not load resouce" + mLabelResId
934 + " from package " + mPackageName);
935 }
936 }
Svetoslav17b7f6e2013-06-24 18:29:33 -0700937 return mLabel;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700938 }
939
940 /**
941 * Gets the media width in mils (thousands of an inch).
942 *
943 * @return The media width.
944 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800945 public @IntRange(from = 1) int getWidthMils() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700946 return mWidthMils;
947 }
948
949 /**
950 * Gets the media height in mils (thousands of an inch).
951 *
952 * @return The media height.
953 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800954 public @IntRange(from = 1) int getHeightMils() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700955 return mHeightMils;
956 }
957
Svetoslav773f54d2013-09-03 14:01:43 -0700958 /**
959 * Gets whether this media size is in portrait which is the
960 * height is greater or equal to the width.
961 *
962 * @return True if the media size is in portrait, false if
963 * it is in landscape.
964 */
965 public boolean isPortrait() {
966 return mHeightMils >= mWidthMils;
967 }
968
969 /**
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700970 * Returns a new media size instance in a portrait orientation,
Svetoslava76233a2013-09-05 09:38:02 -0700971 * which is the height is the greater dimension.
Svetoslav773f54d2013-09-03 14:01:43 -0700972 *
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700973 * @return New instance in landscape orientation if this one
974 * is in landscape, otherwise this instance.
Svetoslav773f54d2013-09-03 14:01:43 -0700975 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800976 public @NonNull MediaSize asPortrait() {
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700977 if (isPortrait()) {
978 return this;
979 }
Svetoslava36285f2013-09-05 11:27:45 -0700980 return new MediaSize(mId, mLabel, mPackageName,
Svetoslava76233a2013-09-05 09:38:02 -0700981 Math.min(mWidthMils, mHeightMils),
982 Math.max(mWidthMils, mHeightMils),
983 mLabelResId);
Svetoslav773f54d2013-09-03 14:01:43 -0700984 }
985
986 /**
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700987 * Returns a new media size instance in a landscape orientation,
Svetoslava76233a2013-09-05 09:38:02 -0700988 * which is the height is the lesser dimension.
Svetoslav773f54d2013-09-03 14:01:43 -0700989 *
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700990 * @return New instance in landscape orientation if this one
991 * is in portrait, otherwise this instance.
Svetoslav773f54d2013-09-03 14:01:43 -0700992 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800993 public @NonNull MediaSize asLandscape() {
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700994 if (!isPortrait()) {
995 return this;
996 }
Svetoslava36285f2013-09-05 11:27:45 -0700997 return new MediaSize(mId, mLabel, mPackageName,
Svetoslav773f54d2013-09-03 14:01:43 -0700998 Math.max(mWidthMils, mHeightMils),
Svetoslava76233a2013-09-05 09:38:02 -0700999 Math.min(mWidthMils, mHeightMils),
1000 mLabelResId);
Svetoslav773f54d2013-09-03 14:01:43 -07001001 }
1002
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001003 void writeToParcel(Parcel parcel) {
1004 parcel.writeString(mId);
Svetoslav Ganov798bed62013-08-11 12:29:39 -07001005 parcel.writeString(mLabel);
Svetoslav773f54d2013-09-03 14:01:43 -07001006 parcel.writeString(mPackageName);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001007 parcel.writeInt(mWidthMils);
1008 parcel.writeInt(mHeightMils);
Svetoslav773f54d2013-09-03 14:01:43 -07001009 parcel.writeInt(mLabelResId);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001010 }
1011
1012 static MediaSize createFromParcel(Parcel parcel) {
1013 return new MediaSize(
1014 parcel.readString(),
Svetoslav Ganov798bed62013-08-11 12:29:39 -07001015 parcel.readString(),
Svetoslav773f54d2013-09-03 14:01:43 -07001016 parcel.readString(),
1017 parcel.readInt(),
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001018 parcel.readInt(),
1019 parcel.readInt());
1020 }
1021
1022 @Override
Svetoslav Ganov85b1f882013-07-24 17:00:06 -07001023 public int hashCode() {
1024 final int prime = 31;
1025 int result = 1;
Svetoslav Ganov85b1f882013-07-24 17:00:06 -07001026 result = prime * result + mWidthMils;
1027 result = prime * result + mHeightMils;
1028 return result;
1029 }
1030
1031 @Override
1032 public boolean equals(Object obj) {
1033 if (this == obj) {
1034 return true;
1035 }
1036 if (obj == null) {
1037 return false;
1038 }
1039 if (getClass() != obj.getClass()) {
1040 return false;
1041 }
1042 MediaSize other = (MediaSize) obj;
Svetoslav Ganov85b1f882013-07-24 17:00:06 -07001043 if (mWidthMils != other.mWidthMils) {
1044 return false;
1045 }
1046 if (mHeightMils != other.mHeightMils) {
1047 return false;
1048 }
1049 return true;
1050 }
1051
1052 @Override
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001053 public String toString() {
1054 StringBuilder builder = new StringBuilder();
1055 builder.append("MediaSize{");
1056 builder.append("id: ").append(mId);
Svetoslav17b7f6e2013-06-24 18:29:33 -07001057 builder.append(", label: ").append(mLabel);
Svetoslav773f54d2013-09-03 14:01:43 -07001058 builder.append(", packageName: ").append(mPackageName);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001059 builder.append(", heightMils: ").append(mHeightMils);
1060 builder.append(", widthMils: ").append(mWidthMils);
Svetoslav773f54d2013-09-03 14:01:43 -07001061 builder.append(", labelResId: ").append(mLabelResId);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001062 builder.append("}");
1063 return builder.toString();
1064 }
Svetoslav Ganov7be27ac2013-09-30 09:04:50 -07001065
1066 /**
1067 * Gets a standard media size given its id.
1068 *
1069 * @param id The media size id.
1070 * @return The media size for the given id or null.
1071 *
1072 * @hide
1073 */
1074 public static MediaSize getStandardMediaSizeById(String id) {
1075 return sIdToMediaSizeMap.get(id);
1076 }
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001077 }
1078
1079 /**
Svetoslav Ganov22cb9172013-08-29 17:42:07 -07001080 * This class specifies a supported resolution in DPI (dots per inch).
1081 * Resolution defines how many points with different color can be placed
1082 * on one inch in horizontal or vertical direction of the target media.
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -07001083 * For example, a printer with 600 DPI can produce higher quality images
1084 * the one with 300 DPI resolution.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001085 */
1086 public static final class Resolution {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001087 private final String mId;
Svetoslav651dd4e2013-09-12 14:37:47 -07001088 private final String mLabel;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001089 private final int mHorizontalDpi;
1090 private final int mVerticalDpi;
1091
1092 /**
Svetoslava76233a2013-09-05 09:38:02 -07001093 * Creates a new instance.
Svetoslav17b7f6e2013-06-24 18:29:33 -07001094 *
Svetoslav Ganov22cb9172013-08-29 17:42:07 -07001095 * @param id The unique resolution id. It is unique amongst other resolutions
1096 * supported by the printer.
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -07001097 * @param label The <strong>localized</strong> human readable label.
Svetoslav Ganov22cb9172013-08-29 17:42:07 -07001098 * @param horizontalDpi The horizontal resolution in DPI (dots per inch).
1099 * @param verticalDpi The vertical resolution in DPI (dots per inch).
Svetoslav17b7f6e2013-06-24 18:29:33 -07001100 *
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -07001101 * @throws IllegalArgumentException If the id is empty or the label is empty
1102 * or the horizontalDpi is less than or equal to zero or the verticalDpi is
1103 * less than or equal to zero.
Svetoslav17b7f6e2013-06-24 18:29:33 -07001104 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001105 public Resolution(@NonNull String id, @NonNull String label,
1106 @IntRange(from = 1) int horizontalDpi, @IntRange(from = 1) int verticalDpi) {
Svetoslav17b7f6e2013-06-24 18:29:33 -07001107 if (TextUtils.isEmpty(id)) {
1108 throw new IllegalArgumentException("id cannot be empty.");
1109 }
1110 if (TextUtils.isEmpty(label)) {
1111 throw new IllegalArgumentException("label cannot be empty.");
1112 }
1113 if (horizontalDpi <= 0) {
1114 throw new IllegalArgumentException("horizontalDpi "
1115 + "cannot be less than or equal to zero.");
1116 }
1117 if (verticalDpi <= 0) {
1118 throw new IllegalArgumentException("verticalDpi"
1119 + " cannot be less than or equal to zero.");
1120 }
1121 mId = id;
1122 mLabel = label;
1123 mHorizontalDpi = horizontalDpi;
1124 mVerticalDpi = verticalDpi;
1125 }
1126
1127 /**
Svetoslav Ganov22cb9172013-08-29 17:42:07 -07001128 * Gets the unique resolution id. It is unique amongst other resolutions
1129 * supported by the printer.
1130 * <p>
1131 * This id is defined by the client that generated the resolution
1132 * instance and should not be interpreted by other parties.
1133 * </p>
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001134 *
1135 * @return The unique resolution id.
1136 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001137 public @NonNull String getId() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001138 return mId;
1139 }
1140
1141 /**
1142 * Gets the resolution human readable label.
1143 *
1144 * @return The human readable label.
1145 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001146 public @NonNull String getLabel() {
Svetoslav17b7f6e2013-06-24 18:29:33 -07001147 return mLabel;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001148 }
1149
1150 /**
Svetoslav Ganov22cb9172013-08-29 17:42:07 -07001151 * Gets the horizontal resolution in DPI (dots per inch).
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001152 *
1153 * @return The horizontal resolution.
1154 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001155 public @IntRange(from = 1) int getHorizontalDpi() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001156 return mHorizontalDpi;
1157 }
1158
1159 /**
Svetoslav Ganov22cb9172013-08-29 17:42:07 -07001160 * Gets the vertical resolution in DPI (dots per inch).
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001161 *
1162 * @return The vertical resolution.
1163 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001164 public @IntRange(from = 1) int getVerticalDpi() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001165 return mVerticalDpi;
1166 }
1167
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001168 void writeToParcel(Parcel parcel) {
1169 parcel.writeString(mId);
Svetoslav Ganov798bed62013-08-11 12:29:39 -07001170 parcel.writeString(mLabel);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001171 parcel.writeInt(mHorizontalDpi);
1172 parcel.writeInt(mVerticalDpi);
1173 }
1174
1175 static Resolution createFromParcel(Parcel parcel) {
1176 return new Resolution(
1177 parcel.readString(),
Svetoslav Ganov798bed62013-08-11 12:29:39 -07001178 parcel.readString(),
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001179 parcel.readInt(),
1180 parcel.readInt());
1181 }
1182
1183 @Override
Svetoslav Ganov85b1f882013-07-24 17:00:06 -07001184 public int hashCode() {
1185 final int prime = 31;
1186 int result = 1;
Svetoslav Ganov85b1f882013-07-24 17:00:06 -07001187 result = prime * result + mHorizontalDpi;
1188 result = prime * result + mVerticalDpi;
1189 return result;
1190 }
1191
1192 @Override
1193 public boolean equals(Object obj) {
1194 if (this == obj) {
1195 return true;
1196 }
1197 if (obj == null) {
1198 return false;
1199 }
1200 if (getClass() != obj.getClass()) {
1201 return false;
1202 }
1203 Resolution other = (Resolution) obj;
Svetoslav Ganov85b1f882013-07-24 17:00:06 -07001204 if (mHorizontalDpi != other.mHorizontalDpi) {
1205 return false;
1206 }
1207 if (mVerticalDpi != other.mVerticalDpi) {
1208 return false;
1209 }
1210 return true;
1211 }
1212
1213 @Override
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001214 public String toString() {
1215 StringBuilder builder = new StringBuilder();
1216 builder.append("Resolution{");
1217 builder.append("id: ").append(mId);
Svetoslav17b7f6e2013-06-24 18:29:33 -07001218 builder.append(", label: ").append(mLabel);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001219 builder.append(", horizontalDpi: ").append(mHorizontalDpi);
1220 builder.append(", verticalDpi: ").append(mVerticalDpi);
1221 builder.append("}");
1222 return builder.toString();
1223 }
1224 }
1225
1226 /**
Svetoslav Ganov22cb9172013-08-29 17:42:07 -07001227 * This class specifies content margins. Margins define the white space
1228 * around the content where the left margin defines the amount of white
1229 * space on the left of the content and so on.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001230 */
1231 public static final class Margins {
Svetoslav Ganovaec14172013-08-27 00:30:54 -07001232 public static final Margins NO_MARGINS = new Margins(0, 0, 0, 0);
1233
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001234 private final int mLeftMils;
1235 private final int mTopMils;
1236 private final int mRightMils;
1237 private final int mBottomMils;
1238
1239 /**
Svetoslav17b7f6e2013-06-24 18:29:33 -07001240 * Creates a new instance.
1241 *
1242 * @param leftMils The left margin in mils (thousands of an inch).
1243 * @param topMils The top margin in mils (thousands of an inch).
1244 * @param rightMils The right margin in mils (thousands of an inch).
1245 * @param bottomMils The bottom margin in mils (thousands of an inch).
Svetoslav17b7f6e2013-06-24 18:29:33 -07001246 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001247 public Margins(@IntRange(from = 0) int leftMils, @IntRange(from = 0) int topMils,
1248 @IntRange(from = 0) int rightMils, @IntRange(from = 0) int bottomMils) {
Svetoslav17b7f6e2013-06-24 18:29:33 -07001249 mTopMils = topMils;
1250 mLeftMils = leftMils;
1251 mRightMils = rightMils;
1252 mBottomMils = bottomMils;
1253 }
1254
1255 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001256 * Gets the left margin in mils (thousands of an inch).
1257 *
1258 * @return The left margin.
1259 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001260 public @IntRange(from = 0) int getLeftMils() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001261 return mLeftMils;
1262 }
1263
1264 /**
1265 * Gets the top margin in mils (thousands of an inch).
1266 *
1267 * @return The top margin.
1268 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001269 public @IntRange(from = 0) int getTopMils() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001270 return mTopMils;
1271 }
1272
1273 /**
1274 * Gets the right margin in mils (thousands of an inch).
1275 *
1276 * @return The right margin.
1277 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001278 public @IntRange(from = 0) int getRightMils() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001279 return mRightMils;
1280 }
1281
1282 /**
1283 * Gets the bottom margin in mils (thousands of an inch).
1284 *
1285 * @return The bottom margin.
1286 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001287 public @IntRange(from = 0) int getBottomMils() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001288 return mBottomMils;
1289 }
1290
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001291 void writeToParcel(Parcel parcel) {
1292 parcel.writeInt(mLeftMils);
1293 parcel.writeInt(mTopMils);
1294 parcel.writeInt(mRightMils);
1295 parcel.writeInt(mBottomMils);
1296 }
1297
1298 static Margins createFromParcel(Parcel parcel) {
1299 return new Margins(
1300 parcel.readInt(),
1301 parcel.readInt(),
1302 parcel.readInt(),
1303 parcel.readInt());
1304 }
1305
1306 @Override
Svetoslav Ganov85b1f882013-07-24 17:00:06 -07001307 public int hashCode() {
1308 final int prime = 31;
1309 int result = 1;
1310 result = prime * result + mBottomMils;
1311 result = prime * result + mLeftMils;
1312 result = prime * result + mRightMils;
1313 result = prime * result + mTopMils;
1314 return result;
1315 }
1316
1317 @Override
1318 public boolean equals(Object obj) {
1319 if (this == obj) {
1320 return true;
1321 }
1322 if (obj == null) {
1323 return false;
1324 }
1325 if (getClass() != obj.getClass()) {
1326 return false;
1327 }
1328 Margins other = (Margins) obj;
1329 if (mBottomMils != other.mBottomMils) {
1330 return false;
1331 }
1332 if (mLeftMils != other.mLeftMils) {
1333 return false;
1334 }
1335 if (mRightMils != other.mRightMils) {
1336 return false;
1337 }
1338 if (mTopMils != other.mTopMils) {
1339 return false;
1340 }
1341 return true;
1342 }
1343
1344 @Override
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001345 public String toString() {
1346 StringBuilder builder = new StringBuilder();
1347 builder.append("Margins{");
1348 builder.append("leftMils: ").append(mLeftMils);
1349 builder.append(", topMils: ").append(mTopMils);
1350 builder.append(", rightMils: ").append(mRightMils);
1351 builder.append(", bottomMils: ").append(mBottomMils);
1352 builder.append("}");
1353 return builder.toString();
1354 }
1355 }
1356
Svetoslav Ganov798bed62013-08-11 12:29:39 -07001357 static String colorModeToString(int colorMode) {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001358 switch (colorMode) {
1359 case COLOR_MODE_MONOCHROME: {
1360 return "COLOR_MODE_MONOCHROME";
1361 }
1362 case COLOR_MODE_COLOR: {
1363 return "COLOR_MODE_COLOR";
1364 }
Svetoslav948c9a62015-02-02 19:47:04 -08001365 default: {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001366 return "COLOR_MODE_UNKNOWN";
Svetoslav948c9a62015-02-02 19:47:04 -08001367 }
1368 }
1369 }
1370
1371 static String duplexModeToString(int duplexMode) {
1372 switch (duplexMode) {
1373 case DUPLEX_MODE_NONE: {
1374 return "DUPLEX_MODE_NONE";
1375 }
1376 case DUPLEX_MODE_LONG_EDGE: {
1377 return "DUPLEX_MODE_LONG_EDGE";
1378 }
1379 case DUPLEX_MODE_SHORT_EDGE: {
1380 return "DUPLEX_MODE_SHORT_EDGE";
1381 }
1382 default: {
1383 return "DUPLEX_MODE_UNKNOWN";
1384 }
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001385 }
1386 }
1387
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001388 static void enforceValidColorMode(int colorMode) {
Svetoslav948c9a62015-02-02 19:47:04 -08001389 if ((colorMode & VALID_COLOR_MODES) == 0 || Integer.bitCount(colorMode) != 1) {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001390 throw new IllegalArgumentException("invalid color mode: " + colorMode);
1391 }
1392 }
1393
Svetoslav948c9a62015-02-02 19:47:04 -08001394 static void enforceValidDuplexMode(int duplexMode) {
1395 if ((duplexMode & VALID_DUPLEX_MODES) == 0 || Integer.bitCount(duplexMode) != 1) {
1396 throw new IllegalArgumentException("invalid duplex mode: " + duplexMode);
1397 }
1398 }
1399
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001400 /**
1401 * Builder for creating {@link PrintAttributes}.
1402 */
1403 public static final class Builder {
1404 private final PrintAttributes mAttributes = new PrintAttributes();
1405
1406 /**
1407 * Sets the media size.
1408 *
1409 * @param mediaSize The media size.
1410 * @return This builder.
1411 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001412 public @NonNull Builder setMediaSize(@NonNull MediaSize mediaSize) {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001413 mAttributes.setMediaSize(mediaSize);
1414 return this;
1415 }
1416
1417 /**
1418 * Sets the resolution.
1419 *
1420 * @param resolution The resolution.
1421 * @return This builder.
1422 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001423 public @NonNull Builder setResolution(@NonNull Resolution resolution) {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001424 mAttributes.setResolution(resolution);
1425 return this;
1426 }
1427
1428 /**
Svetoslav651dd4e2013-09-12 14:37:47 -07001429 * Sets the minimal margins. If the content does not fit
1430 * these margins it will be clipped.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001431 *
1432 * @param margins The margins.
1433 * @return This builder.
1434 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001435 public @NonNull Builder setMinMargins(@NonNull Margins margins) {
Svetoslav651dd4e2013-09-12 14:37:47 -07001436 mAttributes.setMinMargins(margins);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001437 return this;
1438 }
1439
1440 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001441 * Sets the color mode.
1442 *
1443 * @param colorMode A valid color mode or zero.
1444 * @return This builder.
1445 *
1446 * @see PrintAttributes#COLOR_MODE_MONOCHROME
1447 * @see PrintAttributes#COLOR_MODE_COLOR
1448 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001449 public @NonNull Builder setColorMode(@ColorMode int colorMode) {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001450 mAttributes.setColorMode(colorMode);
1451 return this;
1452 }
1453
1454 /**
Svetoslav948c9a62015-02-02 19:47:04 -08001455 * Sets the duplex mode.
1456 *
1457 * @param duplexMode A valid duplex mode or zero.
1458 * @return This builder.
1459 *
1460 * @see PrintAttributes#DUPLEX_MODE_NONE
1461 * @see PrintAttributes#DUPLEX_MODE_LONG_EDGE
1462 * @see PrintAttributes#DUPLEX_MODE_SHORT_EDGE
1463 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001464 public @NonNull Builder setDuplexMode(@DuplexMode int duplexMode) {
Svetoslav948c9a62015-02-02 19:47:04 -08001465 mAttributes.setDuplexMode(duplexMode);
1466 return this;
1467 }
1468
1469 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001470 * Creates a new {@link PrintAttributes} instance.
1471 *
1472 * @return The new instance.
1473 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001474 public @NonNull PrintAttributes build() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001475 return mAttributes;
1476 }
1477 }
1478
1479 public static final Parcelable.Creator<PrintAttributes> CREATOR =
1480 new Creator<PrintAttributes>() {
1481 @Override
1482 public PrintAttributes createFromParcel(Parcel parcel) {
1483 return new PrintAttributes(parcel);
1484 }
1485
1486 @Override
1487 public PrintAttributes[] newArray(int size) {
1488 return new PrintAttributes[size];
1489 }
1490 };
1491}