Search in sources :

Example 6 with PrintManager

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

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)

Example 7 with PrintManager

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

the class SelectPrinterActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActionBar().setIcon(R.drawable.ic_print);
    setContentView(R.layout.select_printer_activity);
    mEnabledPrintServices = new ArrayMap<>();
    mPrinterRegistry = new PrinterRegistry(this, null, LOADER_ID_PRINT_REGISTRY, LOADER_ID_PRINT_REGISTRY_INT);
    // Hook up the list view.
    mListView = (ListView) findViewById(android.R.id.list);
    final DestinationAdapter adapter = new DestinationAdapter();
    adapter.registerDataSetObserver(new DataSetObserver() {

        @Override
        public void onChanged() {
            if (!isFinishing() && adapter.getCount() <= 0) {
                updateEmptyView(adapter);
            }
        }

        @Override
        public void onInvalidated() {
            if (!isFinishing()) {
                updateEmptyView(adapter);
            }
        }
    });
    mListView.setAdapter(adapter);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!((DestinationAdapter) mListView.getAdapter()).isActionable(position)) {
                return;
            }
            PrinterInfo printer = (PrinterInfo) mListView.getAdapter().getItem(position);
            if (printer == null) {
                startAddPrinterActivity();
            } else {
                onPrinterSelected(printer);
            }
        }
    });
    findViewById(R.id.button).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startAddPrinterActivity();
        }
    });
    registerForContextMenu(mListView);
    getLoaderManager().initLoader(LOADER_ID_ENABLED_PRINT_SERVICES, null, this);
    // If some are disabled and some are enabled show a toast to notify the user
    if (savedInstanceState == null || !savedInstanceState.getBoolean(KEY_NOT_FIRST_CREATE)) {
        List<PrintServiceInfo> allServices = ((PrintManager) getSystemService(Context.PRINT_SERVICE)).getPrintServices(PrintManager.ALL_SERVICES);
        boolean hasEnabledServices = false;
        boolean hasDisabledServices = false;
        if (allServices != null) {
            final int numServices = allServices.size();
            for (int i = 0; i < numServices; i++) {
                if (allServices.get(i).isEnabled()) {
                    hasEnabledServices = true;
                } else {
                    hasDisabledServices = true;
                }
            }
        }
        if (!hasEnabledServices) {
            startAddPrinterActivity();
        } else if (hasDisabledServices) {
            String disabledServicesSetting = Settings.Secure.getString(getContentResolver(), Settings.Secure.DISABLED_PRINT_SERVICES);
            if (!TextUtils.isEmpty(disabledServicesSetting)) {
                Toast.makeText(this, getString(R.string.print_services_disabled_toast), Toast.LENGTH_LONG).show();
            }
        }
    }
}
Also used : PrintManager(android.print.PrintManager) DataSetObserver(android.database.DataSetObserver) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(android.widget.SearchView) TextView(android.widget.TextView) ListView(android.widget.ListView) PrintServiceInfo(android.printservice.PrintServiceInfo) OnClickListener(android.view.View.OnClickListener) AdapterView(android.widget.AdapterView) PrinterInfo(android.print.PrinterInfo)

Example 8 with PrintManager

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

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)

Example 9 with PrintManager

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

the class SelectPrinterActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getActionBar().setIcon(R.drawable.ic_print);
    setContentView(R.layout.select_printer_activity);
    mEnabledPrintServices = new ArrayMap<>();
    mPrinterRegistry = new PrinterRegistry(this, null, LOADER_ID_PRINT_REGISTRY, LOADER_ID_PRINT_REGISTRY_INT);
    // Hook up the list view.
    mListView = (ListView) findViewById(android.R.id.list);
    final DestinationAdapter adapter = new DestinationAdapter();
    adapter.registerDataSetObserver(new DataSetObserver() {

        @Override
        public void onChanged() {
            if (!isFinishing() && adapter.getCount() <= 0) {
                updateEmptyView(adapter);
            }
        }

        @Override
        public void onInvalidated() {
            if (!isFinishing()) {
                updateEmptyView(adapter);
            }
        }
    });
    mListView.setAdapter(adapter);
    mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (!((DestinationAdapter) mListView.getAdapter()).isActionable(position)) {
                return;
            }
            PrinterInfo printer = (PrinterInfo) mListView.getAdapter().getItem(position);
            if (printer == null) {
                startAddPrinterActivity();
            } else {
                onPrinterSelected(printer);
            }
        }
    });
    findViewById(R.id.button).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startAddPrinterActivity();
        }
    });
    registerForContextMenu(mListView);
    getLoaderManager().initLoader(LOADER_ID_ENABLED_PRINT_SERVICES, null, this);
    // If some are disabled and some are enabled show a toast to notify the user
    if (savedInstanceState == null || !savedInstanceState.getBoolean(KEY_NOT_FIRST_CREATE)) {
        List<PrintServiceInfo> allServices = ((PrintManager) getSystemService(Context.PRINT_SERVICE)).getPrintServices(PrintManager.ALL_SERVICES);
        boolean hasEnabledServices = false;
        boolean hasDisabledServices = false;
        if (allServices != null) {
            final int numServices = allServices.size();
            for (int i = 0; i < numServices; i++) {
                if (allServices.get(i).isEnabled()) {
                    hasEnabledServices = true;
                } else {
                    hasDisabledServices = true;
                }
            }
        }
        if (!hasEnabledServices) {
            startAddPrinterActivity();
        } else if (hasDisabledServices) {
            String disabledServicesSetting = Settings.Secure.getString(getContentResolver(), Settings.Secure.DISABLED_PRINT_SERVICES);
            if (!TextUtils.isEmpty(disabledServicesSetting)) {
                Toast.makeText(this, getString(R.string.print_services_disabled_toast), Toast.LENGTH_LONG).show();
            }
        }
    }
}
Also used : PrintManager(android.print.PrintManager) DataSetObserver(android.database.DataSetObserver) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) SearchView(android.widget.SearchView) TextView(android.widget.TextView) ListView(android.widget.ListView) PrintServiceInfo(android.printservice.PrintServiceInfo) OnClickListener(android.view.View.OnClickListener) AdapterView(android.widget.AdapterView) PrinterInfo(android.print.PrinterInfo)

Example 10 with PrintManager

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

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