use of com.ferg.awfulapp.provider.AwfulTheme in project Awful.apk by Awful.
the class ThreadDisplay method getContainerHtml.
/**
* Get the main HTML for the containing page.
* <p>
* This contains no post data, but sets up the basic template with the required JS scripts,
* CSS etc., and a container element to insert post data into.
*
* @param aPrefs used to customise the template to the user's preferences
* @param forumId the ID of the forum this thread belongs to, used for themeing
* @return the template containing a container class
*/
public static String getContainerHtml(AwfulPreferences aPrefs, int forumId) {
StringBuilder buffer = new StringBuilder("<!DOCTYPE html>\n<html>\n<head>\n");
buffer.append("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0 maximum-scale=1.0 minimum-scale=1.0, user-scalable=no\" />\n");
buffer.append("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />\n");
buffer.append("<meta name='format-detection' content='telephone=no' />\n");
buffer.append("<meta name='format-detection' content='address=no' />\n");
// build the theme css tag, using the appropriate css path
// the dark-theme attribute can be used to e.g. embed a dark or light widget
AwfulTheme theme = AwfulTheme.forForum(forumId);
buffer.append(String.format("<link id='theme-css' rel='stylesheet' data-dark-theme='%b' href='%s'>\n", theme.isDark(), theme.getCssPath()));
buffer.append("<link rel='stylesheet' href='file:///android_asset/css/general.css' />");
if (!aPrefs.preferredFont.contains("default")) {
buffer.append("<style id='font-face' type='text/css'>@font-face { font-family: userselected; src: url('content://com.ferg.awfulapp.webprovider/").append(aPrefs.preferredFont).append("'); }</style>\n");
}
for (String scriptName : JS_FILES) {
buffer.append("<script src='file:///android_asset/javascript/").append(scriptName).append("' type='text/javascript'></script>\n");
}
buffer.append("</head><body><div id='container' class='container' ").append((!aPrefs.noFAB ? "style='padding-bottom:75px'" : "")).append("></div><script type='text/javascript'>containerInit();</script></body></html>");
return buffer.toString();
}
use of com.ferg.awfulapp.provider.AwfulTheme in project Awful.apk by Awful.
the class ThemeSettings method refreshThemePreference.
/**
* Rebuild the theme-chooser list preference.
*
* Replaces all entries with the stock app themes, and adds any custom ones it can find.
*/
private void refreshThemePreference() {
List<CharSequence> themeNames = new ArrayList<>();
List<CharSequence> themeValues = new ArrayList<>();
ListPreference themePref = (ListPreference) findPrefById(R.string.pref_key_theme);
if (themePref == null) {
throw new RuntimeException("Theme or layout preference is missing!");
}
// add the default app themes
for (AwfulTheme theme : AwfulTheme.APP_THEMES) {
themeNames.add(theme.displayName);
themeValues.add(theme.cssFilename);
}
// get any custom themes
File customDir = getCustomDir();
if (customDir != null) {
/*
* Regex that matches filenames with a '.css' extension
* Group 1 holds the name part (before the extension). If it contains any separating '.' characters,
* e.g. 'like.this.here.css', group 2 will contain the last part ('here') and group 1 holds the rest ('like.this').
*/
Pattern pattern = Pattern.compile("(.+?)(?:\\.([^.]+))?\\.css$", Pattern.CASE_INSENSITIVE);
for (String filename : customDir.list()) {
Matcher matcher = pattern.matcher(filename);
if (matcher.matches()) {
String displayName = matcher.group(1);
String style = matcher.group(2);
themeValues.add(filename);
themeNames.add(displayName + (style == null ? "" : String.format(" (%s)", style)));
}
}
}
setListPreferenceChoices(themePref, themeNames, themeValues);
}
Aggregations