android.print.PrintAttributes Java Examples

The following examples show how to use android.print.PrintAttributes. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProWebView.java    From prowebview with Apache License 2.0 7 votes vote down vote up
/**
 * Print the current web site
 */
@RequiresApi(19)
public void printWebView(@Nullable PrintListener listener) {
    PrintManager printManager = (PrintManager) getContext().getSystemService(Context.PRINT_SERVICE);
    PrintDocumentAdapter printAdapter = createPrintDocumentAdapter();
    PrintAttributes.Builder builder = new PrintAttributes.Builder();
    builder.setMediaSize(PrintAttributes.MediaSize.NA_LETTER);
    if (printManager != null) {
        PrintJob printJob = printManager.print(getTitle(), printAdapter, builder.build());
        if (listener!=null) {
            if(printJob.isCompleted()){
                listener.onSuccess();
            } else {
                listener.onFailed();
            }
        }
    } else {
        if (listener != null) {
            listener.onFailed();
        }
    }
}
 
Example #2
Source File: DetailFragment.java    From kolabnotes-android with GNU Lesser General Public License v3.0 7 votes vote down vote up
private void printNote() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        PrintManager printManager = (PrintManager) activity.getSystemService(Context.PRINT_SERVICE);
        String jobName = getString(R.string.app_name) + " Document";

        // GitHub issue 197
        if(editor != null){
            PrintDocumentAdapter printAdapter = editor.createPrintDocumentAdapter();
            printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());
        }else if(editText != null){
            printEditText(jobName);
        }else{
            Toast.makeText(activity, R.string.empty_note_description, Toast.LENGTH_LONG).show();
        }

    }
}
 
Example #3
Source File: ShareUtil.java    From Stringlate with MIT License 7 votes vote down vote up
/**
 * Print a {@link WebView}'s contents, also allows to create a PDF
 *
 * @param webview WebView
 * @param jobName Name of the job (affects PDF name too)
 * @return {{@link PrintJob}} or null
 */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@SuppressWarnings("deprecation")
public PrintJob print(WebView webview, String jobName) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        PrintDocumentAdapter printAdapter;
        PrintManager printManager = (PrintManager) webview.getContext().getSystemService(Context.PRINT_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            printAdapter = webview.createPrintDocumentAdapter(jobName);
        } else {
            printAdapter = webview.createPrintDocumentAdapter();
        }
        if (printManager != null) {
            return printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());
        }
    } else {
        Log.e(getClass().getName(), "ERROR: Method called on too low Android API version");
    }
    return null;
}
 
Example #4
Source File: PrintedPdfDocument.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new document.
 * <p>
 * <strong>Note:</strong> You must close the document after you are
 * done by calling {@link #close()}.
 * </p>
 *
 * @param context Context instance for accessing resources.
 * @param attributes The print attributes.
 */
public PrintedPdfDocument(@NonNull Context context, @NonNull PrintAttributes attributes) {
    MediaSize mediaSize = attributes.getMediaSize();

    // Compute the size of the target canvas from the attributes.
    mPageWidth = (int) (((float) mediaSize.getWidthMils() / MILS_PER_INCH)
            * POINTS_IN_INCH);
    mPageHeight = (int) (((float) mediaSize.getHeightMils() / MILS_PER_INCH)
            * POINTS_IN_INCH);

    // Compute the content size from the attributes.
    Margins minMargins = attributes.getMinMargins();
    final int marginLeft = (int) (((float) minMargins.getLeftMils() / MILS_PER_INCH)
            * POINTS_IN_INCH);
    final int marginTop = (int) (((float) minMargins.getTopMils() / MILS_PER_INCH)
            * POINTS_IN_INCH);
    final int marginRight = (int) (((float) minMargins.getRightMils() / MILS_PER_INCH)
            * POINTS_IN_INCH);
    final int marginBottom = (int) (((float) minMargins.getBottomMils() / MILS_PER_INCH)
            * POINTS_IN_INCH);
    mContentRect = new Rect(marginLeft, marginTop, mPageWidth - marginRight,
            mPageHeight - marginBottom);
}
 
Example #5
Source File: IdentityPrintDocumentAdapter.java    From secure-quick-reliable-login with MIT License 6 votes vote down vote up
@Override
public void onLayout(
        PrintAttributes oldAttributes,
        PrintAttributes newAttributes,
        CancellationSignal cancellationSignal,
        LayoutResultCallback callback,
        Bundle metadata
) {
    mPdfDocument = new PrintedPdfDocument(activity, newAttributes);
    if (cancellationSignal.isCanceled() ) {
        callback.onLayoutCancelled();
        return;
    }

    PrintDocumentInfo info = new PrintDocumentInfo
            .Builder("Identity.pdf")
            .setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT)
            .setPageCount(1)
            .build();
    callback.onLayoutFinished(info, true);
}
 
Example #6
Source File: RescueCodePrintDocumentAdapter.java    From secure-quick-reliable-login with MIT License 6 votes vote down vote up
@Override
public void onLayout(
        PrintAttributes oldAttributes,
        PrintAttributes newAttributes,
        CancellationSignal cancellationSignal,
        LayoutResultCallback callback,
        Bundle metadata
) {
    mPdfDocument = new PrintedPdfDocument(activity, newAttributes);
    if (cancellationSignal.isCanceled() ) {
        callback.onLayoutCancelled();
        return;
    }

    PrintDocumentInfo info = new PrintDocumentInfo
            .Builder("RescueCode.pdf")
            .setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT)
            .setPageCount(1)
            .build();
    callback.onLayoutFinished(info, true);
}
 
Example #7
Source File: PdfActivity.java    From AndroidAnimationExercise with Apache License 2.0 6 votes vote down vote up
private void genPdfFile() {
    PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);

    // Get a print adapter instance
    PrintDocumentAdapter printAdapter;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        printAdapter = mWebView.createPrintDocumentAdapter("my.pdf");
    } else {
        printAdapter = mWebView.createPrintDocumentAdapter();
    }

    // Create a print job with name and adapter instance
    String jobName = getString(R.string.app_name) + " Document";

    PrintAttributes attributes = new PrintAttributes.Builder()
            .setMediaSize(PrintAttributes.MediaSize.ISO_A4)
            .setResolution(new PrintAttributes.Resolution("id", Context.PRINT_SERVICE, 200, 200))
            .setColorMode(PrintAttributes.COLOR_MODE_COLOR)
            .setMinMargins(PrintAttributes.Margins.NO_MARGINS)
            .build();

    printManager.print(jobName, printAdapter, attributes);


}
 
Example #8
Source File: MainActivity.java    From Notepad with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@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());
}
 
Example #9
Source File: MockFinal.java    From dexmaker with Apache License 2.0 5 votes vote down vote up
@Test
public void mockFinalAndroidFrameworkClass() throws Exception {
    // PrintAttributes is final
    PrintAttributes mockAttributes = mock(PrintAttributes.class);

    assertEquals(0, mockAttributes.getColorMode());

    when(mockAttributes.getColorMode()).thenReturn(42);

    assertEquals(42, mockAttributes.getColorMode());
}
 
Example #10
Source File: TemplatePrinterActivity.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
/**
 * Starts a print job for the given WebView
 *
 * Source: https://developer.android.com/training/printing/html-docs.html
 *
 * @param v the WebView to be printed
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
private void createWebPrintJob(WebView v) {
    // Get a PrintManager instance
    PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);

    // Get a print adapter instance
    PrintDocumentAdapter printAdapter = new PrintDocumentAdapterWrapper(this, v.createPrintDocumentAdapter());

    // Create a print job with name and adapter instance
    printJob = printManager.print(jobName, printAdapter, new PrintAttributes.Builder().build());
}
 
Example #11
Source File: DetailFragment.java    From kolabnotes-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void createWebPrintJob(WebView webView, String jobName) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        // Get a PrintManager instance
        PrintManager printManager = (PrintManager) getActivity()
                .getSystemService(Context.PRINT_SERVICE);

        // Get a print adapter instance
        PrintDocumentAdapter printAdapter = webView.createPrintDocumentAdapter();

        // Create a print job with name and adapter instance
        PrintJob printJob = printManager.print(jobName, printAdapter,
                new PrintAttributes.Builder().build());
    }
}
 
Example #12
Source File: PrintDocumentAdapterWrapper.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onLayout(
        PrintAttributes oldAttributes,
        PrintAttributes newAttributes,
        CancellationSignal cancellationSignal,
        LayoutResultCallback callback,
        Bundle metadata) {
    mPdfGenerator.onLayout(oldAttributes, newAttributes, cancellationSignal,
            new LayoutResultCallbackWrapperImpl(callback), metadata);
}
 
Example #13
Source File: PrintingControllerImpl.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public void onLayout(
        PrintAttributes oldAttributes,
        PrintAttributes newAttributes,
        CancellationSignal cancellationSignal,
        PrintDocumentAdapterWrapper.LayoutResultCallbackWrapper callback,
        Bundle metadata) {
    // NOTE: Chrome printing just supports one DPI, whereas Android has both vertical and
    // horizontal.  These two values are most of the time same, so we just pass one of them.
    mDpi = newAttributes.getResolution().getHorizontalDpi();
    mMediaSize = newAttributes.getMediaSize();

    mNeedNewPdf = !newAttributes.equals(oldAttributes);

    mOnLayoutCallback = callback;
    // We don't want to stack Chromium with multiple PDF generation operations before
    // completion of an ongoing one.
    // TODO(cimamoglu): Whenever onLayout is called, generate a new PDF with the new
    //                  parameters. Hence, we can get the true number of pages.
    if (mPrintingState == PRINTING_STATE_STARTED_FROM_ONLAYOUT) {
        // We don't start a new Chromium PDF generation operation if there's an existing
        // onLayout going on. Use the last known valid page count.
        pageCountEstimationDone(mLastKnownMaxPages);
    } else if (mPrintingState == PRINTING_STATE_STARTED_FROM_ONWRITE) {
        callback.onLayoutFailed(mErrorMessage);
        resetCallbacks();
    } else if (mPrintable.print()) {
        mPrintingState = PRINTING_STATE_STARTED_FROM_ONLAYOUT;
    } else {
        callback.onLayoutFailed(mErrorMessage);
        resetCallbacks();
    }
}
 
Example #14
Source File: ShareUtil.java    From memetastic with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Print a {@link WebView}'s contents, also allows to create a PDF
 *
 * @param webview WebView
 * @param jobName Name of the job (affects PDF name too)
 * @return {{@link PrintJob}} or null
 */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public PrintJob print(final WebView webview, final String jobName, final boolean... landscape) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        final PrintDocumentAdapter printAdapter;
        final PrintManager printManager = (PrintManager) _context.getSystemService(Context.PRINT_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            printAdapter = webview.createPrintDocumentAdapter(jobName);
        } else {
            printAdapter = webview.createPrintDocumentAdapter();
        }
        final PrintAttributes.Builder attrib = new PrintAttributes.Builder();
        if (landscape != null && landscape.length > 0 && landscape[0]) {
            attrib.setMediaSize(new PrintAttributes.MediaSize("ISO_A4", "android", 11690, 8270));
            attrib.setMinMargins(new PrintAttributes.Margins(0, 0, 0, 0));
        }
        if (printManager != null) {
            try {
                return printManager.print(jobName, printAdapter, attrib.build());
            } catch (Exception ignored) {
            }
        }
    } else {
        Log.e(getClass().getName(), "ERROR: Method called on too low Android API version");
    }
    return null;
}
 
Example #15
Source File: MainActivity.java    From Android-SmartWebView with MIT License 5 votes vote down vote up
private void print_page(WebView view, String print_name, boolean manual) {
	PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
	PrintDocumentAdapter printAdapter = view.createPrintDocumentAdapter(print_name);
	PrintAttributes.Builder builder = new PrintAttributes.Builder();
	builder.setMediaSize(PrintAttributes.MediaSize.ISO_A5);
	PrintJob printJob = printManager.print(print_name, printAdapter, builder.build());

	if(printJob.isCompleted()){
		Toast.makeText(getApplicationContext(), R.string.print_complete, Toast.LENGTH_LONG).show();
	}
	else if(printJob.isFailed()){
		Toast.makeText(getApplicationContext(), R.string.print_failed, Toast.LENGTH_LONG).show();
	}
}
 
Example #16
Source File: PreviewFragment.java    From Resume-Builder with MIT License 5 votes vote down vote up
private void createWebPrintJob(WebView webView) {

        // Get a PrintManager instance
        PrintManager printManager = (PrintManager) getActivity()
                .getSystemService(Context.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.app_name) + " Document";
        PrintJob printJob = printManager.print(jobName, printAdapter,
                new PrintAttributes.Builder().build());
    }
 
Example #17
Source File: ShareUtil.java    From openlauncher with Apache License 2.0 4 votes vote down vote up
/**
 * Print a {@link WebView}'s contents, also allows to create a PDF
 *
 * @param webview WebView
 * @param jobName Name of the job (affects PDF name too)
 * @return {{@link PrintJob}} or null
 */
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
public PrintJob print(final WebView webview, final String jobName, final boolean... landscape) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        final PrintDocumentAdapter printAdapter;
        final PrintManager printManager = (PrintManager) _context.getSystemService(Context.PRINT_SERVICE);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            printAdapter = webview.createPrintDocumentAdapter(jobName);
        } else {
            printAdapter = webview.createPrintDocumentAdapter();
        }
        final PrintAttributes.Builder attrib = new PrintAttributes.Builder();
        if (landscape != null && landscape.length > 0 && landscape[0]) {
            attrib.setMediaSize(new PrintAttributes.MediaSize("ISO_A4", "android", 11690, 8270));
            attrib.setMinMargins(new PrintAttributes.Margins(0, 0, 0, 0));
        }
        if (printManager != null) {
            try {
                return printManager.print(jobName, printAdapter, attrib.build());
            } catch (Exception ignored) {
            }
        }
    } else {
        Log.e(getClass().getName(), "ERROR: Method called on too low Android API version");
    }
    return null;
}
 
Example #18
Source File: PrintManagerDelegateImpl.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void print(String printJobName, PrintDocumentAdapter documentAdapter,
        PrintAttributes attributes) {
    dumpJobStatesForDebug();
    mPrintManager.print(printJobName, documentAdapter, attributes);
}
 
Example #19
Source File: PrintDocumentAdapterWrapper.java    From 365browser with Apache License 2.0 4 votes vote down vote up
void onLayout(
PrintAttributes oldAttributes,
PrintAttributes newAttributes,
CancellationSignal cancellationSignal,
PrintDocumentAdapterWrapper.LayoutResultCallbackWrapper callback,
Bundle metadata);
 
Example #20
Source File: PdfPrinter.java    From ViewPrinter with Apache License 2.0 4 votes vote down vote up
/**
 * Prints the current view to a PDF file, in the given directory and with the given
 * filename. If the file exists, it will be deleted.
 *
 * @param printId an (optional) identifier for the process
 * @param directory a directory where the file will be saved
 * @param filename the output file name
 */
@Override
public void print(final String printId, @NonNull final File directory, @NonNull String filename) {
    Context context = mDocument.getContext();
    if (!checkPermission(context, directory)) return;
    if (!checkPreview(printId, directory, filename)) return;
    if (!filename.toLowerCase().endsWith(".pdf")) filename += ".pdf";
    final File file = new File(directory, filename);
    if (!checkFile(printId, file)) return;

    if (mDocument.getPageCount() == 0) return;
    DocumentPage firstPage = mDocument.getPageAt(0);
    PrintSize size = mDocument.getPrintSize();

    // Create doc
    PrintAttributes attrs = new PrintAttributes.Builder()
            .setColorMode(PrintAttributes.COLOR_MODE_COLOR)
            .setMediaSize(size.toMediaSize(firstPage))
            .setMinMargins(PrintAttributes.Margins.NO_MARGINS)
            .build();
    final PrintedPdfDocument doc = new PrintedPdfDocument(context, attrs);

    // Print page
    // Page canvas is passed in PostScript points. In order not to break View drawing,
    // we must scale that up back to pixels.
    dispatchOnPrePrint(mDocument);
    for (int i = 0; i < mDocument.getPageCount(); i++) {
        PdfDocument.Page page = doc.startPage(i);
        Canvas canvas = page.getCanvas();
        float pixelsToPoints = PrintSize.PIXELS_TO_INCHES(context) * PrintSize.INCHES_TO_POINTS;
        canvas.scale(pixelsToPoints, pixelsToPoints, 0, 0);

        DocumentPage view = mDocument.getPageAt(i);
        Drawable background = null;
        if (!mPrintBackground) {
            background = view.getBackground();
            view.setBackground(null);
        }
        view.draw(canvas);
        if (!mPrintBackground) {
            view.setBackground(background);
        }
        doc.finishPage(page);
    }
    dispatchOnPostPrint(mDocument);

    // I am not sure if the above would work with any view. Some views might be checking for
    // canvas.getWidth() or canvas.tryGetHeight(), which now are not consistent. If errors show up,
    // we might have to draw on a separate canvas and then scale the bitmap.
    // This has other drawbacks: the original pdf canvas, for example, takes text as text and
    // makes it selectable in the final PDF.

    // Print in a separate thread.
    // Since we're API 19 we can use try with resources.
    final Handler ui = new Handler();
    new Thread(new Runnable() {
        @Override
        public void run() {
            try (OutputStream stream = new BufferedOutputStream(new FileOutputStream(file))) {
                doc.writeTo(stream);
                ui.post(new Runnable() {
                    @Override
                    public void run() {
                        mCallback.onPrint(printId, file);
                    }
                });

            } catch (final IOException e) {
                ui.post(new Runnable() {
                    @Override
                    public void run() {
                        mCallback.onPrintFailed(printId, new RuntimeException("Invalid file: " + file, e));
                    }
                });
            }
        }
    }, TAG + "Worker").start();
}
 
Example #21
Source File: PrintSize.java    From ViewPrinter with Apache License 2.0 4 votes vote down vote up
private PrintSize(PrintAttributes.MediaSize size, int enumValue) {
    mWidthMils = size.getWidthMils();
    mHeightMils = size.getHeightMils();
    mSize = size;
    SIZES[enumValue] = this;
}
 
Example #22
Source File: TemplatePrinterActivity.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
                     CancellationSignal cancellationSignal,
                     LayoutResultCallback callback, Bundle extras) {
    delegate.onLayout(oldAttributes, newAttributes, cancellationSignal, callback, extras);
}
 
Example #23
Source File: ExportOptionsActivity.java    From secure-quick-reliable-login with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_export_options);

    setupProgressPopupWindow(getLayoutInflater());
    setupErrorPopupWindow(getLayoutInflater());
    final CheckBox cbWithoutPassword = findViewById(R.id.cbWithoutPassword);

    findViewById(R.id.btnShowIdentity).setOnClickListener(v -> {
        Intent showIdentityIntent = new Intent(this, ShowIdentityActivity.class);
        showIdentityIntent.putExtra(EXPORT_WITHOUT_PASSWORD, cbWithoutPassword.isChecked());
        startActivity(showIdentityIntent);
    });

    findViewById(R.id.btnSaveIdentity).setOnClickListener(v -> {
        String uriString = "content://org.ea.sqrl.fileprovider/sqrltmp/";
        File directory = new File(getCacheDir(), "sqrltmp");
        if(!directory.exists()) directory.mkdir();

        if(!directory.exists()) {
            showErrorMessage(R.string.main_activity_could_not_create_dir);
            return;
        }

        SQRLStorage storage = SQRLStorage.getInstance(ExportOptionsActivity.this.getApplicationContext());

        try {
            File file = File.createTempFile("identity", ".sqrl", directory);

            byte[] saveData;
            if(cbWithoutPassword.isChecked()) {
                saveData = storage.createSaveDataWithoutPassword();
            } else {
                saveData = storage.createSaveData();
            }

            FileOutputStream FileOutputStream = new FileOutputStream(file);
            FileOutputStream.write(saveData);
            FileOutputStream.close();

            Intent shareIntent = new Intent();
            shareIntent.setAction(Intent.ACTION_SEND);
            shareIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(uriString + file.getName()));
            shareIntent.setType("application/octet-stream");
            startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.save_identity_to)));
        } catch (Exception e) {
            showErrorMessage(e.getMessage());
            Log.e(TAG, e.getMessage(), e);
        }
    });

    findViewById(R.id.btnPrintIdentity).setOnClickListener(v -> {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
            String jobName = getString(R.string.app_name) + " Document";

            PrintAttributes printAttributes = new PrintAttributes.Builder()
                    .setMediaSize(PrintAttributes.MediaSize.ISO_A4)
                    .build();

            long currentId = SqrlApplication.getCurrentId(this.getApplication());

            String identityName = mDbHelper.getIdentityName(currentId);

            printManager.print(jobName, new IdentityPrintDocumentAdapter(this, identityName, cbWithoutPassword.isChecked()), printAttributes);
        } else {
            showPrintingNotAvailableDialog();
        }
    });
}
 
Example #24
Source File: RescueCodeShowActivity.java    From secure-quick-reliable-login with MIT License 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_rescuecode_show);

    try {
        final EntropyHarvester entropyHarvester = EntropyHarvester.getInstance();
        SQRLStorage storage = SQRLStorage.getInstance(RescueCodeShowActivity.this.getApplicationContext());
        storage.newRescueCode(entropyHarvester);

        List<String> rescueArr = storage.getTempShowableRescueCode();

        final TextView txtRescueCodeShowDescription = findViewById(R.id.txtRescueCodeShowDescription);
        final ViewGroup rootView = findViewById(R.id.rescueCodeShowActivityView);
        final Button btnRescueCodeShowNext = findViewById(R.id.btnRescueCodeShowNext);

        txtRescueCodeShowDescription.setMovementMethod(LinkMovementMethod.getInstance());

        RescueCodeInputHelper rescueCodeInputHelper = new RescueCodeInputHelper(
                this, rootView, btnRescueCodeShowNext, false);
        rescueCodeInputHelper.setInputEnabled(false);
        rescueCodeInputHelper.setRescueCodeInput(rescueArr);

    } catch (Exception e) {
        Log.e(TAG, e.getMessage(), e);
    }

    findViewById(R.id.btnRescueCodeShowNext).setOnClickListener(v -> {
        startActivity(new Intent(this, RescueCodeEnterActivity.class));
    });

    findViewById(R.id.btnPrintRescueCode).setOnClickListener(v -> {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
            String jobName = getString(R.string.app_name) + " Document";

            PrintAttributes printAttributes = new PrintAttributes.Builder()
                    .setMediaSize(PrintAttributes.MediaSize.ISO_A4)
                    .build();

            printManager.print(jobName, new RescueCodePrintDocumentAdapter(this), printAttributes);
        } else {
            showPrintingNotAvailableDialog();
        }
    });
}
 
Example #25
Source File: PrintManagerDelegate.java    From 365browser with Apache License 2.0 2 votes vote down vote up
/**
 * Same as {@link android.print.PrintManager#print}, except this doesn't return a
 * {@link android.print.PrintJob} since the clients don't need it.
 */
void print(String printJobName,
           PrintDocumentAdapter documentAdapter,
           PrintAttributes attributes);