--- /dev/null
+package com.folioreader.ui.base;
+
+import android.content.Context;
+
+import com.folioreader.Config;
+import com.folioreader.Constants;
+import com.folioreader.R;
+
+/**
+ * @author gautam chibde on 14/6/17.
+ */
+
+public final class HtmlUtil {
+
+ /**
+ * Function modifies input html string by adding extra css,js and font information.
+ *
+ * @param context Activity Context
+ * @param htmlContent input html raw data
+ * @return modified raw html string
+ */
+ public static String getHtmlContent(Context context, String htmlContent, Config config) {
+ String cssPath =
+ String.format(context.getString(R.string.css_tag), "file:///android_asset/css/Style.css");
+
+
+ String jsPath = String.format(context.getString(R.string.script_tag),
+ "file:///android_asset/js/jsface.min.js");
+ jsPath =
+ jsPath + String.format(context.getString(R.string.script_tag),
+ "file:///android_asset/js/jquery-3.1.1.min.js");
+
+ jsPath =
+ jsPath + String.format(context.getString(R.string.script_tag),
+ "file:///android_asset/js/rangy-core.js");
+ jsPath =
+ jsPath + String.format(context.getString(R.string.script_tag),
+ "file:///android_asset/js/rangy-highlighter.js");
+ jsPath =
+ jsPath + String.format(context.getString(R.string.script_tag),
+ "file:///android_asset/js/rangy-classapplier.js");
+ jsPath =
+ jsPath + String.format(context.getString(R.string.script_tag),
+ "file:///android_asset/js/rangy-serializer.js");
+ jsPath =
+ jsPath + String.format(context.getString(R.string.script_tag),
+ "file:///android_asset/js/rangy-serializer.js");
+ jsPath =
+ jsPath + String.format(context.getString(R.string.script_tag),
+ "file:///android_asset/js/Bridge.js");
+
+ jsPath =
+ jsPath + String.format(context.getString(R.string.script_tag),
+ "file:///android_asset/android.selection.js");
+ jsPath =
+ jsPath + String.format(context.getString(R.string.script_tag_method_call),
+ "setMediaOverlayStyleColors('#C0ED72','#C0ED72')");
+
+ String toInject = "\n" + cssPath + "\n" + jsPath + "\n</head>";
+ htmlContent = htmlContent.replace("</head>", toInject);
+
+ String classes = "";
+ switch (config.getFont()) {
+ case Constants.FONT_EBGARAMOND:
+ classes = "garamond";
+ break;
+ case Constants.FONT_LATO:
+ classes = "lato";
+ break;
+ case Constants.FONT_LORA:
+ classes = "lora";
+ break;
+ case Constants.FONT_RALEWAY:
+ classes = "raleway";
+ break;
+ default:
+ break;
+ }
+
+ if (config.isNightMode()) {
+ classes += " nightMode";
+ }
+
+ switch (config.getFontSize()) {
+ case 0:
+ classes += " textSizeOne";
+ break;
+ case 1:
+ classes += " textSizeTwo";
+ break;
+ case 2:
+ classes += " textSizeThree";
+ break;
+ case 3:
+ classes += " textSizeFour";
+ break;
+ case 4:
+ classes += " textSizeFive";
+ break;
+ default:
+ break;
+ }
+
+ switch (config.getMarginSize()) {
+ case 0:
+ classes += " marginSizeOne";
+ break;
+ case 1:
+ classes += " marginSizeTwo";
+ break;
+ case 2:
+ classes += " marginSizeThree";
+ break;
+ case 3:
+ classes += " marginSizeFour";
+ break;
+ case 4:
+ classes += " marginSizeFive";
+ break;
+ default:
+ break;
+ }
+
+ switch (config.getInterlineSize()) {
+ case 0:
+ classes += " interlineSizeOne";
+ break;
+ case 1:
+ classes += " interlineSizeTwo";
+ break;
+ case 2:
+ classes += " interlineSizeThree";
+ break;
+ case 3:
+ classes += " interlineSizeFour";
+ break;
+ case 4:
+ classes += " interlineSizeFive";
+ break;
+ default:
+ break;
+ }
+
+ htmlContent = htmlContent.replace("<html ", "<html class=\"" + classes + "\" ");
+ return htmlContent;
+ }
+}