mirror of
https://gitlab.com/SpaccInc/SpaccDotWeb.git
synced 2025-06-05 21:29:12 +02:00
Add SpaccWebView for Android
This commit is contained in:
1
SpaccDotWeb.Android/app/.gitignore
vendored
Normal file
1
SpaccDotWeb.Android/app/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/build
|
28
SpaccDotWeb.Android/app/build.gradle
Normal file
28
SpaccDotWeb.Android/app/build.gradle
Normal file
@@ -0,0 +1,28 @@
|
||||
plugins {
|
||||
id 'com.android.application'
|
||||
}
|
||||
|
||||
android {
|
||||
// Adjust the very following based on the application to ship
|
||||
namespace 'com.example.spaccwebviewapplication'
|
||||
defaultConfig {
|
||||
applicationId 'com.example.spaccwebviewapplication'
|
||||
versionCode 1
|
||||
versionName '1.0'
|
||||
|
||||
minSdk 1
|
||||
targetSdk 34
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
applicationIdSuffix '.dbg'
|
||||
}
|
||||
release {
|
||||
minifyEnabled true
|
||||
signingConfig signingConfigs.debug
|
||||
}
|
||||
}
|
||||
|
||||
compileSdk 34
|
||||
}
|
43
SpaccDotWeb.Android/app/src/main/AndroidManifest.xml
Normal file
43
SpaccDotWeb.Android/app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:installLocation="auto">
|
||||
|
||||
<!-- Lets the app access the Internet — not needed for fully offline apps -->
|
||||
<!-- <uses-permission android:name="android.permission.INTERNET" /> -->
|
||||
|
||||
<!-- Lets the webview load and display files from the device's shared storage -->
|
||||
<!-- <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> -->
|
||||
|
||||
<!-- Additional suggested attributes:
|
||||
android:appCategory=["accessibility" | "audio" | "game" | "image" | "maps" | "news" | "productivity" | "social" | "video"]
|
||||
android:isGame=["true" | "false"]
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
-->
|
||||
<application
|
||||
android:label="@string/app_name"
|
||||
android:theme="@android:style/Theme.DeviceDefault.NoActionBar"
|
||||
android:allowBackup="true"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:hasFragileUserData="true"
|
||||
android:supportsRtl="true"
|
||||
android:hasCode="true"
|
||||
tools:targetApi="34">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize|screenLayout|layoutDirection"
|
||||
android:launchMode="singleTask">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
3
SpaccDotWeb.Android/app/src/main/assets/index.html
Normal file
3
SpaccDotWeb.Android/app/src/main/assets/index.html
Normal file
@@ -0,0 +1,3 @@
|
||||
<!DOCTYPE html>
|
||||
<h1>SpaccWebView Application</h1>
|
||||
<p><a href="https://gitlab.com/SpaccInc/SpaccDotWeb">https://gitlab.com/SpaccInc/SpaccDotWeb</a></p>
|
@@ -0,0 +1,28 @@
|
||||
package com.example.spaccwebviewapplication;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import org.eu.spacc.spaccdotweb.android.*;
|
||||
|
||||
public class MainActivity extends Activity {
|
||||
private SpaccWebView webView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
webView = findViewById(R.id.webview);
|
||||
|
||||
webView.loadAppIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (webView.canGoBack()) {
|
||||
webView.goBack();
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
package org.eu.spacc.spaccdotweb.android;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
public class ApiUtils {
|
||||
|
||||
public static void apiRun(int apiLevel, Runnable action) {
|
||||
if (Build.VERSION.SDK_INT >= apiLevel) {
|
||||
action.run();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package org.eu.spacc.spaccdotweb.android;
|
||||
|
||||
import org.eu.spacc.spaccdotweb.android.Constants.*;
|
||||
|
||||
public class Config {
|
||||
public static final Boolean ALLOW_JAVASCRIPT = true;
|
||||
public static final Boolean ALLOW_STORAGE = true;
|
||||
public static final AppIndex APP_INDEX = AppIndex.LOCAL;
|
||||
public static final String LOCAL_INDEX = "index.html";
|
||||
public static final String REMOTE_INDEX = "https://example.com";
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
package org.eu.spacc.spaccdotweb.android;
|
||||
|
||||
public class Constants {
|
||||
public static enum AppIndex { LOCAL, REMOTE }
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
package org.eu.spacc.spaccdotweb.android;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
|
||||
public class SpaccWebView extends WebView {
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
public SpaccWebView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
WebSettings webSettings = getSettings();
|
||||
|
||||
webSettings.setJavaScriptEnabled(Config.ALLOW_JAVASCRIPT);
|
||||
|
||||
ApiUtils.apiRun(7, () -> webSettings.setDomStorageEnabled(Config.ALLOW_STORAGE));
|
||||
ApiUtils.apiRun(5, () -> webSettings.setDatabaseEnabled(Config.ALLOW_STORAGE));
|
||||
if (Config.ALLOW_STORAGE) {
|
||||
ApiUtils.apiRun(5, () -> webSettings.setDatabasePath(context.getFilesDir().getParent() + "/databases"));
|
||||
}
|
||||
|
||||
ApiUtils.apiRun(3, () -> webSettings.setAllowFileAccess(true));
|
||||
}
|
||||
|
||||
public void loadAppIndex() {
|
||||
String url = null;
|
||||
|
||||
switch (Config.APP_INDEX) {
|
||||
case LOCAL:
|
||||
url = ("file:///android_asset/" + Config.LOCAL_INDEX);
|
||||
break;
|
||||
case REMOTE:
|
||||
url = Config.REMOTE_INDEX;
|
||||
break;
|
||||
}
|
||||
|
||||
loadUrl(url);
|
||||
}
|
||||
}
|
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.widget.LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
<org.eu.spacc.spaccdotweb.android.SpaccWebView
|
||||
android:id="@+id/webview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="visible" />
|
||||
</android.widget.LinearLayout>
|
3
SpaccDotWeb.Android/app/src/main/res/values/strings.xml
Normal file
3
SpaccDotWeb.Android/app/src/main/res/values/strings.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<resources>
|
||||
<string name="app_name">SpaccWebView Application</string>
|
||||
</resources>
|
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<full-backup-content>
|
||||
<include domain="sharedpref" path="."/>
|
||||
</full-backup-content>
|
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<data-extraction-rules>
|
||||
<cloud-backup disableIfNoEncryptionCapabilities="true">
|
||||
<include domain="sharedpref" path="."/>
|
||||
</cloud-backup>
|
||||
<device-transfer>
|
||||
<include domain="sharedpref" path="."/>
|
||||
</device-transfer>
|
||||
</data-extraction-rules>
|
Reference in New Issue
Block a user