android.print.PrintJobInfo Java Examples

The following examples show how to use android.print.PrintJobInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PrintJob.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #2
Source File: PrintService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #3
Source File: TemplatePrinterActivity.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #4
Source File: PrintJob.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
PrintJob(@NonNull Context context, @NonNull PrintJobInfo jobInfo,
        @NonNull IPrintServiceClient client) {
    mContext = context;
    mCachedInfo = jobInfo;
    mPrintServiceClient = client;
    mDocument = new PrintDocument(mCachedInfo.getId(), client,
            jobInfo.getDocumentInfo());
}
 
Example #5
Source File: PrintManagerDelegateImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #6
Source File: PrintJob.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #7
Source File: PrintJob.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private boolean isInImmutableState() {
    final int state = mCachedInfo.getState();
    return state == PrintJobInfo.STATE_COMPLETED
            || state == PrintJobInfo.STATE_CANCELED
            || state == PrintJobInfo.STATE_FAILED;
}
 
Example #8
Source File: PrintJobProxy.java    From NewXmPluginSDK with Apache License 2.0 4 votes vote down vote up
public PrintJobInfo getInfo() {
    return printJob.getInfo();
}
 
Example #9
Source File: PrintJob.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}
 
Example #10
Source File: PrintJob.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}
 
Example #11
Source File: PrintJob.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}
 
Example #12
Source File: PrintJob.java    From android_9.0.0_r45 with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
}
 
Example #13
Source File: PrintJob.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: PrintJob.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * 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;
}
 
Example #15
Source File: PrintJob.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * 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;
}
 
Example #16
Source File: PrintJob.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * 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;
}
 
Example #17
Source File: PrintJob.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * 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;
}
 
Example #18
Source File: PrintJob.java    From android_9.0.0_r45 with Apache License 2.0 2 votes vote down vote up
/**
 * 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;
}