Search in sources :

Example 36 with PrintJobInfo

use of android.print.PrintJobInfo in project android_frameworks_base by crdroidandroid.

the class PrintActivity method onAdvancedPrintOptionsActivityResult.

private void onAdvancedPrintOptionsActivityResult(int resultCode, Intent data) {
    if (resultCode != RESULT_OK || data == null) {
        return;
    }
    PrintJobInfo printJobInfo = data.getParcelableExtra(PrintService.EXTRA_PRINT_JOB_INFO);
    if (printJobInfo == null) {
        return;
    }
    // Take the advanced options without interpretation.
    mPrintJob.setAdvancedOptions(printJobInfo.getAdvancedOptions());
    if (printJobInfo.getCopies() < 1) {
        Log.w(LOG_TAG, "Cannot apply return value from advanced options activity. Copies " + "must be 1 or more. Actual value is: " + printJobInfo.getCopies() + ". " + "Ignoring.");
    } else {
        mCopiesEditText.setText(String.valueOf(printJobInfo.getCopies()));
        mPrintJob.setCopies(printJobInfo.getCopies());
    }
    PrintAttributes currAttributes = mPrintJob.getAttributes();
    PrintAttributes newAttributes = printJobInfo.getAttributes();
    if (newAttributes != null) {
        // Take the media size only if the current printer supports is.
        MediaSize oldMediaSize = currAttributes.getMediaSize();
        MediaSize newMediaSize = newAttributes.getMediaSize();
        if (newMediaSize != null && !oldMediaSize.equals(newMediaSize)) {
            final int mediaSizeCount = mMediaSizeSpinnerAdapter.getCount();
            MediaSize newMediaSizePortrait = newAttributes.getMediaSize().asPortrait();
            for (int i = 0; i < mediaSizeCount; i++) {
                MediaSize supportedSizePortrait = mMediaSizeSpinnerAdapter.getItem(i).value.asPortrait();
                if (supportedSizePortrait.equals(newMediaSizePortrait)) {
                    currAttributes.setMediaSize(newMediaSize);
                    mMediaSizeSpinner.setSelection(i);
                    if (currAttributes.getMediaSize().isPortrait()) {
                        if (mOrientationSpinner.getSelectedItemPosition() != 0) {
                            mOrientationSpinner.setSelection(0);
                        }
                    } else {
                        if (mOrientationSpinner.getSelectedItemPosition() != 1) {
                            mOrientationSpinner.setSelection(1);
                        }
                    }
                    break;
                }
            }
        }
        // Take the resolution only if the current printer supports is.
        Resolution oldResolution = currAttributes.getResolution();
        Resolution newResolution = newAttributes.getResolution();
        if (!oldResolution.equals(newResolution)) {
            PrinterCapabilitiesInfo capabilities = mCurrentPrinter.getCapabilities();
            if (capabilities != null) {
                List<Resolution> resolutions = capabilities.getResolutions();
                final int resolutionCount = resolutions.size();
                for (int i = 0; i < resolutionCount; i++) {
                    Resolution resolution = resolutions.get(i);
                    if (resolution.equals(newResolution)) {
                        currAttributes.setResolution(resolution);
                        break;
                    }
                }
            }
        }
        // Take the color mode only if the current printer supports it.
        final int currColorMode = currAttributes.getColorMode();
        final int newColorMode = newAttributes.getColorMode();
        if (currColorMode != newColorMode) {
            final int colorModeCount = mColorModeSpinner.getCount();
            for (int i = 0; i < colorModeCount; i++) {
                final int supportedColorMode = mColorModeSpinnerAdapter.getItem(i).value;
                if (supportedColorMode == newColorMode) {
                    currAttributes.setColorMode(newColorMode);
                    mColorModeSpinner.setSelection(i);
                    break;
                }
            }
        }
        // Take the duplex mode only if the current printer supports it.
        final int currDuplexMode = currAttributes.getDuplexMode();
        final int newDuplexMode = newAttributes.getDuplexMode();
        if (currDuplexMode != newDuplexMode) {
            final int duplexModeCount = mDuplexModeSpinner.getCount();
            for (int i = 0; i < duplexModeCount; i++) {
                final int supportedDuplexMode = mDuplexModeSpinnerAdapter.getItem(i).value;
                if (supportedDuplexMode == newDuplexMode) {
                    currAttributes.setDuplexMode(newDuplexMode);
                    mDuplexModeSpinner.setSelection(i);
                    break;
                }
            }
        }
    }
    // Handle selected page changes making sure they are in the doc.
    PrintDocumentInfo info = mPrintedDocument.getDocumentInfo().info;
    final int pageCount = (info != null) ? getAdjustedPageCount(info) : 0;
    PageRange[] pageRanges = printJobInfo.getPages();
    if (pageRanges != null && pageCount > 0) {
        pageRanges = PageRangeUtils.normalize(pageRanges);
        List<PageRange> validatedList = new ArrayList<>();
        final int rangeCount = pageRanges.length;
        for (int i = 0; i < rangeCount; i++) {
            PageRange pageRange = pageRanges[i];
            if (pageRange.getEnd() >= pageCount) {
                final int rangeStart = pageRange.getStart();
                final int rangeEnd = pageCount - 1;
                if (rangeStart <= rangeEnd) {
                    pageRange = new PageRange(rangeStart, rangeEnd);
                    validatedList.add(pageRange);
                }
                break;
            }
            validatedList.add(pageRange);
        }
        if (!validatedList.isEmpty()) {
            PageRange[] validatedArray = new PageRange[validatedList.size()];
            validatedList.toArray(validatedArray);
            updateSelectedPages(validatedArray, pageCount);
        }
    }
    // Update the content if needed.
    if (canUpdateDocument()) {
        updateDocument(false);
    }
}
Also used : PrinterCapabilitiesInfo(android.print.PrinterCapabilitiesInfo) MediaSize(android.print.PrintAttributes.MediaSize) PrintJobInfo(android.print.PrintJobInfo) ArrayList(java.util.ArrayList) PrintAttributes(android.print.PrintAttributes) RemotePrintDocumentInfo(com.android.printspooler.model.RemotePrintDocument.RemotePrintDocumentInfo) PrintDocumentInfo(android.print.PrintDocumentInfo) Resolution(android.print.PrintAttributes.Resolution) PageRange(android.print.PageRange)

Example 37 with PrintJobInfo

use of android.print.PrintJobInfo in project android_frameworks_base by crdroidandroid.

the class NotificationController method updateNotifications.

/**
     * Update notifications for the given print jobs, remove all other notifications.
     *
     * @param printJobs The print job that we want to create notifications for.
     */
private void updateNotifications(List<PrintJobInfo> printJobs) {
    ArraySet<PrintJobId> removedPrintJobs = new ArraySet<>(mNotifications);
    final int numPrintJobs = printJobs.size();
    // Create summary notification
    if (numPrintJobs > 1) {
        createStackedNotification(printJobs);
    } else {
        mNotificationManager.cancel(PRINT_JOB_NOTIFICATION_SUMMARY, 0);
    }
    // Create per print job notification
    for (int i = 0; i < numPrintJobs; i++) {
        PrintJobInfo printJob = printJobs.get(i);
        PrintJobId printJobId = printJob.getId();
        removedPrintJobs.remove(printJobId);
        mNotifications.add(printJobId);
        createSimpleNotification(printJob);
    }
    // Remove notifications for print jobs that do not exist anymore
    final int numRemovedPrintJobs = removedPrintJobs.size();
    for (int i = 0; i < numRemovedPrintJobs; i++) {
        PrintJobId removedPrintJob = removedPrintJobs.valueAt(i);
        mNotificationManager.cancel(removedPrintJob.flattenToString(), 0);
        mNotifications.remove(removedPrintJob);
    }
}
Also used : ArraySet(android.util.ArraySet) PrintJobId(android.print.PrintJobId) PrintJobInfo(android.print.PrintJobInfo)

Example 38 with PrintJobInfo

use of android.print.PrintJobInfo in project android_frameworks_base by crdroidandroid.

the class NotificationController method createStackedNotification.

private void createStackedNotification(List<PrintJobInfo> printJobs) {
    Notification.Builder builder = new Notification.Builder(mContext).setContentIntent(createContentIntent(null)).setWhen(System.currentTimeMillis()).setOngoing(true).setShowWhen(true).setGroup(PRINT_JOB_NOTIFICATION_GROUP_KEY).setGroupSummary(true);
    final int printJobCount = printJobs.size();
    InboxStyle inboxStyle = new InboxStyle();
    int icon = com.android.internal.R.drawable.ic_print;
    for (int i = printJobCount - 1; i >= 0; i--) {
        PrintJobInfo printJob = printJobs.get(i);
        inboxStyle.addLine(computeNotificationTitle(printJob));
        // if any print job is in an error state show an error icon for the summary
        if (printJob.getState() == PrintJobInfo.STATE_FAILED || printJob.getState() == PrintJobInfo.STATE_BLOCKED) {
            icon = com.android.internal.R.drawable.ic_print_error;
        }
    }
    builder.setSmallIcon(icon);
    builder.setLargeIcon(((BitmapDrawable) mContext.getResources().getDrawable(icon, null)).getBitmap());
    builder.setNumber(printJobCount);
    builder.setStyle(inboxStyle);
    builder.setColor(mContext.getColor(com.android.internal.R.color.system_notification_accent_color));
    mNotificationManager.notify(PRINT_JOB_NOTIFICATION_SUMMARY, 0, builder.build());
}
Also used : InboxStyle(android.app.Notification.InboxStyle) PrintJobInfo(android.print.PrintJobInfo) Notification(android.app.Notification)

Example 39 with PrintJobInfo

use of android.print.PrintJobInfo in project android_frameworks_base by crdroidandroid.

the class PrintSpoolerService method setPrintJobCancelling.

public void setPrintJobCancelling(PrintJobId printJobId, boolean cancelling) {
    synchronized (mLock) {
        PrintJobInfo printJob = getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY);
        if (printJob != null) {
            printJob.setCancelling(cancelling);
            if (shouldPersistPrintJob(printJob)) {
                mPersistanceManager.writeStateLocked();
            }
            mNotificationController.onUpdateNotifications(mPrintJobs);
            Message message = mHandlerCaller.obtainMessageO(HandlerCallerCallback.MSG_ON_PRINT_JOB_STATE_CHANGED, printJob);
            mHandlerCaller.executeOrSendMessage(message);
        }
    }
}
Also used : Message(android.os.Message) PrintJobInfo(android.print.PrintJobInfo)

Example 40 with PrintJobInfo

use of android.print.PrintJobInfo in project android_frameworks_base by crdroidandroid.

the class PrintSpoolerService method updatePrintJobUserConfigurableOptionsNoPersistence.

public void updatePrintJobUserConfigurableOptionsNoPersistence(PrintJobInfo printJob) {
    synchronized (mLock) {
        final int printJobCount = mPrintJobs.size();
        for (int i = 0; i < printJobCount; i++) {
            PrintJobInfo cachedPrintJob = mPrintJobs.get(i);
            if (cachedPrintJob.getId().equals(printJob.getId())) {
                cachedPrintJob.setPrinterId(printJob.getPrinterId());
                cachedPrintJob.setPrinterName(printJob.getPrinterName());
                cachedPrintJob.setCopies(printJob.getCopies());
                cachedPrintJob.setDocumentInfo(printJob.getDocumentInfo());
                cachedPrintJob.setPages(printJob.getPages());
                cachedPrintJob.setAttributes(printJob.getAttributes());
                cachedPrintJob.setAdvancedOptions(printJob.getAdvancedOptions());
                return;
            }
        }
        throw new IllegalArgumentException("No print job with id:" + printJob.getId());
    }
}
Also used : PrintJobInfo(android.print.PrintJobInfo)

Aggregations

PrintJobInfo (android.print.PrintJobInfo)110 PrintJobId (android.print.PrintJobId)18 AtomicFile (android.util.AtomicFile)15 File (java.io.File)15 PrinterId (android.print.PrinterId)14 ArrayList (java.util.ArrayList)14 MainThread (android.annotation.MainThread)10 ComponentName (android.content.ComponentName)9 NonNull (android.annotation.NonNull)5 Notification (android.app.Notification)5 InboxStyle (android.app.Notification.InboxStyle)5 Message (android.os.Message)5 RemoteException (android.os.RemoteException)5 PageRange (android.print.PageRange)5 PrintAttributes (android.print.PrintAttributes)5 MediaSize (android.print.PrintAttributes.MediaSize)5 Resolution (android.print.PrintAttributes.Resolution)5 PrintDocumentInfo (android.print.PrintDocumentInfo)5 PrinterCapabilitiesInfo (android.print.PrinterCapabilitiesInfo)5 ArraySet (android.util.ArraySet)5