Skip to content

Commit

Permalink
Merge pull request #2444 from AndBible/Double-Tap-to-Search
Browse files Browse the repository at this point in the history
Tap with 2 fingers to show the search dialog
  • Loading branch information
tuomas2 authored Jan 7, 2023
2 parents e4edaa6 + 17a335f commit c67a456
Showing 1 changed file with 40 additions and 26 deletions.
66 changes: 40 additions & 26 deletions app/src/main/java/net/bible/android/view/activity/page/BibleView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import android.content.pm.ResolveInfo
import android.graphics.Rect
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.Looper
import android.text.TextUtils
import android.util.LayoutDirection
Expand All @@ -46,12 +47,15 @@ import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.annotation.RequiresApi
import androidx.core.view.GestureDetectorCompat
import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.webkit.WebViewAssetLoader
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import kotlinx.serialization.Serializable
import kotlinx.serialization.SerializationException
import kotlinx.serialization.Transient
import kotlinx.serialization.serializer
import net.bible.android.activity.R
Expand All @@ -75,6 +79,7 @@ import net.bible.android.control.link.LinkControl
import net.bible.android.control.page.BibleDocument
import net.bible.android.control.page.ClientBookmark
import net.bible.android.control.page.ClientBookmarkLabel
import net.bible.android.control.page.CurrentPageManager
import net.bible.android.control.page.Document
import net.bible.android.control.page.DocumentCategory
import net.bible.android.control.page.DocumentWithBookmarks
Expand All @@ -93,6 +98,7 @@ import net.bible.android.control.versification.toVerseRange
import net.bible.android.database.bookmarks.BookmarkEntities
import net.bible.android.database.bookmarks.KJVA
import net.bible.android.database.json
import net.bible.android.view.activity.base.ActivityBase
import net.bible.android.view.activity.base.DocumentView
import net.bible.android.view.activity.base.IntentHelper
import net.bible.android.view.activity.base.SharedActivityState
Expand All @@ -103,21 +109,25 @@ import net.bible.android.view.activity.page.screen.AfterRemoveWebViewEvent
import net.bible.android.view.activity.page.screen.PageTiltScroller
import net.bible.android.view.activity.page.screen.RestoreButtonsVisibilityChanged
import net.bible.android.view.activity.page.screen.WebViewsBuiltEvent
import net.bible.android.view.activity.search.SearchIndex
import net.bible.android.view.activity.search.SearchResults
import net.bible.android.view.util.UiUtils
import net.bible.android.view.util.widget.ShareWidget
import net.bible.service.common.AndBibleAddons
import net.bible.service.common.AndBibleAddons.fontsByModule
import net.bible.service.common.CommonUtils
import net.bible.service.common.CommonUtils.buildActivityComponent
import net.bible.service.common.ReloadAddonsEvent
import net.bible.service.device.ScreenSettings
import org.crosswire.jsword.book.Books
import org.crosswire.jsword.book.sword.SwordBook
import org.crosswire.jsword.index.IndexStatus
import org.crosswire.jsword.index.search.SearchType
import org.crosswire.jsword.passage.Key
import org.crosswire.jsword.passage.KeyUtil
import org.crosswire.jsword.passage.RangedPassage
import org.crosswire.jsword.passage.Verse
import org.crosswire.jsword.passage.VerseRange
import org.crosswire.jsword.versification.BookName
import org.crosswire.jsword.versification.Versification
import org.crosswire.jsword.versification.system.SystemKJVA
import org.crosswire.jsword.versification.system.Versifications
Expand All @@ -128,21 +138,10 @@ import java.util.*
import javax.inject.Inject
import kotlin.math.min

import net.bible.android.control.page.CurrentPageManager
import android.os.Bundle
import androidx.lifecycle.findViewTreeLifecycleOwner
import androidx.lifecycle.lifecycleScope
import kotlinx.serialization.SerializationException
import net.bible.android.view.activity.search.SearchResults
import net.bible.android.view.activity.search.SearchIndex
import org.crosswire.jsword.index.IndexStatus
import org.crosswire.jsword.index.search.SearchType
import org.crosswire.jsword.versification.BookName

class BibleViewInputFocusChanged(val view: BibleView, val newFocus: Boolean)
class AppSettingsUpdated

const val MAX_DOC_STR_LENGTH = 4000000;
const val MAX_DOC_STR_LENGTH = 4000000

@Serializable
class Selection(val bookInitials: String?, val startOrdinal: Int,
Expand Down Expand Up @@ -738,8 +737,8 @@ class BibleView(val mainBibleActivity: MainBibleActivity,

class ModuleAssetHandler: WebViewAssetLoader.PathHandler {
override fun handle(path: String): WebResourceResponse? {
val parts = path.split("/", limit = 2);
if(parts.size != 2) return null;
val parts = path.split("/", limit = 2)
if(parts.size != 2) return null
val (bookName, resourcePath) = parts
val location = File(Books.installed().getBook(bookName).bookMetaData.location)
val f = File(location, resourcePath)
Expand All @@ -751,8 +750,8 @@ class BibleView(val mainBibleActivity: MainBibleActivity,

class ModuleStylesAssetHandler: WebViewAssetLoader.PathHandler {
override fun handle(path: String): WebResourceResponse? {
val parts = path.split("/", limit = 2);
if(parts.size != 2) return null;
val parts = path.split("/", limit = 2)
if(parts.size != 2) return null
val (bookName, resourcePath) = parts
val book = Books.installed().getBook(bookName) ?: return null
val styleFile = book.bookMetaData.getProperty("AndBibleCSS") ?: return null
Expand All @@ -771,8 +770,8 @@ class BibleView(val mainBibleActivity: MainBibleActivity,

class FontsAssetHandler: WebViewAssetLoader.PathHandler {
override fun handle(path: String): WebResourceResponse? {
val parts = path.split("/", limit = 2);
if(parts.size != 2) return null;
val parts = path.split("/", limit = 2)
if(parts.size != 2) return null
val (moduleName, resourcePath) = parts
val book = Books.installed().getBook(moduleName) ?: return null
if(resourcePath == "fonts.css") {
Expand All @@ -799,8 +798,8 @@ class BibleView(val mainBibleActivity: MainBibleActivity,

class FeatureAssetHandler: WebViewAssetLoader.PathHandler {
override fun handle(path: String): WebResourceResponse? {
val parts = path.split("/", limit = 2);
if(parts.size != 2) return null;
val parts = path.split("/", limit = 2)
if(parts.size != 2) return null
val (moduleName, resourcePath) = parts
val book = Books.installed().getBook(moduleName) ?: return null
val location = File(book.bookMetaData.location)
Expand Down Expand Up @@ -1242,11 +1241,26 @@ class BibleView(val mainBibleActivity: MainBibleActivity,
@SuppressLint("ClickableViewAccessibility")
override fun onTouchEvent(event: MotionEvent): Boolean {
windowControl.activeWindow = window

val handled = super.onTouchEvent(event)

// Allow user to redefine viewing angle by touching screen
pageTiltScroller.recalculateViewingPosition()
var handled = false

when (event.action and MotionEvent.ACTION_MASK) {
MotionEvent.ACTION_POINTER_UP -> {
// Touch with 2 fingers to show search dialog
if (event.pointerCount == 2) {
val currentPage = windowControl.activeWindowPageManager.currentPage
if (currentPage.isSearchable) {
val handlerIntent = searchControl.getSearchIntent(currentPage.currentDocument, mainBibleActivity)
mainBibleActivity.startActivityForResult(handlerIntent, ActivityBase.STD_REQUEST_CODE)
handled = true
}
}
}
}
if (!handled) {
handled = super.onTouchEvent(event)
// Allow user to redefine viewing angle by touching screen
pageTiltScroller.recalculateViewingPosition()
}

return handled
}
Expand Down

0 comments on commit c67a456

Please sign in to comment.