Search in sources :

Example 21 with PrinterInfo

use of android.print.PrinterInfo in project platform_frameworks_base by android.

the class FusedPrintersProvider method updatePrinters.

private void updatePrinters(List<PrinterInfo> printers, List<Pair<PrinterInfo, Location>> favoritePrinters, Location location) {
    if (mPrintersUpdatedBefore && mPrinters.equals(printers) && mFavoritePrinters.equals(favoritePrinters) && Objects.equals(mLocationOfLastPrinterUpdate, location)) {
        return;
    }
    mLocationOfLastPrinterUpdate = location;
    mPrintersUpdatedBefore = true;
    // Some of the found printers may have be a printer that is in the
    // history but with its properties changed. Hence, we try to update the
    // printer to use its current properties instead of the historical one.
    mPersistenceManager.updateHistoricalPrintersIfNeeded(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);
}
Also used : PrinterId(android.print.PrinterId) PrinterInfo(android.print.PrinterInfo) LinkedHashMap(java.util.LinkedHashMap)

Example 22 with PrinterInfo

use of android.print.PrinterInfo in project platform_frameworks_base by android.

the class SelectPrinterActivity method onCreateContextMenu.

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    if (view == mListView) {
        final int position = ((AdapterContextMenuInfo) menuInfo).position;
        PrinterInfo printer = (PrinterInfo) mListView.getAdapter().getItem(position);
        menu.setHeaderTitle(printer.getName());
        // Add the select menu item if applicable.
        if (printer.getStatus() != PrinterInfo.STATUS_UNAVAILABLE) {
            MenuItem selectItem = menu.add(Menu.NONE, R.string.print_select_printer, Menu.NONE, R.string.print_select_printer);
            Intent intent = new Intent();
            intent.putExtra(EXTRA_PRINTER, printer);
            selectItem.setIntent(intent);
        }
        // Add the forget menu item if applicable.
        if (mPrinterRegistry.isFavoritePrinter(printer.getId())) {
            MenuItem forgetItem = menu.add(Menu.NONE, R.string.print_forget_printer, Menu.NONE, R.string.print_forget_printer);
            Intent intent = new Intent();
            intent.putExtra(EXTRA_PRINTER_ID, printer.getId());
            forgetItem.setIntent(intent);
        }
    }
}
Also used : AdapterContextMenuInfo(android.widget.AdapterView.AdapterContextMenuInfo) MenuItem(android.view.MenuItem) Intent(android.content.Intent) PrinterInfo(android.print.PrinterInfo)

Example 23 with PrinterInfo

use of android.print.PrinterInfo in project platform_frameworks_base by android.

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)

Example 24 with PrinterInfo

use of android.print.PrinterInfo in project platform_frameworks_base by android.

the class PrinterDiscoverySession method removePrinters.

/**
     * Removes added printers. Removing an already removed or never added
     * printer has no effect. Removed printers can be added again. You can
     * call this method multiple times during the lifetime of this session.
     * <p>
     * <strong>Note: </strong> Calls to this method after the session is
     * destroyed, that is after the {@link #onDestroy()} callback, will be ignored.
     * </p>
     *
     * @param printerIds The ids of the removed printers.
     *
     * @see #addPrinters(List)
     * @see #getPrinters()
     * @see #isDestroyed()
     */
public final void removePrinters(@NonNull List<PrinterId> printerIds) {
    PrintService.throwIfNotCalledOnMainThread();
    // If the session is destroyed - nothing do to.
    if (mIsDestroyed) {
        Log.w(LOG_TAG, "Not removing printers - session destroyed.");
        return;
    }
    if (mIsDiscoveryStarted) {
        // If during discovery, remove existing printers and send them.
        List<PrinterId> removedPrinterIds = new ArrayList<PrinterId>();
        final int removedPrinterIdCount = printerIds.size();
        for (int i = 0; i < removedPrinterIdCount; i++) {
            PrinterId removedPrinterId = printerIds.get(i);
            if (mPrinters.remove(removedPrinterId) != null) {
                removedPrinterIds.add(removedPrinterId);
            }
        }
        // Send the removed printers, if such.
        if (!removedPrinterIds.isEmpty()) {
            try {
                mObserver.onPrintersRemoved(new ParceledListSlice<PrinterId>(removedPrinterIds));
            } catch (RemoteException re) {
                Log.e(LOG_TAG, "Error sending removed printers", re);
            }
        }
    } else {
        // Remember the last sent printers if needed.
        if (mLastSentPrinters == null) {
            mLastSentPrinters = new ArrayMap<PrinterId, PrinterInfo>(mPrinters);
        }
        // Update the printers.
        final int removedPrinterIdCount = printerIds.size();
        for (int i = 0; i < removedPrinterIdCount; i++) {
            PrinterId removedPrinterId = printerIds.get(i);
            mPrinters.remove(removedPrinterId);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) PrinterId(android.print.PrinterId) RemoteException(android.os.RemoteException) PrinterInfo(android.print.PrinterInfo)

Example 25 with PrinterInfo

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

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