Search in sources :

Example 1 with PrintDocumentAdapter

use of android.print.PrintDocumentAdapter in project Osmand by osmandapp.

the class PrintDialogActivity method createWebPrintJob.

@SuppressLint("NewApi")
private void createWebPrintJob(WebView webView) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
        PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter();
        String jobName = "OsmAnd route info";
        PrintJob printJob = printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());
        printJobId = printJob.getId();
    }
}
Also used : PrintJob(android.print.PrintJob) PrintManager(android.print.PrintManager) PrintDocumentAdapter(android.print.PrintDocumentAdapter) SuppressLint(android.annotation.SuppressLint)

Example 2 with PrintDocumentAdapter

use of android.print.PrintDocumentAdapter in project gh4a by slapperwan.

the class WebViewerActivity method doPrintHtml.

@TargetApi(19)
private void doPrintHtml() {
    if (!isFinishing()) {
        final String title = getDocumentTitle();
        PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
        PrintDocumentAdapter printAdapter = getPrintAdapterForWebView(mPrintWebView, title);
        printManager.print(title, printAdapter, new PrintAttributes.Builder().build());
    }
    mPrintWebView = null;
    supportInvalidateOptionsMenu();
}
Also used : PrintManager(android.print.PrintManager) PrintDocumentAdapter(android.print.PrintDocumentAdapter) TargetApi(android.annotation.TargetApi)

Example 3 with PrintDocumentAdapter

use of android.print.PrintDocumentAdapter in project opacclient by opacapp.

the class SearchResultDetailFragment method print.

@TargetApi(Build.VERSION_CODES.KITKAT)
private void print() {
    WebView webView = new WebView(getActivity());
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView webView, String url) {
            PrintManager printManager = (PrintManager) getActivity().getSystemService(Context.PRINT_SERVICE);
            PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter();
            String jobName = getItem().getTitle();
            if (jobName == null || jobName.equals("")) {
                jobName = getString(R.string.no_title);
            }
            printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());
        }
    });
    String templateDetailles = PrintUtils.printDetails(getItem(), getContext());
    webView.loadDataWithBaseURL(null, templateDetailles, "text/HTML", "UTF-8", null);
}
Also used : WebView(android.webkit.WebView) PrintManager(android.print.PrintManager) PrintDocumentAdapter(android.print.PrintDocumentAdapter) PrintAttributes(android.print.PrintAttributes) WebViewClient(android.webkit.WebViewClient) TargetApi(android.annotation.TargetApi)

Example 4 with PrintDocumentAdapter

use of android.print.PrintDocumentAdapter in project Notepad by farmerbb.

the class MainActivity method createWebPrintJob.

@TargetApi(Build.VERSION_CODES.KITKAT)
private void createWebPrintJob(WebView webView) {
    // Get a PrintManager instance
    PrintManager printManager = (PrintManager) getSystemService(PRINT_SERVICE);
    // Get a print adapter instance
    PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter();
    // Create a print job with name and adapter instance
    String jobName = getString(R.string.document, getString(R.string.app_name));
    printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());
}
Also used : PrintManager(android.print.PrintManager) PrintDocumentAdapter(android.print.PrintDocumentAdapter) TargetApi(android.annotation.TargetApi)

Example 5 with PrintDocumentAdapter

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

the class PrintJobSettingsActivityTest method viewPrintJobSettings.

@Test
@LargeTest
public void viewPrintJobSettings() throws Exception {
    UUID uuid = UUID.randomUUID();
    Object isWriteCalled = new Object();
    // Create adapter that is good enough to start a print preview
    PrintDocumentAdapter adapter = new PrintDocumentAdapter() {

        @Override
        public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes, CancellationSignal cancellationSignal, LayoutResultCallback callback, Bundle extras) {
            callback.onLayoutFinished(new PrintDocumentInfo.Builder(uuid.toString()).build(), true);
        }

        @Override
        public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback) {
            synchronized (isWriteCalled) {
                isWriteCalled.notify();
            }
            callback.onWriteFailed(null);
        }
    };
    Activity activity = mActivityRule.getActivity();
    PrintManager pm = mActivityRule.getActivity().getSystemService(PrintManager.class);
    // Start printing
    PrintJob printJob = pm.print(uuid.toString(), adapter, null);
    // Wait until print preview is up
    synchronized (isWriteCalled) {
        isWriteCalled.wait();
    }
    // Start print job settings
    Intent intent = new Intent(android.provider.Settings.ACTION_PRINT_SETTINGS);
    intent.putExtra(EXTRA_PRINT_JOB_ID, printJob.getId().flattenToString());
    intent.setData(Uri.fromParts("printjob", printJob.getId().flattenToString(), null));
    activity.startActivity(intent);
    UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
    UiObject2 printPrefTitle = uiDevice.wait(Until.findObject(By.text("Configuring " + uuid.toString())), 5000);
    assertNotNull(printPrefTitle);
    Log.i(LOG_TAG, "Found " + printPrefTitle.getText());
}
Also used : PrintJob(android.print.PrintJob) Bundle(android.os.Bundle) UiDevice(android.support.test.uiautomator.UiDevice) Activity(android.app.Activity) Intent(android.content.Intent) PrintAttributes(android.print.PrintAttributes) PrintManager(android.print.PrintManager) ParcelFileDescriptor(android.os.ParcelFileDescriptor) UUID(java.util.UUID) PrintDocumentAdapter(android.print.PrintDocumentAdapter) CancellationSignal(android.os.CancellationSignal) UiObject2(android.support.test.uiautomator.UiObject2) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Aggregations

PrintDocumentAdapter (android.print.PrintDocumentAdapter)9 PrintManager (android.print.PrintManager)9 TargetApi (android.annotation.TargetApi)3 PrintAttributes (android.print.PrintAttributes)3 Intent (android.content.Intent)2 PrintJob (android.print.PrintJob)2 RequiresApi (android.support.annotation.RequiresApi)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 Bundle (android.os.Bundle)1 CancellationSignal (android.os.CancellationSignal)1 ParcelFileDescriptor (android.os.ParcelFileDescriptor)1 UiDevice (android.support.test.uiautomator.UiDevice)1 UiObject2 (android.support.test.uiautomator.UiObject2)1 WebView (android.webkit.WebView)1 WebViewClient (android.webkit.WebViewClient)1 LargeTest (androidx.test.filters.LargeTest)1 UUID (java.util.UUID)1 Test (org.junit.Test)1