From b5ed7014f6902a5c525cd85d63c161aa5e82abee Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Fri, 26 Apr 2024 18:10:22 -0400 Subject: [PATCH] Fix attaching files (aka WebView file picking) on Android. --- GNUmakefile | 10 +++++----- apps/ssb/tf-compose.js | 1 - src/android/AndroidManifest.xml | 2 +- ...Activity.java => TildeFriendsActivity.java} | 18 +++++++++++------- .../{WebView.java => TildeFriendsWebView.java} | 6 +++--- src/android/res/layout/activity_main.xml | 2 +- 6 files changed, 21 insertions(+), 18 deletions(-) rename src/android/com/unprompted/tildefriends/{MainActivity.java => TildeFriendsActivity.java} (95%) rename src/android/com/unprompted/tildefriends/{WebView.java => TildeFriendsWebView.java} (73%) diff --git a/GNUmakefile b/GNUmakefile index 57cb475c..3b6583d9 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -57,11 +57,11 @@ CFLAGS += \ -fno-exceptions \ -g -ANDROID_BUILD_TOOLS := $(ANDROID_SDK)/build-tools/34.0.0 -ANDROID_PLATFORM := $(ANDROID_SDK)/platforms/android-34 -ANDROID_NDK ?= $(ANDROID_SDK)/ndk/26.2.11394342 ANDROID_MIN_SDK_VERSION := 24 ANDROID_TARGET_SDK_VERSION := 34 +ANDROID_BUILD_TOOLS := $(ANDROID_SDK)/build-tools/34.0.0 +ANDROID_PLATFORM := $(ANDROID_SDK)/platforms/android-$(ANDROID_TARGET_SDK_VERSION) +ANDROID_NDK ?= $(ANDROID_SDK)/ndk/26.2.11394342 ANDROID_ARMV7A_TARGETS := \ out/androiddebug-armv7a/tildefriends \ @@ -693,7 +693,7 @@ CLASS_FILES := $(foreach src,$(JAVA_FILES),out/classes/com/unprompted/tildefrien $(CLASS_FILES) &: $(JAVA_FILES) @echo "[javac] $(CLASS_FILES)" - @javac --release 8 -Xlint:deprecation -classpath $(ANDROID_PLATFORM)/android.jar -d out/classes $(JAVA_FILES) + @javac --release 8 -encoding UTF-8 -Xlint:deprecation -XDuseUnsharedTable=true -classpath $(ANDROID_PLATFORM)/android.jar:$(ANDROID_BUILD_TOOLS)/core-lambda-stubs.jar -d out/classes $(JAVA_FILES) out/apk/classes.dex: $(CLASS_FILES) @mkdir -p $(dir $@) @@ -759,7 +759,7 @@ release-apk: out/TildeFriends-arm-release.zopfli.apk out/TildeFriends-x86-releas releaseapkgo: out/TildeFriends-arm-release.apk @adb install -r $< - @adb shell am start com.unprompted.tildefriends/.MainActivity + @adb shell am start com.unprompted.tildefriends/.TildeFriendsActivity .PHONY: releaseapkgo # iOS Support diff --git a/apps/ssb/tf-compose.js b/apps/ssb/tf-compose.js index f654de8f..3fe5664a 100644 --- a/apps/ssb/tf-compose.js +++ b/apps/ssb/tf-compose.js @@ -243,7 +243,6 @@ class TfComposeElement extends LitElement { attach() { let self = this; - let edit = this.renderRoot.getElementById('edit'); let input = document.createElement('input'); input.type = 'file'; input.onchange = function (event) { diff --git a/src/android/AndroidManifest.xml b/src/android/AndroidManifest.xml index 53d42585..0b3aaa04 100644 --- a/src/android/AndroidManifest.xml +++ b/src/android/AndroidManifest.xml @@ -12,7 +12,7 @@ android:extractNativeLibs="true"> diff --git a/src/android/com/unprompted/tildefriends/MainActivity.java b/src/android/com/unprompted/tildefriends/TildeFriendsActivity.java similarity index 95% rename from src/android/com/unprompted/tildefriends/MainActivity.java rename to src/android/com/unprompted/tildefriends/TildeFriendsActivity.java index b0562519..97f04259 100644 --- a/src/android/com/unprompted/tildefriends/MainActivity.java +++ b/src/android/com/unprompted/tildefriends/TildeFriendsActivity.java @@ -21,12 +21,13 @@ import android.view.ViewGroup.LayoutParams; import android.view.Window; import android.webkit.CookieManager; import android.webkit.DownloadListener; +import android.webkit.JsPromptResult; import android.webkit.JsResult; 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; @@ -49,8 +50,8 @@ import java.nio.file.WatchKey; import java.nio.file.WatchService; import java.util.concurrent.TimeUnit; -public class MainActivity extends Activity { - WebView web_view; +public class TildeFriendsActivity extends Activity { + TildeFriendsWebView web_view; String base_url; Process process; Thread thread; @@ -69,7 +70,7 @@ public class MainActivity extends Activity { this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); - web_view = (WebView)findViewById(R.id.web); + web_view = (TildeFriendsWebView)findViewById(R.id.web); set_status("Extracting executable..."); Log.w("tildefriends", String.format("getFilesDir() is %s", getFilesDir().toString())); Log.w("tildefriends", String.format("getPackageResourcePath() is %s", getPackageResourcePath().toString())); @@ -79,7 +80,7 @@ public class MainActivity extends Activity { new File(port_file_path).delete(); base_url = "http://127.0.0.1:12345/"; - MainActivity activity = this; + TildeFriendsActivity activity = this; thread = new Thread(new Runnable() { @Override @@ -182,7 +183,8 @@ public class MainActivity extends Activity { }); web_view.setWebChromeClient(new WebChromeClient() { - public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) { + @Override + public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { new AlertDialog.Builder(view.getContext()) .setTitle("Tilde Friends") .setMessage(message) @@ -210,15 +212,17 @@ 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); intent.addCategory(Intent.CATEGORY_OPENABLE); intent.setType("*/*"); - MainActivity.this.startActivityForResult(Intent.createChooser(intent, "File Chooser"), MainActivity.FILECHOOSER_RESULT); + TildeFriendsActivity.this.startActivityForResult(Intent.createChooser(intent, "File Chooser"), TildeFriendsActivity.FILECHOOSER_RESULT); return true; } + @Override public boolean onConsoleMessage(android.webkit.ConsoleMessage consoleMessage) { Log.d("tildefriends", consoleMessage.message() + " -- From line " + consoleMessage.lineNumber() + " of " + consoleMessage.sourceId()); return true; diff --git a/src/android/com/unprompted/tildefriends/WebView.java b/src/android/com/unprompted/tildefriends/TildeFriendsWebView.java similarity index 73% rename from src/android/com/unprompted/tildefriends/WebView.java rename to src/android/com/unprompted/tildefriends/TildeFriendsWebView.java index 182091e2..e56bee09 100644 --- a/src/android/com/unprompted/tildefriends/WebView.java +++ b/src/android/com/unprompted/tildefriends/TildeFriendsWebView.java @@ -4,14 +4,14 @@ import android.content.Context; import android.util.AttributeSet; import android.util.Log; -public class WebView extends android.webkit.WebView { +public class TildeFriendsWebView extends android.webkit.WebView { boolean overscrolledY = false; - public WebView(final Context context) { + public TildeFriendsWebView(final Context context) { super(context); } - public WebView(final Context context, final AttributeSet attrs) { + public TildeFriendsWebView(final Context context, final AttributeSet attrs) { super(context, attrs); } diff --git a/src/android/res/layout/activity_main.xml b/src/android/res/layout/activity_main.xml index 3d40a7fe..0ae98e86 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"> -