List of usage examples for java.lang StringBuffer append
@Override public synchronized StringBuffer append(double d)
From source file:Main.java
public static String getAppFullVersion(Context context) { StringBuffer ret = new StringBuffer(); try {//from w w w .ja va 2 s . c o m ret.append(context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName); ret.append('.'); int version = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode; ret.append(version); } catch (Exception e) { Log.e(TAG, "error getting version number"); } return ret.toString(); }
From source file:Main.java
public static int getColorFromHex(String color) { if (color.contains("0x")) color = color.replace("0x", ""); // if (color.contains("#")) // color = color.replace("#", ""); // return Integer.parseInt(color, 16) + 0xFF000000; if (!color.contains("#")) { StringBuffer colorBuffer = new StringBuffer("#"); colorBuffer.append(color); return Color.parseColor(colorBuffer.toString()); }/*from w w w .j av a 2 s .c o m*/ // return Color.parseColor(color); // StringBuffer colorBuffer = new StringBuffer("0xff"); // colorBuffer.append(color); // int value = Integer.parseInt(colorBuffer.toString(), 16); // int red = ((value >> 24) & 0xFF) / 255; // int green = ((value >> 16) & 0xFF) / 255; // int blue = ((value >> 8) & 0xFF) / 255; // int alpha = ((value >> 0) & 0xFF) / 255; // Color.parseColor(colorString); // return Color.argb(alpha, red, green, blue); }
From source file:Main.java
/** * Create a simple XML tag with attributes. For example * xmlTag("foo", "bar", new String[]{"foo", "bar}) creates * <foo foo="bar">bar</foo> * @param tagName The name of the tag//from w w w. ja v a2s.c om * @param content The content of the tag * @param attributes The attributes of the element * @return The created XML tag */ public static String xmlTag(String tagName, String content, String[] attributes) { StringBuffer sb = new StringBuffer(); sb.append('<').append(tagName); if (null != attributes) { for (int i = 0; i < attributes.length; i += 2) { sb.append(' ').append(attributes[i]).append("=\"").append(attributes[i + 1]).append('"'); } } if (null == content || 0 == content.length()) { sb.append(" />"); } else { sb.append('>'); sb.append(content); sb.append("</").append(tagName).append('>'); } return sb.toString(); }
From source file:co.turnus.ui.util.HtmlUtil.java
public static String appendStyle(String htmlContent, String name) { StringBuffer b = new StringBuffer(); b.append("<style>"); b.append(fileToString(name + ".css")); b.append("</style>"); b.append(htmlContent);//from w ww . j ava 2s . com return b.toString(); }
From source file:Utils.java
public static final String format(long l) { String s = String.valueOf(l); int digits = 0; while (s.length() > 3) { s = s.substring(0, s.length() - 3); digits++;//w w w. java 2 s . c om } StringBuffer buffer = new StringBuffer(); buffer.append(s); if ((s.length() == 1) && (String.valueOf(l).length() >= 3)) { buffer.append("."); buffer.append(String.valueOf(l).substring(1, 3)); } else if ((s.length() == 2) && (String.valueOf(l).length() >= 3)) { buffer.append("."); buffer.append(String.valueOf(l).substring(2, 3)); } if (digits == 0) { buffer.append(" B"); } else if (digits == 1) { buffer.append(" KB"); } else if (digits == 2) { buffer.append(" MB"); } else if (digits == 3) { buffer.append(" GB"); } else if (digits == 4) { buffer.append(" TB"); } return buffer.toString(); }
From source file:Main.java
private static void indent(StringBuffer buffer, int indent) { for (int loop = 0; loop < indent; loop++) { buffer.append(" "); }//from ww w . ja v a2s .co m }
From source file:Main.java
private static String toHexString(byte[] bytes) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < bytes.length; i++) { sb.append(Integer.toHexString(bytes[i] >> 4 & 0x0f)).append(Integer.toHexString(bytes[i] & 0x0f)); }/* w w w. ja va 2s. c o m*/ return sb.toString(); }
From source file:Main.java
public static final void println(String... argvs) { StringBuffer mStringBuffer = new StringBuffer(); for (String argv : argvs) { mStringBuffer.append(argv); mStringBuffer.append(" "); }//from w w w .j a v a2 s . c o m System.out.println(mStringBuffer.toString()); }
From source file:Main.java
public static String arrayToString(Object[] array) { StringBuffer str = new StringBuffer(); if (array.length > 1) str.append("{"); for (int i = 0; i < array.length; i++) { if (i != 0) str.append(","); Object o = array[i];/*w w w . j a va2 s . c o m*/ str.append(safeToString(o)); } if (array.length > 1) str.append("}"); return str.toString(); }
From source file:Main.java
/** * Returns a string with all fonts used by Swing's UIManager. *///from w w w. j av a 2 s . c o m public static String getUIFonts() { final StringBuffer fonts = new StringBuffer(128); fonts.append("Default font: "); fonts.append(getUIFont().toString()); final Enumeration<Object> keys = UIManager.getLookAndFeelDefaults().keys(); String lf = System.getProperty("line.separator"); while (keys.hasMoreElements()) { final Object key = keys.nextElement(); final Object value = UIManager.get(key); if (value instanceof Font) { final Font ifont = (Font) value; fonts.append(lf + key.toString() + " " + ifont.getName() + " " + ifont.getStyle() + " " + ifont.getSize()); } } return fonts.toString(); }