Java源码示例:android.print.PrintJobInfo

示例1
/**
 * Gets the {@link PrintJobInfo} that describes this job.
 * <p>
 * <strong>Node:</strong>The returned info object is a snapshot of the
 * current print job state. Every call to this method returns a fresh
 * info object that reflects the current print job state.
 * </p>
 *
 * @return The print job info.
 */
@MainThread
public @NonNull PrintJobInfo getInfo() {
    PrintService.throwIfNotCalledOnMainThread();
    if (isInImmutableState()) {
        return mCachedInfo;
    }
    PrintJobInfo info = null;
    try {
        info = mPrintServiceClient.getPrintJobInfo(mCachedInfo.getId());
    } catch (RemoteException re) {
        Log.e(LOG_TAG, "Couldn't get info for job: " + mCachedInfo.getId(), re);
    }
    if (info != null) {
        mCachedInfo = info;
    }
    return mCachedInfo;
}
 
示例2
/**
 * Gets the active print jobs for the printers managed by this service.
 * Active print jobs are ones that are not in a final state, i.e. whose
 * state is queued or started.
 *
 * @return The active print jobs.
 *
 * @see PrintJob#isQueued() PrintJob.isQueued()
 * @see PrintJob#isStarted() PrintJob.isStarted()
 */
public final List<PrintJob> getActivePrintJobs() {
    throwIfNotCalledOnMainThread();
    if (mClient == null) {
        return Collections.emptyList();
    }
    try {
        List<PrintJob> printJobs = null;
        List<PrintJobInfo> printJobInfos = mClient.getPrintJobInfos();
        if (printJobInfos != null) {
            final int printJobInfoCount = printJobInfos.size();
            printJobs = new ArrayList<PrintJob>(printJobInfoCount);
            for (int i = 0; i < printJobInfoCount; i++) {
                printJobs.add(new PrintJob(this, printJobInfos.get(i), mClient));
            }
        }
        if (printJobs != null) {
            return printJobs;
        }
    } catch (RemoteException re) {
        Log.e(LOG_TAG, "Error calling getPrintJobs()", re);
    }
    return Collections.emptyList();
}
 
示例3
PrintJob(@NonNull Context context, @NonNull PrintJobInfo jobInfo,
        @NonNull IPrintServiceClient client) {
    mContext = context;
    mCachedInfo = jobInfo;
    mPrintServiceClient = client;
    mDocument = new PrintDocument(mCachedInfo.getId(), client,
            jobInfo.getDocumentInfo());
}
 
示例4
/**
 * Completes the print job. You should call this method if {@link
 * #isStarted()} returns true and you are done printing.
 *
 * @return Whether the job as completed.
 *
 * @see #isStarted()
 */
@MainThread
public boolean complete() {
    PrintService.throwIfNotCalledOnMainThread();
    if (isStarted()) {
        return setState(PrintJobInfo.STATE_COMPLETED, null);
    }
    return false;
}
 
示例5
@RemovableInRelease
private void dumpJobStatesForDebug() {
    List<PrintJob> printJobs = mPrintManager.getPrintJobs();
    String[] states = new String[printJobs.size()];

    for (int i = 0; i < printJobs.size(); i++) {
        String stateString;
        switch (printJobs.get(i).getInfo().getState()) {
            case PrintJobInfo.STATE_CREATED:
                stateString = "STATE_CREATED";
                break;
            case PrintJobInfo.STATE_QUEUED:
                stateString = "STATE_QUEUED";
                break;
            case PrintJobInfo.STATE_STARTED:
                stateString = "STATE_STARTED";
                break;
            case PrintJobInfo.STATE_BLOCKED:
                stateString = "STATE_BLOCKED";
                break;
            case PrintJobInfo.STATE_FAILED:
                stateString = "STATE_FAILED";
                break;
            case PrintJobInfo.STATE_COMPLETED:
                stateString = "STATE_COMPLETED";
                break;
            case PrintJobInfo.STATE_CANCELED:
                stateString = "STATE_CANCELED";
                break;
            default:
                stateString = "STATE_UNKNOWN";
                break;
        }
        states[i] = stateString;
    }
    Log.v(TAG, "Initiating new print with states in queue: {%s}", TextUtils.join(", ", states));
}
 
示例6
@Override
public void onFinish() {
    delegate.onFinish();
    String printDialogTitle = Localization.get("print.dialog.title");
    String msg = "";
    boolean printInitiated = false;
    switch (printJob.getInfo().getState()) {
        case PrintJobInfo.STATE_BLOCKED:
            msg = Localization.get("printjob.blocked");
            break;
        case PrintJobInfo.STATE_CANCELED:
            msg = Localization.get("printjob.not.started");
            break;
        case PrintJobInfo.STATE_COMPLETED:
            msg = Localization.get("printing.done");
            printInitiated = true;
            break;
        case PrintJobInfo.STATE_FAILED:
            msg = Localization.get("print.error");
            break;
        case PrintJobInfo.STATE_CREATED:
        case PrintJobInfo.STATE_QUEUED:
        case PrintJobInfo.STATE_STARTED:
            msg = Localization.get("printjob.started");
            printInitiated = true;
    }
    TemplatePrinterUtils.showPrintStatusDialog(activity, printDialogTitle, msg,
            printInitiated);
}
 
示例7
private boolean isInImmutableState() {
    final int state = mCachedInfo.getState();
    return state == PrintJobInfo.STATE_COMPLETED
            || state == PrintJobInfo.STATE_CANCELED
            || state == PrintJobInfo.STATE_FAILED;
}
 
示例8
public PrintJobInfo getInfo() {
    return printJob.getInfo();
}
 
示例9
/**
 * Starts the print job. You should call this method if {@link
 * #isQueued()} or {@link #isBlocked()} returns true and you started
 * resumed printing.
 * <p>
 * This resets the print status to null. Set the new status by using {@link #setStatus}.
 * </p>
 *
 * @return Whether the job was started.
 *
 * @see #isQueued()
 * @see #isBlocked()
 */
@MainThread
public boolean start() {
    PrintService.throwIfNotCalledOnMainThread();
    final int state = getInfo().getState();
    if (state == PrintJobInfo.STATE_QUEUED
            || state == PrintJobInfo.STATE_BLOCKED) {
        return setState(PrintJobInfo.STATE_STARTED, null);
    }
    return false;
}
 
示例10
/**
 * Blocks the print job. You should call this method if {@link #isStarted()} returns true and
 * you need to block the print job. For example, the user has to add some paper to continue
 * printing. To resume the print job call {@link #start()}. To change the reason call
 * {@link #setStatus(CharSequence)}.
 *
 * @param reason The human readable, short, and translated reason why the print job is blocked.
 * @return Whether the job was blocked.
 *
 * @see #isStarted()
 * @see #isBlocked()
 */
@MainThread
public boolean block(@Nullable String reason) {
    PrintService.throwIfNotCalledOnMainThread();
    PrintJobInfo info = getInfo();
    final int state = info.getState();
    if (state == PrintJobInfo.STATE_STARTED || state == PrintJobInfo.STATE_BLOCKED) {
        return setState(PrintJobInfo.STATE_BLOCKED, reason);
    }
    return false;
}
 
示例11
/**
 * Fails the print job. You should call this method if {@link
 * #isQueued()} or {@link #isStarted()} or {@link #isBlocked()}
 * returns true you failed while printing.
 *
 * @param error The human readable, short, and translated reason
 * for the failure.
 * @return Whether the job was failed.
 *
 * @see #isQueued()
 * @see #isStarted()
 * @see #isBlocked()
 */
@MainThread
public boolean fail(@Nullable String error) {
    PrintService.throwIfNotCalledOnMainThread();
    if (!isInImmutableState()) {
        return setState(PrintJobInfo.STATE_FAILED, error);
    }
    return false;
}
 
示例12
/**
 * Cancels the print job. You should call this method if {@link
 * #isQueued()} or {@link #isStarted() or #isBlocked()} returns
 * true and you canceled the print job as a response to a call to
 * {@link PrintService#onRequestCancelPrintJob(PrintJob)}.
 *
 * @return Whether the job is canceled.
 *
 * @see #isStarted()
 * @see #isQueued()
 * @see #isBlocked()
 */
@MainThread
public boolean cancel() {
    PrintService.throwIfNotCalledOnMainThread();
    if (!isInImmutableState()) {
        return setState(PrintJobInfo.STATE_CANCELED, null);
    }
    return false;
}
 
示例13
/**
 * Gets whether this print job is queued. Such a print job is
 * ready to be printed and can be started or cancelled.
 *
 * @return Whether the print job is queued.
 *
 * @see #start()
 * @see #cancel()
 */
@MainThread
public boolean isQueued() {
    PrintService.throwIfNotCalledOnMainThread();
    return getInfo().getState() == PrintJobInfo.STATE_QUEUED;
}
 
示例14
/**
 * Gets whether this print job is started. Such a print job is
 * being printed and can be completed or canceled or failed.
 *
 * @return Whether the print job is started.
 *
 * @see #complete()
 * @see #cancel()
 * @see #fail(String)
 */
@MainThread
public boolean isStarted() {
    PrintService.throwIfNotCalledOnMainThread();
    return getInfo().getState() == PrintJobInfo.STATE_STARTED;
}
 
示例15
/**
 * Gets whether this print job is blocked. Such a print job is halted
 * due to an abnormal condition and can be started or canceled or failed.
 *
 * @return Whether the print job is blocked.
 *
 * @see #start()
 * @see #cancel()
 * @see #fail(String)
 */
@MainThread
public boolean isBlocked() {
    PrintService.throwIfNotCalledOnMainThread();
    return getInfo().getState() == PrintJobInfo.STATE_BLOCKED;
}
 
示例16
/**
 * Gets whether this print job is completed. Such a print job
 * is successfully printed. This is a final state.
 *
 * @return Whether the print job is completed.
 *
 * @see #complete()
 */
@MainThread
public boolean isCompleted() {
    PrintService.throwIfNotCalledOnMainThread();
    return getInfo().getState() == PrintJobInfo.STATE_COMPLETED;
}
 
示例17
/**
 * Gets whether this print job is failed. Such a print job is
 * not successfully printed due to an error. This is a final state.
 *
 * @return Whether the print job is failed.
 *
 * @see #fail(String)
 */
@MainThread
public boolean isFailed() {
    PrintService.throwIfNotCalledOnMainThread();
    return getInfo().getState() == PrintJobInfo.STATE_FAILED;
}
 
示例18
/**
 * Gets whether this print job is cancelled. Such a print job was
 * cancelled as a result of a user request. This is a final state.
 *
 * @return Whether the print job is cancelled.
 *
 * @see #cancel()
 */
@MainThread
public boolean isCancelled() {
    PrintService.throwIfNotCalledOnMainThread();
    return getInfo().getState() == PrintJobInfo.STATE_CANCELED;
}