1717package com.duckduckgo.app.browser
1818
1919import android.annotation.SuppressLint
20+ import android.annotation.TargetApi
2021import android.content.Context
22+ import android.os.Build
2123import android.support.v4.view.NestedScrollingChild
2224import android.support.v4.view.NestedScrollingChildHelper
2325import android.support.v4.view.ViewCompat
2426import android.util.AttributeSet
2527import android.view.MotionEvent
28+ import android.view.inputmethod.EditorInfo
29+ import android.view.inputmethod.InputConnection
2630import android.webkit.WebView
2731
2832/* *
29- * NestedWebView which allows the WebView to hide the toolbar when placed in a CoordinatorLayout
33+ * WebView subclass which allows the WebView to
34+ * - hide the toolbar when placed in a CoordinatorLayout
35+ * - add the flag so that users' typing isn't used for personalisation
3036 *
31- * Based on https://github.com/takahirom/webview-in-coordinatorlayout
37+ * Originally based on https://github.com/takahirom/webview-in-coordinatorlayout for scrolling behaviour
3238 */
33- class NestedWebView : WebView , NestedScrollingChild {
39+ class DuckDuckGoWebView : WebView , NestedScrollingChild {
3440 private var lastY: Int = 0
3541 private val scrollOffset = IntArray (2 )
3642 private val scrollConsumed = IntArray (2 )
37- private var nestedOffetY : Int = 0
43+ private var nestedOffsetY : Int = 0
3844 private var nestedScrollHelper: NestedScrollingChildHelper = NestedScrollingChildHelper (this )
3945
4046 constructor (context: Context ) : this (context, null )
@@ -43,17 +49,33 @@ class NestedWebView : WebView, NestedScrollingChild {
4349 isNestedScrollingEnabled = true
4450 }
4551
52+ override fun onCreateInputConnection (outAttrs : EditorInfo ): InputConnection ? {
53+ val inputConnection = super .onCreateInputConnection(outAttrs) ? : return null
54+
55+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
56+ addNoPersonalisedFlag(outAttrs)
57+ }
58+
59+ return inputConnection
60+ }
61+
62+
63+ @TargetApi(Build .VERSION_CODES .O )
64+ private fun addNoPersonalisedFlag (outAttrs : EditorInfo ) {
65+ outAttrs.imeOptions = outAttrs.imeOptions or EditorInfo .IME_FLAG_NO_PERSONALIZED_LEARNING
66+ }
67+
4668 @SuppressLint(" ClickableViewAccessibility" )
4769 override fun onTouchEvent (ev : MotionEvent ): Boolean {
4870 var returnValue = false
4971
5072 val event = MotionEvent .obtain(ev)
5173 val action = event.actionMasked
5274 if (action == MotionEvent .ACTION_DOWN ) {
53- nestedOffetY = 0
75+ nestedOffsetY = 0
5476 }
5577 val eventY = event.y.toInt()
56- event.offsetLocation(0f , nestedOffetY .toFloat())
78+ event.offsetLocation(0f , nestedOffsetY .toFloat())
5779
5880 when (action) {
5981 MotionEvent .ACTION_MOVE -> {
@@ -63,14 +85,14 @@ class NestedWebView : WebView, NestedScrollingChild {
6385 deltaY - = scrollConsumed[1 ]
6486 lastY = eventY - scrollOffset[1 ]
6587 event.offsetLocation(0f , (- scrollOffset[1 ]).toFloat())
66- nestedOffetY + = scrollOffset[1 ]
88+ nestedOffsetY + = scrollOffset[1 ]
6789 }
6890
6991 returnValue = super .onTouchEvent(event)
7092
7193 if (dispatchNestedScroll(0 , scrollOffset[1 ], 0 , deltaY, scrollOffset)) {
7294 event.offsetLocation(0f , scrollOffset[1 ].toFloat())
73- nestedOffetY + = scrollOffset[1 ]
95+ nestedOffsetY + = scrollOffset[1 ]
7496 lastY - = scrollOffset[1 ]
7597 }
7698 }
0 commit comments