This repository has been archived by the owner on Jul 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from readium/feature/DiViNa
Feature: DiViNa
- Loading branch information
Showing
13 changed files
with
589 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>DiViNa Player</title> | ||
<style type="text/css"> | ||
body, html { | ||
height: 100%; | ||
margin: 0; | ||
padding: 0; | ||
overflow: hidden; | ||
background-color: rgb(0, 0, 0); | ||
} | ||
</style> | ||
<script type="text/javascript" src="./divinaTouchHandling.js"></script> | ||
<script type="text/javascript" src="./divinaPlayer.js"></script> | ||
</head> | ||
<body> | ||
<script type="text/javascript"> | ||
var player = null | ||
window.onload = function() { | ||
const Player = window.divinaPlayer | ||
player = new Player(window.document.body) | ||
} | ||
</script> | ||
</body> | ||
</html> |
Large diffs are not rendered by default.
Oops, something went wrong.
65 changes: 65 additions & 0 deletions
65
r2-navigator/src/main/assets/divina/divinaTouchHandling.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
var singleTouchGesture = false; | ||
var startX = 0; | ||
var startY = 0; | ||
var availWidth = window.screen.availWidth; | ||
var availHeight = window.screen.availHeight; | ||
|
||
|
||
window.addEventListener("load", function(){ // on page load | ||
// Get screen X and Y sizes. | ||
// Events listeners for the touches. | ||
window.document.addEventListener("touchstart", handleTouchStart, false); | ||
window.document.addEventListener("touchend", handleTouchEnd, false); | ||
// When device orientation changes, screen X and Y sizes are recalculated. | ||
}, false); | ||
|
||
|
||
|
||
// When a touch is detected records its starting coordinates and if it's a singleTouchGesture. | ||
var handleTouchStart = function(event) { | ||
if (event.target.nodeName.toUpperCase() === 'A') { | ||
console.log("Touched a link."); | ||
// singleTouchGesture = false; | ||
return; | ||
} | ||
console.log("Touch sent to native code."); | ||
singleTouchGesture = event.touches.length == 1; | ||
|
||
var touch = event.changedTouches[0]; | ||
|
||
startX = touch.screenX % availWidth; | ||
startY = touch.screenY % availHeight; | ||
|
||
}; | ||
|
||
// When a touch ends, check if any action has to be made, and contact native code. | ||
var handleTouchEnd = function(event) { | ||
if(!singleTouchGesture) { | ||
return; | ||
} | ||
|
||
var touch = event.changedTouches[0]; | ||
|
||
var relativeDistanceX = Math.abs(((touch.screenX % availWidth) - startX) / availWidth); | ||
var relativeDistanceY = Math.abs(((touch.screenY % availHeight) - startY) / availHeight); | ||
var touchDistance = Math.max(relativeDistanceX, relativeDistanceY); | ||
|
||
var scrollWidth = document.scrollWidth; | ||
var screenWidth = availWidth; | ||
var tapAreaWidth = availWidth * 0.2; | ||
|
||
if(touchDistance < 0.01) { | ||
var position = (touch.screenX % availWidth) / availWidth; | ||
if (position <= 0.2) { | ||
console.log("LeftTapped"); | ||
} else if(position >= 0.8) { | ||
console.log("RightTapped"); | ||
} else { | ||
console.log("CenterTapped"); | ||
Android.centerTapped(); | ||
} | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
return; | ||
} | ||
}; |
38 changes: 38 additions & 0 deletions
38
r2-navigator/src/main/java/org/readium/r2/navigator/R2ActivityListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Module: r2-navigator-kotlin | ||
* Developers: Aferdita Muriqi | ||
* | ||
* Copyright (c) 2019. Readium Foundation. All rights reserved. | ||
* Use of this source code is governed by a BSD-style license which is detailed in the | ||
* LICENSE file present in the project repository where this source code is maintained. | ||
*/ | ||
|
||
package org.readium.r2.navigator | ||
|
||
import android.content.SharedPreferences | ||
import android.view.View | ||
import org.readium.r2.navigator.pager.R2ViewPager | ||
import org.readium.r2.shared.Locations | ||
import org.readium.r2.shared.Publication | ||
|
||
interface R2ActivityListener { | ||
|
||
val publication: Publication | ||
val preferences: SharedPreferences | ||
val publicationIdentifier: String | ||
val resourcePager: R2ViewPager? | ||
get() = null | ||
val allowToggleActionBar: Boolean | ||
get() = true | ||
|
||
fun toggleActionBar() {} | ||
fun toggleActionBar(v: View? = null) {} | ||
fun storeProgression(locations: Locations?) {} | ||
fun nextResource(smoothScroll: Boolean) {} | ||
fun previousResource(smoothScroll: Boolean) {} | ||
fun nextResource(v: View? = null) {} | ||
fun previousResource(v: View? = null) {} | ||
fun onPageChanged(pageIndex: Int, totalPages: Int, url: String) {} | ||
fun onPageEnded(end: Boolean) {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
r2-navigator/src/main/java/org/readium/r2/navigator/R2DiViNaActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* Module: r2-navigator-kotlin | ||
* Developers: Aferdita Muriqi | ||
* | ||
* Copyright (c) 2018. Readium Foundation. All rights reserved. | ||
* Use of this source code is governed by a BSD-style license which is detailed in the | ||
* LICENSE file present in the project repository where this source code is maintained. | ||
*/ | ||
|
||
package org.readium.r2.navigator | ||
|
||
import android.content.Context | ||
import android.content.SharedPreferences | ||
import android.os.Bundle | ||
import android.view.View | ||
import android.webkit.WebView | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.webkit.WebViewClientCompat | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import org.readium.r2.navigator.pager.R2BasicWebView | ||
import org.readium.r2.shared.Publication | ||
import kotlin.coroutines.CoroutineContext | ||
|
||
|
||
open class R2DiViNaActivity : AppCompatActivity(), CoroutineScope, R2ActivityListener { | ||
|
||
/** | ||
* Context of this scope. | ||
*/ | ||
override val coroutineContext: CoroutineContext | ||
get() = Dispatchers.Main | ||
|
||
override lateinit var preferences: SharedPreferences | ||
override lateinit var publication: Publication | ||
override lateinit var publicationIdentifier: String | ||
|
||
lateinit var divinaWebView: R2BasicWebView | ||
private lateinit var publicationPath: String | ||
private lateinit var zipName: String | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_r2_divina) | ||
|
||
preferences = getSharedPreferences("org.readium.r2.settings", Context.MODE_PRIVATE) | ||
divinaWebView = findViewById(R.id.divinaWebView) | ||
divinaWebView.activity = this | ||
divinaWebView.listener = this | ||
|
||
publicationPath = intent.getStringExtra("publicationPath") | ||
publication = intent.getSerializableExtra("publication") as Publication | ||
zipName = intent.getStringExtra("zipName") | ||
|
||
publicationIdentifier = publication.metadata.identifier | ||
title = publication.metadata.title | ||
|
||
toggleActionBar() | ||
|
||
// Set up divinaWebView to enable JavaScript and access to local URLs | ||
divinaWebView.getSettings().setJavaScriptEnabled(true) | ||
divinaWebView.getSettings().setAllowFileAccess(true) | ||
divinaWebView.getSettings().setAllowFileAccessFromFileURLs(true) | ||
divinaWebView.webViewClient = object : WebViewClientCompat() { | ||
|
||
override fun onPageFinished(view: WebView?, url: String?) { | ||
super.onPageFinished(view, url) | ||
// Define the JS toggleMenu function that will call Android's toggleActionBar | ||
// divinaWebView.evaluateJavascript("window.androidObj = function AndroidClass(){};", null) | ||
// divinaWebView.evaluateJavascript("window.androidObj.toggleMenu = function() { Android.toggleMenu() };", null) | ||
|
||
// Now launch the DiViNa player for the folderPath = publicationPath | ||
divinaWebView.evaluateJavascript("if (player) { player.openDiViNaFromPath('${publicationPath}'); };", null) | ||
} | ||
} | ||
divinaWebView.loadUrl("file:///android_asset/divina/divinaPlayer.html") | ||
divinaWebView.addJavascriptInterface(divinaWebView, "Android") | ||
|
||
} | ||
|
||
override fun toggleActionBar() { | ||
launch { | ||
if (supportActionBar!!.isShowing) { | ||
divinaWebView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE | ||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | ||
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | ||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | ||
or View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar | ||
or View.SYSTEM_UI_FLAG_IMMERSIVE) | ||
} else { | ||
divinaWebView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE | ||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | ||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN) | ||
} | ||
} | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
divinaWebView.evaluateJavascript("if (player) { player.destroy(); };", null) | ||
} | ||
} | ||
|
Oops, something went wrong.