2 * Copyright © 2019-2022 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
6 * Privacy Browser Android is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser Android is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser Android. If not, see <http://www.gnu.org/licenses/>.
20 package com.stoutner.privacybrowser.views
22 import android.animation.ObjectAnimator
23 import android.annotation.SuppressLint
24 import android.content.Context
25 import android.graphics.Bitmap
26 import android.graphics.drawable.BitmapDrawable
27 import android.os.Bundle
28 import android.util.AttributeSet
29 import android.view.MotionEvent
30 import android.webkit.WebView
31 import android.webkit.SslErrorHandler
32 import android.webkit.HttpAuthHandler
34 import androidx.core.content.ContextCompat
35 import androidx.core.view.NestedScrollingChild2
36 import androidx.core.view.NestedScrollingChildHelper
37 import androidx.core.view.ViewCompat
39 import com.stoutner.privacybrowser.R
40 import com.stoutner.privacybrowser.activities.MainWebViewActivity
42 import java.util.Collections
45 import kotlin.collections.ArrayList
47 import kotlin.jvm.JvmOverloads
49 // Define the saved state constants.
50 private const val DOMAIN_SETTINGS_APPLIED = "domain_settings_applied"
51 private const val DOMAIN_SETTINGS_DATABASE_ID = "domain_settings_database_id"
52 private const val CURRENT_DOMAIN_NAME = "current_domain_name"
53 private const val CURRENT_URl = "current_url"
54 private const val ACCEPT_COOKIES = "accept_cookies"
55 private const val EASYLIST_ENABLED = "easylist_enabled"
56 private const val EASYPRIVACY_ENABLED = "easyprivacy_enabled"
57 private const val FANBOYS_ANNOYANCE_LIST_ENABLED = "fanboys_annoyance_list_enabled"
58 private const val FANBOYS_SOCIAL_BLOCKING_LIST_ENABLED = "fanboys_social_blocking_list_enabled"
59 private const val ULTRALIST_ENABLED = "ultralist_enabled"
60 private const val ULTRAPRIVACY_ENABLED = "ultraprivacy_enabled"
61 private const val BLOCK_ALL_THIRD_PARTY_REQUESTS = "block_all_third_party_requests"
62 private const val HAS_PINNED_SSL_CERTIFICATE = "has_pinned_ssl_certificate"
63 private const val PINNED_SSL_ISSUED_TO_CNAME = "pinned_ssl_issued_to_cname"
64 private const val PINNED_SSL_ISSUED_TO_ONAME = "pinned_ssl_issued_to_oname"
65 private const val PINNED_SSL_ISSUED_TO_UNAME = "pinned_ssl_issued_to_uname"
66 private const val PINNED_SSL_ISSUED_BY_CNAME = "pinned_ssl_issued_by_cname"
67 private const val PINNED_SSL_ISSUED_BY_ONAME = "pinned_ssl_issued_by_oname"
68 private const val PINNED_SSL_ISSUED_BY_UNAME = "pinned_ssl_issued_by_uname"
69 private const val PINNED_SSL_START_DATE = "pinned_ssl_start_date"
70 private const val PINNED_SSL_END_DATE = "pinned_ssl_end_date"
71 private const val PINNED_IP_ADDRESSES = "pinned_ip_addresses"
72 private const val IGNORE_PINNED_DOMAIN_INFORMATION = "ignore_pinned_domain_information"
73 private const val SWIPE_TO_REFRESH = "swipe_to_refresh"
74 private const val JAVASCRIPT_ENABLED = "javascript_enabled"
75 private const val DOM_STORAGE_ENABLED = "dom_storage_enabled"
76 private const val USER_AGENT = "user_agent"
77 private const val WIDE_VIEWPORT = "wide_viewport"
78 private const val FONT_SIZE = "font_size"
80 // NestedScrollWebView extends WebView to handle nested scrolls (scrolling the app bar off the screen). It also stores extra information about the state of the WebView used by Privacy Browser.
81 class NestedScrollWebView @JvmOverloads constructor(context: Context, attributeSet: AttributeSet? = null, defaultStyle: Int = android.R.attr.webViewStyle) : WebView(context, attributeSet, defaultStyle),
82 NestedScrollingChild2 {
84 // Define the public companion object constants. These can be moved to public class constants once the entire project has migrated to Kotlin.
85 const val BLOCKED_REQUESTS = 0
86 const val EASYLIST = 1
87 const val EASYPRIVACY = 2
88 const val FANBOYS_ANNOYANCE_LIST = 3
89 const val FANBOYS_SOCIAL_BLOCKING_LIST = 4
90 const val ULTRALIST = 5
91 const val ULTRAPRIVACY = 6
92 const val THIRD_PARTY_REQUESTS = 7
95 // Define the public variables.
96 var acceptCookies = false
97 var blockAllThirdPartyRequests = false
98 var currentDomainName = ""
99 var currentIpAddresses = ""
101 var domainSettingsApplied = false
102 var domainSettingsDatabaseId = 0
103 var easyListEnabled = true
104 var easyPrivacyEnabled = true
105 var fanboysAnnoyanceListEnabled = true
106 var fanboysSocialBlockingListEnabled = true
107 var httpAuthHandler: HttpAuthHandler? = null
108 var ignorePinnedDomainInformation = false
109 var pinnedIpAddresses = ""
110 var sslErrorHandler: SslErrorHandler? = null
111 var swipeToRefresh = false
112 var ultraListEnabled = true
113 var ultraPrivacyEnabled = true
114 var waitingForProxyUrlString = ""
115 var webViewFragmentId: Long = 0
118 // Define the private variables.
119 private val nestedScrollingChildHelper: NestedScrollingChildHelper = NestedScrollingChildHelper(this)
120 private lateinit var favoriteOrDefaultIcon: Bitmap
121 private var previousYPosition = 0 // The previous Y position needs to be tracked between motion events.
122 private var hasPinnedSslCertificate = false
123 private var pinnedSslIssuedToCName = ""
124 private var pinnedSslIssuedToOName = ""
125 private var pinnedSslIssuedToUName = ""
126 private var pinnedSslIssuedByCName = ""
127 private var pinnedSslIssuedByOName = ""
128 private var pinnedSslIssuedByUName = ""
129 private var pinnedSslStartDate = Date(0)
130 private var pinnedSslEndDate = Date(0)
131 private val resourceRequests = Collections.synchronizedList(ArrayList<Array<String>>()) // Using a synchronized list makes adding resource requests thread safe.
132 private var blockedRequests = 0
133 private var easyListBlockedRequests = 0
134 private var easyPrivacyBlockedRequests = 0
135 private var fanboysAnnoyanceListBlockedRequests = 0
136 private var fanboysSocialBlockingListBlockedRequests = 0
137 private var ultraListBlockedRequests = 0
138 private var ultraPrivacyBlockedRequests = 0
139 private var thirdPartyBlockedRequests = 0
142 // Enable nested scrolling by default.
143 nestedScrollingChildHelper.isNestedScrollingEnabled = true
145 // Initialize the favorite icon.
146 initializeFavoriteIcon()
150 // Favorite or default icon.
151 fun initializeFavoriteIcon() {
152 // Get the default favorite icon drawable. `ContextCompat` must be used until API >= 21.
153 val favoriteIconDrawable = ContextCompat.getDrawable(context, R.drawable.world)
155 // Cast the favorite icon drawable to a bitmap drawable.
156 val favoriteIconBitmapDrawable = (favoriteIconDrawable as BitmapDrawable?)!!
158 // Store the default icon bitmap.
159 favoriteOrDefaultIcon = favoriteIconBitmapDrawable.bitmap
162 fun setFavoriteOrDefaultIcon(icon: Bitmap) {
163 // Scale the favorite icon bitmap down if it is larger than 256 x 256. Filtering uses bilinear interpolation.
164 favoriteOrDefaultIcon = if (icon.height > 256 || icon.width > 256) {
165 Bitmap.createScaledBitmap(icon, 256, 256, true)
167 // Store the icon as presented.
172 fun getFavoriteOrDefaultIcon(): Bitmap {
173 // Return the favorite or default icon. This is the only way to return a non-nullable variable while retaining the custom initialization and setter functions above.
174 return favoriteOrDefaultIcon
178 // Reset the handlers.
179 fun resetSslErrorHandler() {
180 // Reset the current SSL error handler.
181 sslErrorHandler = null
184 fun resetHttpAuthHandler() {
185 // Reset the current HTTP authentication handler.
186 httpAuthHandler = null
190 // Pinned SSL certificates.
191 fun hasPinnedSslCertificate(): Boolean {
192 // Return the status of the pinned SSL certificate.
193 return hasPinnedSslCertificate
196 fun setPinnedSslCertificate(issuedToCName: String, issuedToOName: String, issuedToUName: String, issuedByCName: String, issuedByOName: String, issuedByUName: String, startDate: Date, endDate: Date) {
197 // Store the pinned SSL certificate information.
198 pinnedSslIssuedToCName = issuedToCName
199 pinnedSslIssuedToOName = issuedToOName
200 pinnedSslIssuedToUName = issuedToUName
201 pinnedSslIssuedByCName = issuedByCName
202 pinnedSslIssuedByOName = issuedByOName
203 pinnedSslIssuedByUName = issuedByUName
204 pinnedSslStartDate = startDate
205 pinnedSslEndDate = endDate
207 // Set the pinned SSL certificate tracker.
208 hasPinnedSslCertificate = true
211 fun getPinnedSslCertificate(): ArrayList<Any> {
212 // Initialize an array list.
213 val arrayList = ArrayList<Any>()
215 // Create the SSL certificate string array.
216 val sslCertificateStringArray = arrayOf(pinnedSslIssuedToCName, pinnedSslIssuedToOName, pinnedSslIssuedToUName, pinnedSslIssuedByCName, pinnedSslIssuedByOName, pinnedSslIssuedByUName)
218 // Create the SSL certificate date array.
219 val sslCertificateDateArray = arrayOf(pinnedSslStartDate, pinnedSslEndDate)
221 // Add the arrays to the array list.
222 arrayList.add(sslCertificateStringArray)
223 arrayList.add(sslCertificateDateArray)
225 // Return the pinned SSL certificate array list.
229 fun clearPinnedSslCertificate() {
230 // Clear the pinned SSL certificate.
231 pinnedSslIssuedToCName = ""
232 pinnedSslIssuedToOName = ""
233 pinnedSslIssuedToUName = ""
234 pinnedSslIssuedByCName = ""
235 pinnedSslIssuedByOName = ""
236 pinnedSslIssuedByUName = ""
237 pinnedSslStartDate = Date(0)
238 pinnedSslEndDate = Date(0)
240 // Clear the pinned SSL certificate tracker.
241 hasPinnedSslCertificate = false
245 // Resource requests.
246 fun addResourceRequest(resourceRequest: Array<String>) {
247 // Add the resource request to the list.
248 resourceRequests.add(resourceRequest)
251 fun getResourceRequests(): List<Array<String>> {
252 // Return the list of resource requests as an array list.
253 return resourceRequests
256 fun clearResourceRequests() {
257 // Clear the resource requests.
258 resourceRequests.clear()
262 // Resource request counters.
263 fun incrementRequestsCount(blocklist: Int) {
264 // Increment the count of the indicated blocklist.
266 BLOCKED_REQUESTS -> blockedRequests++
267 EASYLIST -> easyListBlockedRequests++
268 EASYPRIVACY -> easyPrivacyBlockedRequests++
269 FANBOYS_ANNOYANCE_LIST -> fanboysAnnoyanceListBlockedRequests++
270 FANBOYS_SOCIAL_BLOCKING_LIST -> fanboysSocialBlockingListBlockedRequests++
271 ULTRALIST -> ultraListBlockedRequests++
272 ULTRAPRIVACY -> ultraPrivacyBlockedRequests++
273 THIRD_PARTY_REQUESTS -> thirdPartyBlockedRequests++
277 fun getRequestsCount(blocklist: Int): Int {
278 // Return the count of the indicated blocklist.
279 return when (blocklist) {
280 BLOCKED_REQUESTS -> blockedRequests
281 EASYLIST -> easyListBlockedRequests
282 EASYPRIVACY -> easyPrivacyBlockedRequests
283 FANBOYS_ANNOYANCE_LIST -> fanboysAnnoyanceListBlockedRequests
284 FANBOYS_SOCIAL_BLOCKING_LIST -> fanboysSocialBlockingListBlockedRequests
285 ULTRALIST -> ultraListBlockedRequests
286 ULTRAPRIVACY -> ultraPrivacyBlockedRequests
287 THIRD_PARTY_REQUESTS -> thirdPartyBlockedRequests
288 else -> 0 // Return 0. This should never be called, but it is required by the return when statement.
292 fun resetRequestsCounters() {
293 // Reset all the resource request counters.
295 easyListBlockedRequests = 0
296 easyPrivacyBlockedRequests = 0
297 fanboysAnnoyanceListBlockedRequests = 0
298 fanboysSocialBlockingListBlockedRequests = 0
299 ultraListBlockedRequests = 0
300 ultraPrivacyBlockedRequests = 0
301 thirdPartyBlockedRequests = 0
305 // Publicly expose the scroll ranges.
306 fun getHorizontalScrollRange(): Int {
307 // Return the horizontal scroll range.
308 return computeHorizontalScrollRange()
311 fun getVerticalScrollRange(): Int {
312 // Return the vertical scroll range.
313 return computeVerticalScrollRange()
316 override fun onOverScrolled(scrollX: Int, scrollY: Int, clampedX: Boolean, clampedY: Boolean) {
317 // Run the default commands.
318 super.onOverScrolled(scrollX, scrollY, clampedX, clampedY)
320 // Display the bottom app bar if it has been hidden and the WebView was over-scrolled at the top of the screen.
321 if ((MainWebViewActivity.appBarLayout.translationY != 0f) && (scrollY == 0) && clampedY) {
322 // Animate the bottom app bar onto the screen.
323 val objectAnimator = ObjectAnimator.ofFloat(MainWebViewActivity.appBarLayout, "translationY", 0f)
326 objectAnimator.start()
331 @SuppressLint("ClickableViewAccessibility")
332 override fun onTouchEvent(motionEvent: MotionEvent): Boolean {
333 // Run the commands for the given motion event action.
334 when (motionEvent.action) {
335 MotionEvent.ACTION_DOWN -> {
336 // Start nested scrolling along the vertical axis. `ViewCompat` must be used until the minimum API >= 21.
337 startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL)
339 // Save the current Y position. Action down will not be called again until a new motion starts.
340 previousYPosition = motionEvent.y.toInt()
342 MotionEvent.ACTION_MOVE -> {
343 // Get the current Y position.
344 val currentYMotionPosition = motionEvent.y.toInt()
346 // Calculate the pre-scroll delta Y.
347 val preScrollDeltaY = previousYPosition - currentYMotionPosition
349 // Initialize a variable to track how much of the scroll is consumed.
350 val consumedScroll = IntArray(2)
352 // Initialize a variable to track the offset in the window.
353 val offsetInWindow = IntArray(2)
355 // Get the WebView Y position.
356 val webViewYPosition = scrollY
358 // Set the scroll delta Y to initially be the same as the pre-scroll delta Y.
359 var scrollDeltaY = preScrollDeltaY
361 // Dispatch the nested pre-school. This scrolls the app bar if it needs it. `offsetInWindow` will be returned with an updated value.
362 if (dispatchNestedPreScroll(0, preScrollDeltaY, consumedScroll, offsetInWindow)) {
363 // Update the scroll delta Y if some of it was consumed.
364 scrollDeltaY = preScrollDeltaY - consumedScroll[1]
367 // Check to see if the WebView is at the top and and the scroll action is downward.
368 if (webViewYPosition == 0 && scrollDeltaY < 0) { // Swipe to refresh is being engaged.
369 // Stop the nested scroll so that swipe to refresh has complete control. This way releasing the scroll to refresh circle doesn't scroll the WebView at the same time.
371 } else { // Swipe to refresh is not being engaged.
372 // Start the nested scroll so that the app bar can scroll off the screen.
373 startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL)
375 // Dispatch the nested scroll. This scrolls the WebView. The delta Y unconsumed normally controls the swipe refresh layout, but that is handled with the `if` statement above.
376 dispatchNestedScroll(0, scrollDeltaY, 0, 0, offsetInWindow)
378 // Store the current Y position for use in the next action move.
379 previousYPosition -= scrollDeltaY
382 else -> stopNestedScroll() // Stop nested scrolling.
385 // Perform a click. This is required by the Android accessibility guidelines.
388 // Run the default commands and return the result.
389 return super.onTouchEvent(motionEvent)
393 // Save and restore state.
394 fun saveNestedScrollWebViewState(): Bundle {
395 // Create a saved state bundle.
396 val savedState = Bundle()
398 // Populate the saved state bundle.
399 savedState.putBoolean(DOMAIN_SETTINGS_APPLIED, domainSettingsApplied)
400 savedState.putInt(DOMAIN_SETTINGS_DATABASE_ID, domainSettingsDatabaseId)
401 savedState.putString(CURRENT_DOMAIN_NAME, currentDomainName)
402 savedState.putString(CURRENT_URl, currentUrl)
403 savedState.putBoolean(ACCEPT_COOKIES, acceptCookies)
404 savedState.putBoolean(EASYLIST_ENABLED, easyListEnabled)
405 savedState.putBoolean(EASYPRIVACY_ENABLED, easyPrivacyEnabled)
406 savedState.putBoolean(FANBOYS_ANNOYANCE_LIST_ENABLED, fanboysAnnoyanceListEnabled)
407 savedState.putBoolean(FANBOYS_SOCIAL_BLOCKING_LIST_ENABLED, fanboysSocialBlockingListEnabled)
408 savedState.putBoolean(ULTRALIST_ENABLED, ultraListEnabled)
409 savedState.putBoolean(ULTRAPRIVACY_ENABLED, ultraPrivacyEnabled)
410 savedState.putBoolean(BLOCK_ALL_THIRD_PARTY_REQUESTS, blockAllThirdPartyRequests)
411 savedState.putBoolean(HAS_PINNED_SSL_CERTIFICATE, hasPinnedSslCertificate)
412 savedState.putString(PINNED_SSL_ISSUED_TO_CNAME, pinnedSslIssuedToCName)
413 savedState.putString(PINNED_SSL_ISSUED_TO_ONAME, pinnedSslIssuedToOName)
414 savedState.putString(PINNED_SSL_ISSUED_TO_UNAME, pinnedSslIssuedToUName)
415 savedState.putString(PINNED_SSL_ISSUED_BY_CNAME, pinnedSslIssuedByCName)
416 savedState.putString(PINNED_SSL_ISSUED_BY_ONAME, pinnedSslIssuedByOName)
417 savedState.putString(PINNED_SSL_ISSUED_BY_UNAME, pinnedSslIssuedByUName)
418 savedState.putLong(PINNED_SSL_START_DATE, pinnedSslStartDate.time)
419 savedState.putLong(PINNED_SSL_END_DATE, pinnedSslEndDate.time)
420 savedState.putString(PINNED_IP_ADDRESSES, pinnedIpAddresses)
421 savedState.putBoolean(IGNORE_PINNED_DOMAIN_INFORMATION, ignorePinnedDomainInformation)
422 savedState.putBoolean(SWIPE_TO_REFRESH, swipeToRefresh)
423 savedState.putBoolean(JAVASCRIPT_ENABLED, this.settings.javaScriptEnabled)
424 savedState.putBoolean(DOM_STORAGE_ENABLED, this.settings.domStorageEnabled)
425 savedState.putString(USER_AGENT, this.settings.userAgentString)
426 savedState.putBoolean(WIDE_VIEWPORT, this.settings.useWideViewPort)
427 savedState.putInt(FONT_SIZE, this.settings.textZoom)
429 // Return the saved state bundle.
433 fun restoreNestedScrollWebViewState(savedState: Bundle) {
434 // Restore the class variables.
435 domainSettingsApplied = savedState.getBoolean(DOMAIN_SETTINGS_APPLIED)
436 domainSettingsDatabaseId = savedState.getInt(DOMAIN_SETTINGS_DATABASE_ID)
437 currentDomainName = savedState.getString(CURRENT_DOMAIN_NAME)!!
438 currentUrl = savedState.getString(CURRENT_URl)!!
439 acceptCookies = savedState.getBoolean(ACCEPT_COOKIES)
440 easyListEnabled = savedState.getBoolean(EASYLIST_ENABLED)
441 easyPrivacyEnabled = savedState.getBoolean(EASYPRIVACY_ENABLED)
442 fanboysAnnoyanceListEnabled = savedState.getBoolean(FANBOYS_ANNOYANCE_LIST_ENABLED)
443 fanboysSocialBlockingListEnabled = savedState.getBoolean(FANBOYS_SOCIAL_BLOCKING_LIST_ENABLED)
444 ultraListEnabled = savedState.getBoolean(ULTRALIST_ENABLED)
445 ultraPrivacyEnabled = savedState.getBoolean(ULTRAPRIVACY_ENABLED)
446 blockAllThirdPartyRequests = savedState.getBoolean(BLOCK_ALL_THIRD_PARTY_REQUESTS)
447 hasPinnedSslCertificate = savedState.getBoolean(HAS_PINNED_SSL_CERTIFICATE)
448 pinnedSslIssuedToCName = savedState.getString(PINNED_SSL_ISSUED_TO_CNAME)!!
449 pinnedSslIssuedToOName = savedState.getString(PINNED_SSL_ISSUED_TO_ONAME)!!
450 pinnedSslIssuedToUName = savedState.getString(PINNED_SSL_ISSUED_TO_UNAME)!!
451 pinnedSslIssuedByCName = savedState.getString(PINNED_SSL_ISSUED_BY_CNAME)!!
452 pinnedSslIssuedByOName = savedState.getString(PINNED_SSL_ISSUED_BY_ONAME)!!
453 pinnedSslIssuedByUName = savedState.getString(PINNED_SSL_ISSUED_BY_UNAME)!!
454 pinnedSslStartDate = Date(savedState.getLong(PINNED_SSL_START_DATE))
455 pinnedSslEndDate = Date(savedState.getLong(PINNED_SSL_END_DATE))
456 pinnedIpAddresses = savedState.getString(PINNED_IP_ADDRESSES)!!
457 ignorePinnedDomainInformation = savedState.getBoolean(IGNORE_PINNED_DOMAIN_INFORMATION)
458 swipeToRefresh = savedState.getBoolean(SWIPE_TO_REFRESH)
459 this.settings.javaScriptEnabled = savedState.getBoolean(JAVASCRIPT_ENABLED)
460 this.settings.domStorageEnabled = savedState.getBoolean(DOM_STORAGE_ENABLED)
461 this.settings.userAgentString = savedState.getString(USER_AGENT)
462 this.settings.useWideViewPort = savedState.getBoolean(WIDE_VIEWPORT)
463 this.settings.textZoom = savedState.getInt(FONT_SIZE)
467 // Method from NestedScrollingChild.
468 override fun setNestedScrollingEnabled(status: Boolean) {
469 // Set the status of the nested scrolling.
470 nestedScrollingChildHelper.isNestedScrollingEnabled = status
473 // Method from NestedScrollingChild.
474 override fun isNestedScrollingEnabled(): Boolean {
475 // Return the status of nested scrolling.
476 return nestedScrollingChildHelper.isNestedScrollingEnabled
479 // Method from NestedScrollingChild.
480 override fun startNestedScroll(axes: Int): Boolean {
481 // Start a nested scroll along the indicated axes.
482 return nestedScrollingChildHelper.startNestedScroll(axes)
485 // Method from NestedScrollingChild2.
486 override fun startNestedScroll(axes: Int, type: Int): Boolean {
487 // Start a nested scroll along the indicated axes for the given type of input which caused the scroll event.
488 return nestedScrollingChildHelper.startNestedScroll(axes, type)
491 // Method from NestedScrollingChild.
492 override fun stopNestedScroll() {
493 // Stop the nested scroll.
494 nestedScrollingChildHelper.stopNestedScroll()
497 // Method from NestedScrollingChild2.
498 override fun stopNestedScroll(type: Int) {
499 // Stop the nested scroll of the given type of input which caused the scroll event.
500 nestedScrollingChildHelper.stopNestedScroll(type)
503 // Method from NestedScrollingChild.
504 override fun hasNestedScrollingParent(): Boolean {
505 // Return the status of the nested scrolling parent.
506 return nestedScrollingChildHelper.hasNestedScrollingParent()
509 // Method from NestedScrollingChild2.
510 override fun hasNestedScrollingParent(type: Int): Boolean {
511 // return the status of the nested scrolling parent for the given type of input which caused the scroll event.
512 return nestedScrollingChildHelper.hasNestedScrollingParent(type)
515 // Method from NestedScrollingChild.
516 override fun dispatchNestedPreScroll(deltaX: Int, deltaY: Int, consumed: IntArray?, offsetInWindow: IntArray?): Boolean {
517 // Dispatch a nested pre-scroll with the specified deltas, which lets a parent to consume some of the scroll if desired.
518 return nestedScrollingChildHelper.dispatchNestedPreScroll(deltaX, deltaY, consumed, offsetInWindow)
521 // Method from NestedScrollingChild2.
522 override fun dispatchNestedPreScroll(deltaX: Int, deltaY: Int, consumed: IntArray?, offsetInWindow: IntArray?, type: Int): Boolean {
523 // Dispatch a nested pre-scroll with the specified deltas for the given type of input which caused the scroll event, which lets a parent to consume some of the scroll if desired.
524 return nestedScrollingChildHelper.dispatchNestedPreScroll(deltaX, deltaY, consumed, offsetInWindow, type)
527 // Method from NestedScrollingChild.
528 override fun dispatchNestedScroll(deltaXConsumed: Int, deltaYConsumed: Int, deltaXUnconsumed: Int, deltaYUnconsumed: Int, offsetInWindow: IntArray?): Boolean {
529 // Dispatch a nested scroll with the specified deltas.
530 return nestedScrollingChildHelper.dispatchNestedScroll(deltaXConsumed, deltaYConsumed, deltaXUnconsumed, deltaYUnconsumed, offsetInWindow)
533 // Method from NestedScrollingChild2.
534 override fun dispatchNestedScroll(deltaXConsumed: Int, deltaYConsumed: Int, deltaXUnconsumed: Int, deltaYUnconsumed: Int, offsetInWindow: IntArray?, type: Int): Boolean {
535 // Dispatch a nested scroll with the specified deltas for the given type of input which caused the scroll event.
536 return nestedScrollingChildHelper.dispatchNestedScroll(deltaXConsumed, deltaYConsumed, deltaXUnconsumed, deltaYUnconsumed, offsetInWindow, type)
539 // Method from NestedScrollingChild.
540 override fun dispatchNestedPreFling(velocityX: Float, velocityY: Float): Boolean {
541 // Dispatch a nested pre-fling with the specified velocity, which lets a parent consume the fling if desired.
542 return nestedScrollingChildHelper.dispatchNestedPreFling(velocityX, velocityY)
545 // Method from NestedScrollingChild.
546 override fun dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean): Boolean {
547 // Dispatch a nested fling with the specified velocity.
548 return nestedScrollingChildHelper.dispatchNestedFling(velocityX, velocityY, consumed)