Skip to content

Commit 4c26bc6

Browse files
CDRussellsubsymbolic
authored andcommitted
Add flag so that users' typed text isn't used for personalisation (#217)
1 parent b958310 commit 4c26bc6

File tree

3 files changed

+33
-11
lines changed

3 files changed

+33
-11
lines changed

app/src/main/java/com/duckduckgo/app/browser/NestedWebView.kt renamed to app/src/main/java/com/duckduckgo/app/browser/DuckDuckGoWebView.kt

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,30 @@
1717
package com.duckduckgo.app.browser
1818

1919
import android.annotation.SuppressLint
20+
import android.annotation.TargetApi
2021
import android.content.Context
22+
import android.os.Build
2123
import android.support.v4.view.NestedScrollingChild
2224
import android.support.v4.view.NestedScrollingChildHelper
2325
import android.support.v4.view.ViewCompat
2426
import android.util.AttributeSet
2527
import android.view.MotionEvent
28+
import android.view.inputmethod.EditorInfo
29+
import android.view.inputmethod.InputConnection
2630
import 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
}

app/src/main/res/layout/fragment_browser_tab.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494
android:elevation="4dp"
9595
android:fontFamily="sans-serif-medium"
9696
android:hint="@string/omnibarInputHint"
97-
android:imeOptions="flagNoExtractUi|actionDone"
97+
android:imeOptions="flagNoExtractUi|actionDone|flagNoPersonalizedLearning"
9898
android:inputType="textUri|textNoSuggestions"
9999
android:maxLines="1"
100100
android:paddingBottom="4dp"

app/src/main/res/layout/include_duckduckgo_browser_webview.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
~ limitations under the License.
1515
-->
1616

17-
<com.duckduckgo.app.browser.NestedWebView xmlns:android="http://schemas.android.com/apk/res/android"
17+
<com.duckduckgo.app.browser.DuckDuckGoWebView xmlns:android="http://schemas.android.com/apk/res/android"
1818
xmlns:tools="http://schemas.android.com/tools"
1919
android:id="@+id/browserWebView"
2020
android:layout_width="match_parent"
@@ -31,4 +31,4 @@
3131
android:visibility="gone"
3232
tools:visibility="visible">
3333

34-
</com.duckduckgo.app.browser.NestedWebView>
34+
</com.duckduckgo.app.browser.DuckDuckGoWebView>

0 commit comments

Comments
 (0)