/** * 用本函数代替{@link #setText(CharSequence)} * * @param cs */ public void setMText(CharSequence cs) { text = cs; obList.clear(); // contentList.clear(); ArrayList<IS> isList = new ArrayList<MTextView.IS>(); useDefault = false; if (cs instanceof SpannableString) { SpannableString ss = (SpannableString) cs; ImageSpan[] imageSpans = ss.getSpans(0, ss.length(), ImageSpan.class); for (int i = 0; i < imageSpans.length; i++) { int s = ss.getSpanStart(imageSpans[i]); int e = ss.getSpanEnd(imageSpans[i]); IS iS = new IS(); iS.is = imageSpans[i]; iS.start = s; iS.end = e; isList.add(iS); } } String str = cs.toString(); for (int i = 0, j = 0; i < cs.length(); ) { if (j < isList.size()) { IS is = isList.get(j); if (i < is.start) { Integer cp = str.codePointAt(i); // 支持增补字符 if (Character.isSupplementaryCodePoint(cp)) { i += 2; } else { i++; } obList.add(new String(Character.toChars(cp))); } else if (i >= is.start) { obList.add(is.is); j++; i = is.end; } } else { Integer cp = str.codePointAt(i); if (Character.isSupplementaryCodePoint(cp)) { i += 2; } else { i++; } obList.add(new String(Character.toChars(cp))); } } requestLayout(); }
static { List<String> directives = new ArrayList<String>(); List<String> keywords = new ArrayList<String>(); List<String> pseudoKeywords = new ArrayList<String>(); List<String> operators = new ArrayList<String>(); com.google.dart.compiler.parser.Token[] tokens = com.google.dart.compiler.parser.Token.values(); for (int i = 0; i < tokens.length; i++) { com.google.dart.compiler.parser.Token token = tokens[i]; if ((BREAK.ordinal() <= token.ordinal() && token.ordinal() <= WITH.ordinal()) || token.ordinal() == AS.ordinal() || token.ordinal() == IS.ordinal()) { keywords.add(token.getSyntax()); } if ((LIBRARY.ordinal() <= token.ordinal()) && (token.ordinal() <= NATIVE.ordinal())) { String name = token.getSyntax(); directives.add(name.substring(1)); } if (token.isBinaryOperator() || token.isUnaryOperator()) { operators.add(token.getSyntax()); } } for (String kw : DartParser.PSEUDO_KEYWORDS) { pseudoKeywords.add(kw); } DIRECTIVES = directives.toArray(new String[directives.size()]); KEYWORDS = keywords.toArray(new String[keywords.size()]); PSEUDO_KEYWORDS = pseudoKeywords.toArray(new String[pseudoKeywords.size()]); OPERATORS = operators.toArray(new String[operators.size()]); }