Search in sources :

Example 11 with PrintManager

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

the class FusedPrintersProvider method loadInternal.

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, getCurrentLocation());
            }
        });
        final int favoriteCount = mFavoritePrinters.size();
        List<PrinterId> printerIds = new ArrayList<>(favoriteCount);
        for (int i = 0; i < favoriteCount; i++) {
            printerIds.add(mFavoritePrinters.get(i).first.getId());
        }
        mDiscoverySession.startPrinterDiscovery(printerIds);
        List<PrinterInfo> printers = mDiscoverySession.getPrinters();
        updatePrinters(printers, mFavoritePrinters, getCurrentLocation());
    }
}
Also used : OnPrintersChangeListener(android.print.PrinterDiscoverySession.OnPrintersChangeListener) ArrayList(java.util.ArrayList) PrinterId(android.print.PrinterId) PrintManager(android.print.PrintManager) PrinterInfo(android.print.PrinterInfo)

Aggregations

PrintManager (android.print.PrintManager)11 PrinterInfo (android.print.PrinterInfo)10 DataSetObserver (android.database.DataSetObserver)5 OnPrintersChangeListener (android.print.PrinterDiscoverySession.OnPrintersChangeListener)5 PrinterId (android.print.PrinterId)5 PrintServiceInfo (android.printservice.PrintServiceInfo)5 View (android.view.View)5 OnClickListener (android.view.View.OnClickListener)5 AdapterView (android.widget.AdapterView)5 ImageView (android.widget.ImageView)5 ListView (android.widget.ListView)5 SearchView (android.widget.SearchView)5 TextView (android.widget.TextView)5 ArrayList (java.util.ArrayList)5 Intent (android.content.Intent)1 PrintDocumentAdapter (android.print.PrintDocumentAdapter)1