PrintJob.java revision a00271533f639c8ed36429c663889ac9f654bc72
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
17package android.print;
18
19
20/**
21 * This class represents a print job from the perspective of
22 * an application.
23 */
24public final class PrintJob {
25
26    private final int mId;
27
28    private final PrintManager mPrintManager;
29
30    private PrintJobInfo mCachedInfo;
31
32    PrintJob(PrintJobInfo info, PrintManager printManager) {
33        mCachedInfo = info;
34        mPrintManager = printManager;
35        mId = info.getId();
36    }
37
38    /**
39     * Gets the unique print job id.
40     *
41     * @return The id.
42     */
43    public int getId() {
44        return mId;
45    }
46
47    /**
48     * Gets the {@link PrintJobInfo} that describes this job.
49     * <p>
50     * <strong>Node:</strong>The returned info object is a snapshot of the
51     * current print job state. Every call to this method returns a fresh
52     * info object that reflects the current print job state.
53     * </p>
54     *
55     * @return The print job info.
56     */
57    public PrintJobInfo getInfo() {
58        PrintJobInfo info = mPrintManager.getPrintJobInfo(mId);
59        if (info != null) {
60            mCachedInfo = info;
61        }
62        return mCachedInfo;
63    }
64
65    /**
66     * Cancels this print job.
67     */
68    public void cancel() {
69        mPrintManager.cancelPrintJob(mId);
70    }
71
72    @Override
73    public boolean equals(Object obj) {
74        if (this == obj) {
75            return true;
76        }
77        if (obj == null) {
78            return false;
79        }
80        if (getClass() != obj.getClass()) {
81            return false;
82        }
83        PrintJob other = (PrintJob) obj;
84        return mId == other.mId;
85    }
86
87    @Override
88    public int hashCode() {
89        return mId;
90    }
91}
92