Android pull refresh fixes. Sigh.

This commit is contained in:
Cory McWilliams 2024-04-17 22:37:24 -04:00
parent 5448e773d8
commit 96037d4da6
3 changed files with 36 additions and 8 deletions

View File

@ -26,7 +26,7 @@ import android.webkit.URLUtil;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
import android.webkit.WebChromeClient; import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest; import android.webkit.WebResourceRequest;
import android.webkit.WebView; //import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
@ -182,7 +182,6 @@ public class MainActivity extends Activity {
}); });
web_view.setWebChromeClient(new WebChromeClient() { web_view.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) { public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
new AlertDialog.Builder(view.getContext()) new AlertDialog.Builder(view.getContext())
.setTitle("Tilde Friends") .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 ** https://stackoverflow.com/questions/8586691/how-to-open-file-save-dialog-in-android
*/ */
@Override
public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> message, WebChromeClient.FileChooserParams params) { public boolean onShowFileChooser(WebView view, ValueCallback<Uri[]> message, WebChromeClient.FileChooserParams params) {
upload_message = message; upload_message = message;
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
@ -221,7 +219,6 @@ public class MainActivity extends Activity {
return true; return true;
} }
@Override
public boolean onConsoleMessage(android.webkit.ConsoleMessage consoleMessage) { public boolean onConsoleMessage(android.webkit.ConsoleMessage consoleMessage) {
Log.d("tildefriends", consoleMessage.message() + " -- From line " + consoleMessage.lineNumber() + " of " + consoleMessage.sourceId()); Log.d("tildefriends", consoleMessage.message() + " -- From line " + consoleMessage.lineNumber() + " of " + consoleMessage.sourceId());
return true; return true;
@ -229,7 +226,6 @@ public class MainActivity extends Activity {
}); });
web_view.setWebViewClient(new WebViewClient() { web_view.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request)
{ {
if (request.getUrl() != null && request.getUrl().toString().startsWith(base_url)) { if (request.getUrl() != null && request.getUrl().toString().startsWith(base_url)) {
@ -304,10 +300,11 @@ public class MainActivity extends Activity {
switch (event.getActionMasked()) { switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_DOWN:
touch_down_y = event.getY(); touch_down_y = event.getY();
web_view.clearOverscrolledY();
break; break;
case MotionEvent.ACTION_MOVE: 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); TextView refresh = (TextView)findViewById(R.id.refresh);
LayoutParams layout = refresh.getLayoutParams(); LayoutParams layout = refresh.getLayoutParams();
layout.height = layout.height =
@ -319,7 +316,7 @@ public class MainActivity extends Activity {
break; break;
case MotionEvent.ACTION_UP: 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) { if (delta > getWindow().getDecorView().getHeight() / 4) {
web_view.reload(); web_view.reload();
} }

View File

@ -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;
}
}

View File

@ -4,7 +4,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<WebView <com.unprompted.tildefriends.WebView
android:id="@+id/web" android:id="@+id/web"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"/> android:layout_height="match_parent"/>