PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/activities/LicenseActivity.java

100 lines
4.0 KiB
Java
Raw Normal View History

2019-09-28 17:52:49 +00:00
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* This is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by
* the Free Software Foundation either version 3 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*/
package code.name.monkey.retromusic.activities;
import android.graphics.Color;
import android.os.Bundle;
import android.view.MenuItem;
import android.webkit.WebView;
2019-09-28 17:52:49 +00:00
import androidx.annotation.NonNull;
2019-09-29 09:01:13 +00:00
import androidx.appcompat.widget.Toolbar;
import org.jetbrains.annotations.Nullable;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
2019-09-28 17:52:49 +00:00
import code.name.monkey.appthemehelper.ThemeStore;
2020-02-21 18:18:11 +00:00
import code.name.monkey.appthemehelper.util.ATHUtil;
2019-09-28 17:52:49 +00:00
import code.name.monkey.appthemehelper.util.ColorUtil;
import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper;
import code.name.monkey.retromusic.R;
import code.name.monkey.retromusic.activities.base.AbsBaseActivity;
/**
* Created by hemanths on 2019-09-27.
*/
public class LicenseActivity extends AbsBaseActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
2019-12-05 18:18:54 +00:00
setDrawUnderStatusBar();
2019-09-28 17:52:49 +00:00
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_license);
setStatusbarColorAuto();
2019-12-05 18:18:54 +00:00
setNavigationbarColorAuto();
2019-09-28 17:52:49 +00:00
setLightNavigationBar(true);
2019-09-29 09:01:13 +00:00
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
2019-11-15 16:30:10 +00:00
ToolbarContentTintHelper.colorBackButton(toolbar);
2020-02-21 18:18:11 +00:00
toolbar.setBackgroundColor(ATHUtil.INSTANCE.resolveColor(this, R.attr.colorSurface));
2019-09-28 17:52:49 +00:00
WebView webView = findViewById(R.id.license);
try {
StringBuilder buf = new StringBuilder();
2020-05-03 19:24:11 +00:00
InputStream json = getAssets().open("oldindex.html");
2019-09-28 17:52:49 +00:00
BufferedReader in = new BufferedReader(new InputStreamReader(json, StandardCharsets.UTF_8));
String str;
2019-12-30 11:01:50 +00:00
while ((str = in.readLine()) != null) {
2019-09-28 17:52:49 +00:00
buf.append(str);
2019-12-30 11:01:50 +00:00
}
2019-09-28 17:52:49 +00:00
in.close();
// Inject color values for WebView body background and links
2020-02-21 18:18:11 +00:00
final boolean isDark = ATHUtil.INSTANCE.isWindowBackgroundDark(this);
final String backgroundColor = colorToCSS(ATHUtil.INSTANCE.resolveColor(this, R.attr.colorSurface,
2019-12-30 11:01:50 +00:00
Color.parseColor(isDark ? "#424242" : "#ffffff")));
2019-09-28 17:52:49 +00:00
final String contentColor = colorToCSS(Color.parseColor(isDark ? "#ffffff" : "#000000"));
final String changeLog = buf.toString()
.replace("{style-placeholder}",
String.format("body { background-color: %s; color: %s; }", backgroundColor, contentColor))
.replace("{link-color}", colorToCSS(ThemeStore.Companion.accentColor(this)))
2019-12-30 11:01:50 +00:00
.replace("{link-color-active}",
colorToCSS(ColorUtil.INSTANCE.lightenColor(ThemeStore.Companion.accentColor(this))));
2019-09-28 17:52:49 +00:00
webView.loadData(changeLog, "text/html", "UTF-8");
} catch (Throwable e) {
webView.loadData("<h1>Unable to load</h1><p>" + e.getLocalizedMessage() + "</p>", "text/html", "UTF-8");
}
}
2019-12-30 11:01:50 +00:00
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) {
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
private String colorToCSS(int color) {
return String.format("rgb(%d, %d, %d)", Color.red(color), Color.green(color),
Color.blue(color)); // on API 29, WebView doesn't load with hex colors
}
2019-09-28 17:52:49 +00:00
}