From 2af1e7bb4451e46a819b996e37378d2fa457132b Mon Sep 17 00:00:00 2001 From: Andrew Rogers Date: Wed, 4 Jan 2023 20:53:43 +0630 Subject: [PATCH 1/2] Initial attempt to enable the dual tap to activate search dialog And fixed some code suggestions. --- .../android/view/activity/page/BibleView.kt | 68 +++++++++++-------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/net/bible/android/view/activity/page/BibleView.kt b/app/src/main/java/net/bible/android/view/activity/page/BibleView.kt index a3c0fc685d..257b15e8b7 100644 --- a/app/src/main/java/net/bible/android/view/activity/page/BibleView.kt +++ b/app/src/main/java/net/bible/android/view/activity/page/BibleView.kt @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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, @@ -686,7 +685,7 @@ class BibleView(val mainBibleActivity: MainBibleActivity, "?lang=$lang&fontModuleNames=$fontModuleNames&styleModuleNames=$styleModuleNames&featureModuleNames=$featureModuleNames&rtl=$isRtl&night=$nightMode") } - fun onEvent(e: ReloadAddonsEvent) { + fun onEvent() { val fontModuleNames = json.encodeToString(serializer(), AndBibleAddons.fontModuleNames) val featureModuleNames = json.encodeToString(serializer(), AndBibleAddons.featureModuleNames) val styleModuleNames = json.encodeToString(serializer(), AndBibleAddons.styleModuleNames) @@ -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) @@ -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 @@ -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") { @@ -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) @@ -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 } From 17a335fb26ea3a05601aa4cbafa715794073d0b3 Mon Sep 17 00:00:00 2001 From: Tuomas Airaksinen Date: Sat, 7 Jan 2023 10:27:36 +0200 Subject: [PATCH 2/2] Apply suggestions from code review --- .../main/java/net/bible/android/view/activity/page/BibleView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/net/bible/android/view/activity/page/BibleView.kt b/app/src/main/java/net/bible/android/view/activity/page/BibleView.kt index 257b15e8b7..c46564e376 100644 --- a/app/src/main/java/net/bible/android/view/activity/page/BibleView.kt +++ b/app/src/main/java/net/bible/android/view/activity/page/BibleView.kt @@ -685,7 +685,7 @@ class BibleView(val mainBibleActivity: MainBibleActivity, "?lang=$lang&fontModuleNames=$fontModuleNames&styleModuleNames=$styleModuleNames&featureModuleNames=$featureModuleNames&rtl=$isRtl&night=$nightMode") } - fun onEvent() { + fun onEvent(e: ReloadAddonsEvent) { val fontModuleNames = json.encodeToString(serializer(), AndBibleAddons.fontModuleNames) val featureModuleNames = json.encodeToString(serializer(), AndBibleAddons.featureModuleNames) val styleModuleNames = json.encodeToString(serializer(), AndBibleAddons.styleModuleNames)