First signs of WebView working.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4213 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2023-03-11 02:37:27 +00:00
parent 12a8b7a058
commit f74f4f6da9
4 changed files with 39 additions and 8 deletions

View File

@ -791,6 +791,11 @@ async function loadSettings() {
} catch (error) { } catch (error) {
print("Settings not found in database:", error); print("Settings not found in database:", error);
} }
for (let [key, value] of Object.entries(k_global_settings)) {
if (data[key] === undefined) {
data[key] = value.default_value;
}
}
gGlobalSettings = data; gGlobalSettings = data;
} }

View File

@ -5,7 +5,7 @@
versionName="0.0.4"> versionName="0.0.4">
<uses-sdk android:minSdkVersion="16"/> <uses-sdk android:minSdkVersion="16"/>
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.INTERNET"/>
<application android:label="Tilde Friends"> <application android:label="Tilde Friends" android:usesCleartextTraffic="true">
<activity android:name=".MainActivity"> <activity android:name=".MainActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN"/> <action android:name="android.intent.action.MAIN"/>

View File

@ -1,20 +1,46 @@
package com.unprompted.tildefriends; package com.unprompted.tildefriends;
import android.app.Activity; import android.app.Activity;
import android.util.Log; import android.content.Intent;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.widget.TextView; import android.os.CountDownTimer;
import android.os.SystemClock;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import java.lang.Thread;
public class MainActivity extends Activity { public class MainActivity extends Activity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
TextView text = (TextView)findViewById(R.id.my_text);
WebView web = (WebView)findViewById(R.id.web);
Log.w("tildefriends", String.format("getFilesDir() is %s", getFilesDir().toString())); Log.w("tildefriends", String.format("getFilesDir() is %s", getFilesDir().toString()));
Log.w("tildefriends", String.format("getPackageResourcePath() is %s", getPackageResourcePath().toString())); Log.w("tildefriends", String.format("getPackageResourcePath() is %s", getPackageResourcePath().toString()));
Log.w("tildefriends", String.format("getPackageCodePath() is %s", getPackageCodePath().toString())); Log.w("tildefriends", String.format("getPackageCodePath() is %s", getPackageCodePath().toString()));
setFilesPath(getFilesDir().toString(), getPackageResourcePath().toString()); setFilesPath(getFilesDir().toString(), getPackageResourcePath().toString());
try {
Thread.sleep(1000);
} catch (java.lang.InterruptedException e) {
}
web.getSettings().setJavaScriptEnabled(true);
web.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (url != null && url.startsWith("http://127.0.0.1:12345/")) {
return false;
} else {
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
}
}
});
web.loadUrl("http://127.0.0.1:12345/~core/apps/");
} }
public native void setFilesPath(String files_path, String apk_path); public native void setFilesPath(String files_path, String apk_path);

View File

@ -5,8 +5,8 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center" android:gravity="center"
android:orientation="vertical"> android:orientation="vertical">
<TextView <WebView
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="match_parent"
android:id="@+id/my_text"/> android:id="@+id/web"/>
</LinearLayout> </LinearLayout>