Package 

Interface HyperlinkNavigator.Listener

    • Method Summary

      Modifier and Type Method Description
      Boolean shouldFollowInternalLink(Link link, HyperlinkNavigator.LinkContext context) Called when a link to an internal resource was clicked in the navigator.
      abstract Unit onExternalLinkActivated(AbsoluteUrl url) Called when a link to an external URL was activated in the navigator.
      • Methods inherited from class org.readium.r2.navigator.HyperlinkNavigator.Listener

        onJumpToLocator, onResourceLoadFailed
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • shouldFollowInternalLink

         Boolean shouldFollowInternalLink(Link link, HyperlinkNavigator.LinkContext context)

        Called when a link to an internal resource was clicked in the navigator.

        You can use this callback to perform custom navigation like opening a new window or other operations.

        By returning false the navigator wont try to open the link itself and it is up to the calling app to decide how to display the resource.

      • onExternalLinkActivated

         abstract Unit onExternalLinkActivated(AbsoluteUrl url)

        Called when a link to an external URL was activated in the navigator.

        If it is an HTTP URL, you should open it with a CustomTabsIntent or WebView, for example:

        override fun onExternalLinkActivated(url: AbsoluteUrl) {
            if (!url.isHttp) return
        
            val context = requireActivity()
            val uri = url.toUri()
        
            try {
                CustomTabsIntent.Builder()
                    .build()
                    .launchUrl(context, uri)
            } catch (e: ActivityNotFoundException) {
                context.startActivity(Intent(Intent.ACTION_VIEW, uri))
            }
        }