@Test public void applyHtmlStyle() { }
public static String applyHtmlStyle(String html, Context context){ TypedValue typedColor = new TypedValue(); context.getTheme().resolveAttribute(R.attr.attr_color_text, typedColor, true); int txtColor = typedColor.data; context.getTheme().resolveAttribute(R.attr.attr_color_text_link, typedColor, true); int linkColor = typedColor.data; context.getTheme().resolveAttribute(R.attr.attr_color_accent, typedColor, true); int codeColor = typedColor.data; context.getTheme().resolveAttribute(R.attr.attr_color_text_secondary, typedColor, true); int codeBackground = typedColor.data; String textColorStr = "#" + Integer.toHexString(Color.red(txtColor)) + Integer.toHexString(Color.green(txtColor)) + Integer.toHexString(Color.blue(txtColor)); String linkColorStr = "#" + Integer.toHexString(Color.red(linkColor)) + Integer.toHexString(Color.green(linkColor)) + Integer.toHexString(Color.blue(linkColor)); String codeColorStr = "#" + Integer.toHexString(Color.red(codeColor)) + Integer.toHexString(Color.green(codeColor)) + Integer.toHexString(Color.blue(codeColor)); String codeBackgroundStr = "#" + Integer.toHexString(Color.red(codeBackground)) + Integer.toHexString(Color.green(codeBackground)) + Integer.toHexString(Color.blue(codeBackground)); if (html == null || html.equals("")){ return ""; } Document document = Jsoup.parse(html); document.head() .append( "<style type=\"text/css\">" + "body{width:95%;}" + "* {" + " color:" + textColorStr + ";" + "}" + "a {" + " color:" + linkColorStr + ";" + "word-wrap:break-word;" + "}" + "code,pre {" + " color: " + codeColorStr + ";" + " background: " + codeBackgroundStr + ";" + " padding: 3px;" + " border-radius: 5px;" + "word-wrap:normal;" + "} img { border:1px solid grey;}" + "</style>"); document.head() .append("<meta name=\"content-type\" content=\"text/html; charset=utf-8\">" + "<meta http-equlv=\"Content-Type\" content=\"text/html;charset=utf-8\">"); for (Element img:document.select("img")){ img.attr("width","100%"); img.attr("height","auto"); } document.charset(Charset.forName("utf-8")); return document.toString(); }
HtmlUtil { public static String applyHtmlStyle(String html, Context context){ TypedValue typedColor = new TypedValue(); context.getTheme().resolveAttribute(R.attr.attr_color_text, typedColor, true); int txtColor = typedColor.data; context.getTheme().resolveAttribute(R.attr.attr_color_text_link, typedColor, true); int linkColor = typedColor.data; context.getTheme().resolveAttribute(R.attr.attr_color_accent, typedColor, true); int codeColor = typedColor.data; context.getTheme().resolveAttribute(R.attr.attr_color_text_secondary, typedColor, true); int codeBackground = typedColor.data; String textColorStr = "#" + Integer.toHexString(Color.red(txtColor)) + Integer.toHexString(Color.green(txtColor)) + Integer.toHexString(Color.blue(txtColor)); String linkColorStr = "#" + Integer.toHexString(Color.red(linkColor)) + Integer.toHexString(Color.green(linkColor)) + Integer.toHexString(Color.blue(linkColor)); String codeColorStr = "#" + Integer.toHexString(Color.red(codeColor)) + Integer.toHexString(Color.green(codeColor)) + Integer.toHexString(Color.blue(codeColor)); String codeBackgroundStr = "#" + Integer.toHexString(Color.red(codeBackground)) + Integer.toHexString(Color.green(codeBackground)) + Integer.toHexString(Color.blue(codeBackground)); if (html == null || html.equals("")){ return ""; } Document document = Jsoup.parse(html); document.head() .append( "<style type=\"text/css\">" + "body{width:95%;}" + "* {" + " color:" + textColorStr + ";" + "}" + "a {" + " color:" + linkColorStr + ";" + "word-wrap:break-word;" + "}" + "code,pre {" + " color: " + codeColorStr + ";" + " background: " + codeBackgroundStr + ";" + " padding: 3px;" + " border-radius: 5px;" + "word-wrap:normal;" + "} img { border:1px solid grey;}" + "</style>"); document.head() .append("<meta name=\"content-type\" content=\"text/html; charset=utf-8\">" + "<meta http-equlv=\"Content-Type\" content=\"text/html;charset=utf-8\">"); for (Element img:document.select("img")){ img.attr("width","100%"); img.attr("height","auto"); } document.charset(Charset.forName("utf-8")); return document.toString(); } }
HtmlUtil { public static String applyHtmlStyle(String html, Context context){ TypedValue typedColor = new TypedValue(); context.getTheme().resolveAttribute(R.attr.attr_color_text, typedColor, true); int txtColor = typedColor.data; context.getTheme().resolveAttribute(R.attr.attr_color_text_link, typedColor, true); int linkColor = typedColor.data; context.getTheme().resolveAttribute(R.attr.attr_color_accent, typedColor, true); int codeColor = typedColor.data; context.getTheme().resolveAttribute(R.attr.attr_color_text_secondary, typedColor, true); int codeBackground = typedColor.data; String textColorStr = "#" + Integer.toHexString(Color.red(txtColor)) + Integer.toHexString(Color.green(txtColor)) + Integer.toHexString(Color.blue(txtColor)); String linkColorStr = "#" + Integer.toHexString(Color.red(linkColor)) + Integer.toHexString(Color.green(linkColor)) + Integer.toHexString(Color.blue(linkColor)); String codeColorStr = "#" + Integer.toHexString(Color.red(codeColor)) + Integer.toHexString(Color.green(codeColor)) + Integer.toHexString(Color.blue(codeColor)); String codeBackgroundStr = "#" + Integer.toHexString(Color.red(codeBackground)) + Integer.toHexString(Color.green(codeBackground)) + Integer.toHexString(Color.blue(codeBackground)); if (html == null || html.equals("")){ return ""; } Document document = Jsoup.parse(html); document.head() .append( "<style type=\"text/css\">" + "body{width:95%;}" + "* {" + " color:" + textColorStr + ";" + "}" + "a {" + " color:" + linkColorStr + ";" + "word-wrap:break-word;" + "}" + "code,pre {" + " color: " + codeColorStr + ";" + " background: " + codeBackgroundStr + ";" + " padding: 3px;" + " border-radius: 5px;" + "word-wrap:normal;" + "} img { border:1px solid grey;}" + "</style>"); document.head() .append("<meta name=\"content-type\" content=\"text/html; charset=utf-8\">" + "<meta http-equlv=\"Content-Type\" content=\"text/html;charset=utf-8\">"); for (Element img:document.select("img")){ img.attr("width","100%"); img.attr("height","auto"); } document.charset(Charset.forName("utf-8")); return document.toString(); }  }
HtmlUtil { public static String applyHtmlStyle(String html, Context context){ TypedValue typedColor = new TypedValue(); context.getTheme().resolveAttribute(R.attr.attr_color_text, typedColor, true); int txtColor = typedColor.data; context.getTheme().resolveAttribute(R.attr.attr_color_text_link, typedColor, true); int linkColor = typedColor.data; context.getTheme().resolveAttribute(R.attr.attr_color_accent, typedColor, true); int codeColor = typedColor.data; context.getTheme().resolveAttribute(R.attr.attr_color_text_secondary, typedColor, true); int codeBackground = typedColor.data; String textColorStr = "#" + Integer.toHexString(Color.red(txtColor)) + Integer.toHexString(Color.green(txtColor)) + Integer.toHexString(Color.blue(txtColor)); String linkColorStr = "#" + Integer.toHexString(Color.red(linkColor)) + Integer.toHexString(Color.green(linkColor)) + Integer.toHexString(Color.blue(linkColor)); String codeColorStr = "#" + Integer.toHexString(Color.red(codeColor)) + Integer.toHexString(Color.green(codeColor)) + Integer.toHexString(Color.blue(codeColor)); String codeBackgroundStr = "#" + Integer.toHexString(Color.red(codeBackground)) + Integer.toHexString(Color.green(codeBackground)) + Integer.toHexString(Color.blue(codeBackground)); if (html == null || html.equals("")){ return ""; } Document document = Jsoup.parse(html); document.head() .append( "<style type=\"text/css\">" + "body{width:95%;}" + "* {" + " color:" + textColorStr + ";" + "}" + "a {" + " color:" + linkColorStr + ";" + "word-wrap:break-word;" + "}" + "code,pre {" + " color: " + codeColorStr + ";" + " background: " + codeBackgroundStr + ";" + " padding: 3px;" + " border-radius: 5px;" + "word-wrap:normal;" + "} img { border:1px solid grey;}" + "</style>"); document.head() .append("<meta name=\"content-type\" content=\"text/html; charset=utf-8\">" + "<meta http-equlv=\"Content-Type\" content=\"text/html;charset=utf-8\">"); for (Element img:document.select("img")){ img.attr("width","100%"); img.attr("height","auto"); } document.charset(Charset.forName("utf-8")); return document.toString(); }  static String[] getLoginFieldName(String html); static int getOnceFromPostTopicPage(String html); static int getOnceFromSignInPage(String html); static List<Topic> getTopics(String html); static Topic getTopicAndReplies(String html); static List<Reply> getReplies(String html); static void attachCreatedTopics(Member member, String html); static void attachAccountInfo(Account account, String html); static String applyHtmlStyle(String html, Context context); static String matcherGroup1(Pattern pattern, String str); static int matcherGroup1Int(Pattern pattern, String str); }
HtmlUtil { public static String applyHtmlStyle(String html, Context context){ TypedValue typedColor = new TypedValue(); context.getTheme().resolveAttribute(R.attr.attr_color_text, typedColor, true); int txtColor = typedColor.data; context.getTheme().resolveAttribute(R.attr.attr_color_text_link, typedColor, true); int linkColor = typedColor.data; context.getTheme().resolveAttribute(R.attr.attr_color_accent, typedColor, true); int codeColor = typedColor.data; context.getTheme().resolveAttribute(R.attr.attr_color_text_secondary, typedColor, true); int codeBackground = typedColor.data; String textColorStr = "#" + Integer.toHexString(Color.red(txtColor)) + Integer.toHexString(Color.green(txtColor)) + Integer.toHexString(Color.blue(txtColor)); String linkColorStr = "#" + Integer.toHexString(Color.red(linkColor)) + Integer.toHexString(Color.green(linkColor)) + Integer.toHexString(Color.blue(linkColor)); String codeColorStr = "#" + Integer.toHexString(Color.red(codeColor)) + Integer.toHexString(Color.green(codeColor)) + Integer.toHexString(Color.blue(codeColor)); String codeBackgroundStr = "#" + Integer.toHexString(Color.red(codeBackground)) + Integer.toHexString(Color.green(codeBackground)) + Integer.toHexString(Color.blue(codeBackground)); if (html == null || html.equals("")){ return ""; } Document document = Jsoup.parse(html); document.head() .append( "<style type=\"text/css\">" + "body{width:95%;}" + "* {" + " color:" + textColorStr + ";" + "}" + "a {" + " color:" + linkColorStr + ";" + "word-wrap:break-word;" + "}" + "code,pre {" + " color: " + codeColorStr + ";" + " background: " + codeBackgroundStr + ";" + " padding: 3px;" + " border-radius: 5px;" + "word-wrap:normal;" + "} img { border:1px solid grey;}" + "</style>"); document.head() .append("<meta name=\"content-type\" content=\"text/html; charset=utf-8\">" + "<meta http-equlv=\"Content-Type\" content=\"text/html;charset=utf-8\">"); for (Element img:document.select("img")){ img.attr("width","100%"); img.attr("height","auto"); } document.charset(Charset.forName("utf-8")); return document.toString(); }  static String[] getLoginFieldName(String html); static int getOnceFromPostTopicPage(String html); static int getOnceFromSignInPage(String html); static List<Topic> getTopics(String html); static Topic getTopicAndReplies(String html); static List<Reply> getReplies(String html); static void attachCreatedTopics(Member member, String html); static void attachAccountInfo(Account account, String html); static String applyHtmlStyle(String html, Context context); static String matcherGroup1(Pattern pattern, String str); static int matcherGroup1Int(Pattern pattern, String str);  }