1
0
Fork 0

the Help screen is now styled using the app colors

This commit is contained in:
sspanak 2025-01-12 14:55:02 +02:00
parent 2269ac4717
commit 28801ba95b
3 changed files with 35 additions and 10 deletions

View file

@ -20,19 +20,14 @@ static markdownToHtml(markdownPath, htmlPath) {
static getStyles() { static getStyles() {
return "body {padding: 0 6px; background-color: #f4f4f4; color: #000;}" + return "body {color: default; padding: 0 6px;}" +
"a {color: #225682}" + "a {color: accent;}" +
"a:visited {color: #644280}" + "a:visited {color: inherit;}" +
"li {margin: 4px 0; padding: 1px;}" + "li {margin: 4px 0; padding: 1px;}" +
"p {text-align: left;}" + "p {text-align: left;}" +
"p.wrap{word-wrap: break-word;}" + "p.wrap{word-wrap: break-word;}" +
".toc {border: 1px solid; display: inline-block; padding: 12px 20px 12px 0; margin: 12px 0;}" + ".toc {border: 1px solid; display: inline-block; padding: 12px 20px 12px 0; margin: 12px 0;}" +
".toc > h3 {text-align: center; margin: 0;}" + ".toc > h3 {text-align: center; margin: 0;}"
"@media (prefers-color-scheme: dark) {" +
"body { background-color: #333; color: #c8c8c8; }" +
"a {color: #a0c1de}" +
"a:visited {color: #d9bce1}" +
"}"
} }

View file

@ -1,5 +1,8 @@
package io.github.sspanak.tt9.preferences; package io.github.sspanak.tt9.preferences;
import android.util.TypedValue;
import android.widget.TextView;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
@ -8,6 +11,10 @@ import io.github.sspanak.tt9.util.Logger;
import io.github.sspanak.tt9.util.SystemSettings; import io.github.sspanak.tt9.util.SystemSettings;
public class HelpActivity extends WebViewActivity { public class HelpActivity extends WebViewActivity {
public HelpActivity() {
transparentBackground = true;
}
@Override @Override
protected String getMimeType() { protected String getMimeType() {
return "text/html"; return "text/html";
@ -22,7 +29,9 @@ public class HelpActivity extends WebViewActivity {
while ((line = reader.readLine()) != null) { while ((line = reader.readLine()) != null) {
builder.append(line); builder.append(line);
} }
return builder.toString(); return builder.toString()
.replaceFirst("color: default", getTextColor())
.replaceFirst("color: accent", getLinkColor());
} catch (Exception e) { } catch (Exception e) {
Logger.e(getClass().getSimpleName(), "Failed opening the help HTML document."); Logger.e(getClass().getSimpleName(), "Failed opening the help HTML document.");
return ""; return "";
@ -35,4 +44,20 @@ public class HelpActivity extends WebViewActivity {
file = file.exists() ? file : new HelpFile(this); file = file.exists() ? file : new HelpFile(this);
return file.getReader(); return file.getReader();
} }
private String getTextColor() {
return colorToHex(new TextView(this).getTextColors().getDefaultColor());
}
private String getLinkColor() {
final TypedValue value = new TypedValue();
getTheme().resolveAttribute(android.R.attr.colorAccent, value, true);
return colorToHex(value.data);
}
private String colorToHex(int color) {
String textColor = String.format("%06x", color);
textColor = textColor.length() == 8 ? textColor.substring(2) : textColor;
return "color: #" + textColor;
}
} }

View file

@ -1,5 +1,6 @@
package io.github.sspanak.tt9.ui; package io.github.sspanak.tt9.ui;
import android.graphics.Color;
import android.os.Bundle; import android.os.Bundle;
import android.util.Base64; import android.util.Base64;
import android.view.View; import android.view.View;
@ -11,6 +12,7 @@ import androidx.appcompat.app.ActionBar;
abstract public class WebViewActivity extends EdgeToEdgeActivity implements View.OnAttachStateChangeListener { abstract public class WebViewActivity extends EdgeToEdgeActivity implements View.OnAttachStateChangeListener {
private WebView webView; private WebView webView;
protected boolean transparentBackground = false;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -55,6 +57,9 @@ abstract public class WebViewActivity extends EdgeToEdgeActivity implements View
webView = new WebView(this); webView = new WebView(this);
webView.addOnAttachStateChangeListener(this); webView.addOnAttachStateChangeListener(this);
webView.setWebViewClient(new WebViewSafeClient(this)); webView.setWebViewClient(new WebViewSafeClient(this));
if (transparentBackground) {
webView.setBackgroundColor(Color.TRANSPARENT);
}
// On API > 30 the WebView does not load the entire String with .loadData(), // On API > 30 the WebView does not load the entire String with .loadData(),
// so we need to do this weird shit. // so we need to do this weird shit.