Skip to content

Commit a305198

Browse files
committed
Add Android WebView wrapper app
1 parent f864c7c commit a305198

File tree

9 files changed

+255
-0
lines changed

9 files changed

+255
-0
lines changed

android-app/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# DeadNet Android WebView App
2+
3+
Simple WebView wrapper that connects to DeadNet server running in Termux.
4+
5+
## Requirements
6+
- DeadNet installed in Termux
7+
- Server running (`deadnet` command)
8+
9+
## Build APK
10+
11+
### Option 1: Android Studio
12+
1. Open this folder in Android Studio
13+
2. Build > Build Bundle(s) / APK(s) > Build APK(s)
14+
3. APK will be in `app/build/outputs/apk/`
15+
16+
### Option 2: Command Line (requires Android SDK)
17+
```bash
18+
cd android-app
19+
./gradlew assembleRelease
20+
```
21+
22+
## Usage
23+
1. Run `deadnet` in Termux first
24+
2. Open DeadNet app
25+
3. App will connect to `http://127.0.0.1:5000`
26+
27+
## Note
28+
This app is just a WebView wrapper. The actual DeadNet server runs in Termux.
29+
Make sure Termux is running with `deadnet` command before opening the app.

android-app/app/build.gradle

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
namespace 'com.deadnet.app'
7+
compileSdk 34
8+
9+
defaultConfig {
10+
applicationId "com.deadnet.app"
11+
minSdk 24
12+
targetSdk 34
13+
versionCode 1
14+
versionName "2.0.0"
15+
}
16+
17+
buildTypes {
18+
release {
19+
minifyEnabled true
20+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt')
21+
}
22+
}
23+
24+
compileOptions {
25+
sourceCompatibility JavaVersion.VERSION_1_8
26+
targetCompatibility JavaVersion.VERSION_1_8
27+
}
28+
}
29+
30+
dependencies {
31+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.deadnet.app">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7+
8+
<application
9+
android:allowBackup="true"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="DeadNet"
12+
android:theme="@style/Theme.DeadNet"
13+
android:usesCleartextTraffic="true">
14+
15+
<activity
16+
android:name=".MainActivity"
17+
android:exported="true"
18+
android:configChanges="orientation|screenSize"
19+
android:screenOrientation="portrait">
20+
<intent-filter>
21+
<action android:name="android.intent.action.MAIN" />
22+
<category android:name="android.intent.category.LAUNCHER" />
23+
</intent-filter>
24+
</activity>
25+
</application>
26+
</manifest>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package com.deadnet.app;
2+
3+
import android.app.Activity;
4+
import android.app.AlertDialog;
5+
import android.os.Bundle;
6+
import android.view.View;
7+
import android.view.Window;
8+
import android.view.WindowManager;
9+
import android.webkit.WebChromeClient;
10+
import android.webkit.WebSettings;
11+
import android.webkit.WebView;
12+
import android.webkit.WebViewClient;
13+
import android.widget.ProgressBar;
14+
import android.widget.Toast;
15+
16+
public class MainActivity extends Activity {
17+
private WebView webView;
18+
private ProgressBar progressBar;
19+
private static final String SERVER_URL = "http://127.0.0.1:5000";
20+
21+
@Override
22+
protected void onCreate(Bundle savedInstanceState) {
23+
super.onCreate(savedInstanceState);
24+
25+
// Fullscreen
26+
requestWindowFeature(Window.FEATURE_NO_TITLE);
27+
getWindow().setFlags(
28+
WindowManager.LayoutParams.FLAG_FULLSCREEN,
29+
WindowManager.LayoutParams.FLAG_FULLSCREEN
30+
);
31+
32+
setContentView(R.layout.activity_main);
33+
34+
webView = findViewById(R.id.webView);
35+
progressBar = findViewById(R.id.progressBar);
36+
37+
setupWebView();
38+
loadServer();
39+
}
40+
41+
private void setupWebView() {
42+
WebSettings settings = webView.getSettings();
43+
settings.setJavaScriptEnabled(true);
44+
settings.setDomStorageEnabled(true);
45+
settings.setAllowFileAccess(true);
46+
settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
47+
48+
webView.setWebViewClient(new WebViewClient() {
49+
@Override
50+
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
51+
showConnectionError();
52+
}
53+
54+
@Override
55+
public void onPageFinished(WebView view, String url) {
56+
progressBar.setVisibility(View.GONE);
57+
webView.setVisibility(View.VISIBLE);
58+
}
59+
});
60+
61+
webView.setWebChromeClient(new WebChromeClient() {
62+
@Override
63+
public void onProgressChanged(WebView view, int newProgress) {
64+
progressBar.setProgress(newProgress);
65+
}
66+
});
67+
}
68+
69+
private void loadServer() {
70+
progressBar.setVisibility(View.VISIBLE);
71+
webView.setVisibility(View.GONE);
72+
webView.loadUrl(SERVER_URL);
73+
}
74+
75+
private void showConnectionError() {
76+
new AlertDialog.Builder(this)
77+
.setTitle("Connection Error")
78+
.setMessage("Cannot connect to DeadNet server.\n\nMake sure you run 'deadnet' in Termux first!")
79+
.setPositiveButton("Retry", (d, w) -> loadServer())
80+
.setNegativeButton("Exit", (d, w) -> finish())
81+
.setCancelable(false)
82+
.show();
83+
}
84+
85+
@Override
86+
public void onBackPressed() {
87+
if (webView.canGoBack()) {
88+
webView.goBack();
89+
} else {
90+
new AlertDialog.Builder(this)
91+
.setTitle("Exit DeadNet?")
92+
.setMessage("Server will keep running in Termux.")
93+
.setPositiveButton("Exit", (d, w) -> finish())
94+
.setNegativeButton("Cancel", null)
95+
.show();
96+
}
97+
}
98+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:background="#0a0a0a">
6+
7+
<WebView
8+
android:id="@+id/webView"
9+
android:layout_width="match_parent"
10+
android:layout_height="match_parent"
11+
android:visibility="gone" />
12+
13+
<LinearLayout
14+
android:layout_width="match_parent"
15+
android:layout_height="match_parent"
16+
android:gravity="center"
17+
android:orientation="vertical">
18+
19+
<ProgressBar
20+
android:id="@+id/progressBar"
21+
style="@android:style/Widget.ProgressBar.Horizontal"
22+
android:layout_width="200dp"
23+
android:layout_height="wrap_content"
24+
android:max="100"
25+
android:progressTint="#00ff00" />
26+
27+
<TextView
28+
android:layout_width="wrap_content"
29+
android:layout_height="wrap_content"
30+
android:layout_marginTop="16dp"
31+
android:text="Connecting to DeadNet..."
32+
android:textColor="#888888"
33+
android:textSize="14sp" />
34+
</LinearLayout>
35+
</FrameLayout>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<style name="Theme.DeadNet" parent="android:Theme.Material.NoActionBar">
4+
<item name="android:windowBackground">#0a0a0a</item>
5+
<item name="android:statusBarColor">#000000</item>
6+
<item name="android:navigationBarColor">#000000</item>
7+
</style>
8+
</resources>

android-app/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
id 'com.android.application' version '8.2.0' apply false
3+
}
4+
5+
task clean(type: Delete) {
6+
delete rootProject.buildDir
7+
}

android-app/gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
2+
android.useAndroidX=false
3+
android.nonTransitiveRClass=true

android-app/settings.gradle

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
pluginManagement {
2+
repositories {
3+
google()
4+
mavenCentral()
5+
gradlePluginPortal()
6+
}
7+
}
8+
9+
dependencyResolutionManagement {
10+
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
11+
repositories {
12+
google()
13+
mavenCentral()
14+
}
15+
}
16+
17+
rootProject.name = "DeadNet"
18+
include ':app'

0 commit comments

Comments
 (0)