mirror of https://github.com/beemdevelopment/Aegis
Add a dialog for Aegis' license
parent
e6e2809c9c
commit
bda1a1d5af
@ -0,0 +1 @@
|
|||||||
|
../../../../LICENSE
|
@ -0,0 +1,14 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style type="text/css">
|
||||||
|
body {
|
||||||
|
background-color: %2$s;
|
||||||
|
color: %3$s;
|
||||||
|
font-size: 0.8em;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<pre>%1$s</pre>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1,94 +0,0 @@
|
|||||||
package com.beemdevelopment.aegis.ui;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.pm.PackageInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.InflateException;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.webkit.WebView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.fragment.app.DialogFragment;
|
|
||||||
|
|
||||||
import com.beemdevelopment.aegis.R;
|
|
||||||
import com.beemdevelopment.aegis.Theme;
|
|
||||||
import com.beemdevelopment.aegis.helpers.ThemeHelper;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
|
|
||||||
public class ChangelogDialog extends DialogFragment {
|
|
||||||
private Theme _themeStyle;
|
|
||||||
|
|
||||||
public static ChangelogDialog create() {
|
|
||||||
return new ChangelogDialog();
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("InflateParams")
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
||||||
final View customView;
|
|
||||||
try {
|
|
||||||
customView = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_web_view, null);
|
|
||||||
} catch (InflateException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return new AlertDialog.Builder(getActivity())
|
|
||||||
.setTitle(android.R.string.dialog_alert_title)
|
|
||||||
.setMessage(getString(R.string.webview_error))
|
|
||||||
.setPositiveButton(android.R.string.ok, null)
|
|
||||||
.show();
|
|
||||||
}
|
|
||||||
AlertDialog dialog = new AlertDialog.Builder(getActivity())
|
|
||||||
.setTitle("Changelog")
|
|
||||||
.setView(customView)
|
|
||||||
.setPositiveButton(android.R.string.ok, null)
|
|
||||||
.show();
|
|
||||||
|
|
||||||
final WebView webView = customView.findViewById(R.id.web_view);
|
|
||||||
StringBuilder buf = new StringBuilder();
|
|
||||||
|
|
||||||
try (InputStream html = getActivity().getAssets().open("changelog.html")) {
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(html, "UTF-8"));
|
|
||||||
String str;
|
|
||||||
while ((str = in.readLine()) != null)
|
|
||||||
buf.append(str);
|
|
||||||
|
|
||||||
in.close();
|
|
||||||
String changelog = buf.toString();
|
|
||||||
changelog = replaceStylesheet(changelog);
|
|
||||||
webView.loadData(changelog, "text/html", "UTF-8");
|
|
||||||
} catch (IOException e) {
|
|
||||||
webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8");
|
|
||||||
}
|
|
||||||
return dialog;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String replaceStylesheet(String changelog) {
|
|
||||||
int backgroundColorResource = _themeStyle == Theme.AMOLED ? R.attr.cardBackgroundFocused : R.attr.cardBackground;
|
|
||||||
String backgroundColor = colorToCSS(ThemeHelper.getThemeColor(backgroundColorResource, getContext().getTheme()));
|
|
||||||
String textColor = colorToCSS(0xFFFFFF & ThemeHelper.getThemeColor(R.attr.primaryText, getContext().getTheme()));
|
|
||||||
|
|
||||||
return String.format(changelog, backgroundColor, textColor);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String colorToCSS(int color) {
|
|
||||||
return String.format("rgb(%d, %d, %d)", Color.red(color), Color.green(color), Color.blue(color));
|
|
||||||
}
|
|
||||||
|
|
||||||
public ChangelogDialog setTheme(Theme theme) {
|
|
||||||
_themeStyle = theme;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.beemdevelopment.aegis.ui.dialogs;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.beemdevelopment.aegis.R;
|
||||||
|
|
||||||
|
public class ChangelogDialog extends SimpleWebViewDialog {
|
||||||
|
private ChangelogDialog() {
|
||||||
|
super(R.string.changelog);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ChangelogDialog create() {
|
||||||
|
return new ChangelogDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getContent(Context context) {
|
||||||
|
String content = readAssetAsString(context, "changelog.html");
|
||||||
|
return String.format(content, getBackgroundColor(), getTextColor());
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.beemdevelopment.aegis.ui;
|
package com.beemdevelopment.aegis.ui.dialogs;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.beemdevelopment.aegis.ui.dialogs;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import com.beemdevelopment.aegis.R;
|
||||||
|
|
||||||
|
public class LicenseDialog extends SimpleWebViewDialog {
|
||||||
|
private LicenseDialog() {
|
||||||
|
super(R.string.license);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static LicenseDialog create() {
|
||||||
|
return new LicenseDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getContent(Context context) {
|
||||||
|
String license = readAssetAsString(context, "LICENSE");
|
||||||
|
String html = readAssetAsString(context, "license.html");
|
||||||
|
return String.format(html, license, getBackgroundColor(), getTextColor());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
package com.beemdevelopment.aegis.ui.dialogs;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.InflateException;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.StringRes;
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.fragment.app.DialogFragment;
|
||||||
|
|
||||||
|
import com.beemdevelopment.aegis.R;
|
||||||
|
import com.beemdevelopment.aegis.Theme;
|
||||||
|
import com.beemdevelopment.aegis.helpers.ThemeHelper;
|
||||||
|
import com.google.common.io.CharStreams;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
|
public abstract class SimpleWebViewDialog extends DialogFragment {
|
||||||
|
private Theme _theme;
|
||||||
|
private final @StringRes int _title;
|
||||||
|
|
||||||
|
protected SimpleWebViewDialog(@StringRes int title) {
|
||||||
|
_title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract String getContent(Context context);
|
||||||
|
|
||||||
|
@SuppressLint("InflateParams")
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
final View view;
|
||||||
|
try {
|
||||||
|
view = LayoutInflater.from(getActivity()).inflate(R.layout.dialog_web_view, null);
|
||||||
|
} catch (InflateException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return new AlertDialog.Builder(getActivity())
|
||||||
|
.setTitle(android.R.string.dialog_alert_title)
|
||||||
|
.setMessage(getString(R.string.webview_error))
|
||||||
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
AlertDialog dialog = new AlertDialog.Builder(getActivity())
|
||||||
|
.setTitle(_title)
|
||||||
|
.setView(view)
|
||||||
|
.setPositiveButton(android.R.string.ok, null)
|
||||||
|
.show();
|
||||||
|
|
||||||
|
String content = getContent(getContext());
|
||||||
|
final WebView webView = view.findViewById(R.id.web_view);
|
||||||
|
webView.loadData(content, "text/html", "UTF-8");
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SimpleWebViewDialog setTheme(Theme theme) {
|
||||||
|
_theme = theme;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getBackgroundColor() {
|
||||||
|
int backgroundColorResource = _theme == Theme.AMOLED ? R.attr.cardBackgroundFocused : R.attr.cardBackground;
|
||||||
|
return colorToCSS(ThemeHelper.getThemeColor(backgroundColorResource, getContext().getTheme()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getTextColor() {
|
||||||
|
return colorToCSS(0xFFFFFF & ThemeHelper.getThemeColor(R.attr.primaryText, getContext().getTheme()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("DefaultLocale")
|
||||||
|
private static String colorToCSS(int color) {
|
||||||
|
return String.format("rgb(%d, %d, %d)", Color.red(color), Color.green(color), Color.blue(color));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static String readAssetAsString(Context context, String name) {
|
||||||
|
try (InputStream inStream = context.getAssets().open(name);
|
||||||
|
InputStreamReader reader = new InputStreamReader(inStream, StandardCharsets.UTF_8)) {
|
||||||
|
return CharStreams.toString(reader);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue