import android.text.ClipboardManager;
import android.text.InputType;
import android.text.Spannable;
+import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.StyleSpan;
private void dictionaryOpenFail(Exception e) {
Log.e(LOG, "Unable to load dictionary.", e);
if (dictRaf != null) {
+ indexAdapter = null;
+ setListAdapter(null);
try {
dictRaf.close();
} catch (IOException e1) {
textToSpeech.shutdown();
textToSpeech = null;
+ indexAdapter = null;
+ setListAdapter(null);
+
try {
Log.d(LOG, "Closing RAF.");
dictRaf.close();
}
}
+ private void addBoldSpans(String token, String col1Text, Spannable col1Spannable) {
+ int startPos = 0;
+ while ((startPos = col1Text.indexOf(token, startPos)) != -1) {
+ col1Spannable.setSpan(new StyleSpan(Typeface.BOLD), startPos, startPos
+ + token.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
+ startPos += token.length();
+ }
+ }
+
private TableLayout getView(final int position, PairEntry.Row row, ViewGroup parent,
TableLayout result) {
final Context context = parent.getContext();
final int rowCount = entry.pairs.size();
if (result == null) {
result = new TableLayout(context);
+ result.setStretchAllColumns(true);
// Because we have a Button inside a ListView row:
// http://groups.google.com/group/android-developers/browse_thread/thread/3d96af1530a7d62a?pli=1
result.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
result.removeViews(rowCount, result.getChildCount() - rowCount);
}
- final TableRow.LayoutParams layoutParams = new TableRow.LayoutParams();
- layoutParams.weight = 0.5f;
- layoutParams.leftMargin = mPaddingLarge;
-
for (int r = result.getChildCount(); r < rowCount; ++r) {
+ final TableRow.LayoutParams layoutParams = new TableRow.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT);
+ layoutParams.leftMargin = mPaddingLarge;
+
final TableRow tableRow = new TableRow(result.getContext());
final TextView col1 = new TextView(tableRow.getContext());
col1.setTextIsSelectable(true);
col2.setTextIsSelectable(true);
}
+ col1.setTextColor(textColorFg);
+ col2.setTextColor(textColorFg);
// Set the columns in the table.
if (r > 0) {
final Pair pair = entry.pairs.get(r);
final String col1Text = index.swapPairEntries ? pair.lang2 : pair.lang1;
final String col2Text = index.swapPairEntries ? pair.lang1 : pair.lang2;
-
- col1.setText(col1Text, TextView.BufferType.SPANNABLE);
- col2.setText(col2Text, TextView.BufferType.SPANNABLE);
+ final Spannable col1Spannable = new SpannableString(col1Text);
+ final Spannable col2Spannable = new SpannableString(col2Text);
// Bold the token instances in col1.
- final Set<String> toBold = toHighlight != null ? this.toHighlight : Collections
- .singleton(row.getTokenRow(true).getToken());
- final Spannable col1Spannable = (Spannable) col1.getText();
- for (final String token : toBold) {
- int startPos = 0;
- while ((startPos = col1Text.indexOf(token, startPos)) != -1) {
- col1Spannable.setSpan(new StyleSpan(Typeface.BOLD), startPos, startPos
- + token.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
- startPos += token.length();
+ if (toHighlight != null) {
+ for (final String token : toHighlight) {
+ addBoldSpans(token, col1Text, col1Spannable);
}
- }
+ } else
+ addBoldSpans(row.getTokenRow(true).getToken(), col1Text, col1Spannable);
createTokenLinkSpans(col1, col1Spannable, col1Text);
- createTokenLinkSpans(col2, (Spannable) col2.getText(), col2Text);
+ createTokenLinkSpans(col2, col2Spannable, col2Text);
+
+ col1.setText(col1Spannable);
+ col2.setText(col2Spannable);
}
result.setOnClickListener(new TextView.OnClickListener() {
: theme.tokenRowOtherBg);
// Make it so we can long-click on these token rows, too:
- textView.setText(text, BufferType.SPANNABLE);
- createTokenLinkSpans(textView, (Spannable) textView.getText(), text);
+ final Spannable textSpannable = new SpannableString(text);
+ createTokenLinkSpans(textView, textSpannable, text);
if (!htmlEntries.isEmpty()) {
final ClickableSpan clickableSpan = new ClickableSpan() {
public void onClick(View widget) {
}
};
- ((Spannable) textView.getText()).setSpan(clickableSpan, 0, text.length(),
+ textSpannable.setSpan(clickableSpan, 0, text.length(),
Spannable.SPAN_INCLUSIVE_INCLUSIVE);
textView.setOnClickListener(new OnClickListener() {
@Override
}
});
}
+ textView.setText(textSpannable);
return textView;
}
textView.setMovementMethod(LinkMovementMethod.getInstance());
final Matcher matcher = CHAR_DASH.matcher(text);
while (matcher.find()) {
- spannable.setSpan(new NonLinkClickableSpan(textColorFg), matcher.start(),
+ spannable.setSpan(new NonLinkClickableSpan(), matcher.start(),
matcher.end(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}