diff --git a/app/src/main/java/com/duckduckgo/app/browser/NestedWebView.kt b/app/src/main/java/com/duckduckgo/app/browser/DuckDuckGoWebView.kt similarity index 76% rename from app/src/main/java/com/duckduckgo/app/browser/NestedWebView.kt rename to app/src/main/java/com/duckduckgo/app/browser/DuckDuckGoWebView.kt index 57ab51aa1179..d92bedfd8bdd 100644 --- a/app/src/main/java/com/duckduckgo/app/browser/NestedWebView.kt +++ b/app/src/main/java/com/duckduckgo/app/browser/DuckDuckGoWebView.kt @@ -17,24 +17,30 @@ package com.duckduckgo.app.browser import android.annotation.SuppressLint +import android.annotation.TargetApi import android.content.Context +import android.os.Build import android.support.v4.view.NestedScrollingChild import android.support.v4.view.NestedScrollingChildHelper import android.support.v4.view.ViewCompat import android.util.AttributeSet import android.view.MotionEvent +import android.view.inputmethod.EditorInfo +import android.view.inputmethod.InputConnection import android.webkit.WebView /** - * NestedWebView which allows the WebView to hide the toolbar when placed in a CoordinatorLayout + * WebView subclass which allows the WebView to + * - hide the toolbar when placed in a CoordinatorLayout + * - add the flag so that users' typing isn't used for personalisation * - * Based on https://github.com/takahirom/webview-in-coordinatorlayout + * Originally based on https://github.com/takahirom/webview-in-coordinatorlayout for scrolling behaviour */ -class NestedWebView : WebView, NestedScrollingChild { +class DuckDuckGoWebView : WebView, NestedScrollingChild { private var lastY: Int = 0 private val scrollOffset = IntArray(2) private val scrollConsumed = IntArray(2) - private var nestedOffetY: Int = 0 + private var nestedOffsetY: Int = 0 private var nestedScrollHelper: NestedScrollingChildHelper = NestedScrollingChildHelper(this) constructor(context: Context) : this(context, null) @@ -43,6 +49,22 @@ class NestedWebView : WebView, NestedScrollingChild { isNestedScrollingEnabled = true } + override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection? { + val inputConnection = super.onCreateInputConnection(outAttrs) ?: return null + + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + addNoPersonalisedFlag(outAttrs) + } + + return inputConnection + } + + + @TargetApi(Build.VERSION_CODES.O) + private fun addNoPersonalisedFlag(outAttrs: EditorInfo) { + outAttrs.imeOptions = outAttrs.imeOptions or EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING + } + @SuppressLint("ClickableViewAccessibility") override fun onTouchEvent(ev: MotionEvent): Boolean { var returnValue = false @@ -50,10 +72,10 @@ class NestedWebView : WebView, NestedScrollingChild { val event = MotionEvent.obtain(ev) val action = event.actionMasked if (action == MotionEvent.ACTION_DOWN) { - nestedOffetY = 0 + nestedOffsetY = 0 } val eventY = event.y.toInt() - event.offsetLocation(0f, nestedOffetY.toFloat()) + event.offsetLocation(0f, nestedOffsetY.toFloat()) when (action) { MotionEvent.ACTION_MOVE -> { @@ -63,14 +85,14 @@ class NestedWebView : WebView, NestedScrollingChild { deltaY -= scrollConsumed[1] lastY = eventY - scrollOffset[1] event.offsetLocation(0f, (-scrollOffset[1]).toFloat()) - nestedOffetY += scrollOffset[1] + nestedOffsetY += scrollOffset[1] } returnValue = super.onTouchEvent(event) if (dispatchNestedScroll(0, scrollOffset[1], 0, deltaY, scrollOffset)) { event.offsetLocation(0f, scrollOffset[1].toFloat()) - nestedOffetY += scrollOffset[1] + nestedOffsetY += scrollOffset[1] lastY -= scrollOffset[1] } } diff --git a/app/src/main/res/layout/fragment_browser_tab.xml b/app/src/main/res/layout/fragment_browser_tab.xml index d31ee5843294..932200994e8c 100644 --- a/app/src/main/res/layout/fragment_browser_tab.xml +++ b/app/src/main/res/layout/fragment_browser_tab.xml @@ -104,7 +104,7 @@ android:elevation="4dp" android:fontFamily="sans-serif-medium" android:hint="@string/omnibarInputHint" - android:imeOptions="flagNoExtractUi|actionDone" + android:imeOptions="flagNoExtractUi|actionDone|flagNoPersonalizedLearning" android:inputType="textUri|textNoSuggestions" android:maxLines="1" android:paddingBottom="4dp" diff --git a/app/src/main/res/layout/include_duckduckgo_browser_webview.xml b/app/src/main/res/layout/include_duckduckgo_browser_webview.xml index f6041a4c73d6..bd8e5518ce57 100644 --- a/app/src/main/res/layout/include_duckduckgo_browser_webview.xml +++ b/app/src/main/res/layout/include_duckduckgo_browser_webview.xml @@ -14,7 +14,7 @@ ~ limitations under the License. --> - - \ No newline at end of file + \ No newline at end of file