Search in sources :

Example 6 with PrinterInfo

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

the class PrintActivity method onSelectPrinterActivityResult.

private void onSelectPrinterActivityResult(int resultCode, Intent data) {
    if (resultCode == RESULT_OK && data != null) {
        PrinterInfo printerInfo = data.getParcelableExtra(SelectPrinterActivity.INTENT_EXTRA_PRINTER);
        if (printerInfo != null) {
            mCurrentPrinter = printerInfo;
            mPrintJob.setPrinterId(printerInfo.getId());
            mPrintJob.setPrinterName(printerInfo.getName());
            mDestinationSpinnerAdapter.ensurePrinterInVisibleAdapterPosition(printerInfo);
        }
    }
    if (mCurrentPrinter != null) {
        // Trigger PrintersObserver.onChanged() to adjust selection back to current printer
        mDestinationSpinnerAdapter.notifyDataSetChanged();
    }
}
Also used : PrinterInfo(android.print.PrinterInfo)

Example 7 with PrinterInfo

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

the class FusedPrintersProvider method computeAndDeliverResult.

/**
     * Compute the printers, order them appropriately and deliver the printers to the clients. We
     * prefer printers that have been previously used (favorites) and printers that have been used
     * previously close to the current location (near printers).
     *
     * @param discoveredPrinters All printers currently discovered by the print discovery session.
     * @param favoritePrinters The ordered list of printers. The earlier in the list, the more
     *            preferred.
     */
private void computeAndDeliverResult(Map<PrinterId, PrinterInfo> discoveredPrinters, List<Pair<PrinterInfo, Location>> favoritePrinters) {
    List<PrinterInfo> printers = new ArrayList<>();
    // Store the printerIds that have already been added. We cannot compare the printerInfos in
    // "printers" as they might have been taken from discoveredPrinters and the printerInfo does
    // not equals() anymore
    HashSet<PrinterId> alreadyAddedPrinter = new HashSet<>(MAX_FAVORITE_PRINTER_COUNT);
    Location location = getCurrentLocation();
    // Add the favorite printers that have last been used close to the current location
    final int favoritePrinterCount = favoritePrinters.size();
    if (location != null) {
        for (int i = 0; i < favoritePrinterCount; i++) {
            // Only add a certain amount of favorite printers
            if (printers.size() == MAX_FAVORITE_PRINTER_COUNT) {
                break;
            }
            PrinterInfo favoritePrinter = favoritePrinters.get(i).first;
            Location printerLocation = favoritePrinters.get(i).second;
            if (printerLocation != null && !alreadyAddedPrinter.contains(favoritePrinter.getId())) {
                if (printerLocation.distanceTo(location) <= MAX_PRINTER_DISTANCE) {
                    updateAndAddPrinter(printers, favoritePrinter, discoveredPrinters);
                    alreadyAddedPrinter.add(favoritePrinter.getId());
                }
            }
        }
    }
    // Add the other favorite printers
    for (int i = 0; i < favoritePrinterCount; i++) {
        // Only add a certain amount of favorite printers
        if (printers.size() == MAX_FAVORITE_PRINTER_COUNT) {
            break;
        }
        PrinterInfo favoritePrinter = favoritePrinters.get(i).first;
        if (!alreadyAddedPrinter.contains(favoritePrinter.getId())) {
            updateAndAddPrinter(printers, favoritePrinter, discoveredPrinters);
            alreadyAddedPrinter.add(favoritePrinter.getId());
        }
    }
    // Add other updated printers. Printers that have already been added have been removed from
    // discoveredPrinters in the calls to updateAndAddPrinter
    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();
    }
}
Also used : ArrayList(java.util.ArrayList) PrinterId(android.print.PrinterId) PrinterInfo(android.print.PrinterInfo) HashSet(java.util.HashSet) Location(android.location.Location)

Example 8 with PrinterInfo

use of android.print.PrinterInfo in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PrintServiceSettingsFragment method initComponents.

private void initComponents() {
    mPrintersAdapter = new PrintersAdapter();
    mPrintersAdapter.registerDataSetObserver(mDataObserver);
    final SettingsActivity activity = (SettingsActivity) getActivity();
    mSwitchBar = activity.getSwitchBar();
    mSwitchBar.addOnSwitchChangeListener(this);
    mSwitchBar.show();
    mToggleSwitch = mSwitchBar.getSwitch();
    mToggleSwitch.setOnBeforeCheckedChangeListener(new ToggleSwitch.OnBeforeCheckedChangeListener() {

        @Override
        public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) {
            onPreferenceToggled(mPreferenceKey, checked);
            return false;
        }
    });
    getBackupListView().setSelector(new ColorDrawable(Color.TRANSPARENT));
    getBackupListView().setAdapter(mPrintersAdapter);
    getBackupListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            PrinterInfo printer = (PrinterInfo) mPrintersAdapter.getItem(position);
            if (printer.getInfoIntent() != null) {
                try {
                    getActivity().startIntentSender(printer.getInfoIntent().getIntentSender(), null, 0, 0, 0);
                } catch (SendIntentException e) {
                    Log.e(LOG_TAG, "Could not execute info intent: %s", e);
                }
            }
        }
    });
}
Also used : ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) SearchView(android.widget.SearchView) SendIntentException(android.content.IntentSender.SendIntentException) ColorDrawable(android.graphics.drawable.ColorDrawable) ToggleSwitch(com.android.settings.widget.ToggleSwitch) AdapterView(android.widget.AdapterView) PrinterInfo(android.print.PrinterInfo) SettingsActivity(com.android.settings.SettingsActivity)

Example 9 with PrinterInfo

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

the class PrintActivity method onSelectPrinterActivityResult.

private void onSelectPrinterActivityResult(int resultCode, Intent data) {
    if (resultCode == RESULT_OK && data != null) {
        PrinterInfo printerInfo = data.getParcelableExtra(SelectPrinterActivity.INTENT_EXTRA_PRINTER);
        if (printerInfo != null) {
            mCurrentPrinter = printerInfo;
            mPrintJob.setPrinterId(printerInfo.getId());
            mPrintJob.setPrinterName(printerInfo.getName());
            mDestinationSpinnerAdapter.ensurePrinterInVisibleAdapterPosition(printerInfo);
        }
    }
    if (mCurrentPrinter != null) {
        // Trigger PrintersObserver.onChanged() to adjust selection back to current printer
        mDestinationSpinnerAdapter.notifyDataSetChanged();
    }
}
Also used : PrinterInfo(android.print.PrinterInfo)

Example 10 with PrinterInfo

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

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

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