diff --git a/app/src/main/assets/base.js b/app/src/main/assets/base.js deleted file mode 100644 index f73584c35..000000000 --- a/app/src/main/assets/base.js +++ /dev/null @@ -1,3 +0,0 @@ -function setSerifFontFamily(value) { - document.getElementById("html-base-body").style.fontFamily = value ? "serif" : null; -} diff --git a/app/src/main/assets/dark.css b/app/src/main/assets/dark.css index 4de38a3ef..2790017f5 100755 --- a/app/src/main/assets/dark.css +++ b/app/src/main/assets/dark.css @@ -24,6 +24,10 @@ body { background: #000; } +.serif-font { + font-family: serif; +} + /* ========================================================================== 1 = Style Guide ========================================================================== */ diff --git a/app/src/main/assets/main.css b/app/src/main/assets/main.css index 8cedddcbe..cc7a3421a 100755 --- a/app/src/main/assets/main.css +++ b/app/src/main/assets/main.css @@ -23,6 +23,10 @@ body { font-weight: 600; } +.serif-font { + font-family: serif; +} + /* ========================================================================== 1 = Style Guide ========================================================================== */ diff --git a/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java b/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java index 6336bc1cd..277bc97d9 100644 --- a/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java +++ b/app/src/main/java/fr/gaulupeau/apps/Poche/ui/ReadArticleActivity.java @@ -84,7 +84,6 @@ public class ReadArticleActivity extends BaseActionBarActivity { private Settings settings; private int fontSize = 100; - private boolean serifFont; public void onCreate(Bundle savedInstanceState) { Themes.applyTheme(this); @@ -132,14 +131,14 @@ public void onCreate(Bundle savedInstanceState) { } fontSize = settings.getInt(Settings.FONT_SIZE, fontSize); - serifFont = settings.getBoolean(Settings.SERIF_FONT, serifFont); + boolean serifFont = settings.getBoolean(Settings.SERIF_FONT, false); if(fontSize < 5) fontSize = 100; // TODO: remove: temp hack for compatibility List additionalClasses = new ArrayList<>(1); if(highContrast) additionalClasses.add("high-contrast"); + if(serifFont) additionalClasses.add("serif-font"); - // TODO: remove? String classAttr; if(!additionalClasses.isEmpty()) { StringBuilder sb = new StringBuilder(); @@ -345,22 +344,14 @@ private void loadingFinished() { private boolean applyDisplaySettings() { prepareToRestorePosition(false); - boolean result = false; + boolean changed = false; if(fontSize != 100) { - result = true; - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { - setFontSizeNew(webViewContent, fontSize); - } else { - setFontSizeOld(webViewContent, fontSize); - } - } - if(serifFont) { - result = true; - setSerifFont(webViewContent, serifFont); + changed = true; + setFontSize(webViewContent, fontSize); } - return result; + return changed; } private boolean openUrl(final String url) { @@ -522,9 +513,6 @@ public boolean onOptionsItemSelected(MenuItem item) { case R.id.menuDecreaseFontSize: changeFontSize(false); return true; - case R.id.menuSwitchFontFamily: - changeFontFamily(); - return true; default: return super.onOptionsItemSelected(item); } @@ -661,70 +649,31 @@ private void changeFontSize(boolean increase) { int step = 5; fontSize += step * (increase ? 1 : -1); + if(!increase && fontSize < 5) fontSize = 5; - if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { - setFontSizeNew(webViewContent, fontSize); - } else { - setFontSizeOld(webViewContent, fontSize); - } + setFontSize(webViewContent, fontSize); settings.setInt(Settings.FONT_SIZE, fontSize); restorePositionAfterUpdate(); } - private void changeFontFamily() { - setFontFamily(!serifFont); - } - - private void setFontFamily(boolean serif) { - prepareToRestorePosition(true); - - serifFont = serif; - - setSerifFont(webViewContent, serifFont); - - settings.setBoolean(Settings.SERIF_FONT, serifFont); - - restorePositionAfterUpdate(); + private void setFontSize(WebView view, int size) { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { + setFontSizeNew(view, size); + } else { + setFontSizeOld(view, size); + } } @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) private void setFontSizeNew(WebView view, int size) { - webViewContent.getSettings().setTextZoom(size); + view.getSettings().setTextZoom(size); } + @TargetApi(Build.VERSION_CODES.FROYO) private void setFontSizeOld(WebView view, int size) { - webViewContent.getSettings().setDefaultFontSize(size); - } - - private static void setSerifFont(WebView view, boolean flag) { - callJavaScript(view, "setSerifFontFamily", flag); - } - - private static void callJavaScript(WebView webView, String methodName, Object... params) { - StringBuilder sb = new StringBuilder(); - sb.append("try{").append(methodName).append("("); - boolean first = true; - for(Object param: params) { - if(first) first = false; - else sb.append(", "); - - if(param instanceof String) { - sb.append("'").append(param).append("'"); - } else { - sb.append(param); - } - } - sb.append(")}catch(error){console.error(error.message);}"); - String call = sb.toString(); - Log.v(TAG, "callJavaScript: call=" + call); - - if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) { - webView.evaluateJavascript(call, null); - } else { - webView.loadUrl("javascript:" + call); - } + view.getSettings().setDefaultFontSize(size); } private Drawable getIcon(int id, Resources.Theme theme) { diff --git a/app/src/main/res/menu/option_article.xml b/app/src/main/res/menu/option_article.xml index 58fe92a44..696a6a204 100644 --- a/app/src/main/res/menu/option_article.xml +++ b/app/src/main/res/menu/option_article.xml @@ -28,7 +28,4 @@ - diff --git a/app/src/main/res/raw/webview_htmlbase.html b/app/src/main/res/raw/webview_htmlbase.html index d213a2be4..9de761956 100644 --- a/app/src/main/res/raw/webview_htmlbase.html +++ b/app/src/main/res/raw/webview_htmlbase.html @@ -4,10 +4,9 @@ -
- +