the Help screen is now styled using the app colors
This commit is contained in:
parent
2269ac4717
commit
28801ba95b
3 changed files with 35 additions and 10 deletions
|
|
@ -20,19 +20,14 @@ static markdownToHtml(markdownPath, htmlPath) {
|
|||
|
||||
|
||||
static getStyles() {
|
||||
return "body {padding: 0 6px; background-color: #f4f4f4; color: #000;}" +
|
||||
"a {color: #225682}" +
|
||||
"a:visited {color: #644280}" +
|
||||
return "body {color: default; padding: 0 6px;}" +
|
||||
"a {color: accent;}" +
|
||||
"a:visited {color: inherit;}" +
|
||||
"li {margin: 4px 0; padding: 1px;}" +
|
||||
"p {text-align: left;}" +
|
||||
"p.wrap{word-wrap: break-word;}" +
|
||||
".toc {border: 1px solid; display: inline-block; padding: 12px 20px 12px 0; margin: 12px 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}" +
|
||||
"}"
|
||||
".toc > h3 {text-align: center; margin: 0;}"
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package io.github.sspanak.tt9.preferences;
|
||||
|
||||
import android.util.TypedValue;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
|
|
@ -8,6 +11,10 @@ import io.github.sspanak.tt9.util.Logger;
|
|||
import io.github.sspanak.tt9.util.SystemSettings;
|
||||
|
||||
public class HelpActivity extends WebViewActivity {
|
||||
public HelpActivity() {
|
||||
transparentBackground = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getMimeType() {
|
||||
return "text/html";
|
||||
|
|
@ -22,7 +29,9 @@ public class HelpActivity extends WebViewActivity {
|
|||
while ((line = reader.readLine()) != null) {
|
||||
builder.append(line);
|
||||
}
|
||||
return builder.toString();
|
||||
return builder.toString()
|
||||
.replaceFirst("color: default", getTextColor())
|
||||
.replaceFirst("color: accent", getLinkColor());
|
||||
} catch (Exception e) {
|
||||
Logger.e(getClass().getSimpleName(), "Failed opening the help HTML document.");
|
||||
return "";
|
||||
|
|
@ -35,4 +44,20 @@ public class HelpActivity extends WebViewActivity {
|
|||
file = file.exists() ? file : new HelpFile(this);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package io.github.sspanak.tt9.ui;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.Base64;
|
||||
import android.view.View;
|
||||
|
|
@ -11,6 +12,7 @@ import androidx.appcompat.app.ActionBar;
|
|||
|
||||
abstract public class WebViewActivity extends EdgeToEdgeActivity implements View.OnAttachStateChangeListener {
|
||||
private WebView webView;
|
||||
protected boolean transparentBackground = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
|
@ -55,6 +57,9 @@ abstract public class WebViewActivity extends EdgeToEdgeActivity implements View
|
|||
webView = new WebView(this);
|
||||
webView.addOnAttachStateChangeListener(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(),
|
||||
// so we need to do this weird shit.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue