Methods Summary |
---|
private static int | computeNotificationIcon(android.print.PrintJobInfo printJob)
switch (printJob.getState()) {
case PrintJobInfo.STATE_FAILED:
case PrintJobInfo.STATE_BLOCKED: {
return com.android.internal.R.drawable.ic_print_error;
}
default: {
if (!printJob.isCancelling()) {
return com.android.internal.R.drawable.ic_print;
} else {
return R.drawable.stat_notify_cancelling;
}
}
}
|
private java.lang.String | computeNotificationTitle(android.print.PrintJobInfo printJob)
switch (printJob.getState()) {
case PrintJobInfo.STATE_FAILED: {
return mContext.getString(R.string.failed_notification_title_template,
printJob.getLabel());
}
case PrintJobInfo.STATE_BLOCKED: {
if (!printJob.isCancelling()) {
return mContext.getString(R.string.blocked_notification_title_template,
printJob.getLabel());
} else {
return mContext.getString(
R.string.cancelling_notification_title_template,
printJob.getLabel());
}
}
default: {
if (!printJob.isCancelling()) {
return mContext.getString(R.string.printing_notification_title_template,
printJob.getLabel());
} else {
return mContext.getString(
R.string.cancelling_notification_title_template,
printJob.getLabel());
}
}
}
|
private void | createBlockedNotification(android.print.PrintJobInfo printJob)
Notification.Builder builder = new Notification.Builder(mContext)
.setContentIntent(createContentIntent(printJob.getId()))
.setSmallIcon(computeNotificationIcon(printJob))
.setContentTitle(computeNotificationTitle(printJob))
.addAction(R.drawable.stat_notify_cancelling, mContext.getString(R.string.cancel),
createCancelIntent(printJob))
.setContentText(printJob.getPrinterName())
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.setShowWhen(true)
.setColor(mContext.getResources().getColor(
com.android.internal.R.color.system_notification_accent_color));
mNotificationManager.notify(0, builder.build());
|
private android.app.PendingIntent | createCancelIntent(android.print.PrintJobInfo printJob)
Intent intent = new Intent(mContext, NotificationBroadcastReceiver.class);
intent.setAction(INTENT_ACTION_CANCEL_PRINTJOB + "_" + printJob.getId().flattenToString());
intent.putExtra(EXTRA_PRINT_JOB_ID, printJob.getId());
return PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT);
|
private void | createCancellingNotification(android.print.PrintJobInfo printJob)
Notification.Builder builder = new Notification.Builder(mContext)
.setContentIntent(createContentIntent(printJob.getId()))
.setSmallIcon(computeNotificationIcon(printJob))
.setContentTitle(computeNotificationTitle(printJob))
.setContentText(printJob.getPrinterName())
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.setShowWhen(true)
.setColor(mContext.getResources().getColor(
com.android.internal.R.color.system_notification_accent_color));
mNotificationManager.notify(0, builder.build());
|
private android.app.PendingIntent | createContentIntent(android.print.PrintJobId printJobId)
Intent intent = new Intent(Settings.ACTION_PRINT_SETTINGS);
if (printJobId != null) {
intent.putExtra(EXTRA_PRINT_JOB_ID, printJobId.flattenToString());
intent.setData(Uri.fromParts("printjob", printJobId.flattenToString(), null));
}
return PendingIntent.getActivity(mContext, 0, intent, 0);
|
private void | createFailedNotification(android.print.PrintJobInfo printJob)
Notification.Builder builder = new Notification.Builder(mContext)
.setContentIntent(createContentIntent(printJob.getId()))
.setSmallIcon(computeNotificationIcon(printJob))
.setContentTitle(computeNotificationTitle(printJob))
.addAction(R.drawable.stat_notify_cancelling, mContext.getString(R.string.cancel),
createCancelIntent(printJob))
.addAction(R.drawable.ic_restart, mContext.getString(R.string.restart),
createRestartIntent(printJob.getId()))
.setContentText(printJob.getPrinterName())
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.setShowWhen(true)
.setColor(mContext.getResources().getColor(
com.android.internal.R.color.system_notification_accent_color));
mNotificationManager.notify(0, builder.build());
|
private void | createPrintingNotification(android.print.PrintJobInfo printJob)
Notification.Builder builder = new Notification.Builder(mContext)
.setContentIntent(createContentIntent(printJob.getId()))
.setSmallIcon(computeNotificationIcon(printJob))
.setContentTitle(computeNotificationTitle(printJob))
.addAction(R.drawable.stat_notify_cancelling, mContext.getString(R.string.cancel),
createCancelIntent(printJob))
.setContentText(printJob.getPrinterName())
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.setShowWhen(true)
.setColor(mContext.getResources().getColor(
com.android.internal.R.color.system_notification_accent_color));
mNotificationManager.notify(0, builder.build());
|
private android.app.PendingIntent | createRestartIntent(android.print.PrintJobId printJobId)
Intent intent = new Intent(mContext, NotificationBroadcastReceiver.class);
intent.setAction(INTENT_ACTION_RESTART_PRINTJOB + "_" + printJobId.flattenToString());
intent.putExtra(EXTRA_PRINT_JOB_ID, printJobId);
return PendingIntent.getBroadcast(mContext, 0, intent, PendingIntent.FLAG_ONE_SHOT);
|
private void | createSimpleNotification(android.print.PrintJobInfo printJob)
switch (printJob.getState()) {
case PrintJobInfo.STATE_FAILED: {
createFailedNotification(printJob);
} break;
case PrintJobInfo.STATE_BLOCKED: {
if (!printJob.isCancelling()) {
createBlockedNotification(printJob);
} else {
createCancellingNotification(printJob);
}
} break;
default: {
if (!printJob.isCancelling()) {
createPrintingNotification(printJob);
} else {
createCancellingNotification(printJob);
}
} break;
}
|
private void | createStackedNotification(java.util.List printJobs)
Notification.Builder builder = new Notification.Builder(mContext)
.setContentIntent(createContentIntent(null))
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.setShowWhen(true);
final int printJobCount = printJobs.size();
InboxStyle inboxStyle = new InboxStyle();
inboxStyle.setBigContentTitle(String.format(mContext.getResources().getQuantityText(
R.plurals.composite_notification_title_template,
printJobCount).toString(), printJobCount));
for (int i = printJobCount - 1; i>= 0; i--) {
PrintJobInfo printJob = printJobs.get(i);
if (i == printJobCount - 1) {
builder.setLargeIcon(((BitmapDrawable) mContext.getResources().getDrawable(
computeNotificationIcon(printJob))).getBitmap());
builder.setSmallIcon(computeNotificationIcon(printJob));
builder.setContentTitle(computeNotificationTitle(printJob));
builder.setContentText(printJob.getPrinterName());
}
inboxStyle.addLine(computeNotificationTitle(printJob));
}
builder.setNumber(printJobCount);
builder.setStyle(inboxStyle);
builder.setColor(mContext.getResources().getColor(
com.android.internal.R.color.system_notification_accent_color));
mNotificationManager.notify(0, builder.build());
|
public void | onUpdateNotifications(java.util.List 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);
}
}
updateNotification(notifyPrintJobs);
|
private void | removeNotification()
mNotificationManager.cancel(0);
|
private static boolean | shouldNotifyForState(int state)
switch (state) {
case PrintJobInfo.STATE_QUEUED:
case PrintJobInfo.STATE_STARTED:
case PrintJobInfo.STATE_FAILED:
case PrintJobInfo.STATE_COMPLETED:
case PrintJobInfo.STATE_CANCELED:
case PrintJobInfo.STATE_BLOCKED: {
return true;
}
}
return false;
|
private void | updateNotification(java.util.List printJobs)
if (printJobs.size() <= 0) {
removeNotification();
} else if (printJobs.size() == 1) {
createSimpleNotification(printJobs.get(0));
} else {
createStackedNotification(printJobs);
}
|