Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.print; |
| 18 | |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 19 | import android.annotation.FloatRange; |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 20 | import android.annotation.IntDef; |
| 21 | import android.annotation.IntRange; |
| 22 | import android.annotation.NonNull; |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 23 | import android.annotation.Nullable; |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 24 | import android.annotation.StringRes; |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 25 | import android.annotation.TestApi; |
Mathew Inwood | 06bf4b7 | 2018-07-31 16:36:56 +0100 | [diff] [blame] | 26 | import android.annotation.UnsupportedAppUsage; |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 27 | import android.content.pm.PackageManager; |
| 28 | import android.content.res.Resources; |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 29 | import android.os.Bundle; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 30 | import android.os.Parcel; |
| 31 | import android.os.Parcelable; |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 32 | import android.service.print.PrintJobInfoProto; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 33 | |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 34 | import com.android.internal.util.Preconditions; |
| 35 | |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 36 | import java.lang.annotation.Retention; |
| 37 | import java.lang.annotation.RetentionPolicy; |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 38 | import java.util.Arrays; |
| 39 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 40 | /** |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 41 | * This class represents the description of a print job. The print job |
| 42 | * state includes properties such as its id, print attributes used for |
| 43 | * generating the content, and so on. Note that the print jobs state may |
| 44 | * change over time and this class represents a snapshot of this state. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 45 | */ |
| 46 | public final class PrintJobInfo implements Parcelable { |
| 47 | |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 48 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 49 | @IntDef(prefix = { "STATE_" }, value = { |
| 50 | STATE_CREATED, |
| 51 | STATE_QUEUED, |
| 52 | STATE_STARTED, |
| 53 | STATE_BLOCKED, |
| 54 | STATE_COMPLETED, |
| 55 | STATE_FAILED, |
| 56 | STATE_CANCELED |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 57 | }) |
| 58 | @Retention(RetentionPolicy.SOURCE) |
| 59 | public @interface State { |
| 60 | } |
| 61 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 62 | /** |
| 63 | * Constant for matching any print job state. |
| 64 | * |
| 65 | * @hide |
| 66 | */ |
| 67 | public static final int STATE_ANY = -1; |
| 68 | |
| 69 | /** |
Svetoslav Ganov | 88d1991 | 2013-07-22 12:32:03 -0700 | [diff] [blame] | 70 | * Constant for matching any print job state. |
| 71 | * |
| 72 | * @hide |
| 73 | */ |
| 74 | public static final int STATE_ANY_VISIBLE_TO_CLIENTS = -2; |
| 75 | |
| 76 | /** |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 77 | * Constant for matching any active print job state. |
| 78 | * |
| 79 | * @hide |
| 80 | */ |
| 81 | public static final int STATE_ANY_ACTIVE = -3; |
| 82 | |
| 83 | /** |
Svetoslav Ganov | 9b6d3a1 | 2013-10-12 12:35:41 -0700 | [diff] [blame] | 84 | * Constant for matching any scheduled, i.e. delivered to a print |
| 85 | * service, print job state. |
| 86 | * |
| 87 | * @hide |
| 88 | */ |
| 89 | public static final int STATE_ANY_SCHEDULED = -4; |
| 90 | |
| 91 | /** |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 92 | * Print job state: The print job is being created but not yet |
| 93 | * ready to be printed. |
| 94 | * <p> |
| 95 | * Next valid states: {@link #STATE_QUEUED} |
| 96 | * </p> |
| 97 | */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 98 | public static final int STATE_CREATED = PrintJobInfoProto.STATE_CREATED; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 99 | |
| 100 | /** |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 101 | * Print job state: The print jobs is created, it is ready |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 102 | * to be printed and should be processed. |
| 103 | * <p> |
| 104 | * Next valid states: {@link #STATE_STARTED}, {@link #STATE_FAILED}, |
| 105 | * {@link #STATE_CANCELED} |
| 106 | * </p> |
| 107 | */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 108 | public static final int STATE_QUEUED = PrintJobInfoProto.STATE_QUEUED; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 109 | |
| 110 | /** |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 111 | * Print job state: The print job is being printed. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 112 | * <p> |
| 113 | * Next valid states: {@link #STATE_COMPLETED}, {@link #STATE_FAILED}, |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 114 | * {@link #STATE_CANCELED}, {@link #STATE_BLOCKED} |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 115 | * </p> |
| 116 | */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 117 | public static final int STATE_STARTED = PrintJobInfoProto.STATE_STARTED; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 118 | |
| 119 | /** |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 120 | * Print job state: The print job is blocked. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 121 | * <p> |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 122 | * Next valid states: {@link #STATE_FAILED}, {@link #STATE_CANCELED}, |
| 123 | * {@link #STATE_STARTED} |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 124 | * </p> |
| 125 | */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 126 | public static final int STATE_BLOCKED = PrintJobInfoProto.STATE_BLOCKED; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 127 | |
| 128 | /** |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 129 | * Print job state: The print job is successfully printed. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 130 | * This is a terminal state. |
| 131 | * <p> |
| 132 | * Next valid states: None |
| 133 | * </p> |
| 134 | */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 135 | public static final int STATE_COMPLETED = PrintJobInfoProto.STATE_COMPLETED; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 136 | |
| 137 | /** |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 138 | * Print job state: The print job was printing but printing failed. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 139 | * <p> |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 140 | * Next valid states: {@link #STATE_CANCELED}, {@link #STATE_STARTED} |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 141 | * </p> |
| 142 | */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 143 | public static final int STATE_FAILED = PrintJobInfoProto.STATE_FAILED; |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 144 | |
| 145 | /** |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 146 | * Print job state: The print job is canceled. |
Svetoslav Ganov | d26d489 | 2013-08-28 14:37:54 -0700 | [diff] [blame] | 147 | * This is a terminal state. |
| 148 | * <p> |
| 149 | * Next valid states: None |
| 150 | * </p> |
| 151 | */ |
Philip P. Moltmann | c0a128d | 2017-06-19 10:55:09 -0700 | [diff] [blame] | 152 | public static final int STATE_CANCELED = PrintJobInfoProto.STATE_CANCELED; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 153 | |
| 154 | /** The unique print job id. */ |
Svetoslav | 2fbd2a7 | 2013-09-16 17:53:51 -0700 | [diff] [blame] | 155 | private PrintJobId mId; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 156 | |
| 157 | /** The human readable print job label. */ |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 158 | private String mLabel; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 159 | |
| 160 | /** The unique id of the printer. */ |
| 161 | private PrinterId mPrinterId; |
| 162 | |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 163 | /** The name of the printer - internally used */ |
| 164 | private String mPrinterName; |
| 165 | |
Svetoslav Ganov | d91cb3e | 2013-10-12 15:44:42 -0700 | [diff] [blame] | 166 | /** The state of the print job. */ |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 167 | private int mState; |
| 168 | |
| 169 | /** The id of the app that created the job. */ |
| 170 | private int mAppId; |
| 171 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 172 | /** Optional tag assigned by a print service.*/ |
| 173 | private String mTag; |
| 174 | |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 175 | /** The wall time when the print job was created. */ |
| 176 | private long mCreationTime; |
| 177 | |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 178 | /** How many copies to print. */ |
| 179 | private int mCopies; |
| 180 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 181 | /** The pages to print */ |
| 182 | private PageRange[] mPageRanges; |
| 183 | |
| 184 | /** The print job attributes size. */ |
| 185 | private PrintAttributes mAttributes; |
| 186 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 187 | /** Information about the printed document. */ |
| 188 | private PrintDocumentInfo mDocumentInfo; |
| 189 | |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 190 | /** The progress made on printing this job or -1 if not set. */ |
| 191 | private float mProgress; |
| 192 | |
| 193 | /** A short string describing the status of this job. */ |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 194 | private @Nullable CharSequence mStatus; |
| 195 | |
| 196 | /** A string resource describing the status of this job. */ |
| 197 | private @StringRes int mStatusRes; |
| 198 | private @Nullable CharSequence mStatusResAppPackageName; |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 199 | |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 200 | /** Advanced printer specific options. */ |
| 201 | private Bundle mAdvancedOptions; |
| 202 | |
Svetoslav Ganov | a18661d | 2013-10-09 22:55:49 -0700 | [diff] [blame] | 203 | /** Whether we are trying to cancel this print job. */ |
| 204 | private boolean mCanceling; |
| 205 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 206 | /** @hide*/ |
| 207 | public PrintJobInfo() { |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 208 | mProgress = -1; |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | /** @hide */ |
| 212 | public PrintJobInfo(PrintJobInfo other) { |
| 213 | mId = other.mId; |
| 214 | mLabel = other.mLabel; |
| 215 | mPrinterId = other.mPrinterId; |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 216 | mPrinterName = other.mPrinterName; |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 217 | mState = other.mState; |
| 218 | mAppId = other.mAppId; |
Svetoslav Ganov | 88d1991 | 2013-07-22 12:32:03 -0700 | [diff] [blame] | 219 | mTag = other.mTag; |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 220 | mCreationTime = other.mCreationTime; |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 221 | mCopies = other.mCopies; |
| 222 | mPageRanges = other.mPageRanges; |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 223 | mAttributes = other.mAttributes; |
| 224 | mDocumentInfo = other.mDocumentInfo; |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 225 | mProgress = other.mProgress; |
| 226 | mStatus = other.mStatus; |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 227 | mStatusRes = other.mStatusRes; |
| 228 | mStatusResAppPackageName = other.mStatusResAppPackageName; |
Svetoslav Ganov | a18661d | 2013-10-09 22:55:49 -0700 | [diff] [blame] | 229 | mCanceling = other.mCanceling; |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 230 | mAdvancedOptions = other.mAdvancedOptions; |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 233 | private PrintJobInfo(@NonNull Parcel parcel) { |
Svetoslav | 2fbd2a7 | 2013-09-16 17:53:51 -0700 | [diff] [blame] | 234 | mId = parcel.readParcelable(null); |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 235 | mLabel = parcel.readString(); |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 236 | mPrinterId = parcel.readParcelable(null); |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 237 | mPrinterName = parcel.readString(); |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 238 | mState = parcel.readInt(); |
| 239 | mAppId = parcel.readInt(); |
Svetoslav Ganov | 88d1991 | 2013-07-22 12:32:03 -0700 | [diff] [blame] | 240 | mTag = parcel.readString(); |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 241 | mCreationTime = parcel.readLong(); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 242 | mCopies = parcel.readInt(); |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 243 | Parcelable[] parcelables = parcel.readParcelableArray(null); |
| 244 | if (parcelables != null) { |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 245 | mPageRanges = new PageRange[parcelables.length]; |
| 246 | for (int i = 0; i < parcelables.length; i++) { |
| 247 | mPageRanges[i] = (PageRange) parcelables[i]; |
| 248 | } |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 249 | } |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 250 | mAttributes = (PrintAttributes) parcel.readParcelable(null); |
| 251 | mDocumentInfo = (PrintDocumentInfo) parcel.readParcelable(null); |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 252 | mProgress = parcel.readFloat(); |
| 253 | mStatus = parcel.readCharSequence(); |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 254 | mStatusRes = parcel.readInt(); |
| 255 | mStatusResAppPackageName = parcel.readCharSequence(); |
Svetoslav Ganov | a18661d | 2013-10-09 22:55:49 -0700 | [diff] [blame] | 256 | mCanceling = (parcel.readInt() == 1); |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 257 | mAdvancedOptions = parcel.readBundle(); |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 258 | |
| 259 | if (mAdvancedOptions != null) { |
| 260 | Preconditions.checkArgument(!mAdvancedOptions.containsKey(null)); |
| 261 | } |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 264 | /** |
| 265 | * Gets the unique print job id. |
| 266 | * |
| 267 | * @return The id. |
| 268 | */ |
Philip P. Moltmann | 22f86b4 | 2016-01-15 09:49:00 -0800 | [diff] [blame] | 269 | public @Nullable PrintJobId getId() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 270 | return mId; |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Sets the unique print job id. |
| 275 | * |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 276 | * @param id The job id. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 277 | * |
| 278 | * @hide |
| 279 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 280 | public void setId(@NonNull PrintJobId id) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 281 | this.mId = id; |
| 282 | } |
| 283 | |
| 284 | /** |
| 285 | * Gets the human readable job label. |
| 286 | * |
| 287 | * @return The label. |
| 288 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 289 | public @NonNull String getLabel() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 290 | return mLabel; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Sets the human readable job label. |
| 295 | * |
| 296 | * @param label The label. |
| 297 | * |
| 298 | * @hide |
| 299 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 300 | public void setLabel(@NonNull String label) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 301 | mLabel = label; |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Gets the unique target printer id. |
| 306 | * |
| 307 | * @return The target printer id. |
| 308 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 309 | public @Nullable PrinterId getPrinterId() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 310 | return mPrinterId; |
| 311 | } |
| 312 | |
| 313 | /** |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 314 | * Sets the unique target printer id. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 315 | * |
| 316 | * @param printerId The target printer id. |
| 317 | * |
| 318 | * @hide |
| 319 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 320 | public void setPrinterId(@NonNull PrinterId printerId) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 321 | mPrinterId = printerId; |
| 322 | } |
| 323 | |
| 324 | /** |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 325 | * Gets the name of the target printer. |
| 326 | * |
| 327 | * @return The printer name. |
| 328 | * |
| 329 | * @hide |
| 330 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 331 | public @Nullable String getPrinterName() { |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 332 | return mPrinterName; |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Sets the name of the target printer. |
| 337 | * |
| 338 | * @param printerName The printer name. |
| 339 | * |
| 340 | * @hide |
| 341 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 342 | public void setPrinterName(@NonNull String printerName) { |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 343 | mPrinterName = printerName; |
| 344 | } |
| 345 | |
| 346 | /** |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 347 | * Gets the current job state. |
| 348 | * |
| 349 | * @return The job state. |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 350 | * |
| 351 | * @see #STATE_CREATED |
| 352 | * @see #STATE_QUEUED |
| 353 | * @see #STATE_STARTED |
| 354 | * @see #STATE_COMPLETED |
| 355 | * @see #STATE_BLOCKED |
| 356 | * @see #STATE_FAILED |
| 357 | * @see #STATE_CANCELED |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 358 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 359 | public @State int getState() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 360 | return mState; |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Sets the current job state. |
| 365 | * |
| 366 | * @param state The job state. |
| 367 | * |
| 368 | * @hide |
| 369 | */ |
| 370 | public void setState(int state) { |
| 371 | mState = state; |
| 372 | } |
| 373 | |
| 374 | /** |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 375 | * Sets the progress of the print job. |
| 376 | * |
| 377 | * @param progress the progress of the job |
| 378 | * |
| 379 | * @hide |
| 380 | */ |
| 381 | public void setProgress(@FloatRange(from=0.0, to=1.0) float progress) { |
| 382 | Preconditions.checkArgumentInRange(progress, 0, 1, "progress"); |
| 383 | |
| 384 | mProgress = progress; |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * Sets the status of the print job. |
| 389 | * |
| 390 | * @param status the status of the job, can be null |
| 391 | * |
| 392 | * @hide |
| 393 | */ |
| 394 | public void setStatus(@Nullable CharSequence status) { |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 395 | mStatusRes = 0; |
| 396 | mStatusResAppPackageName = null; |
| 397 | |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 398 | mStatus = status; |
| 399 | } |
| 400 | |
| 401 | /** |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 402 | * Sets the status of the print job. |
| 403 | * |
| 404 | * @param status The new status as a string resource |
| 405 | * @param appPackageName App package name the resource belongs to |
| 406 | * |
| 407 | * @hide |
| 408 | */ |
| 409 | public void setStatus(@StringRes int status, @NonNull CharSequence appPackageName) { |
| 410 | mStatus = null; |
| 411 | |
| 412 | mStatusRes = status; |
| 413 | mStatusResAppPackageName = appPackageName; |
| 414 | } |
| 415 | |
| 416 | /** |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 417 | * Sets the owning application id. |
| 418 | * |
| 419 | * @return The owning app id. |
| 420 | * |
| 421 | * @hide |
| 422 | */ |
| 423 | public int getAppId() { |
| 424 | return mAppId; |
| 425 | } |
| 426 | |
| 427 | /** |
| 428 | * Sets the owning application id. |
| 429 | * |
| 430 | * @param appId The owning app id. |
| 431 | * |
| 432 | * @hide |
| 433 | */ |
| 434 | public void setAppId(int appId) { |
| 435 | mAppId = appId; |
| 436 | } |
| 437 | |
| 438 | /** |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 439 | * Gets the optional tag assigned by a print service. |
| 440 | * |
| 441 | * @return The tag. |
Svetoslav | b450d0d | 2013-10-04 16:20:00 -0700 | [diff] [blame] | 442 | * |
| 443 | * @hide |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 444 | */ |
| 445 | public String getTag() { |
| 446 | return mTag; |
| 447 | } |
| 448 | |
| 449 | /** |
| 450 | * Sets the optional tag assigned by a print service. |
| 451 | * |
| 452 | * @param tag The tag. |
| 453 | * |
| 454 | * @hide |
| 455 | */ |
| 456 | public void setTag(String tag) { |
| 457 | mTag = tag; |
| 458 | } |
| 459 | |
| 460 | /** |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 461 | * Gets the wall time in millisecond when this print job was created. |
| 462 | * |
| 463 | * @return The creation time in milliseconds. |
| 464 | */ |
| 465 | public long getCreationTime() { |
| 466 | return mCreationTime; |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * Sets the wall time in milliseconds when this print job was created. |
| 471 | * |
| 472 | * @param creationTime The creation time in milliseconds. |
| 473 | * |
| 474 | * @hide |
| 475 | */ |
| 476 | public void setCreationTime(long creationTime) { |
| 477 | if (creationTime < 0) { |
| 478 | throw new IllegalArgumentException("creationTime must be non-negative."); |
| 479 | } |
| 480 | mCreationTime = creationTime; |
| 481 | } |
| 482 | |
| 483 | /** |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 484 | * Gets the number of copies. |
| 485 | * |
| 486 | * @return The number of copies or zero if not set. |
| 487 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 488 | public @IntRange(from = 0) int getCopies() { |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 489 | return mCopies; |
| 490 | } |
| 491 | |
| 492 | /** |
| 493 | * Sets the number of copies. |
| 494 | * |
| 495 | * @param copyCount The number of copies. |
| 496 | * |
| 497 | * @hide |
| 498 | */ |
| 499 | public void setCopies(int copyCount) { |
| 500 | if (copyCount < 1) { |
| 501 | throw new IllegalArgumentException("Copies must be more than one."); |
| 502 | } |
| 503 | mCopies = copyCount; |
| 504 | } |
| 505 | |
| 506 | /** |
Svetoslav | 53f57d1 | 2013-06-22 00:26:49 -0700 | [diff] [blame] | 507 | * Gets the included pages. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 508 | * |
Svetoslav | 53f57d1 | 2013-06-22 00:26:49 -0700 | [diff] [blame] | 509 | * @return The included pages or <code>null</code> if not set. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 510 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 511 | public @Nullable PageRange[] getPages() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 512 | return mPageRanges; |
| 513 | } |
| 514 | |
| 515 | /** |
Svetoslav | 53f57d1 | 2013-06-22 00:26:49 -0700 | [diff] [blame] | 516 | * Sets the included pages. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 517 | * |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 518 | * @param pageRanges The included pages. |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 519 | * |
| 520 | * @hide |
| 521 | */ |
Svetoslav | 53f57d1 | 2013-06-22 00:26:49 -0700 | [diff] [blame] | 522 | public void setPages(PageRange[] pageRanges) { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 523 | mPageRanges = pageRanges; |
| 524 | } |
| 525 | |
| 526 | /** |
| 527 | * Gets the print job attributes. |
| 528 | * |
| 529 | * @return The attributes. |
| 530 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 531 | public @NonNull PrintAttributes getAttributes() { |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 532 | return mAttributes; |
| 533 | } |
| 534 | |
| 535 | /** |
| 536 | * Sets the print job attributes. |
| 537 | * |
| 538 | * @param attributes The attributes. |
| 539 | * |
| 540 | * @hide |
| 541 | */ |
| 542 | public void setAttributes(PrintAttributes attributes) { |
| 543 | mAttributes = attributes; |
| 544 | } |
| 545 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 546 | /** |
| 547 | * Gets the info describing the printed document. |
| 548 | * |
| 549 | * @return The document info. |
| 550 | * |
| 551 | * @hide |
| 552 | */ |
Mathew Inwood | 06bf4b7 | 2018-07-31 16:36:56 +0100 | [diff] [blame] | 553 | @UnsupportedAppUsage |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 554 | public PrintDocumentInfo getDocumentInfo() { |
| 555 | return mDocumentInfo; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 558 | /** |
| 559 | * Sets the info describing the printed document. |
| 560 | * |
| 561 | * @param info The document info. |
| 562 | * |
| 563 | * @hide |
| 564 | */ |
| 565 | public void setDocumentInfo(PrintDocumentInfo info) { |
| 566 | mDocumentInfo = info; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 567 | } |
| 568 | |
Svetoslav Ganov | a18661d | 2013-10-09 22:55:49 -0700 | [diff] [blame] | 569 | /** |
| 570 | * Gets whether this print is being cancelled. |
| 571 | * |
| 572 | * @return True if the print job is being cancelled. |
| 573 | * |
| 574 | * @hide |
| 575 | */ |
| 576 | public boolean isCancelling() { |
| 577 | return mCanceling; |
| 578 | } |
| 579 | |
| 580 | /** |
| 581 | * Sets whether this print is being cancelled. |
| 582 | * |
| 583 | * @param cancelling True if the print job is being cancelled. |
| 584 | * |
| 585 | * @hide |
| 586 | */ |
| 587 | public void setCancelling(boolean cancelling) { |
| 588 | mCanceling = cancelling; |
| 589 | } |
| 590 | |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 591 | /** |
Philip P. Moltmann | 9462032 | 2018-05-15 12:59:38 -0700 | [diff] [blame] | 592 | * If the print job is actively processed, i.e. the device needs to stay on. |
| 593 | * |
| 594 | * @hide |
| 595 | */ |
| 596 | public boolean shouldStayAwake() { |
| 597 | return mCanceling || mState == STATE_STARTED || mState == STATE_QUEUED; |
| 598 | } |
| 599 | |
| 600 | /** |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 601 | * Gets whether this job has a given advanced (printer specific) print |
| 602 | * option. |
| 603 | * |
| 604 | * @param key The option key. |
| 605 | * @return Whether the option is present. |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 606 | */ |
| 607 | public boolean hasAdvancedOption(String key) { |
| 608 | return mAdvancedOptions != null && mAdvancedOptions.containsKey(key); |
| 609 | } |
| 610 | |
| 611 | /** |
| 612 | * Gets the value of an advanced (printer specific) print option. |
| 613 | * |
| 614 | * @param key The option key. |
| 615 | * @return The option value. |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 616 | */ |
| 617 | public String getAdvancedStringOption(String key) { |
| 618 | if (mAdvancedOptions != null) { |
| 619 | return mAdvancedOptions.getString(key); |
| 620 | } |
| 621 | return null; |
| 622 | } |
| 623 | |
| 624 | /** |
| 625 | * Gets the value of an advanced (printer specific) print option. |
| 626 | * |
| 627 | * @param key The option key. |
| 628 | * @return The option value. |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 629 | */ |
| 630 | public int getAdvancedIntOption(String key) { |
| 631 | if (mAdvancedOptions != null) { |
| 632 | return mAdvancedOptions.getInt(key); |
| 633 | } |
| 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | /** |
| 638 | * Gets the advanced options. |
| 639 | * |
| 640 | * @return The advanced options. |
| 641 | * |
| 642 | * @hide |
| 643 | */ |
Mathew Inwood | 06bf4b7 | 2018-07-31 16:36:56 +0100 | [diff] [blame] | 644 | @UnsupportedAppUsage |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 645 | public Bundle getAdvancedOptions() { |
| 646 | return mAdvancedOptions; |
| 647 | } |
| 648 | |
| 649 | /** |
| 650 | * Sets the advanced options. |
| 651 | * |
| 652 | * @param options The advanced options. |
| 653 | * |
| 654 | * @hide |
| 655 | */ |
| 656 | public void setAdvancedOptions(Bundle options) { |
| 657 | mAdvancedOptions = options; |
| 658 | } |
| 659 | |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 660 | @Override |
| 661 | public int describeContents() { |
| 662 | return 0; |
| 663 | } |
| 664 | |
| 665 | @Override |
| 666 | public void writeToParcel(Parcel parcel, int flags) { |
Svetoslav | 2fbd2a7 | 2013-09-16 17:53:51 -0700 | [diff] [blame] | 667 | parcel.writeParcelable(mId, flags); |
Svetoslav | 269403b | 2013-08-14 17:31:04 -0700 | [diff] [blame] | 668 | parcel.writeString(mLabel); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 669 | parcel.writeParcelable(mPrinterId, flags); |
Svetoslav Ganov | 798bed6 | 2013-08-11 12:29:39 -0700 | [diff] [blame] | 670 | parcel.writeString(mPrinterName); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 671 | parcel.writeInt(mState); |
| 672 | parcel.writeInt(mAppId); |
Svetoslav Ganov | 88d1991 | 2013-07-22 12:32:03 -0700 | [diff] [blame] | 673 | parcel.writeString(mTag); |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 674 | parcel.writeLong(mCreationTime); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 675 | parcel.writeInt(mCopies); |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 676 | parcel.writeParcelableArray(mPageRanges, flags); |
| 677 | parcel.writeParcelable(mAttributes, flags); |
| 678 | parcel.writeParcelable(mDocumentInfo, 0); |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 679 | parcel.writeFloat(mProgress); |
| 680 | parcel.writeCharSequence(mStatus); |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 681 | parcel.writeInt(mStatusRes); |
| 682 | parcel.writeCharSequence(mStatusResAppPackageName); |
Svetoslav Ganov | a18661d | 2013-10-09 22:55:49 -0700 | [diff] [blame] | 683 | parcel.writeInt(mCanceling ? 1 : 0); |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 684 | parcel.writeBundle(mAdvancedOptions); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | @Override |
| 688 | public String toString() { |
| 689 | StringBuilder builder = new StringBuilder(); |
| 690 | builder.append("PrintJobInfo{"); |
| 691 | builder.append("label: ").append(mLabel); |
| 692 | builder.append(", id: ").append(mId); |
Svetoslav Ganov | d91cb3e | 2013-10-12 15:44:42 -0700 | [diff] [blame] | 693 | builder.append(", state: ").append(stateToString(mState)); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 694 | builder.append(", printer: " + mPrinterId); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 695 | builder.append(", tag: ").append(mTag); |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 696 | builder.append(", creationTime: " + mCreationTime); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 697 | builder.append(", copies: ").append(mCopies); |
Svetoslav Ganov | a002715 | 2013-06-25 14:59:53 -0700 | [diff] [blame] | 698 | builder.append(", attributes: " + (mAttributes != null |
| 699 | ? mAttributes.toString() : null)); |
| 700 | builder.append(", documentInfo: " + (mDocumentInfo != null |
| 701 | ? mDocumentInfo.toString() : null)); |
Svetoslav Ganov | a18661d | 2013-10-09 22:55:49 -0700 | [diff] [blame] | 702 | builder.append(", cancelling: " + mCanceling); |
Svetoslav Ganov | 85b1f88 | 2013-07-24 17:00:06 -0700 | [diff] [blame] | 703 | builder.append(", pages: " + (mPageRanges != null |
| 704 | ? Arrays.toString(mPageRanges) : null)); |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 705 | builder.append(", hasAdvancedOptions: " + (mAdvancedOptions != null)); |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 706 | builder.append(", progress: " + mProgress); |
| 707 | builder.append(", status: " + (mStatus != null |
| 708 | ? mStatus.toString() : null)); |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 709 | builder.append(", statusRes: " + mStatusRes); |
| 710 | builder.append(", statusResAppPackageName: " + (mStatusResAppPackageName != null |
| 711 | ? mStatusResAppPackageName.toString() : null)); |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 712 | builder.append("}"); |
| 713 | return builder.toString(); |
| 714 | } |
| 715 | |
| 716 | /** @hide */ |
| 717 | public static String stateToString(int state) { |
| 718 | switch (state) { |
| 719 | case STATE_CREATED: { |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 720 | return "STATE_CREATED"; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 721 | } |
| 722 | case STATE_QUEUED: { |
| 723 | return "STATE_QUEUED"; |
| 724 | } |
| 725 | case STATE_STARTED: { |
| 726 | return "STATE_STARTED"; |
| 727 | } |
Svetoslav Ganov | d91cb3e | 2013-10-12 15:44:42 -0700 | [diff] [blame] | 728 | case STATE_BLOCKED: { |
| 729 | return "STATE_BLOCKED"; |
| 730 | } |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 731 | case STATE_FAILED: { |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 732 | return "STATE_FAILED"; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 733 | } |
| 734 | case STATE_COMPLETED: { |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 735 | return "STATE_COMPLETED"; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 736 | } |
| 737 | case STATE_CANCELED: { |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 738 | return "STATE_CANCELED"; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 739 | } |
| 740 | default: { |
Svetoslav Ganov | 704697b | 2013-09-21 20:30:24 -0700 | [diff] [blame] | 741 | return "STATE_UNKNOWN"; |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 742 | } |
| 743 | } |
| 744 | } |
| 745 | |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 746 | /** |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 747 | * Get the progress that has been made printing this job. |
| 748 | * |
| 749 | * @return the print progress or -1 if not set |
| 750 | * @hide |
| 751 | */ |
| 752 | @TestApi |
| 753 | public float getProgress() { |
| 754 | return mProgress; |
| 755 | } |
| 756 | |
| 757 | /** |
| 758 | * Get the status of this job. |
| 759 | * |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 760 | * @param pm Package manager used to resolve the string |
| 761 | * |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 762 | * @return the status of this job or null if not set |
| 763 | * @hide |
| 764 | */ |
| 765 | @TestApi |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 766 | public @Nullable CharSequence getStatus(@NonNull PackageManager pm) { |
| 767 | if (mStatusRes == 0) { |
| 768 | return mStatus; |
| 769 | } else { |
| 770 | try { |
| 771 | return pm.getResourcesForApplication(mStatusResAppPackageName.toString()) |
| 772 | .getString(mStatusRes); |
| 773 | } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) { |
| 774 | return null; |
| 775 | } |
| 776 | } |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 777 | } |
| 778 | |
| 779 | /** |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 780 | * Builder for creating a {@link PrintJobInfo}. |
| 781 | */ |
| 782 | public static final class Builder { |
| 783 | private final PrintJobInfo mPrototype; |
| 784 | |
| 785 | /** |
| 786 | * Constructor. |
| 787 | * |
| 788 | * @param prototype Prototype to use as a starting point. |
Svetoslav Ganov | 4d4c66d | 2013-10-24 18:04:39 -0700 | [diff] [blame] | 789 | * Can be <code>null</code>. |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 790 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 791 | public Builder(@Nullable PrintJobInfo prototype) { |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 792 | mPrototype = (prototype != null) |
| 793 | ? new PrintJobInfo(prototype) |
| 794 | : new PrintJobInfo(); |
| 795 | } |
| 796 | |
| 797 | /** |
| 798 | * Sets the number of copies. |
| 799 | * |
| 800 | * @param copies The number of copies. |
| 801 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 802 | public void setCopies(@IntRange(from = 1) int copies) { |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 803 | mPrototype.mCopies = copies; |
| 804 | } |
| 805 | |
| 806 | /** |
| 807 | * Sets the print job attributes. |
| 808 | * |
| 809 | * @param attributes The attributes. |
| 810 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 811 | public void setAttributes(@NonNull PrintAttributes attributes) { |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 812 | mPrototype.mAttributes = attributes; |
| 813 | } |
| 814 | |
| 815 | /** |
| 816 | * Sets the included pages. |
| 817 | * |
| 818 | * @param pages The included pages. |
| 819 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 820 | public void setPages(@NonNull PageRange[] pages) { |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 821 | mPrototype.mPageRanges = pages; |
| 822 | } |
| 823 | |
| 824 | /** |
Philip P. Moltmann | b3078c2 | 2015-11-23 16:12:39 -0800 | [diff] [blame] | 825 | * Sets the progress of the print job. |
| 826 | * |
| 827 | * @param progress the progress of the job |
| 828 | * @hide |
| 829 | */ |
| 830 | public void setProgress(@FloatRange(from=0.0, to=1.0) float progress) { |
| 831 | Preconditions.checkArgumentInRange(progress, 0, 1, "progress"); |
| 832 | |
| 833 | mPrototype.mProgress = progress; |
| 834 | } |
| 835 | |
| 836 | /** |
| 837 | * Sets the status of the print job. |
| 838 | * |
| 839 | * @param status the status of the job, can be null |
| 840 | * @hide |
| 841 | */ |
| 842 | public void setStatus(@Nullable CharSequence status) { |
| 843 | mPrototype.mStatus = status; |
| 844 | } |
| 845 | |
| 846 | /** |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 847 | * Puts an advanced (printer specific) option. |
| 848 | * |
| 849 | * @param key The option key. |
| 850 | * @param value The option value. |
| 851 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 852 | public void putAdvancedOption(@NonNull String key, @Nullable String value) { |
Philip P. Moltmann | d74d1e5 | 2016-03-17 16:37:47 -0700 | [diff] [blame] | 853 | Preconditions.checkNotNull(key, "key cannot be null"); |
| 854 | |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 855 | if (mPrototype.mAdvancedOptions == null) { |
| 856 | mPrototype.mAdvancedOptions = new Bundle(); |
| 857 | } |
| 858 | mPrototype.mAdvancedOptions.putString(key, value); |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | /** |
| 862 | * Puts an advanced (printer specific) option. |
| 863 | * |
| 864 | * @param key The option key. |
| 865 | * @param value The option value. |
| 866 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 867 | public void putAdvancedOption(@NonNull String key, int value) { |
Svetoslav | b4fda13 | 2013-10-25 18:57:43 -0700 | [diff] [blame] | 868 | if (mPrototype.mAdvancedOptions == null) { |
| 869 | mPrototype.mAdvancedOptions = new Bundle(); |
| 870 | } |
| 871 | mPrototype.mAdvancedOptions.putInt(key, value); |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | /** |
| 875 | * Creates a new {@link PrintJobInfo} instance. |
| 876 | * |
| 877 | * @return The new instance. |
| 878 | */ |
Philip P. Moltmann | c43639c | 2015-12-18 13:58:40 -0800 | [diff] [blame] | 879 | public @NonNull PrintJobInfo build() { |
Svetoslav | 1c43fce | 2013-10-16 10:57:48 -0700 | [diff] [blame] | 880 | return mPrototype; |
| 881 | } |
| 882 | } |
| 883 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 884 | public static final @android.annotation.NonNull Parcelable.Creator<PrintJobInfo> CREATOR = |
Svetoslav Ganov | 4b9a4d1 | 2013-06-11 15:20:06 -0700 | [diff] [blame] | 885 | new Creator<PrintJobInfo>() { |
| 886 | @Override |
| 887 | public PrintJobInfo createFromParcel(Parcel parcel) { |
| 888 | return new PrintJobInfo(parcel); |
| 889 | } |
| 890 | |
| 891 | @Override |
| 892 | public PrintJobInfo[] newArray(int size) { |
| 893 | return new PrintJobInfo[size]; |
| 894 | } |
| 895 | }; |
| 896 | } |