blob: ce5b11ee33f106a0048461634f1856bd53069eac [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;
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -070023import android.annotation.StringRes;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070024import android.content.pm.PackageManager;
25import android.content.pm.PackageManager.NameNotFoundException;
Svetoslav773f54d2013-09-03 14:01:43 -070026import android.content.res.Resources.NotFoundException;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070027import android.os.Parcel;
28import android.os.Parcelable;
Philip P. Moltmannc0a128d2017-06-19 10:55:09 -070029import android.service.print.PrintAttributesProto;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070030import android.text.TextUtils;
Svetoslav Ganov7be27ac2013-09-30 09:04:50 -070031import android.util.ArrayMap;
Philip P. Moltmann4959caf2016-01-21 14:30:56 -080032import android.util.ArraySet;
Svetoslav773f54d2013-09-03 14:01:43 -070033import android.util.Log;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070034
35import com.android.internal.R;
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -070036import com.android.internal.util.Preconditions;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070037
Philip P. Moltmannc43639c2015-12-18 13:58:40 -080038import java.lang.annotation.Retention;
39import java.lang.annotation.RetentionPolicy;
Svetoslav Ganov7be27ac2013-09-30 09:04:50 -070040import java.util.Map;
41
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070042/**
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -070043 * 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 Ganov4b9a4d12013-06-11 15:20:06 -070048 */
49public final class PrintAttributes implements Parcelable {
Philip P. Moltmannc43639c2015-12-18 13:58:40 -080050 /** @hide */
51 @Retention(RetentionPolicy.SOURCE)
52 @IntDef(flag = true, value = {
53 COLOR_MODE_MONOCHROME, COLOR_MODE_COLOR
54 })
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -070055 @interface ColorMode {
Philip P. Moltmannc43639c2015-12-18 13:58:40 -080056 }
Svetoslav Ganov22cb9172013-08-29 17:42:07 -070057 /** Color mode: Monochrome color scheme, for example one color is used. */
Philip P. Moltmannc0a128d2017-06-19 10:55:09 -070058 public static final int COLOR_MODE_MONOCHROME = PrintAttributesProto.COLOR_MODE_MONOCHROME;
Svetoslav Ganov22cb9172013-08-29 17:42:07 -070059 /** Color mode: Color color scheme, for example many colors are used. */
Philip P. Moltmannc0a128d2017-06-19 10:55:09 -070060 public static final int COLOR_MODE_COLOR = PrintAttributesProto.COLOR_MODE_COLOR;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070061
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070062 private static final int VALID_COLOR_MODES =
63 COLOR_MODE_MONOCHROME | COLOR_MODE_COLOR;
64
Philip P. Moltmannc43639c2015-12-18 13:58:40 -080065 /** @hide */
66 @Retention(RetentionPolicy.SOURCE)
67 @IntDef(flag = true, value = {
68 DUPLEX_MODE_NONE, DUPLEX_MODE_LONG_EDGE, DUPLEX_MODE_SHORT_EDGE
69 })
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -070070 @interface DuplexMode {
Philip P. Moltmannc43639c2015-12-18 13:58:40 -080071 }
Svetoslav948c9a62015-02-02 19:47:04 -080072 /** Duplex mode: No duplexing. */
Philip P. Moltmannc0a128d2017-06-19 10:55:09 -070073 public static final int DUPLEX_MODE_NONE = PrintAttributesProto.DUPLEX_MODE_NONE;
Svetoslav948c9a62015-02-02 19:47:04 -080074 /** Duplex mode: Pages are turned sideways along the long edge - like a book. */
Philip P. Moltmannc0a128d2017-06-19 10:55:09 -070075 public static final int DUPLEX_MODE_LONG_EDGE = PrintAttributesProto.DUPLEX_MODE_LONG_EDGE;
Svetoslav948c9a62015-02-02 19:47:04 -080076 /** Duplex mode: Pages are turned upwards along the short edge - like a notpad. */
Philip P. Moltmannc0a128d2017-06-19 10:55:09 -070077 public static final int DUPLEX_MODE_SHORT_EDGE = PrintAttributesProto.DUPLEX_MODE_SHORT_EDGE;
Svetoslav948c9a62015-02-02 19:47:04 -080078
79 private static final int VALID_DUPLEX_MODES =
80 DUPLEX_MODE_NONE | DUPLEX_MODE_LONG_EDGE | DUPLEX_MODE_SHORT_EDGE;
81
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -070082 private @Nullable MediaSize mMediaSize;
83 private @Nullable Resolution mResolution;
84 private @Nullable Margins mMinMargins;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070085
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -070086 private @IntRange(from = 0) int mColorMode;
87 private @IntRange(from = 0) int mDuplexMode;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070088
89 PrintAttributes() {
90 /* hide constructor */
91 }
92
Philip P. Moltmannc43639c2015-12-18 13:58:40 -080093 private PrintAttributes(@NonNull Parcel parcel) {
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -070094 mMediaSize = (parcel.readInt() == 1) ? MediaSize.createFromParcel(parcel) : null;
95 mResolution = (parcel.readInt() == 1) ? Resolution.createFromParcel(parcel) : null;
96 mMinMargins = (parcel.readInt() == 1) ? Margins.createFromParcel(parcel) : null;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -070097 mColorMode = parcel.readInt();
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -070098 if (mColorMode != 0) {
99 enforceValidColorMode(mColorMode);
100 }
Svetoslav948c9a62015-02-02 19:47:04 -0800101 mDuplexMode = parcel.readInt();
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700102 if (mDuplexMode != 0) {
103 enforceValidDuplexMode(mDuplexMode);
104 }
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700105 }
106
107 /**
108 * Gets the media size.
109 *
110 * @return The media size or <code>null</code> if not set.
111 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800112 public @Nullable MediaSize getMediaSize() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700113 return mMediaSize;
114 }
115
116 /**
117 * Sets the media size.
118 *
Svetoslav948c9a62015-02-02 19:47:04 -0800119 * @param mediaSize The media size.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700120 *
121 * @hide
122 */
123 public void setMediaSize(MediaSize mediaSize) {
124 mMediaSize = mediaSize;
125 }
126
127 /**
128 * Gets the resolution.
129 *
130 * @return The resolution or <code>null</code> if not set.
131 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800132 public @Nullable Resolution getResolution() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700133 return mResolution;
134 }
135
136 /**
137 * Sets the resolution.
138 *
Svetoslav948c9a62015-02-02 19:47:04 -0800139 * @param resolution The resolution.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700140 *
141 * @hide
142 */
143 public void setResolution(Resolution resolution) {
144 mResolution = resolution;
145 }
146
147 /**
Svetoslav651dd4e2013-09-12 14:37:47 -0700148 * Gets the minimal margins. If the content does not fit
149 * these margins it will be clipped.
Svet Ganov525a66b2014-06-14 22:29:00 -0700150 * <p>
151 * <strong>These margins are physically imposed by the printer and they
152 * are <em>not</em> rotated, i.e. they are the same for both portrait and
153 * landscape. For example, a printer may not be able to print in a stripe
154 * on both left and right sides of the page.
155 * </strong>
156 * </p>
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700157 *
158 * @return The margins or <code>null</code> if not set.
159 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800160 public @Nullable Margins getMinMargins() {
Svetoslav651dd4e2013-09-12 14:37:47 -0700161 return mMinMargins;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700162 }
163
164 /**
Svetoslav651dd4e2013-09-12 14:37:47 -0700165 * Sets the minimal margins. If the content does not fit
166 * these margins it will be clipped.
Svet Ganov525a66b2014-06-14 22:29:00 -0700167 * <p>
168 * <strong>These margins are physically imposed by the printer and they
169 * are <em>not</em> rotated, i.e. they are the same for both portrait and
170 * landscape. For example, a printer may not be able to print in a stripe
171 * on both left and right sides of the page.
172 * </strong>
173 * </p>
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700174 *
Svetoslav948c9a62015-02-02 19:47:04 -0800175 * @param margins The margins.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700176 *
177 * @hide
178 */
Svetoslav651dd4e2013-09-12 14:37:47 -0700179 public void setMinMargins(Margins margins) {
180 mMinMargins = margins;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700181 }
182
183 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700184 * Gets the color mode.
185 *
186 * @return The color mode or zero if not set.
187 *
188 * @see #COLOR_MODE_COLOR
189 * @see #COLOR_MODE_MONOCHROME
190 */
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700191 public @IntRange(from = 0) int getColorMode() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700192 return mColorMode;
193 }
194
195 /**
196 * Sets the color mode.
197 *
Svetoslav948c9a62015-02-02 19:47:04 -0800198 * @param colorMode The color mode.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700199 *
200 * @see #COLOR_MODE_MONOCHROME
201 * @see #COLOR_MODE_COLOR
202 *
203 * @hide
204 */
205 public void setColorMode(int colorMode) {
206 enforceValidColorMode(colorMode);
207 mColorMode = colorMode;
208 }
209
Svetoslava798c0a2014-05-15 10:47:19 -0700210 /**
211 * Gets whether this print attributes are in portrait orientation,
212 * which is the media size is in portrait and all orientation dependent
213 * attributes such as resolution and margins are properly adjusted.
214 *
215 * @return Whether this print attributes are in portrait.
216 *
217 * @hide
218 */
219 public boolean isPortrait() {
220 return mMediaSize.isPortrait();
221 }
222
223 /**
Svetoslav948c9a62015-02-02 19:47:04 -0800224 * Gets the duplex mode.
225 *
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700226 * @return The duplex mode or zero if not set.
Svetoslav948c9a62015-02-02 19:47:04 -0800227 *
228 * @see #DUPLEX_MODE_NONE
229 * @see #DUPLEX_MODE_LONG_EDGE
230 * @see #DUPLEX_MODE_SHORT_EDGE
231 */
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700232 public @IntRange(from = 0) int getDuplexMode() {
Svetoslav948c9a62015-02-02 19:47:04 -0800233 return mDuplexMode;
234 }
235
236 /**
237 * Sets the duplex mode.
238 *
239 * @param duplexMode The duplex mode.
240 *
241 * @see #DUPLEX_MODE_NONE
242 * @see #DUPLEX_MODE_LONG_EDGE
243 * @see #DUPLEX_MODE_SHORT_EDGE
244 *
245 * @hide
246 */
247 public void setDuplexMode(int duplexMode) {
248 enforceValidDuplexMode(duplexMode);
249 mDuplexMode = duplexMode;
250 }
251
252 /**
Svetoslava798c0a2014-05-15 10:47:19 -0700253 * Gets a new print attributes instance which is in portrait orientation,
254 * which is the media size is in portrait and all orientation dependent
255 * attributes such as resolution and margins are properly adjusted.
256 *
257 * @return New instance in portrait orientation if this one is in
258 * landscape, otherwise this instance.
259 *
260 * @hide
261 */
262 public PrintAttributes asPortrait() {
263 if (isPortrait()) {
264 return this;
265 }
266
267 PrintAttributes attributes = new PrintAttributes();
268
269 // Rotate the media size.
270 attributes.setMediaSize(getMediaSize().asPortrait());
271
272 // Rotate the resolution.
273 Resolution oldResolution = getResolution();
274 Resolution newResolution = new Resolution(
275 oldResolution.getId(),
276 oldResolution.getLabel(),
277 oldResolution.getVerticalDpi(),
278 oldResolution.getHorizontalDpi());
279 attributes.setResolution(newResolution);
280
Svet Ganov525a66b2014-06-14 22:29:00 -0700281 // Do not rotate the physical margins.
282 attributes.setMinMargins(getMinMargins());
Svetoslava798c0a2014-05-15 10:47:19 -0700283
284 attributes.setColorMode(getColorMode());
Svetoslav948c9a62015-02-02 19:47:04 -0800285 attributes.setDuplexMode(getDuplexMode());
Svetoslava798c0a2014-05-15 10:47:19 -0700286
287 return attributes;
288 }
289
290 /**
291 * Gets a new print attributes instance which is in landscape orientation,
292 * which is the media size is in landscape and all orientation dependent
293 * attributes such as resolution and margins are properly adjusted.
294 *
295 * @return New instance in landscape orientation if this one is in
296 * portrait, otherwise this instance.
297 *
298 * @hide
299 */
300 public PrintAttributes asLandscape() {
301 if (!isPortrait()) {
302 return this;
303 }
304
305 PrintAttributes attributes = new PrintAttributes();
306
307 // Rotate the media size.
308 attributes.setMediaSize(getMediaSize().asLandscape());
309
310 // Rotate the resolution.
311 Resolution oldResolution = getResolution();
312 Resolution newResolution = new Resolution(
313 oldResolution.getId(),
314 oldResolution.getLabel(),
315 oldResolution.getVerticalDpi(),
316 oldResolution.getHorizontalDpi());
317 attributes.setResolution(newResolution);
318
Svet Ganov525a66b2014-06-14 22:29:00 -0700319 // Do not rotate the physical margins.
320 attributes.setMinMargins(getMinMargins());
Svetoslava798c0a2014-05-15 10:47:19 -0700321
322 attributes.setColorMode(getColorMode());
Svetoslav948c9a62015-02-02 19:47:04 -0800323 attributes.setDuplexMode(getDuplexMode());
Svetoslava798c0a2014-05-15 10:47:19 -0700324
325 return attributes;
326 }
327
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700328 @Override
329 public void writeToParcel(Parcel parcel, int flags) {
330 if (mMediaSize != null) {
331 parcel.writeInt(1);
332 mMediaSize.writeToParcel(parcel);
333 } else {
334 parcel.writeInt(0);
335 }
336 if (mResolution != null) {
337 parcel.writeInt(1);
338 mResolution.writeToParcel(parcel);
339 } else {
340 parcel.writeInt(0);
341 }
Svetoslav651dd4e2013-09-12 14:37:47 -0700342 if (mMinMargins != null) {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700343 parcel.writeInt(1);
Svetoslav651dd4e2013-09-12 14:37:47 -0700344 mMinMargins.writeToParcel(parcel);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700345 } else {
346 parcel.writeInt(0);
347 }
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700348 parcel.writeInt(mColorMode);
Svetoslav948c9a62015-02-02 19:47:04 -0800349 parcel.writeInt(mDuplexMode);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700350 }
351
352 @Override
353 public int describeContents() {
354 return 0;
355 }
356
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700357 @Override
358 public int hashCode() {
359 final int prime = 31;
360 int result = 1;
361 result = prime * result + mColorMode;
Svetoslav948c9a62015-02-02 19:47:04 -0800362 result = prime * result + mDuplexMode;
Svetoslav651dd4e2013-09-12 14:37:47 -0700363 result = prime * result + ((mMinMargins == null) ? 0 : mMinMargins.hashCode());
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700364 result = prime * result + ((mMediaSize == null) ? 0 : mMediaSize.hashCode());
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700365 result = prime * result + ((mResolution == null) ? 0 : mResolution.hashCode());
366 return result;
367 }
368
369 @Override
370 public boolean equals(Object obj) {
371 if (this == obj) {
372 return true;
373 }
374 if (obj == null) {
375 return false;
376 }
377 if (getClass() != obj.getClass()) {
378 return false;
379 }
380 PrintAttributes other = (PrintAttributes) obj;
381 if (mColorMode != other.mColorMode) {
382 return false;
383 }
Svetoslav948c9a62015-02-02 19:47:04 -0800384 if (mDuplexMode != other.mDuplexMode) {
385 return false;
386 }
Svetoslav651dd4e2013-09-12 14:37:47 -0700387 if (mMinMargins == null) {
388 if (other.mMinMargins != null) {
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700389 return false;
390 }
Svetoslav651dd4e2013-09-12 14:37:47 -0700391 } else if (!mMinMargins.equals(other.mMinMargins)) {
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700392 return false;
393 }
394 if (mMediaSize == null) {
395 if (other.mMediaSize != null) {
396 return false;
397 }
398 } else if (!mMediaSize.equals(other.mMediaSize)) {
399 return false;
400 }
401 if (mResolution == null) {
402 if (other.mResolution != null) {
403 return false;
404 }
405 } else if (!mResolution.equals(other.mResolution)) {
406 return false;
407 }
408 return true;
409 }
410
411 @Override
412 public String toString() {
413 StringBuilder builder = new StringBuilder();
414 builder.append("PrintAttributes{");
415 builder.append("mediaSize: ").append(mMediaSize);
Svetoslavcc65b0c2013-09-10 21:08:32 -0700416 if (mMediaSize != null) {
417 builder.append(", orientation: ").append(mMediaSize.isPortrait()
418 ? "portrait" : "landscape");
419 } else {
420 builder.append(", orientation: ").append("null");
421 }
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700422 builder.append(", resolution: ").append(mResolution);
Svetoslav651dd4e2013-09-12 14:37:47 -0700423 builder.append(", minMargins: ").append(mMinMargins);
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700424 builder.append(", colorMode: ").append(colorModeToString(mColorMode));
Svetoslav948c9a62015-02-02 19:47:04 -0800425 builder.append(", duplexMode: ").append(duplexModeToString(mDuplexMode));
Svetoslav Ganov85b1f882013-07-24 17:00:06 -0700426 builder.append("}");
427 return builder.toString();
428 }
429
Svetoslav81d40142013-09-18 14:38:26 -0700430 /** @hide */
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700431 public void clear() {
432 mMediaSize = null;
433 mResolution = null;
Svetoslav651dd4e2013-09-12 14:37:47 -0700434 mMinMargins = null;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700435 mColorMode = 0;
Philip P. Moltmannb4efdb42015-11-10 14:58:44 -0800436 mDuplexMode = 0;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700437 }
438
439 /**
Svetoslav Ganov0d1daa52013-07-23 13:29:31 -0700440 * @hide
441 */
442 public void copyFrom(PrintAttributes other) {
443 mMediaSize = other.mMediaSize;
444 mResolution = other.mResolution;
Svetoslav651dd4e2013-09-12 14:37:47 -0700445 mMinMargins = other.mMinMargins;
Svetoslav Ganov0d1daa52013-07-23 13:29:31 -0700446 mColorMode = other.mColorMode;
Svetoslav948c9a62015-02-02 19:47:04 -0800447 mDuplexMode = other.mDuplexMode;
Svetoslav Ganov0d1daa52013-07-23 13:29:31 -0700448 }
449
450 /**
Svetoslav Ganov22cb9172013-08-29 17:42:07 -0700451 * This class specifies a supported media size. Media size is the
452 * dimension of the media on which the content is printed. For
453 * example, the {@link #NA_LETTER} media size designates a page
454 * with size 8.5" x 11".
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700455 */
456 public static final class MediaSize {
Svetoslav773f54d2013-09-03 14:01:43 -0700457 private static final String LOG_TAG = "MediaSize";
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700458
Svetoslav Ganov7be27ac2013-09-30 09:04:50 -0700459 private static final Map<String, MediaSize> sIdToMediaSizeMap =
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700460 new ArrayMap<>();
Svetoslav Ganov7be27ac2013-09-30 09:04:50 -0700461
Svetoslavd8f391b2013-09-20 16:25:52 -0700462 /**
463 * Unknown media size in portrait mode.
464 * <p>
465 * <strong>Note: </strong>This is for specifying orientation without media
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700466 * size. You should not use the dimensions reported by this instance.
Svetoslavd8f391b2013-09-20 16:25:52 -0700467 * </p>
468 */
469 public static final MediaSize UNKNOWN_PORTRAIT =
470 new MediaSize("UNKNOWN_PORTRAIT", "android",
Svetoslav Ganovb2420c92013-10-06 19:44:14 -0700471 R.string.mediasize_unknown_portrait, 1, Integer.MAX_VALUE);
Svetoslavd8f391b2013-09-20 16:25:52 -0700472
473 /**
474 * Unknown media size in landscape mode.
475 * <p>
476 * <strong>Note: </strong>This is for specifying orientation without media
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700477 * size. You should not use the dimensions reported by this instance.
Svetoslavd8f391b2013-09-20 16:25:52 -0700478 * </p>
479 */
480 public static final MediaSize UNKNOWN_LANDSCAPE =
481 new MediaSize("UNKNOWN_LANDSCAPE", "android",
Svetoslav Ganovb2420c92013-10-06 19:44:14 -0700482 R.string.mediasize_unknown_landscape, Integer.MAX_VALUE, 1);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700483
484 // ISO sizes
485
Svetoslav773f54d2013-09-03 14:01:43 -0700486 /** ISO A0 media size: 841mm x 1189mm (33.11" x 46.81") */
487 public static final MediaSize ISO_A0 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700488 new MediaSize("ISO_A0", "android", R.string.mediasize_iso_a0, 33110, 46810);
Svetoslav773f54d2013-09-03 14:01:43 -0700489 /** ISO A1 media size: 594mm x 841mm (23.39" x 33.11") */
490 public static final MediaSize ISO_A1 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700491 new MediaSize("ISO_A1", "android", R.string.mediasize_iso_a1, 23390, 33110);
Svetoslav773f54d2013-09-03 14:01:43 -0700492 /** ISO A2 media size: 420mm x 594mm (16.54" x 23.39") */
493 public static final MediaSize ISO_A2 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700494 new MediaSize("ISO_A2", "android", R.string.mediasize_iso_a2, 16540, 23390);
Svetoslav773f54d2013-09-03 14:01:43 -0700495 /** ISO A3 media size: 297mm x 420mm (11.69" x 16.54") */
496 public static final MediaSize ISO_A3 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700497 new MediaSize("ISO_A3", "android", R.string.mediasize_iso_a3, 11690, 16540);
Svetoslav773f54d2013-09-03 14:01:43 -0700498 /** ISO A4 media size: 210mm x 297mm (8.27" x 11.69") */
499 public static final MediaSize ISO_A4 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700500 new MediaSize("ISO_A4", "android", R.string.mediasize_iso_a4, 8270, 11690);
Svetoslav773f54d2013-09-03 14:01:43 -0700501 /** ISO A5 media size: 148mm x 210mm (5.83" x 8.27") */
502 public static final MediaSize ISO_A5 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700503 new MediaSize("ISO_A5", "android", R.string.mediasize_iso_a5, 5830, 8270);
Svetoslav773f54d2013-09-03 14:01:43 -0700504 /** ISO A6 media size: 105mm x 148mm (4.13" x 5.83") */
505 public static final MediaSize ISO_A6 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700506 new MediaSize("ISO_A6", "android", R.string.mediasize_iso_a6, 4130, 5830);
Svetoslav773f54d2013-09-03 14:01:43 -0700507 /** ISO A7 media size: 74mm x 105mm (2.91" x 4.13") */
508 public static final MediaSize ISO_A7 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700509 new MediaSize("ISO_A7", "android", R.string.mediasize_iso_a7, 2910, 4130);
Svetoslav773f54d2013-09-03 14:01:43 -0700510 /** ISO A8 media size: 52mm x 74mm (2.05" x 2.91") */
511 public static final MediaSize ISO_A8 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700512 new MediaSize("ISO_A8", "android", R.string.mediasize_iso_a8, 2050, 2910);
Svetoslav773f54d2013-09-03 14:01:43 -0700513 /** ISO A9 media size: 37mm x 52mm (1.46" x 2.05") */
514 public static final MediaSize ISO_A9 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700515 new MediaSize("ISO_A9", "android", R.string.mediasize_iso_a9, 1460, 2050);
Svetoslav773f54d2013-09-03 14:01:43 -0700516 /** ISO A10 media size: 26mm x 37mm (1.02" x 1.46") */
517 public static final MediaSize ISO_A10 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700518 new MediaSize("ISO_A10", "android", R.string.mediasize_iso_a10, 1020, 1460);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700519
Svetoslav773f54d2013-09-03 14:01:43 -0700520 /** ISO B0 media size: 1000mm x 1414mm (39.37" x 55.67") */
521 public static final MediaSize ISO_B0 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700522 new MediaSize("ISO_B0", "android", R.string.mediasize_iso_b0, 39370, 55670);
Svetoslav773f54d2013-09-03 14:01:43 -0700523 /** ISO B1 media size: 707mm x 1000mm (27.83" x 39.37") */
524 public static final MediaSize ISO_B1 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700525 new MediaSize("ISO_B1", "android", R.string.mediasize_iso_b1, 27830, 39370);
Svetoslav773f54d2013-09-03 14:01:43 -0700526 /** ISO B2 media size: 500mm x 707mm (19.69" x 27.83") */
527 public static final MediaSize ISO_B2 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700528 new MediaSize("ISO_B2", "android", R.string.mediasize_iso_b2, 19690, 27830);
Svetoslav773f54d2013-09-03 14:01:43 -0700529 /** ISO B3 media size: 353mm x 500mm (13.90" x 19.69") */
530 public static final MediaSize ISO_B3 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700531 new MediaSize("ISO_B3", "android", R.string.mediasize_iso_b3, 13900, 19690);
Svetoslav773f54d2013-09-03 14:01:43 -0700532 /** ISO B4 media size: 250mm x 353mm (9.84" x 13.90") */
533 public static final MediaSize ISO_B4 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700534 new MediaSize("ISO_B4", "android", R.string.mediasize_iso_b4, 9840, 13900);
Svetoslav773f54d2013-09-03 14:01:43 -0700535 /** ISO B5 media size: 176mm x 250mm (6.93" x 9.84") */
536 public static final MediaSize ISO_B5 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700537 new MediaSize("ISO_B5", "android", R.string.mediasize_iso_b5, 6930, 9840);
Svetoslav773f54d2013-09-03 14:01:43 -0700538 /** ISO B6 media size: 125mm x 176mm (4.92" x 6.93") */
539 public static final MediaSize ISO_B6 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700540 new MediaSize("ISO_B6", "android", R.string.mediasize_iso_b6, 4920, 6930);
Svetoslav773f54d2013-09-03 14:01:43 -0700541 /** ISO B7 media size: 88mm x 125mm (3.46" x 4.92") */
542 public static final MediaSize ISO_B7 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700543 new MediaSize("ISO_B7", "android", R.string.mediasize_iso_b7, 3460, 4920);
Svetoslav773f54d2013-09-03 14:01:43 -0700544 /** ISO B8 media size: 62mm x 88mm (2.44" x 3.46") */
545 public static final MediaSize ISO_B8 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700546 new MediaSize("ISO_B8", "android", R.string.mediasize_iso_b8, 2440, 3460);
Svetoslav773f54d2013-09-03 14:01:43 -0700547 /** ISO B9 media size: 44mm x 62mm (1.73" x 2.44") */
548 public static final MediaSize ISO_B9 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700549 new MediaSize("ISO_B9", "android", R.string.mediasize_iso_b9, 1730, 2440);
Svetoslav773f54d2013-09-03 14:01:43 -0700550 /** ISO B10 media size: 31mm x 44mm (1.22" x 1.73") */
551 public static final MediaSize ISO_B10 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700552 new MediaSize("ISO_B10", "android", R.string.mediasize_iso_b10, 1220, 1730);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700553
Svetoslav773f54d2013-09-03 14:01:43 -0700554 /** ISO C0 media size: 917mm x 1297mm (36.10" x 51.06") */
555 public static final MediaSize ISO_C0 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700556 new MediaSize("ISO_C0", "android", R.string.mediasize_iso_c0, 36100, 51060);
Svetoslav773f54d2013-09-03 14:01:43 -0700557 /** ISO C1 media size: 648mm x 917mm (25.51" x 36.10") */
558 public static final MediaSize ISO_C1 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700559 new MediaSize("ISO_C1", "android", R.string.mediasize_iso_c1, 25510, 36100);
Svetoslav773f54d2013-09-03 14:01:43 -0700560 /** ISO C2 media size: 458mm x 648mm (18.03" x 25.51") */
561 public static final MediaSize ISO_C2 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700562 new MediaSize("ISO_C2", "android", R.string.mediasize_iso_c2, 18030, 25510);
Svetoslav773f54d2013-09-03 14:01:43 -0700563 /** ISO C3 media size: 324mm x 458mm (12.76" x 18.03") */
564 public static final MediaSize ISO_C3 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700565 new MediaSize("ISO_C3", "android", R.string.mediasize_iso_c3, 12760, 18030);
Svetoslav773f54d2013-09-03 14:01:43 -0700566 /** ISO C4 media size: 229mm x 324mm (9.02" x 12.76") */
567 public static final MediaSize ISO_C4 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700568 new MediaSize("ISO_C4", "android", R.string.mediasize_iso_c4, 9020, 12760);
Svetoslav773f54d2013-09-03 14:01:43 -0700569 /** ISO C5 media size: 162mm x 229mm (6.38" x 9.02") */
570 public static final MediaSize ISO_C5 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700571 new MediaSize("ISO_C5", "android", R.string.mediasize_iso_c5, 6380, 9020);
Svetoslav773f54d2013-09-03 14:01:43 -0700572 /** ISO C6 media size: 114mm x 162mm (4.49" x 6.38") */
573 public static final MediaSize ISO_C6 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700574 new MediaSize("ISO_C6", "android", R.string.mediasize_iso_c6, 4490, 6380);
Svetoslav773f54d2013-09-03 14:01:43 -0700575 /** ISO C7 media size: 81mm x 114mm (3.19" x 4.49") */
576 public static final MediaSize ISO_C7 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700577 new MediaSize("ISO_C7", "android", R.string.mediasize_iso_c7, 3190, 4490);
Svetoslav773f54d2013-09-03 14:01:43 -0700578 /** ISO C8 media size: 57mm x 81mm (2.24" x 3.19") */
579 public static final MediaSize ISO_C8 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700580 new MediaSize("ISO_C8", "android", R.string.mediasize_iso_c8, 2240, 3190);
Svetoslav773f54d2013-09-03 14:01:43 -0700581 /** ISO C9 media size: 40mm x 57mm (1.57" x 2.24") */
582 public static final MediaSize ISO_C9 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700583 new MediaSize("ISO_C9", "android", R.string.mediasize_iso_c9, 1570, 2240);
Svetoslav773f54d2013-09-03 14:01:43 -0700584 /** ISO C10 media size: 28mm x 40mm (1.10" x 1.57") */
585 public static final MediaSize ISO_C10 =
Svetoslavd8f391b2013-09-20 16:25:52 -0700586 new MediaSize("ISO_C10", "android", R.string.mediasize_iso_c10, 1100, 1570);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700587
588 // North America
589
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700590 /** North America Letter media size: 8.5" x 11" (279mm x 216mm) */
Svetoslav773f54d2013-09-03 14:01:43 -0700591 public static final MediaSize NA_LETTER =
Svetoslavd8f391b2013-09-20 16:25:52 -0700592 new MediaSize("NA_LETTER", "android", R.string.mediasize_na_letter, 8500, 11000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700593 /** North America Government-Letter media size: 8.0" x 10.5" (203mm x 267mm) */
Svetoslav773f54d2013-09-03 14:01:43 -0700594 public static final MediaSize NA_GOVT_LETTER =
595 new MediaSize("NA_GOVT_LETTER", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700596 R.string.mediasize_na_gvrnmt_letter, 8000, 10500);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700597 /** North America Legal media size: 8.5" x 14" (216mm x 356mm) */
Svetoslav773f54d2013-09-03 14:01:43 -0700598 public static final MediaSize NA_LEGAL =
Svetoslavd8f391b2013-09-20 16:25:52 -0700599 new MediaSize("NA_LEGAL", "android", R.string.mediasize_na_legal, 8500, 14000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700600 /** North America Junior Legal media size: 8.0" x 5.0" (203mm × 127mm) */
Svetoslav773f54d2013-09-03 14:01:43 -0700601 public static final MediaSize NA_JUNIOR_LEGAL =
602 new MediaSize("NA_JUNIOR_LEGAL", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700603 R.string.mediasize_na_junior_legal, 8000, 5000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700604 /** North America Ledger media size: 17" x 11" (432mm × 279mm) */
Svetoslav773f54d2013-09-03 14:01:43 -0700605 public static final MediaSize NA_LEDGER =
Svetoslavd8f391b2013-09-20 16:25:52 -0700606 new MediaSize("NA_LEDGER", "android", R.string.mediasize_na_ledger, 17000, 11000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700607 /** North America Tabloid media size: 11" x 17" (279mm × 432mm) */
Svetoslav013b8162013-09-18 12:31:23 -0700608 public static final MediaSize NA_TABLOID =
Svetoslav773f54d2013-09-03 14:01:43 -0700609 new MediaSize("NA_TABLOID", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700610 R.string.mediasize_na_tabloid, 11000, 17000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700611 /** North America Index Card 3x5 media size: 3" x 5" (76mm x 127mm) */
612 public static final MediaSize NA_INDEX_3X5 =
613 new MediaSize("NA_INDEX_3X5", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700614 R.string.mediasize_na_index_3x5, 3000, 5000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700615 /** North America Index Card 4x6 media size: 4" x 6" (102mm x 152mm) */
616 public static final MediaSize NA_INDEX_4X6 =
617 new MediaSize("NA_INDEX_4X6", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700618 R.string.mediasize_na_index_4x6, 4000, 6000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700619 /** North America Index Card 5x8 media size: 5" x 8" (127mm x 203mm) */
620 public static final MediaSize NA_INDEX_5X8 =
621 new MediaSize("NA_INDEX_5X8", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700622 R.string.mediasize_na_index_5x8, 5000, 8000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700623 /** North America Monarch media size: 7.25" x 10.5" (184mm x 267mm) */
624 public static final MediaSize NA_MONARCH =
625 new MediaSize("NA_MONARCH", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700626 R.string.mediasize_na_monarch, 7250, 10500);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700627 /** North America Quarto media size: 8" x 10" (203mm x 254mm) */
628 public static final MediaSize NA_QUARTO =
629 new MediaSize("NA_QUARTO", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700630 R.string.mediasize_na_quarto, 8000, 10000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700631 /** North America Foolscap media size: 8" x 13" (203mm x 330mm) */
632 public static final MediaSize NA_FOOLSCAP =
633 new MediaSize("NA_FOOLSCAP", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700634 R.string.mediasize_na_foolscap, 8000, 13000);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700635
636 // Chinese
637
638 /** Chinese ROC 8K media size: 270mm x 390mm (10.629" x 15.3543") */
639 public static final MediaSize ROC_8K =
640 new MediaSize("ROC_8K", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700641 R.string.mediasize_chinese_roc_8k, 10629, 15354);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700642 /** Chinese ROC 16K media size: 195mm x 270mm (7.677" x 10.629") */
643 public static final MediaSize ROC_16K =
644 new MediaSize("ROC_16K", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700645 R.string.mediasize_chinese_roc_16k, 7677, 10629);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700646
647 /** Chinese PRC 1 media size: 102mm x 165mm (4.015" x 6.496") */
648 public static final MediaSize PRC_1 =
649 new MediaSize("PRC_1", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700650 R.string.mediasize_chinese_prc_1, 4015, 6496);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700651 /** Chinese PRC 2 media size: 102mm x 176mm (4.015" x 6.929") */
652 public static final MediaSize PRC_2 =
653 new MediaSize("PRC_2", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700654 R.string.mediasize_chinese_prc_2, 4015, 6929);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700655 /** Chinese PRC 3 media size: 125mm x 176mm (4.921" x 6.929") */
656 public static final MediaSize PRC_3 =
657 new MediaSize("PRC_3", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700658 R.string.mediasize_chinese_prc_3, 4921, 6929);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700659 /** Chinese PRC 4 media size: 110mm x 208mm (4.330" x 8.189") */
660 public static final MediaSize PRC_4 =
661 new MediaSize("PRC_4", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700662 R.string.mediasize_chinese_prc_4, 4330, 8189);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700663 /** Chinese PRC 5 media size: 110mm x 220mm (4.330" x 8.661") */
664 public static final MediaSize PRC_5 =
665 new MediaSize("PRC_5", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700666 R.string.mediasize_chinese_prc_5, 4330, 8661);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700667 /** Chinese PRC 6 media size: 120mm x 320mm (4.724" x 12.599") */
668 public static final MediaSize PRC_6 =
669 new MediaSize("PRC_6", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700670 R.string.mediasize_chinese_prc_6, 4724, 12599);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700671 /** Chinese PRC 7 media size: 160mm x 230mm (6.299" x 9.055") */
672 public static final MediaSize PRC_7 =
673 new MediaSize("PRC_7", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700674 R.string.mediasize_chinese_prc_7, 6299, 9055);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700675 /** Chinese PRC 8 media size: 120mm x 309mm (4.724" x 12.165") */
676 public static final MediaSize PRC_8 =
677 new MediaSize("PRC_8", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700678 R.string.mediasize_chinese_prc_8, 4724, 12165);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700679 /** Chinese PRC 9 media size: 229mm x 324mm (9.016" x 12.756") */
680 public static final MediaSize PRC_9 =
681 new MediaSize("PRC_9", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700682 R.string.mediasize_chinese_prc_9, 9016, 12756);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700683 /** Chinese PRC 10 media size: 324mm x 458mm (12.756" x 18.032") */
684 public static final MediaSize PRC_10 =
685 new MediaSize("PRC_10", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700686 R.string.mediasize_chinese_prc_10, 12756, 18032);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700687
688 /** Chinese PRC 16k media size: 146mm x 215mm (5.749" x 8.465") */
Svetoslav Ganov7be27ac2013-09-30 09:04:50 -0700689 public static final MediaSize PRC_16K =
690 new MediaSize("PRC_16K", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700691 R.string.mediasize_chinese_prc_16k, 5749, 8465);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700692 /** Chinese Pa Kai media size: 267mm x 389mm (10.512" x 15.315") */
693 public static final MediaSize OM_PA_KAI =
694 new MediaSize("OM_PA_KAI", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700695 R.string.mediasize_chinese_om_pa_kai, 10512, 15315);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700696 /** Chinese Dai Pa Kai media size: 275mm x 395mm (10.827" x 15.551") */
697 public static final MediaSize OM_DAI_PA_KAI =
698 new MediaSize("OM_DAI_PA_KAI", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700699 R.string.mediasize_chinese_om_dai_pa_kai, 10827, 15551);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700700 /** Chinese Jurro Ku Kai media size: 198mm x 275mm (7.796" x 10.827") */
701 public static final MediaSize OM_JUURO_KU_KAI =
702 new MediaSize("OM_JUURO_KU_KAI", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700703 R.string.mediasize_chinese_om_jurro_ku_kai, 7796, 10827);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700704
705 // Japanese
706
707 /** Japanese JIS B10 media size: 32mm x 45mm (1.259" x 1.772") */
708 public static final MediaSize JIS_B10 =
709 new MediaSize("JIS_B10", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700710 R.string.mediasize_japanese_jis_b10, 1259, 1772);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700711 /** Japanese JIS B9 media size: 45mm x 64mm (1.772" x 2.52") */
712 public static final MediaSize JIS_B9 =
713 new MediaSize("JIS_B9", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700714 R.string.mediasize_japanese_jis_b9, 1772, 2520);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700715 /** Japanese JIS B8 media size: 64mm x 91mm (2.52" x 3.583") */
716 public static final MediaSize JIS_B8 =
717 new MediaSize("JIS_B8", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700718 R.string.mediasize_japanese_jis_b8, 2520, 3583);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700719 /** Japanese JIS B7 media size: 91mm x 128mm (3.583" x 5.049") */
720 public static final MediaSize JIS_B7 =
721 new MediaSize("JIS_B7", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700722 R.string.mediasize_japanese_jis_b7, 3583, 5049);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700723 /** Japanese JIS B6 media size: 128mm x 182mm (5.049" x 7.165") */
724 public static final MediaSize JIS_B6 =
725 new MediaSize("JIS_B6", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700726 R.string.mediasize_japanese_jis_b6, 5049, 7165);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700727 /** Japanese JIS B5 media size: 182mm x 257mm (7.165" x 10.118") */
728 public static final MediaSize JIS_B5 =
729 new MediaSize("JIS_B5", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700730 R.string.mediasize_japanese_jis_b5, 7165, 10118);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700731 /** Japanese JIS B4 media size: 257mm x 364mm (10.118" x 14.331") */
732 public static final MediaSize JIS_B4 =
733 new MediaSize("JIS_B4", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700734 R.string.mediasize_japanese_jis_b4, 10118, 14331);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700735 /** Japanese JIS B3 media size: 364mm x 515mm (14.331" x 20.276") */
736 public static final MediaSize JIS_B3 =
737 new MediaSize("JIS_B3", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700738 R.string.mediasize_japanese_jis_b3, 14331, 20276);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700739 /** Japanese JIS B2 media size: 515mm x 728mm (20.276" x 28.661") */
740 public static final MediaSize JIS_B2 =
741 new MediaSize("JIS_B2", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700742 R.string.mediasize_japanese_jis_b2, 20276, 28661);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700743 /** Japanese JIS B1 media size: 728mm x 1030mm (28.661" x 40.551") */
744 public static final MediaSize JIS_B1 =
745 new MediaSize("JIS_B1", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700746 R.string.mediasize_japanese_jis_b1, 28661, 40551);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700747 /** Japanese JIS B0 media size: 1030mm x 1456mm (40.551" x 57.323") */
748 public static final MediaSize JIS_B0 =
749 new MediaSize("JIS_B0", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700750 R.string.mediasize_japanese_jis_b0, 40551, 57323);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700751
752 /** Japanese JIS Exec media size: 216mm x 330mm (8.504" x 12.992") */
753 public static final MediaSize JIS_EXEC =
754 new MediaSize("JIS_EXEC", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700755 R.string.mediasize_japanese_jis_exec, 8504, 12992);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700756
757 /** Japanese Chou4 media size: 90mm x 205mm (3.543" x 8.071") */
758 public static final MediaSize JPN_CHOU4 =
759 new MediaSize("JPN_CHOU4", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700760 R.string.mediasize_japanese_chou4, 3543, 8071);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700761 /** Japanese Chou3 media size: 120mm x 235mm (4.724" x 9.252") */
762 public static final MediaSize JPN_CHOU3 =
763 new MediaSize("JPN_CHOU3", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700764 R.string.mediasize_japanese_chou3, 4724, 9252);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700765 /** Japanese Chou2 media size: 111.1mm x 146mm (4.374" x 5.748") */
766 public static final MediaSize JPN_CHOU2 =
767 new MediaSize("JPN_CHOU2", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700768 R.string.mediasize_japanese_chou2, 4374, 5748);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700769
770 /** Japanese Hagaki media size: 100mm x 148mm (3.937" x 5.827") */
771 public static final MediaSize JPN_HAGAKI =
772 new MediaSize("JPN_HAGAKI", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700773 R.string.mediasize_japanese_hagaki, 3937, 5827);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700774 /** Japanese Oufuku media size: 148mm x 200mm (5.827" x 7.874") */
775 public static final MediaSize JPN_OUFUKU =
776 new MediaSize("JPN_OUFUKU", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700777 R.string.mediasize_japanese_oufuku, 5827, 7874);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700778
779 /** Japanese Kahu media size: 240mm x 322.1mm (9.449" x 12.681") */
780 public static final MediaSize JPN_KAHU =
781 new MediaSize("JPN_KAHU", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700782 R.string.mediasize_japanese_kahu, 9449, 12681);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700783 /** Japanese Kaku2 media size: 240mm x 332mm (9.449" x 13.071") */
784 public static final MediaSize JPN_KAKU2 =
785 new MediaSize("JPN_KAKU2", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700786 R.string.mediasize_japanese_kaku2, 9449, 13071);
Svetoslav Ganovfa77ece2013-09-17 09:44:40 -0700787
788 /** Japanese You4 media size: 105mm x 235mm (4.134" x 9.252") */
789 public static final MediaSize JPN_YOU4 =
790 new MediaSize("JPN_YOU4", "android",
Svetoslavd8f391b2013-09-20 16:25:52 -0700791 R.string.mediasize_japanese_you4, 4134, 9252);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700792
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700793 private final @NonNull String mId;
Svetoslav773f54d2013-09-03 14:01:43 -0700794 /**@hide */
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700795 public final @NonNull String mLabel;
Svetoslav773f54d2013-09-03 14:01:43 -0700796 /**@hide */
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700797 public final @Nullable String mPackageName;
Svetoslav773f54d2013-09-03 14:01:43 -0700798 /**@hide */
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700799 public final @StringRes int mLabelResId;
800 private final @IntRange(from = 1) int mWidthMils;
801 private final @IntRange(from = 1) int mHeightMils;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700802
803 /**
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700804 * Creates a new instance.
Svetoslav773f54d2013-09-03 14:01:43 -0700805 *
806 * @param id The unique media size id.
807 * @param packageName The name of the creating package.
808 * @param labelResId The resource if of a human readable label.
Philip P. Moltmann823715d2016-04-21 16:28:02 -0700809 * @param widthMils The width in mils (thousandths of an inch).
810 * @param heightMils The height in mils (thousandths of an inch).
Svetoslav773f54d2013-09-03 14:01:43 -0700811 *
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700812 * @throws IllegalArgumentException If the id is empty or the label
813 * is empty or the widthMils is less than or equal to zero or the
814 * heightMils is less than or equal to zero.
Svetoslava76233a2013-09-05 09:38:02 -0700815 *
816 * @hide
Svetoslav773f54d2013-09-03 14:01:43 -0700817 */
818 public MediaSize(String id, String packageName, int labelResId,
819 int widthMils, int heightMils) {
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700820 this(id, null, packageName, widthMils, heightMils, labelResId);
Svetoslav Ganov7be27ac2013-09-30 09:04:50 -0700821
822 // Build this mapping only for predefined media sizes.
823 sIdToMediaSizeMap.put(mId, this);
Svetoslav773f54d2013-09-03 14:01:43 -0700824 }
825
826 /**
Svetoslava76233a2013-09-05 09:38:02 -0700827 * Creates a new instance.
Svetoslav17b7f6e2013-06-24 18:29:33 -0700828 *
Svetoslav Ganov22cb9172013-08-29 17:42:07 -0700829 * @param id The unique media size id. It is unique amongst other media sizes
830 * supported by the printer.
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700831 * @param label The <strong>localized</strong> human readable label.
Philip P. Moltmann823715d2016-04-21 16:28:02 -0700832 * @param widthMils The width in mils (thousandths of an inch).
833 * @param heightMils The height in mils (thousandths of an inch).
Svetoslav17b7f6e2013-06-24 18:29:33 -0700834 *
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700835 * @throws IllegalArgumentException If the id is empty or the label is empty
836 * or the widthMils is less than or equal to zero or the heightMils is less
837 * than or equal to zero.
Svetoslav17b7f6e2013-06-24 18:29:33 -0700838 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800839 public MediaSize(@NonNull String id, @NonNull String label,
840 @IntRange(from = 1) int widthMils, @IntRange(from = 1) int heightMils) {
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700841 this(id, label, null, widthMils, heightMils, 0);
Svetoslav773f54d2013-09-03 14:01:43 -0700842 }
843
Philip P. Moltmann4959caf2016-01-21 14:30:56 -0800844 /**
845 * Get the Id of all predefined media sizes beside the {@link #UNKNOWN_PORTRAIT} and
846 * {@link #UNKNOWN_LANDSCAPE}.
847 *
848 * @return List of all predefined media sizes
849 *
850 * @hide
851 */
852 public static @NonNull ArraySet<MediaSize> getAllPredefinedSizes() {
853 ArraySet<MediaSize> definedMediaSizes = new ArraySet<>(sIdToMediaSizeMap.values());
854
855 definedMediaSizes.remove(UNKNOWN_PORTRAIT);
856 definedMediaSizes.remove(UNKNOWN_LANDSCAPE);
857
858 return definedMediaSizes;
859 }
860
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700861 /**
862 * Creates a new instance.
863 *
864 * @param id The unique media size id. It is unique amongst other media sizes
865 * supported by the printer.
866 * @param label The <strong>localized</strong> human readable label.
867 * @param packageName The name of the creating package.
Philip P. Moltmann823715d2016-04-21 16:28:02 -0700868 * @param widthMils The width in mils (thousandths of an inch).
869 * @param heightMils The height in mils (thousandths of an inch).
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700870 * @param labelResId The resource if of a human readable label.
871 *
872 * @throws IllegalArgumentException If the id is empty or the label is unset
873 * or the widthMils is less than or equal to zero or the heightMils is less
874 * than or equal to zero.
875 *
876 * @hide
877 */
878 public MediaSize(String id, String label, String packageName, int widthMils, int heightMils,
879 int labelResId) {
Svetoslav773f54d2013-09-03 14:01:43 -0700880 mPackageName = packageName;
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700881 mId = Preconditions.checkStringNotEmpty(id, "id cannot be empty.");
Svetoslav773f54d2013-09-03 14:01:43 -0700882 mLabelResId = labelResId;
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700883 mWidthMils = Preconditions.checkArgumentPositive(widthMils, "widthMils cannot be " +
884 "less than or equal to zero.");
885 mHeightMils = Preconditions.checkArgumentPositive(heightMils, "heightMils cannot be " +
886 "less than or equal to zero.");
Svetoslav773f54d2013-09-03 14:01:43 -0700887 mLabel = label;
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700888
889 // The label has to be either a string ot a StringRes
890 Preconditions.checkArgument(!TextUtils.isEmpty(label) !=
891 (!TextUtils.isEmpty(packageName) && labelResId != 0), "label cannot be empty.");
Svetoslav17b7f6e2013-06-24 18:29:33 -0700892 }
893
894 /**
Svetoslav Ganov22cb9172013-08-29 17:42:07 -0700895 * Gets the unique media size id. It is unique amongst other media sizes
896 * supported by the printer.
897 * <p>
898 * This id is defined by the client that generated the media size
899 * instance and should not be interpreted by other parties.
900 * </p>
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700901 *
902 * @return The unique media size id.
903 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800904 public @NonNull String getId() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700905 return mId;
906 }
907
908 /**
909 * Gets the human readable media size label.
910 *
Svetoslav773f54d2013-09-03 14:01:43 -0700911 * @param packageManager The package manager for loading the label.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700912 * @return The human readable label.
913 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800914 public @NonNull String getLabel(@NonNull PackageManager packageManager) {
Svetoslav773f54d2013-09-03 14:01:43 -0700915 if (!TextUtils.isEmpty(mPackageName) && mLabelResId > 0) {
916 try {
917 return packageManager.getResourcesForApplication(
918 mPackageName).getString(mLabelResId);
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -0700919 } catch (NotFoundException | NameNotFoundException e) {
Svetoslav773f54d2013-09-03 14:01:43 -0700920 Log.w(LOG_TAG, "Could not load resouce" + mLabelResId
921 + " from package " + mPackageName);
922 }
923 }
Svetoslav17b7f6e2013-06-24 18:29:33 -0700924 return mLabel;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700925 }
926
927 /**
Philip P. Moltmann823715d2016-04-21 16:28:02 -0700928 * Gets the media width in mils (thousandths of an inch).
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700929 *
930 * @return The media width.
931 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800932 public @IntRange(from = 1) int getWidthMils() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700933 return mWidthMils;
934 }
935
936 /**
Philip P. Moltmann823715d2016-04-21 16:28:02 -0700937 * Gets the media height in mils (thousandths of an inch).
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700938 *
939 * @return The media height.
940 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800941 public @IntRange(from = 1) int getHeightMils() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700942 return mHeightMils;
943 }
944
Svetoslav773f54d2013-09-03 14:01:43 -0700945 /**
946 * Gets whether this media size is in portrait which is the
947 * height is greater or equal to the width.
948 *
949 * @return True if the media size is in portrait, false if
950 * it is in landscape.
951 */
952 public boolean isPortrait() {
953 return mHeightMils >= mWidthMils;
954 }
955
956 /**
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700957 * Returns a new media size instance in a portrait orientation,
Svetoslava76233a2013-09-05 09:38:02 -0700958 * which is the height is the greater dimension.
Svetoslav773f54d2013-09-03 14:01:43 -0700959 *
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700960 * @return New instance in landscape orientation if this one
961 * is in landscape, otherwise this instance.
Svetoslav773f54d2013-09-03 14:01:43 -0700962 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800963 public @NonNull MediaSize asPortrait() {
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700964 if (isPortrait()) {
965 return this;
966 }
Svetoslava36285f2013-09-05 11:27:45 -0700967 return new MediaSize(mId, mLabel, mPackageName,
Svetoslava76233a2013-09-05 09:38:02 -0700968 Math.min(mWidthMils, mHeightMils),
969 Math.max(mWidthMils, mHeightMils),
970 mLabelResId);
Svetoslav773f54d2013-09-03 14:01:43 -0700971 }
972
973 /**
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700974 * Returns a new media size instance in a landscape orientation,
Svetoslava76233a2013-09-05 09:38:02 -0700975 * which is the height is the lesser dimension.
Svetoslav773f54d2013-09-03 14:01:43 -0700976 *
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700977 * @return New instance in landscape orientation if this one
978 * is in portrait, otherwise this instance.
Svetoslav773f54d2013-09-03 14:01:43 -0700979 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -0800980 public @NonNull MediaSize asLandscape() {
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -0700981 if (!isPortrait()) {
982 return this;
983 }
Svetoslava36285f2013-09-05 11:27:45 -0700984 return new MediaSize(mId, mLabel, mPackageName,
Svetoslav773f54d2013-09-03 14:01:43 -0700985 Math.max(mWidthMils, mHeightMils),
Svetoslava76233a2013-09-05 09:38:02 -0700986 Math.min(mWidthMils, mHeightMils),
987 mLabelResId);
Svetoslav773f54d2013-09-03 14:01:43 -0700988 }
989
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700990 void writeToParcel(Parcel parcel) {
991 parcel.writeString(mId);
Svetoslav Ganov798bed62013-08-11 12:29:39 -0700992 parcel.writeString(mLabel);
Svetoslav773f54d2013-09-03 14:01:43 -0700993 parcel.writeString(mPackageName);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700994 parcel.writeInt(mWidthMils);
995 parcel.writeInt(mHeightMils);
Svetoslav773f54d2013-09-03 14:01:43 -0700996 parcel.writeInt(mLabelResId);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -0700997 }
998
999 static MediaSize createFromParcel(Parcel parcel) {
1000 return new MediaSize(
1001 parcel.readString(),
Svetoslav Ganov798bed62013-08-11 12:29:39 -07001002 parcel.readString(),
Svetoslav773f54d2013-09-03 14:01:43 -07001003 parcel.readString(),
1004 parcel.readInt(),
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001005 parcel.readInt(),
1006 parcel.readInt());
1007 }
1008
1009 @Override
Svetoslav Ganov85b1f882013-07-24 17:00:06 -07001010 public int hashCode() {
1011 final int prime = 31;
1012 int result = 1;
Svetoslav Ganov85b1f882013-07-24 17:00:06 -07001013 result = prime * result + mWidthMils;
1014 result = prime * result + mHeightMils;
1015 return result;
1016 }
1017
1018 @Override
1019 public boolean equals(Object obj) {
1020 if (this == obj) {
1021 return true;
1022 }
1023 if (obj == null) {
1024 return false;
1025 }
1026 if (getClass() != obj.getClass()) {
1027 return false;
1028 }
1029 MediaSize other = (MediaSize) obj;
Svetoslav Ganov85b1f882013-07-24 17:00:06 -07001030 if (mWidthMils != other.mWidthMils) {
1031 return false;
1032 }
1033 if (mHeightMils != other.mHeightMils) {
1034 return false;
1035 }
1036 return true;
1037 }
1038
1039 @Override
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001040 public String toString() {
1041 StringBuilder builder = new StringBuilder();
1042 builder.append("MediaSize{");
1043 builder.append("id: ").append(mId);
Svetoslav17b7f6e2013-06-24 18:29:33 -07001044 builder.append(", label: ").append(mLabel);
Svetoslav773f54d2013-09-03 14:01:43 -07001045 builder.append(", packageName: ").append(mPackageName);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001046 builder.append(", heightMils: ").append(mHeightMils);
1047 builder.append(", widthMils: ").append(mWidthMils);
Svetoslav773f54d2013-09-03 14:01:43 -07001048 builder.append(", labelResId: ").append(mLabelResId);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001049 builder.append("}");
1050 return builder.toString();
1051 }
Svetoslav Ganov7be27ac2013-09-30 09:04:50 -07001052
1053 /**
1054 * Gets a standard media size given its id.
1055 *
1056 * @param id The media size id.
1057 * @return The media size for the given id or null.
1058 *
1059 * @hide
1060 */
1061 public static MediaSize getStandardMediaSizeById(String id) {
1062 return sIdToMediaSizeMap.get(id);
1063 }
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001064 }
1065
1066 /**
Svetoslav Ganov22cb9172013-08-29 17:42:07 -07001067 * This class specifies a supported resolution in DPI (dots per inch).
1068 * Resolution defines how many points with different color can be placed
1069 * on one inch in horizontal or vertical direction of the target media.
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -07001070 * For example, a printer with 600 DPI can produce higher quality images
1071 * the one with 300 DPI resolution.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001072 */
1073 public static final class Resolution {
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -07001074 private final @NonNull String mId;
1075 private final @NonNull String mLabel;
1076 private final @IntRange(from = 1) int mHorizontalDpi;
1077 private final @IntRange(from = 1) int mVerticalDpi;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001078
1079 /**
Svetoslava76233a2013-09-05 09:38:02 -07001080 * Creates a new instance.
Svetoslav17b7f6e2013-06-24 18:29:33 -07001081 *
Svetoslav Ganov22cb9172013-08-29 17:42:07 -07001082 * @param id The unique resolution id. It is unique amongst other resolutions
1083 * supported by the printer.
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -07001084 * @param label The <strong>localized</strong> human readable label.
Svetoslav Ganov22cb9172013-08-29 17:42:07 -07001085 * @param horizontalDpi The horizontal resolution in DPI (dots per inch).
1086 * @param verticalDpi The vertical resolution in DPI (dots per inch).
Svetoslav17b7f6e2013-06-24 18:29:33 -07001087 *
Svetoslav Ganov4d4c66d2013-10-24 18:04:39 -07001088 * @throws IllegalArgumentException If the id is empty or the label is empty
1089 * or the horizontalDpi is less than or equal to zero or the verticalDpi is
1090 * less than or equal to zero.
Svetoslav17b7f6e2013-06-24 18:29:33 -07001091 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001092 public Resolution(@NonNull String id, @NonNull String label,
1093 @IntRange(from = 1) int horizontalDpi, @IntRange(from = 1) int verticalDpi) {
Svetoslav17b7f6e2013-06-24 18:29:33 -07001094 if (TextUtils.isEmpty(id)) {
1095 throw new IllegalArgumentException("id cannot be empty.");
1096 }
1097 if (TextUtils.isEmpty(label)) {
1098 throw new IllegalArgumentException("label cannot be empty.");
1099 }
1100 if (horizontalDpi <= 0) {
1101 throw new IllegalArgumentException("horizontalDpi "
1102 + "cannot be less than or equal to zero.");
1103 }
1104 if (verticalDpi <= 0) {
1105 throw new IllegalArgumentException("verticalDpi"
1106 + " cannot be less than or equal to zero.");
1107 }
1108 mId = id;
1109 mLabel = label;
1110 mHorizontalDpi = horizontalDpi;
1111 mVerticalDpi = verticalDpi;
1112 }
1113
1114 /**
Svetoslav Ganov22cb9172013-08-29 17:42:07 -07001115 * Gets the unique resolution id. It is unique amongst other resolutions
1116 * supported by the printer.
1117 * <p>
1118 * This id is defined by the client that generated the resolution
1119 * instance and should not be interpreted by other parties.
1120 * </p>
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001121 *
1122 * @return The unique resolution id.
1123 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001124 public @NonNull String getId() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001125 return mId;
1126 }
1127
1128 /**
1129 * Gets the resolution human readable label.
1130 *
1131 * @return The human readable label.
1132 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001133 public @NonNull String getLabel() {
Svetoslav17b7f6e2013-06-24 18:29:33 -07001134 return mLabel;
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001135 }
1136
1137 /**
Svetoslav Ganov22cb9172013-08-29 17:42:07 -07001138 * Gets the horizontal resolution in DPI (dots per inch).
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001139 *
1140 * @return The horizontal resolution.
1141 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001142 public @IntRange(from = 1) int getHorizontalDpi() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001143 return mHorizontalDpi;
1144 }
1145
1146 /**
Svetoslav Ganov22cb9172013-08-29 17:42:07 -07001147 * Gets the vertical resolution in DPI (dots per inch).
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001148 *
1149 * @return The vertical resolution.
1150 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001151 public @IntRange(from = 1) int getVerticalDpi() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001152 return mVerticalDpi;
1153 }
1154
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001155 void writeToParcel(Parcel parcel) {
1156 parcel.writeString(mId);
Svetoslav Ganov798bed62013-08-11 12:29:39 -07001157 parcel.writeString(mLabel);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001158 parcel.writeInt(mHorizontalDpi);
1159 parcel.writeInt(mVerticalDpi);
1160 }
1161
1162 static Resolution createFromParcel(Parcel parcel) {
1163 return new Resolution(
1164 parcel.readString(),
Svetoslav Ganov798bed62013-08-11 12:29:39 -07001165 parcel.readString(),
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001166 parcel.readInt(),
1167 parcel.readInt());
1168 }
1169
1170 @Override
Svetoslav Ganov85b1f882013-07-24 17:00:06 -07001171 public int hashCode() {
1172 final int prime = 31;
1173 int result = 1;
Svetoslav Ganov85b1f882013-07-24 17:00:06 -07001174 result = prime * result + mHorizontalDpi;
1175 result = prime * result + mVerticalDpi;
1176 return result;
1177 }
1178
1179 @Override
1180 public boolean equals(Object obj) {
1181 if (this == obj) {
1182 return true;
1183 }
1184 if (obj == null) {
1185 return false;
1186 }
1187 if (getClass() != obj.getClass()) {
1188 return false;
1189 }
1190 Resolution other = (Resolution) obj;
Svetoslav Ganov85b1f882013-07-24 17:00:06 -07001191 if (mHorizontalDpi != other.mHorizontalDpi) {
1192 return false;
1193 }
1194 if (mVerticalDpi != other.mVerticalDpi) {
1195 return false;
1196 }
1197 return true;
1198 }
1199
1200 @Override
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001201 public String toString() {
1202 StringBuilder builder = new StringBuilder();
1203 builder.append("Resolution{");
1204 builder.append("id: ").append(mId);
Svetoslav17b7f6e2013-06-24 18:29:33 -07001205 builder.append(", label: ").append(mLabel);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001206 builder.append(", horizontalDpi: ").append(mHorizontalDpi);
1207 builder.append(", verticalDpi: ").append(mVerticalDpi);
1208 builder.append("}");
1209 return builder.toString();
1210 }
1211 }
1212
1213 /**
Svetoslav Ganov22cb9172013-08-29 17:42:07 -07001214 * This class specifies content margins. Margins define the white space
1215 * around the content where the left margin defines the amount of white
1216 * space on the left of the content and so on.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001217 */
1218 public static final class Margins {
Svetoslav Ganovaec14172013-08-27 00:30:54 -07001219 public static final Margins NO_MARGINS = new Margins(0, 0, 0, 0);
1220
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001221 private final int mLeftMils;
1222 private final int mTopMils;
1223 private final int mRightMils;
1224 private final int mBottomMils;
1225
1226 /**
Svetoslav17b7f6e2013-06-24 18:29:33 -07001227 * Creates a new instance.
1228 *
Philip P. Moltmann823715d2016-04-21 16:28:02 -07001229 * @param leftMils The left margin in mils (thousandths of an inch).
1230 * @param topMils The top margin in mils (thousandths of an inch).
1231 * @param rightMils The right margin in mils (thousandths of an inch).
1232 * @param bottomMils The bottom margin in mils (thousandths of an inch).
Svetoslav17b7f6e2013-06-24 18:29:33 -07001233 */
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -07001234 public Margins(int leftMils, int topMils, int rightMils, int bottomMils) {
Svetoslav17b7f6e2013-06-24 18:29:33 -07001235 mTopMils = topMils;
1236 mLeftMils = leftMils;
1237 mRightMils = rightMils;
1238 mBottomMils = bottomMils;
1239 }
1240
1241 /**
Philip P. Moltmann823715d2016-04-21 16:28:02 -07001242 * Gets the left margin in mils (thousandths of an inch).
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001243 *
1244 * @return The left margin.
1245 */
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -07001246 public int getLeftMils() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001247 return mLeftMils;
1248 }
1249
1250 /**
Philip P. Moltmann823715d2016-04-21 16:28:02 -07001251 * Gets the top margin in mils (thousandths of an inch).
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001252 *
1253 * @return The top margin.
1254 */
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -07001255 public int getTopMils() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001256 return mTopMils;
1257 }
1258
1259 /**
Philip P. Moltmann823715d2016-04-21 16:28:02 -07001260 * Gets the right margin in mils (thousandths of an inch).
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001261 *
1262 * @return The right margin.
1263 */
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -07001264 public int getRightMils() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001265 return mRightMils;
1266 }
1267
1268 /**
Philip P. Moltmann823715d2016-04-21 16:28:02 -07001269 * Gets the bottom margin in mils (thousandths of an inch).
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001270 *
1271 * @return The bottom margin.
1272 */
Philip P. Moltmannaa8a4fe2016-03-30 09:07:36 -07001273 public int getBottomMils() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001274 return mBottomMils;
1275 }
1276
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001277 void writeToParcel(Parcel parcel) {
1278 parcel.writeInt(mLeftMils);
1279 parcel.writeInt(mTopMils);
1280 parcel.writeInt(mRightMils);
1281 parcel.writeInt(mBottomMils);
1282 }
1283
1284 static Margins createFromParcel(Parcel parcel) {
1285 return new Margins(
1286 parcel.readInt(),
1287 parcel.readInt(),
1288 parcel.readInt(),
1289 parcel.readInt());
1290 }
1291
1292 @Override
Svetoslav Ganov85b1f882013-07-24 17:00:06 -07001293 public int hashCode() {
1294 final int prime = 31;
1295 int result = 1;
1296 result = prime * result + mBottomMils;
1297 result = prime * result + mLeftMils;
1298 result = prime * result + mRightMils;
1299 result = prime * result + mTopMils;
1300 return result;
1301 }
1302
1303 @Override
1304 public boolean equals(Object obj) {
1305 if (this == obj) {
1306 return true;
1307 }
1308 if (obj == null) {
1309 return false;
1310 }
1311 if (getClass() != obj.getClass()) {
1312 return false;
1313 }
1314 Margins other = (Margins) obj;
1315 if (mBottomMils != other.mBottomMils) {
1316 return false;
1317 }
1318 if (mLeftMils != other.mLeftMils) {
1319 return false;
1320 }
1321 if (mRightMils != other.mRightMils) {
1322 return false;
1323 }
1324 if (mTopMils != other.mTopMils) {
1325 return false;
1326 }
1327 return true;
1328 }
1329
1330 @Override
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001331 public String toString() {
1332 StringBuilder builder = new StringBuilder();
1333 builder.append("Margins{");
1334 builder.append("leftMils: ").append(mLeftMils);
1335 builder.append(", topMils: ").append(mTopMils);
1336 builder.append(", rightMils: ").append(mRightMils);
1337 builder.append(", bottomMils: ").append(mBottomMils);
1338 builder.append("}");
1339 return builder.toString();
1340 }
1341 }
1342
Svetoslav Ganov798bed62013-08-11 12:29:39 -07001343 static String colorModeToString(int colorMode) {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001344 switch (colorMode) {
1345 case COLOR_MODE_MONOCHROME: {
1346 return "COLOR_MODE_MONOCHROME";
1347 }
1348 case COLOR_MODE_COLOR: {
1349 return "COLOR_MODE_COLOR";
1350 }
Svetoslav948c9a62015-02-02 19:47:04 -08001351 default: {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001352 return "COLOR_MODE_UNKNOWN";
Svetoslav948c9a62015-02-02 19:47:04 -08001353 }
1354 }
1355 }
1356
1357 static String duplexModeToString(int duplexMode) {
1358 switch (duplexMode) {
1359 case DUPLEX_MODE_NONE: {
1360 return "DUPLEX_MODE_NONE";
1361 }
1362 case DUPLEX_MODE_LONG_EDGE: {
1363 return "DUPLEX_MODE_LONG_EDGE";
1364 }
1365 case DUPLEX_MODE_SHORT_EDGE: {
1366 return "DUPLEX_MODE_SHORT_EDGE";
1367 }
1368 default: {
1369 return "DUPLEX_MODE_UNKNOWN";
1370 }
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001371 }
1372 }
1373
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001374 static void enforceValidColorMode(int colorMode) {
Svetoslav948c9a62015-02-02 19:47:04 -08001375 if ((colorMode & VALID_COLOR_MODES) == 0 || Integer.bitCount(colorMode) != 1) {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001376 throw new IllegalArgumentException("invalid color mode: " + colorMode);
1377 }
1378 }
1379
Svetoslav948c9a62015-02-02 19:47:04 -08001380 static void enforceValidDuplexMode(int duplexMode) {
1381 if ((duplexMode & VALID_DUPLEX_MODES) == 0 || Integer.bitCount(duplexMode) != 1) {
1382 throw new IllegalArgumentException("invalid duplex mode: " + duplexMode);
1383 }
1384 }
1385
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001386 /**
1387 * Builder for creating {@link PrintAttributes}.
1388 */
1389 public static final class Builder {
1390 private final PrintAttributes mAttributes = new PrintAttributes();
1391
1392 /**
1393 * Sets the media size.
1394 *
1395 * @param mediaSize The media size.
1396 * @return This builder.
1397 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001398 public @NonNull Builder setMediaSize(@NonNull MediaSize mediaSize) {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001399 mAttributes.setMediaSize(mediaSize);
1400 return this;
1401 }
1402
1403 /**
1404 * Sets the resolution.
1405 *
1406 * @param resolution The resolution.
1407 * @return This builder.
1408 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001409 public @NonNull Builder setResolution(@NonNull Resolution resolution) {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001410 mAttributes.setResolution(resolution);
1411 return this;
1412 }
1413
1414 /**
Svetoslav651dd4e2013-09-12 14:37:47 -07001415 * Sets the minimal margins. If the content does not fit
1416 * these margins it will be clipped.
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001417 *
1418 * @param margins The margins.
1419 * @return This builder.
1420 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001421 public @NonNull Builder setMinMargins(@NonNull Margins margins) {
Svetoslav651dd4e2013-09-12 14:37:47 -07001422 mAttributes.setMinMargins(margins);
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001423 return this;
1424 }
1425
1426 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001427 * Sets the color mode.
1428 *
1429 * @param colorMode A valid color mode or zero.
1430 * @return This builder.
1431 *
1432 * @see PrintAttributes#COLOR_MODE_MONOCHROME
1433 * @see PrintAttributes#COLOR_MODE_COLOR
1434 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001435 public @NonNull Builder setColorMode(@ColorMode int colorMode) {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001436 mAttributes.setColorMode(colorMode);
1437 return this;
1438 }
1439
1440 /**
Svetoslav948c9a62015-02-02 19:47:04 -08001441 * Sets the duplex mode.
1442 *
1443 * @param duplexMode A valid duplex mode or zero.
1444 * @return This builder.
1445 *
1446 * @see PrintAttributes#DUPLEX_MODE_NONE
1447 * @see PrintAttributes#DUPLEX_MODE_LONG_EDGE
1448 * @see PrintAttributes#DUPLEX_MODE_SHORT_EDGE
1449 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001450 public @NonNull Builder setDuplexMode(@DuplexMode int duplexMode) {
Svetoslav948c9a62015-02-02 19:47:04 -08001451 mAttributes.setDuplexMode(duplexMode);
1452 return this;
1453 }
1454
1455 /**
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001456 * Creates a new {@link PrintAttributes} instance.
1457 *
1458 * @return The new instance.
1459 */
Philip P. Moltmannc43639c2015-12-18 13:58:40 -08001460 public @NonNull PrintAttributes build() {
Svetoslav Ganov4b9a4d12013-06-11 15:20:06 -07001461 return mAttributes;
1462 }
1463 }
1464
1465 public static final Parcelable.Creator<PrintAttributes> CREATOR =
1466 new Creator<PrintAttributes>() {
1467 @Override
1468 public PrintAttributes createFromParcel(Parcel parcel) {
1469 return new PrintAttributes(parcel);
1470 }
1471
1472 @Override
1473 public PrintAttributes[] newArray(int size) {
1474 return new PrintAttributes[size];
1475 }
1476 };
1477}