Methods Summary |
---|
public void | addHistoricalPrinter(android.print.PrinterInfo printer)
mPersistenceManager.addPrinterAndWritePrinterHistory(printer);
|
public boolean | areHistoricalPrintersLoaded()
return mPersistenceManager.mReadHistoryCompleted;
|
private boolean | cancelInternal()
if (mDiscoverySession != null
&& mDiscoverySession.isPrinterDiscoveryStarted()) {
if (mTrackedPrinter != null) {
mDiscoverySession.stopPrinterStateTracking(mTrackedPrinter);
mTrackedPrinter = null;
}
mDiscoverySession.stopPrinterDiscovery();
return true;
} else if (mPersistenceManager.isReadHistoryInProgress()) {
return mPersistenceManager.stopReadPrinterHistory();
}
return false;
|
private void | computeAndDeliverResult(java.util.Map discoveredPrinters, java.util.List favoritePrinters)
List<PrinterInfo> printers = new ArrayList<>();
// Add the updated favorite printers.
final int favoritePrinterCount = favoritePrinters.size();
for (int i = 0; i < favoritePrinterCount; i++) {
PrinterInfo favoritePrinter = favoritePrinters.get(i);
PrinterInfo updatedPrinter = discoveredPrinters.remove(
favoritePrinter.getId());
if (updatedPrinter != null) {
printers.add(updatedPrinter);
} else {
printers.add(favoritePrinter);
}
}
// Add other updated printers.
final int printerCount = mPrinters.size();
for (int i = 0; i < printerCount; i++) {
PrinterInfo printer = mPrinters.get(i);
PrinterInfo updatedPrinter = discoveredPrinters.remove(
printer.getId());
if (updatedPrinter != null) {
printers.add(updatedPrinter);
}
}
// Add the new printers, i.e. what is left.
printers.addAll(discoveredPrinters.values());
// Update the list of printers.
mPrinters.clear();
mPrinters.addAll(printers);
if (isStarted()) {
// If stated deliver the new printers.
deliverResult(printers);
} else {
// Otherwise, take a note for the change.
onContentChanged();
}
|
public void | forgetFavoritePrinter(android.print.PrinterId printerId)
List<PrinterInfo> newFavoritePrinters = null;
// Remove the printer from the favorites.
final int favoritePrinterCount = mFavoritePrinters.size();
for (int i = 0; i < favoritePrinterCount; i++) {
PrinterInfo favoritePrinter = mFavoritePrinters.get(i);
if (favoritePrinter.getId().equals(printerId)) {
newFavoritePrinters = new ArrayList<>();
newFavoritePrinters.addAll(mPrinters);
newFavoritePrinters.remove(i);
break;
}
}
// If we removed a favorite printer, we have work to do.
if (newFavoritePrinters != null) {
// Remove the printer from history and persist the latter.
mPersistenceManager.removeHistoricalPrinterAndWritePrinterHistory(printerId);
// Recompute and deliver the printers.
updatePrinters(mDiscoverySession.getPrinters(), newFavoritePrinters);
}
|
public boolean | isFavoritePrinter(android.print.PrinterId printerId)
final int printerCount = mFavoritePrinters.size();
for (int i = 0; i < printerCount; i++) {
PrinterInfo favoritePritner = mFavoritePrinters.get(i);
if (favoritePritner.getId().equals(printerId)) {
return true;
}
}
return false;
|
private void | loadInternal()
if (mDiscoverySession == null) {
PrintManager printManager = (PrintManager) getContext()
.getSystemService(Context.PRINT_SERVICE);
mDiscoverySession = printManager.createPrinterDiscoverySession();
mPersistenceManager.readPrinterHistory();
} else if (mPersistenceManager.isHistoryChanged()) {
mPersistenceManager.readPrinterHistory();
}
if (mPersistenceManager.isReadHistoryCompleted()
&& !mDiscoverySession.isPrinterDiscoveryStarted()) {
mDiscoverySession.setOnPrintersChangeListener(new OnPrintersChangeListener() {
@Override
public void onPrintersChanged() {
if (DEBUG) {
Log.i(LOG_TAG, "onPrintersChanged() count:"
+ mDiscoverySession.getPrinters().size()
+ " " + FusedPrintersProvider.this.hashCode());
}
updatePrinters(mDiscoverySession.getPrinters(), mFavoritePrinters);
}
});
final int favoriteCount = mFavoritePrinters.size();
List<PrinterId> printerIds = new ArrayList<>(favoriteCount);
for (int i = 0; i < favoriteCount; i++) {
printerIds.add(mFavoritePrinters.get(i).getId());
}
mDiscoverySession.startPrinterDiscovery(printerIds);
List<PrinterInfo> printers = mDiscoverySession.getPrinters();
if (!printers.isEmpty()) {
updatePrinters(printers, mFavoritePrinters);
}
}
|
protected void | onAbandon()
if (DEBUG) {
Log.i(LOG_TAG, "onAbandon() " + FusedPrintersProvider.this.hashCode());
}
onStopLoading();
|
protected boolean | onCancelLoad()
if (DEBUG) {
Log.i(LOG_TAG, "onCancelLoad() " + FusedPrintersProvider.this.hashCode());
}
return cancelInternal();
|
protected void | onForceLoad()
if (DEBUG) {
Log.i(LOG_TAG, "onForceLoad() " + FusedPrintersProvider.this.hashCode());
}
loadInternal();
|
protected void | onReset()
if (DEBUG) {
Log.i(LOG_TAG, "onReset() " + FusedPrintersProvider.this.hashCode());
}
onStopLoading();
mPrinters.clear();
if (mDiscoverySession != null) {
mDiscoverySession.destroy();
mDiscoverySession = null;
}
|
protected void | onStartLoading()
if (DEBUG) {
Log.i(LOG_TAG, "onStartLoading() " + FusedPrintersProvider.this.hashCode());
}
// The contract is that if we already have a valid,
// result the we have to deliver it immediately.
if (!mPrinters.isEmpty()) {
deliverResult(new ArrayList<>(mPrinters));
}
// Always load the data to ensure discovery period is
// started and to make sure obsolete printers are updated.
onForceLoad();
|
protected void | onStopLoading()
if (DEBUG) {
Log.i(LOG_TAG, "onStopLoading() " + FusedPrintersProvider.this.hashCode());
}
onCancelLoad();
|
public void | setTrackedPrinter(android.print.PrinterId printerId)
if (isStarted() && mDiscoverySession != null
&& mDiscoverySession.isPrinterDiscoveryStarted()) {
if (mTrackedPrinter != null) {
if (mTrackedPrinter.equals(printerId)) {
return;
}
mDiscoverySession.stopPrinterStateTracking(mTrackedPrinter);
}
mTrackedPrinter = printerId;
if (printerId != null) {
mDiscoverySession.startPrinterStateTracking(printerId);
}
}
|
private void | updatePrinters(java.util.List printers, java.util.List favoritePrinters)
if (mPrintersUpdatedBefore && mPrinters.equals(printers)
&& mFavoritePrinters.equals(favoritePrinters)) {
return;
}
mPrintersUpdatedBefore = true;
// Some of the found printers may have be a printer that is in the
// history but with its name changed. Hence, we try to update the
// printer to use its current name instead of the historical one.
mPersistenceManager.updatePrintersHistoricalNamesIfNeeded(printers);
Map<PrinterId, PrinterInfo> printersMap = new LinkedHashMap<>();
final int printerCount = printers.size();
for (int i = 0; i < printerCount; i++) {
PrinterInfo printer = printers.get(i);
printersMap.put(printer.getId(), printer);
}
computeAndDeliverResult(printersMap, favoritePrinters);
|