From 96037d4da60d3dada37f12bd4af79646079ab342 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 17 Apr 2024 22:37:24 -0400 Subject: [PATCH] Android pull refresh fixes. Sigh. --- .../unprompted/tildefriends/MainActivity.java | 11 +++---- .../com/unprompted/tildefriends/WebView.java | 31 +++++++++++++++++++ src/android/res/layout/activity_main.xml | 2 +- 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 src/android/com/unprompted/tildefriends/WebView.java diff --git a/src/android/com/unprompted/tildefriends/MainActivity.java b/src/android/com/unprompted/tildefriends/MainActivity.java index a4b55632..b0562519 100644 --- a/src/android/com/unprompted/tildefriends/MainActivity.java +++ b/src/android/com/unprompted/tildefriends/MainActivity.java @@ -26,7 +26,7 @@ import android.webkit.URLUtil; import android.webkit.ValueCallback; import android.webkit.WebChromeClient; import android.webkit.WebResourceRequest; -import android.webkit.WebView; +//import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Button; import android.widget.TextView; @@ -182,7 +182,6 @@ public class MainActivity extends Activity { }); web_view.setWebChromeClient(new WebChromeClient() { - @Override public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) { new AlertDialog.Builder(view.getContext()) .setTitle("Tilde Friends") @@ -211,7 +210,6 @@ public class MainActivity extends Activity { ** https://stackoverflow.com/questions/8586691/how-to-open-file-save-dialog-in-android */ - @Override public boolean onShowFileChooser(WebView view, ValueCallback message, WebChromeClient.FileChooserParams params) { upload_message = message; Intent intent = new Intent(Intent.ACTION_GET_CONTENT); @@ -221,7 +219,6 @@ public class MainActivity extends Activity { return true; } - @Override public boolean onConsoleMessage(android.webkit.ConsoleMessage consoleMessage) { Log.d("tildefriends", consoleMessage.message() + " -- From line " + consoleMessage.lineNumber() + " of " + consoleMessage.sourceId()); return true; @@ -229,7 +226,6 @@ public class MainActivity extends Activity { }); web_view.setWebViewClient(new WebViewClient() { - @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { if (request.getUrl() != null && request.getUrl().toString().startsWith(base_url)) { @@ -304,10 +300,11 @@ public class MainActivity extends Activity { switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: touch_down_y = event.getY(); + web_view.clearOverscrolledY(); break; case MotionEvent.ACTION_MOVE: { - float delta = event.getY() - touch_down_y; + float delta = web_view.getOverscrolledY() ? event.getY() - touch_down_y : 0.0f; TextView refresh = (TextView)findViewById(R.id.refresh); LayoutParams layout = refresh.getLayoutParams(); layout.height = @@ -319,7 +316,7 @@ public class MainActivity extends Activity { break; case MotionEvent.ACTION_UP: { - float delta = event.getY() - touch_down_y; + float delta = web_view.getOverscrolledY() ? event.getY() - touch_down_y : 0.0f; if (delta > getWindow().getDecorView().getHeight() / 4) { web_view.reload(); } diff --git a/src/android/com/unprompted/tildefriends/WebView.java b/src/android/com/unprompted/tildefriends/WebView.java new file mode 100644 index 00000000..182091e2 --- /dev/null +++ b/src/android/com/unprompted/tildefriends/WebView.java @@ -0,0 +1,31 @@ +package com.unprompted.tildefriends; + +import android.content.Context; +import android.util.AttributeSet; +import android.util.Log; + +public class WebView extends android.webkit.WebView { + boolean overscrolledY = false; + + public WebView(final Context context) { + super(context); + } + + public WebView(final Context context, final AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) { + super.onOverScrolled(scrollX, scrollY, clampedX, clampedY); + overscrolledY = true; + } + + public boolean getOverscrolledY() { + return overscrolledY; + } + + public void clearOverscrolledY() { + overscrolledY = false; + } +} diff --git a/src/android/res/layout/activity_main.xml b/src/android/res/layout/activity_main.xml index da4a4708..3d40a7fe 100644 --- a/src/android/res/layout/activity_main.xml +++ b/src/android/res/layout/activity_main.xml @@ -4,7 +4,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> -