Configure PdfActivity interactively and preview the result.
/* * Copyright © 2020-2026 PSPDFKit GmbH. All rights reserved. * * The PSPDFKit Sample applications are licensed with a modified BSD license. * Please see License for details. This notice may not be removed from this file. */package com.pspdfkit.catalog.examples.kotlin
import android.content.Contextimport android.content.Intentimport android.util.Logimport android.view.Menuimport android.view.MenuItemimport com.pspdfkit.catalog.Rimport com.pspdfkit.catalog.SdkExampleimport com.pspdfkit.catalog.SdkExample.Companion.TAGimport com.pspdfkit.catalog.ui.DocumentPickerActivityimport com.pspdfkit.configuration.activity.PdfActivityConfigurationimport com.pspdfkit.document.PdfDocumentimport com.pspdfkit.ui.PdfActivity
/** * Playground example that opens an activity extending the [PdfActivity] class. */class PlaygroundExample(context: Context) : SdkExample(context, R.string.playgroundExampleTitle, R.string.playgroundExampleDescription) { override fun launchExample(context: Context, configuration: PdfActivityConfiguration.Builder) { // Launch the picker activity to let users choose between default or custom document. val intent = Intent(context, PlaygroundExamplePickerActivity::class.java) intent.putExtra(DocumentPickerActivity.EXTRA_CONFIGURATION, configuration.build()) context.startActivity(intent) }}
/** * Activity that lets the user choose between picking a PDF and using the default document. */class PlaygroundExamplePickerActivity : DocumentPickerActivity() { override val targetActivityClass = PlaygroundActivity::class.java}
/** * Playground activity that provides an options menu accessible via the overflow menu (the three dots) * with a customizable button action, see [menuItemClicked]; and a callback when the document is successfully * loaded, see [onDocumentLoaded]. */class PlaygroundActivity : PdfActivity() { override fun onCreateOptionsMenu(menu: Menu): Boolean { super.onCreateOptionsMenu(menu) menu.add(0, CUSTOM_MENU_ITEM_ID, 0, "Custom Menu Item") menu.add(0, FREEZE_UI_MENU_ITEM_ID, 0, "Freeze UI thread (15s)") return true }
override fun onOptionsItemSelected(item: MenuItem): Boolean = when (item.itemId) { CUSTOM_MENU_ITEM_ID -> { menuItemClicked() true }
FREEZE_UI_MENU_ITEM_ID -> { freezeUiThread() true }
else -> super.onOptionsItemSelected(item) }
override fun onDocumentLoaded(document: PdfDocument) { super.onDocumentLoaded(document) Log.d(TAG, "Document loaded.") // Do your magic here... }
private fun menuItemClicked() { Log.d(TAG, "Menu item clicked.") }
private fun freezeUiThread() { Log.d(TAG, "Freezing UI thread for 15s — watch logcat for tag \"FreezeDetector\".") Thread.sleep(15_000) }
companion object { private const val CUSTOM_MENU_ITEM_ID = 1 private const val FREEZE_UI_MENU_ITEM_ID = 2 }}This code sample is an example that illustrates how to use our SDK. Please adapt it to your specific use case.