use of android.print.PrintJobInfo in project android_frameworks_base by ResurrectionRemix.
the class NotificationController method onUpdateNotifications.
public void onUpdateNotifications(List<PrintJobInfo> printJobs) {
List<PrintJobInfo> notifyPrintJobs = new ArrayList<>();
final int printJobCount = printJobs.size();
for (int i = 0; i < printJobCount; i++) {
PrintJobInfo printJob = printJobs.get(i);
if (shouldNotifyForState(printJob.getState())) {
notifyPrintJobs.add(printJob);
}
}
updateNotifications(notifyPrintJobs);
}
use of android.print.PrintJobInfo in project android_frameworks_base by ResurrectionRemix.
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());
}
use of android.print.PrintJobInfo in project android_frameworks_base by ResurrectionRemix.
the class PrintSpoolerService method setStatus.
/**
* Set the status for a print job.
*
* @param printJobId ID of the print job to update
* @param status the new status
*/
public void setStatus(@NonNull PrintJobId printJobId, @Nullable CharSequence status) {
synchronized (mLock) {
PrintJobInfo printJob = getPrintJobInfo(printJobId, PrintManager.APP_ID_ANY);
if (printJob != null) {
printJob.setStatus(status);
notifyPrintJobUpdated(printJob);
}
}
}
use of android.print.PrintJobInfo in project android_frameworks_base by ResurrectionRemix.
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());
}
}
use of android.print.PrintJobInfo in project android_frameworks_base by ResurrectionRemix.
the class PrintSpoolerService method handleReadPrintJobsLocked.
private void handleReadPrintJobsLocked() {
// Make a map with the files for a print job since we may have
// to delete some. One example of getting orphan files if the
// spooler crashes while constructing a print job. We do not
// persist partially populated print jobs under construction to
// avoid special handling for various attributes missing.
ArrayMap<PrintJobId, File> fileForJobMap = null;
File[] files = getFilesDir().listFiles();
if (files != null) {
final int fileCount = files.length;
for (int i = 0; i < fileCount; i++) {
File file = files[i];
if (file.isFile() && file.getName().startsWith(PRINT_JOB_FILE_PREFIX)) {
if (fileForJobMap == null) {
fileForJobMap = new ArrayMap<PrintJobId, File>();
}
String printJobIdString = file.getName().substring(PRINT_JOB_FILE_PREFIX.length(), file.getName().indexOf('.'));
PrintJobId printJobId = PrintJobId.unflattenFromString(printJobIdString);
fileForJobMap.put(printJobId, file);
}
}
}
final int printJobCount = mPrintJobs.size();
for (int i = 0; i < printJobCount; i++) {
PrintJobInfo printJob = mPrintJobs.get(i);
// We want to have only the orphan files at the end.
if (fileForJobMap != null) {
fileForJobMap.remove(printJob.getId());
}
switch(printJob.getState()) {
case PrintJobInfo.STATE_QUEUED:
case PrintJobInfo.STATE_STARTED:
case PrintJobInfo.STATE_BLOCKED:
{
// We have a print job that was queued or started or blocked in
// the past but the device battery died or a crash occurred. In
// this case we assume the print job failed and let the user
// decide whether to restart the job or just cancel it.
setPrintJobState(printJob.getId(), PrintJobInfo.STATE_FAILED, getString(R.string.no_connection_to_printer));
}
break;
}
}
if (!mPrintJobs.isEmpty()) {
// Update the notification.
mNotificationController.onUpdateNotifications(mPrintJobs);
}
// Delete the orphan files.
if (fileForJobMap != null) {
final int orphanFileCount = fileForJobMap.size();
for (int i = 0; i < orphanFileCount; i++) {
File file = fileForJobMap.valueAt(i);
file.delete();
}
}
}
Aggregations