Back to project page leedReader.
The source code is released under:
CC by-nc-sa 4.0
If you think the Android project leedReader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.barbogogo.leedreader; //from w w w . jav a 2 s .c om import java.io.IOException; import java.lang.StringBuilder; import java.net.MalformedURLException; import java.net.URL; import java.util.Formatter; import java.util.regex.Matcher; import java.util.regex.Pattern; import com.leed.reader.R; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.NetworkOnMainThreadException; public class Utils { public static String hex(byte[] src) { Formatter fmt = new Formatter(new StringBuilder(src.length * 2)); for (byte b : src) { fmt.format("%02x", b); } String hex = fmt.toString(); fmt.close(); return hex; } public static String htmlspecialchars(String src) { src = src.replace("&", "&"); src = src.replace("\"", """); src = src.replace("'", "'"); src = src.replace("<", "<"); src = src.replace(">", ">"); return src; } public static int versionCompare(String actualVersion, String serverVersion) { int versionCompare = 0; actualVersion = actualVersion.replace("Beta", "").trim(); serverVersion = serverVersion.replace("Beta", "").trim(); String[] vals1 = serverVersion.split("\\."); String[] vals2 = actualVersion.split("\\."); int i = 0; while (i < vals1.length && i < vals2.length && vals1[i].equals(vals2[i])) { i++; } if (i < vals1.length && i < vals2.length) { int diff = Integer.valueOf(vals1[i]).compareTo(Integer.valueOf(vals2[i])); versionCompare = diff < 0 ? -1 : diff == 0 ? 0 : 1; } else versionCompare = vals1.length < vals2.length ? -1 : vals1.length == vals2.length ? 0 : 1; return versionCompare; } public static String extractArticle(String article, int length) { String output = ""; String pattern = "<([^><]*)>"; Matcher matches2 = Pattern.compile(pattern).matcher(article); while (matches2.find()) { output = matches2.replaceAll(""); } String[] test = output.split(" "); output = ""; for (int i = 0; i < length; i++) { if (test.length > i) { output += test[i] + " "; } } output = output.replaceAll("Á", "??"); output = output.replaceAll("á", ""); output = output.replaceAll("À", ""); output = output.replaceAll("à", ""); output = output.replaceAll("Â", ""); output = output.replaceAll("â", ""); output = output.replaceAll("Ä", ""); output = output.replaceAll("ä", ""); output = output.replaceAll("Ã", ""); output = output.replaceAll("ã", ""); output = output.replaceAll("Å", ""); output = output.replaceAll("å", ""); output = output.replaceAll("&Aelig;", ""); output = output.replaceAll("æ", ""); output = output.replaceAll("Ç", ""); output = output.replaceAll("ç", ""); output = output.replaceAll("&Eth;", "??"); output = output.replaceAll("ð", ""); output = output.replaceAll("É", ""); output = output.replaceAll("é", ""); output = output.replaceAll("È", ""); output = output.replaceAll("è", ""); output = output.replaceAll("Ê", ""); output = output.replaceAll("ê", ""); output = output.replaceAll("Ë", ""); output = output.replaceAll("ë", ""); output = output.replaceAll("Í", "??"); output = output.replaceAll("í", ""); output = output.replaceAll("Ì", ""); output = output.replaceAll("ì", ""); output = output.replaceAll("Î", ""); output = output.replaceAll("î", ""); output = output.replaceAll("Ï", "??"); output = output.replaceAll("ï", ""); output = output.replaceAll("Ñ", ""); output = output.replaceAll("ñ", ""); output = output.replaceAll("Ó", ""); output = output.replaceAll("ó", ""); output = output.replaceAll("Ò", ""); output = output.replaceAll("ò", ""); output = output.replaceAll("Ô", ""); output = output.replaceAll("ô", ""); output = output.replaceAll("Ö", ""); output = output.replaceAll("ö", ""); output = output.replaceAll("Õ", ""); output = output.replaceAll("õ", ""); output = output.replaceAll("Ø", ""); output = output.replaceAll("ø", ""); output = output.replaceAll("œ", ""); output = output.replaceAll("Œ", ""); output = output.replaceAll("ß", ""); output = output.replaceAll("&Thorn;", ""); output = output.replaceAll("þ", ""); output = output.replaceAll("Ú", ""); output = output.replaceAll("ú", ""); output = output.replaceAll("Ù", ""); output = output.replaceAll("ù", ""); output = output.replaceAll("Û", ""); output = output.replaceAll("û", ""); output = output.replaceAll("Ü", ""); output = output.replaceAll("ü", ""); output = output.replaceAll("Ý", "??"); output = output.replaceAll("ý", ""); output = output.replaceAll("ÿ", ""); output = output.replaceAll("©", ""); output = output.replaceAll("®", ""); output = output.replaceAll("™", ""); output = output.replaceAll("&", "&"); output = output.replaceAll("<", "<"); output = output.replaceAll(">", ">"); output = output.replaceAll("€", ""); output = output.replaceAll("¢", ""); output = output.replaceAll("£", ""); output = output.replaceAll(""", "\""); output = output.replaceAll("‘", ""); output = output.replaceAll("’", ""); output = output.replaceAll("“", ""); output = output.replaceAll("”", "??"); output = output.replaceAll("«", ""); output = output.replaceAll("»", ""); output = output.replaceAll("—", ""); output = output.replaceAll("–", ""); output = output.replaceAll("°", ""); output = output.replaceAll("±", ""); output = output.replaceAll("¼", ""); output = output.replaceAll("½", ""); output = output.replaceAll("¾", ""); output = output.replaceAll("×", ""); output = output.replaceAll("÷", ""); output = output.replaceAll("α", "?"); output = output.replaceAll("β", ""); output = output.replaceAll("∞", "?"); output = output.replaceAll(" ", " "); output = output + "..."; return output; } public static String extractImage(Context context, String article) { String output = ""; String pattern = "<img ([^><]*) src=\"([^=\"><]*)\" ([^><]*)>"; Matcher matches2 = Pattern.compile(pattern).matcher(article); if (matches2.find()) { output = matches2.group(2); } if (output.isEmpty()) { output = null; } // Bitmap outputBmp = getBitmapFromURL(context, output); return output; } public static Bitmap getBitmapFromURL(Context context, String src) { Bitmap myBitmap = null; URL url; try { url = new URL(src); myBitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream()); } catch (MalformedURLException e) { myBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.logo); } catch (IOException e) { myBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.logo); } catch (NetworkOnMainThreadException e) { myBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.logo); } return myBitmap; } }