Search in sources :

Example 46 with PrinterInfo

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

the class PrinterDiscoverySession method sendOutOfDiscoveryPeriodPrinterChanges.

private void sendOutOfDiscoveryPeriodPrinterChanges() {
    // Noting changed since the last discovery period - nothing to do.
    if (mLastSentPrinters == null || mLastSentPrinters.isEmpty()) {
        mLastSentPrinters = null;
        return;
    }
    // Determine the added printers.
    List<PrinterInfo> addedPrinters = null;
    for (PrinterInfo printer : mPrinters.values()) {
        PrinterInfo sentPrinter = mLastSentPrinters.get(printer.getId());
        if (sentPrinter == null || !sentPrinter.equals(printer)) {
            if (addedPrinters == null) {
                addedPrinters = new ArrayList<PrinterInfo>();
            }
            addedPrinters.add(printer);
        }
    }
    // Send the added printers, if such.
    if (addedPrinters != null) {
        try {
            mObserver.onPrintersAdded(new ParceledListSlice<PrinterInfo>(addedPrinters));
        } catch (RemoteException re) {
            Log.e(LOG_TAG, "Error sending added printers", re);
        }
    }
    // Determine the removed printers.
    List<PrinterId> removedPrinterIds = null;
    for (PrinterInfo sentPrinter : mLastSentPrinters.values()) {
        if (!mPrinters.containsKey(sentPrinter.getId())) {
            if (removedPrinterIds == null) {
                removedPrinterIds = new ArrayList<PrinterId>();
            }
            removedPrinterIds.add(sentPrinter.getId());
        }
    }
    // Send the removed printers, if such.
    if (removedPrinterIds != null) {
        try {
            mObserver.onPrintersRemoved(new ParceledListSlice<PrinterId>(removedPrinterIds));
        } catch (RemoteException re) {
            Log.e(LOG_TAG, "Error sending removed printers", re);
        }
    }
    mLastSentPrinters = null;
}
Also used : PrinterId(android.print.PrinterId) PrinterInfo(android.print.PrinterInfo) RemoteException(android.os.RemoteException)

Aggregations

PrinterInfo (android.print.PrinterInfo)46 PrinterId (android.print.PrinterId)30 RemoteException (android.os.RemoteException)15 ArrayList (java.util.ArrayList)15 PrintManager (android.print.PrintManager)10 View (android.view.View)6 AdapterView (android.widget.AdapterView)6 ImageView (android.widget.ImageView)6 ListView (android.widget.ListView)6 SearchView (android.widget.SearchView)6 TextView (android.widget.TextView)6 Intent (android.content.Intent)5 DataSetObserver (android.database.DataSetObserver)5 Location (android.location.Location)5 OnPrintersChangeListener (android.print.PrinterDiscoverySession.OnPrintersChangeListener)5 PrintServiceInfo (android.printservice.PrintServiceInfo)5 MenuItem (android.view.MenuItem)5 OnClickListener (android.view.View.OnClickListener)5 AdapterContextMenuInfo (android.widget.AdapterView.AdapterContextMenuInfo)5 HashSet (java.util.HashSet)5