Skip to content

Commit

Permalink
upgrade android template
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Sep 8, 2024
1 parent eedc5af commit e168cec
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 49 deletions.
3 changes: 1 addition & 2 deletions src/happyx_native/android/tmpl/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ android {
}

dependencies {
implementation 'com.google.android.material:material:1.10.0'
implementation "androidx.webkit:webkit:1.9.0"
implementation "androidx.webkit:webkit:1.11.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

<application
android:allowBackup="true"
Expand All @@ -13,7 +14,6 @@
android:usesCleartextTraffic="true"
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/Theme.Tmpl"
tools:targetApi="34">
<activity
android:name=".MainActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebViewFeature;

public class MainActivity extends Activity {
private WebView w;
private boolean paused = false;
Expand All @@ -21,14 +17,14 @@ public class MainActivity extends Activity {
protected void onCreate(Bundle s) {
super.onCreate(s);
setContentView(R.layout.activity_main);

getActionBar().hide();
w = findViewById(R.id.webView);

if (!paused) {
new Thread(() -> Native.start(this)).start();

Native n = new Native(this);
n.uiLoop();
new Thread(n::uiLoop).start();
}
setupWebView();
}
Expand All @@ -43,24 +39,13 @@ public void onPageFinished(WebView v, String u) {
super.onPageFinished(v, u);
}
});
if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) {
switch (getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK) {
case Configuration.UI_MODE_NIGHT_YES:
WebSettingsCompat.setForceDark(w.getSettings(), WebSettingsCompat.FORCE_DARK_ON);
break;
case Configuration.UI_MODE_NIGHT_NO:
case Configuration.UI_MODE_NIGHT_UNDEFINED:
WebSettingsCompat.setForceDark(w.getSettings(), WebSettingsCompat.FORCE_DARK_OFF);
break;
}
}

WebSettings ws = w.getSettings();
ws.setJavaScriptEnabled(true);
ws.setDomStorageEnabled(true);
ws.setBuiltInZoomControls(true);
ws.setDisplayZoomControls(false);
ws.setSupportZoom(true);
ws.setSupportZoom(false);
ws.setDefaultTextEncodingName("utf-8");

w.loadUrl("http://localhost:15123/");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,2 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Tmpl" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
14 changes: 0 additions & 14 deletions src/happyx_native/android/tmpl/app/src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,2 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Tmpl" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>

0 comments on commit e168cec

Please sign in to comment.