Small corrections to the code that generates the print summary in the settings.
- Optimize when the listener is active and rely on it to be cleaned up automatically - Only count print jobs that should be shown (i.e. not ones that are already finished.) Change-Id: Idba995f1036e736f47ca7402d493210600eae91c
This commit is contained in:
@@ -590,7 +590,14 @@ public class PrintSettingsFragment extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
return printJobInfos;
|
return printJobInfos;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Should the print job the shown to the user in the settings app.
|
||||||
|
*
|
||||||
|
* @param printJob The print job in question.
|
||||||
|
* @return true iff the print job should be shown.
|
||||||
|
*/
|
||||||
private static boolean shouldShowToUser(PrintJobInfo printJob) {
|
private static boolean shouldShowToUser(PrintJobInfo printJob) {
|
||||||
switch (printJob.getState()) {
|
switch (printJob.getState()) {
|
||||||
case PrintJobInfo.STATE_QUEUED:
|
case PrintJobInfo.STATE_QUEUED:
|
||||||
@@ -602,7 +609,6 @@ public class PrintSettingsFragment extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provider for the print settings summary
|
* Provider for the print settings summary
|
||||||
@@ -624,29 +630,32 @@ public class PrintSettingsFragment extends SettingsPreferenceFragment
|
|||||||
mSummaryLoader = summaryLoader;
|
mSummaryLoader = summaryLoader;
|
||||||
mPrintManager = ((PrintManager) context.getSystemService(Context.PRINT_SERVICE))
|
mPrintManager = ((PrintManager) context.getSystemService(Context.PRINT_SERVICE))
|
||||||
.getGlobalPrintManagerForUser(context.getUserId());
|
.getGlobalPrintManagerForUser(context.getUserId());
|
||||||
mPrintManager.addPrintJobStateChangeListener(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setListening(boolean isListening) {
|
public void setListening(boolean isListening) {
|
||||||
mPrintManager.removePrintJobStateChangeListener(this);
|
|
||||||
|
|
||||||
if (isListening) {
|
if (isListening) {
|
||||||
mPrintManager.addPrintJobStateChangeListener(this);
|
mPrintManager.addPrintJobStateChangeListener(this);
|
||||||
}
|
|
||||||
onPrintJobStateChanged(null);
|
onPrintJobStateChanged(null);
|
||||||
|
} else {
|
||||||
|
mPrintManager.removePrintJobStateChangeListener(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPrintJobStateChanged(PrintJobId printJobId) {
|
public void onPrintJobStateChanged(PrintJobId printJobId) {
|
||||||
int numPrintJobs = mPrintManager.getPrintJobs().size();
|
List<PrintJob> printJobs = mPrintManager.getPrintJobs();
|
||||||
mSummaryLoader.setSummary(this, mContext.getResources().getQuantityString(
|
|
||||||
R.plurals.print_settings_title, numPrintJobs, numPrintJobs));
|
int numActivePrintJobs = 0;
|
||||||
|
final int numPrintJobs = printJobs.size();
|
||||||
|
for (int i = 0; i < numPrintJobs; i++) {
|
||||||
|
if (shouldShowToUser(printJobs.get(i).getInfo())) {
|
||||||
|
numActivePrintJobs++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
mSummaryLoader.setSummary(this, mContext.getResources().getQuantityString(
|
||||||
protected void finalize() {
|
R.plurals.print_settings_title, numActivePrintJobs, numActivePrintJobs));
|
||||||
mPrintManager.removePrintJobStateChangeListener(this);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user