From 37edbd9824ef7265b8a92439c756dc0e1deff5b6 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Tue, 14 Mar 2023 02:38:56 +0000 Subject: [PATCH] Get forward and back gestures working, and hide the title bar. Hiding the action bar still eludes me. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4219 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- .../unprompted/tildefriends/MainActivity.java | 36 +++++++++++++++---- src/android/res/layout/activity_main.xml | 1 - 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/android/com/unprompted/tildefriends/MainActivity.java b/src/android/com/unprompted/tildefriends/MainActivity.java index ddd8aed4..9f34b4f5 100644 --- a/src/android/com/unprompted/tildefriends/MainActivity.java +++ b/src/android/com/unprompted/tildefriends/MainActivity.java @@ -9,6 +9,8 @@ import android.os.Bundle; import android.os.CountDownTimer; import android.os.SystemClock; import android.util.Log; +import android.view.KeyEvent; +import android.view.Window; import android.webkit.JsResult; import android.webkit.WebChromeClient; import android.webkit.WebView; @@ -24,12 +26,15 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; public class MainActivity extends Activity { + WebView web_view; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); - WebView web = (WebView)findViewById(R.id.web); + web_view = (WebView)findViewById(R.id.web); Log.w("tildefriends", String.format("getFilesDir() is %s", getFilesDir().toString())); Log.w("tildefriends", String.format("getPackageResourcePath() is %s", getPackageResourcePath().toString())); @@ -75,11 +80,11 @@ public class MainActivity extends Activity { Thread.sleep(1000); } catch (java.lang.InterruptedException e) { } - web.getSettings().setJavaScriptEnabled(true); - web.getSettings().setDatabaseEnabled(true); - web.getSettings().setDomStorageEnabled(true); + web_view.getSettings().setJavaScriptEnabled(true); + web_view.getSettings().setDatabaseEnabled(true); + web_view.getSettings().setDomStorageEnabled(true); - web.setWebChromeClient(new WebChromeClient() { + web_view.setWebChromeClient(new WebChromeClient() { @Override public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) { new AlertDialog.Builder(view.getContext()) @@ -105,7 +110,7 @@ public class MainActivity extends Activity { } }); - web.setWebViewClient(new WebViewClient() { + web_view.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { @@ -118,6 +123,23 @@ public class MainActivity extends Activity { } }); - web.loadUrl("http://127.0.0.1:12345/"); + web_view.loadUrl("http://127.0.0.1:12345/"); + } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (keyCode == KeyEvent.KEYCODE_BACK && web_view.canGoBack()) { + web_view.goBack(); + return true; + } else if (keyCode == KeyEvent.KEYCODE_FORWARD && web_view.canGoForward()) { + web_view.goForward(); + return true; +/* + } else if (keyCode == KeyEvent.KEYCODE_REFRESH) { + web_view.reload(); + return true; +*/ + } + return super.onKeyDown(keyCode, event); } } diff --git a/src/android/res/layout/activity_main.xml b/src/android/res/layout/activity_main.xml index 810a83f1..12d30a3f 100644 --- a/src/android/res/layout/activity_main.xml +++ b/src/android/res/layout/activity_main.xml @@ -3,7 +3,6 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - android:gravity="center" android:orientation="vertical">